Mercurial > hg > sidinfo
changeset 62:0d01efc3c803
Factor escape printing to a separate function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Dec 2015 00:03:08 +0200 |
parents | 6916aaeda941 |
children | 6bbe11ae6bf5 |
files | sidinfo.c |
diffstat | 1 files changed, 25 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/sidinfo.c Sat Dec 26 23:22:43 2015 +0200 +++ b/sidinfo.c Sun Dec 27 00:03:08 2015 +0200 @@ -605,6 +605,29 @@ } +static void siPrintStrEscapes(FILE *outFile, const char *str) +{ + while (*str) + { + if (*str == '\\') + { + str++; + switch (*str) + { + case 'n': fputc('\n', outFile); break; + case 'r': fputc('\r', outFile); break; + case 't': fputc('\r', outFile); break; + case '\\': fputc('\\', outFile); break; + } + } + else + fputc(*str, outFile); + + str++; + } +} + + static void siPrintFieldPrefix(FILE *outFile, const char *name) { if (!optNoNamePrefix && !optFormat.nitems) @@ -720,27 +743,7 @@ switch (item->cmd) { case -1: - { - char *str = item->str; - while (*str) - { - if (*str == '\\') - { - str++; - switch (*str) - { - case 'n': fputc('\n', outFile); break; - case 'r': fputc('\r', outFile); break; - case 't': fputc('\r', outFile); break; - case '\\': fputc('\\', outFile); break; - } - } - else - fputc(*str, outFile); - - str++; - } - } + siPrintStrEscapes(outFile, item->str); break; case -2: @@ -749,6 +752,7 @@ default: siPrintPSIDInformationField(outFile, filename, &psid, &shown, item->cmd); + break; } } }