# HG changeset patch # User Matti Hamalainen # Date 1530911145 -10800 # Node ID 6913c5dbbb58c287360f1fc0ca0763533f8af497 # Parent 63a0069ab217b1f10b0d8c2515bea6a912d8a322 Add separate escape characters option (-e ), but make -l option to set escape chars if it has not been explicitly set via -e. diff -r 63a0069ab217 -r 6913c5dbbb58 sidinfo.c --- a/sidinfo.c Fri Jul 06 21:11:26 2018 +0300 +++ b/sidinfo.c Sat Jul 07 00:05:45 2018 +0300 @@ -99,9 +99,9 @@ optParsable = FALSE, optNoNamePrefix = FALSE, optHexadecimal = FALSE, - optOneLine = FALSE, optFieldOutput = TRUE; -char *optFieldSep = NULL; +char *optOneLineFieldSep = NULL, + *optEscapeChars = NULL; int optNFiles = 0; PSFStack optFormat; @@ -124,6 +124,7 @@ { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE }, { 6, 'l', "line", "Output in one line format, -l ", OPT_ARGREQ }, + {11, 'e', "escape", "Escape these characters in fields (see note)", OPT_ARGREQ }, { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ }, @@ -204,6 +205,9 @@ "\n" "When specifying HVSC path, it is preferable to use -H/--hvsc option,\n" "as STIL.txt and Songlengths.txt will be automatically used from there.\n" + "\n" + "NOTE: One line output (-l ) also sets escape characters\n" + "(option -e ), if escape characters have NOT been separately set.\n" , th_prog_name); } @@ -701,8 +705,7 @@ break; case 6: - optOneLine = TRUE; - optFieldSep = optArg; + optOneLineFieldSep = optArg; break; case 7: @@ -719,6 +722,10 @@ setSLDBPath = th_strdup(optArg); break; + case 11: + optEscapeChars = optArg; + break; + default: THERR("Unknown option '%s'.\n", currArg); return FALSE; @@ -797,7 +804,7 @@ static void siPrintFieldSeparator(FILE *outFile) { if (optFieldOutput) - fputs(optOneLine ? optFieldSep : "\n", outFile); + fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile); } @@ -832,14 +839,14 @@ if (setUseChConv && d_str != NULL && useConv) { char *tmp2 = siConvertCharset(setChConv, d_str); - tmp = siEscapeString(tmp2, optFieldSep); + tmp = siEscapeString(tmp2, optEscapeChars); th_free(tmp2); } else - tmp = siEscapeString(d_str, optFieldSep); + tmp = siEscapeString(d_str, optEscapeChars); #else (void) useConv; - tmp = siEscapeString(d_str, optFieldSep); + tmp = siEscapeString(d_str, optEscapeChars); #endif if ((str = siItemFormatStrPrint(fmt, opt, tmp, d_int)) != NULL) @@ -1004,7 +1011,7 @@ if (optFieldOutput) { - if (shown && optOneLine) + if (shown && optOneLineFieldSep != NULL) fprintf(outFile, "\n"); } @@ -1047,11 +1054,15 @@ argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) return -1; - if (optOneLine) + if (optOneLineFieldSep != NULL) { // For one-line format, disable parsing and prefixes optParsable = FALSE; optNoNamePrefix = TRUE; + + // If no escape chars have been set, use the field separator(s) + if (optEscapeChars == NULL) + optEscapeChars = optOneLineFieldSep; } if (optFieldOutput && optFormat.nitems == 0)