Escape macro bodies when displaying in help.

This commit is contained in:
Felicity Tarnell 2014-03-08 12:31:58 +00:00
parent 34712e643c
commit 0bf6dd5766
3 changed files with 50 additions and 5 deletions

View file

@ -527,10 +527,12 @@ binding_t *bi;
else
swprintf(t, wsizeof(t), L"%lc", bi->bi_code);
if (bi->bi_macro)
if (bi->bi_macro) {
wchar_t *esc = escstr(bi->bi_macro);
swprintf(s, wsizeof(s), L"%-10ls execute macro: %ls",
t, bi->bi_macro);
else
t, esc);
free(esc);
} else
swprintf(s, wsizeof(s), L"%-10ls %ls (%ls)",
t, bi->bi_func->fn_desc, bi->bi_func->fn_name);

44
str.c
View file

@ -135,7 +135,7 @@ wchar_t **p;
time_t
parsetime(tm)
wchar_t *tm;
const wchar_t *tm;
{
int h = 0, m = 0, s = 0;
time_t i = 0, r = 0;
@ -211,3 +211,45 @@ wchar_t t[16];
return wcsdup(res);
}
wchar_t *
escstr(s)
const wchar_t *s;
{
wchar_t *ret, *p;
if ((ret = calloc(sizeof(wchar_t), wcslen(s) * 2 + 1)) == NULL)
return NULL;
for (p = ret; *s; s++) {
switch (*s) {
case '\\':
*p++ = L'\\';
*p++ = L'\\';
continue;
case '\n':
*p++ = L'\\';
*p++ = L'n';
continue;
case '\t':
*p++ = L'\\';
*p++ = L't';
continue;
case '\v':
*p++ = L'\\';
*p++ = L'v';
continue;
case '\r':
*p++ = L'\\';
*p++ = L'r';
continue;
case '"':
*p++ = L'\\';
*p++ = L'"';
continue;
}
*p++ = *s;
}
return ret;
}

3
str.h
View file

@ -17,7 +17,8 @@
size_t tokenise (const wchar_t *, wchar_t ***result);
void tokfree (wchar_t ***);
time_t parsetime (wchar_t *);
time_t parsetime (const wchar_t *);
wchar_t *maketime (time_t);
wchar_t *escstr (const wchar_t *);
#endif /* !TTS_STR_H */