comparison sidinfo.c @ 33:39d9df17c8b1

Add field separator argument to -l option.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 26 Sep 2014 00:16:42 +0300
parents 93a432519b84
children 50fe65830c03
comparison
equal deleted inserted replaced
32:93a432519b84 33:39d9df17c8b1
75 // Option variables 75 // Option variables
76 BOOL optParsable = FALSE, 76 BOOL optParsable = FALSE,
77 optNoNamePrefix = FALSE, 77 optNoNamePrefix = FALSE,
78 optHexadecimal = FALSE, 78 optHexadecimal = FALSE,
79 optOneLine = FALSE; 79 optOneLine = FALSE;
80 char * optFieldSep = NULL;
80 uint32_t optFields = PSF_ALL; 81 uint32_t optFields = PSF_ALL;
81 int optNFiles = 0; 82 int optNFiles = 0;
82 83
83 84
84 // Define option arguments 85 // Define option arguments
86 { 87 {
87 { 0, '?', "help", "Show this help", OPT_NONE }, 88 { 0, '?', "help", "Show this help", OPT_NONE },
88 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, 89 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
89 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, 90 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE },
90 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE }, 91 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE },
91 { 6, 'l', "oneline", "Output in one line format", OPT_NONE }, 92 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ },
92 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, 93 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
93 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, 94 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE },
94 }; 95 };
95 96
96 static const int optListN = (sizeof(optList) / sizeof(optList[0])); 97 static const int optListN = (sizeof(optList) / sizeof(optList[0]));
217 optNoNamePrefix = TRUE; 218 optNoNamePrefix = TRUE;
218 break; 219 break;
219 220
220 case 6: 221 case 6:
221 optOneLine = TRUE; 222 optOneLine = TRUE;
223 optFieldSep = optArg;
222 break; 224 break;
223 225
224 default: 226 default:
225 THERR("Unknown option '%s'.\n", currArg); 227 THERR("Unknown option '%s'.\n", currArg);
226 return FALSE; 228 return FALSE;
414 if (!optNoNamePrefix) 416 if (!optNoNamePrefix)
415 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name); 417 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
416 } 418 }
417 419
418 420
421 static void siPrintFieldSeparator(FILE *outFile)
422 {
423 fprintf(outFile, optOneLine ? optFieldSep : "\n");
424 }
425
426
419 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...) 427 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...)
420 { 428 {
421 const PSFOption *opt = &optPSFlags[xindex]; 429 const PSFOption *opt = &optPSFlags[xindex];
422 if (optFields & opt->flag) 430 if (optFields & opt->flag)
423 { 431 {
433 else 441 else
434 vfprintf(outFile, fmt, ap); 442 vfprintf(outFile, fmt, ap);
435 443
436 va_end(ap); 444 va_end(ap);
437 445
438 fprintf(outFile, optOneLine ? "|" : "\n"); 446 siPrintFieldSeparator(outFile);
439 *shown = TRUE; 447 *shown = TRUE;
440 } 448 }
441 } 449 }
442 450
443 #define PR(xindex, xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, &shown, xindex, xfmt, xaltfmt, __VA_ARGS__ ) 451 #define PR(xindex, xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, &shown, xindex, xfmt, xaltfmt, __VA_ARGS__ )
465 473
466 if (optFields & PSF_HASH) 474 if (optFields & PSF_HASH)
467 { 475 {
468 siPrintFieldPrefix(outFile, "Hash"); 476 siPrintFieldPrefix(outFile, "Hash");
469 th_md5_print(outFile, psid->hash); 477 th_md5_print(outFile, psid->hash);
470 fprintf(outFile, optOneLine ? "|" : "\n"); 478 siPrintFieldSeparator(outFile);
471 } 479 }
472 480
473 if (shown) 481 if (shown)
474 fprintf(outFile, "\n"); 482 fprintf(outFile, "\n");
475 } 483 }