diff --git a/functions.c b/functions.c index 2ee9194..eafa4ba 100644 --- a/functions.c +++ b/functions.c @@ -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); diff --git a/str.c b/str.c index 98c29ff..397105c 100644 --- a/str.c +++ b/str.c @@ -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; +} diff --git a/str.h b/str.h index 857d03f..47d65c2 100644 --- a/str.h +++ b/str.h @@ -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 */