diff options
author | Gustav HÃ¥llberg <gustav@gmail.com> | 2008-12-29 18:51:01 (GMT) |
---|---|---|
committer | Gustav HÃ¥llberg <gustav@gmail.com> | 2009-01-16 23:37:02 (GMT) |
commit | 0e21ca9d04d9edd02fde19562d5b98fb38074092 (patch) | |
tree | db5ca9a264b9c5e639465218e9c05ad2d3080775 /edit.c | |
parent | 8b5e00d0d36aa59d86cf6d6e8e710817a7ee772a (diff) | |
download | powwow-0e21ca9d04d9edd02fde19562d5b98fb38074092.zip powwow-0e21ca9d04d9edd02fde19562d5b98fb38074092.tar.gz powwow-0e21ca9d04d9edd02fde19562d5b98fb38074092.tar.bz2 |
fixed problem when a tcp packet ends with an unterminated escape code
Diffstat (limited to 'edit.c')
-rw-r--r-- | edit.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -107,6 +107,21 @@ int lookup_edit_function __P1 (function_str,funct) return 0; } +/* return pointer to any unterminated escape code at the end of s */ +static char *find_partial_esc __P1 (char *,s) +{ + size_t len = strlen(s); + char *end = s + len; + while (end > s) { + char c = *--end; + if (c == '\033') + return end; + if (isalpha(c)) + return NULL; + } + return NULL; +} + /* * redisplay the prompt * assume cursor is at beginning of line @@ -114,12 +129,23 @@ int lookup_edit_function __P1 (function_str,funct) void draw_prompt __P0 (void) { if (promptlen && prompt_status == 1) { + char *esc, *pstr; int e = error; error = 0; marked_prompt = ptraddmarks(marked_prompt, prompt->str); if (MEM_ERROR) { promptzero(); errmsg("malloc(prompt)"); return; } - tty_puts(ptrdata(marked_prompt)); - col0 = printstrlen(promptstr); /* same as printstrlen(marked_prompt) */ + + /* if prompt ends in unterminated escape code, do not print + * that part */ + pstr = ptrdata(marked_prompt); + esc = find_partial_esc(pstr); + if (esc) + *esc = 0; + tty_puts(pstr); + col0 = printstrlen(pstr); + if (esc) + *esc = '\033'; + error = e; } prompt_status = 0; |