Mercurial > hg > sidinfo
comparison sidinfo.c @ 180:6913c5dbbb58
Add separate escape characters option (-e <chars>), but make -l <separator>
option to set escape chars if it has not been explicitly set via -e.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Jul 2018 00:05:45 +0300 |
parents | 6a73d17f0c34 |
children | 5bc837384177 |
comparison
equal
deleted
inserted
replaced
179:63a0069ab217 | 180:6913c5dbbb58 |
---|---|
97 *setSLDBPath = NULL; | 97 *setSLDBPath = NULL; |
98 BOOL setSLDBNewFormat = FALSE, | 98 BOOL setSLDBNewFormat = FALSE, |
99 optParsable = FALSE, | 99 optParsable = FALSE, |
100 optNoNamePrefix = FALSE, | 100 optNoNamePrefix = FALSE, |
101 optHexadecimal = FALSE, | 101 optHexadecimal = FALSE, |
102 optOneLine = FALSE, | |
103 optFieldOutput = TRUE; | 102 optFieldOutput = TRUE; |
104 char *optFieldSep = NULL; | 103 char *optOneLineFieldSep = NULL, |
104 *optEscapeChars = NULL; | |
105 int optNFiles = 0; | 105 int optNFiles = 0; |
106 | 106 |
107 PSFStack optFormat; | 107 PSFStack optFormat; |
108 | 108 |
109 SIDLibSLDB *sidSLDB = NULL; | 109 SIDLibSLDB *sidSLDB = NULL; |
122 {10, 0, "license", "Print out this program's license agreement", OPT_NONE }, | 122 {10, 0, "license", "Print out this program's license agreement", OPT_NONE }, |
123 | 123 |
124 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, | 124 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE }, |
125 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE }, | 125 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE }, |
126 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ }, | 126 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ }, |
127 {11, 'e', "escape", "Escape these characters in fields (see note)", OPT_ARGREQ }, | |
127 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, | 128 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ }, |
128 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, | 129 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE }, |
129 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ }, | 130 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ }, |
130 { 8, 'H', "hvsc", "Specify path to HVSC documents directory", OPT_ARGREQ }, | 131 { 8, 'H', "hvsc", "Specify path to HVSC documents directory", OPT_ARGREQ }, |
131 { 9, 'S', "sldb", "Specify Songlengths.txt file (use -H if possible)", OPT_ARGREQ }, | 132 { 9, 'S', "sldb", "Specify Songlengths.txt file (use -H if possible)", OPT_ARGREQ }, |
202 "The -F fields can be further formatted via printf-style specifiers:\n" | 203 "The -F fields can be further formatted via printf-style specifiers:\n" |
203 "-F \"@copyright:'%%-30s'@\"\n" | 204 "-F \"@copyright:'%%-30s'@\"\n" |
204 "\n" | 205 "\n" |
205 "When specifying HVSC path, it is preferable to use -H/--hvsc option,\n" | 206 "When specifying HVSC path, it is preferable to use -H/--hvsc option,\n" |
206 "as STIL.txt and Songlengths.txt will be automatically used from there.\n" | 207 "as STIL.txt and Songlengths.txt will be automatically used from there.\n" |
208 "\n" | |
209 "NOTE: One line output (-l <field separator>) also sets escape characters\n" | |
210 "(option -e <chars>), if escape characters have NOT been separately set.\n" | |
207 , th_prog_name); | 211 , th_prog_name); |
208 } | 212 } |
209 | 213 |
210 | 214 |
211 int argMatchPSField(const char *field) | 215 int argMatchPSField(const char *field) |
699 case 5: | 703 case 5: |
700 optNoNamePrefix = TRUE; | 704 optNoNamePrefix = TRUE; |
701 break; | 705 break; |
702 | 706 |
703 case 6: | 707 case 6: |
704 optOneLine = TRUE; | 708 optOneLineFieldSep = optArg; |
705 optFieldSep = optArg; | |
706 break; | 709 break; |
707 | 710 |
708 case 7: | 711 case 7: |
709 optFieldOutput = FALSE; | 712 optFieldOutput = FALSE; |
710 if (!argParsePSFormatStr(&optFormat, optArg)) | 713 if (!argParsePSFormatStr(&optFormat, optArg)) |
717 | 720 |
718 case 9: | 721 case 9: |
719 setSLDBPath = th_strdup(optArg); | 722 setSLDBPath = th_strdup(optArg); |
720 break; | 723 break; |
721 | 724 |
725 case 11: | |
726 optEscapeChars = optArg; | |
727 break; | |
728 | |
722 default: | 729 default: |
723 THERR("Unknown option '%s'.\n", currArg); | 730 THERR("Unknown option '%s'.\n", currArg); |
724 return FALSE; | 731 return FALSE; |
725 } | 732 } |
726 | 733 |
795 | 802 |
796 | 803 |
797 static void siPrintFieldSeparator(FILE *outFile) | 804 static void siPrintFieldSeparator(FILE *outFile) |
798 { | 805 { |
799 if (optFieldOutput) | 806 if (optFieldOutput) |
800 fputs(optOneLine ? optFieldSep : "\n", outFile); | 807 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile); |
801 } | 808 } |
802 | 809 |
803 | 810 |
804 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFStackItem *item, const char *d_str, const int d_int, const BOOL useConv) | 811 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFStackItem *item, const char *d_str, const int d_int, const BOOL useConv) |
805 { | 812 { |
830 | 837 |
831 #ifdef HAVE_ICONV | 838 #ifdef HAVE_ICONV |
832 if (setUseChConv && d_str != NULL && useConv) | 839 if (setUseChConv && d_str != NULL && useConv) |
833 { | 840 { |
834 char *tmp2 = siConvertCharset(setChConv, d_str); | 841 char *tmp2 = siConvertCharset(setChConv, d_str); |
835 tmp = siEscapeString(tmp2, optFieldSep); | 842 tmp = siEscapeString(tmp2, optEscapeChars); |
836 th_free(tmp2); | 843 th_free(tmp2); |
837 } | 844 } |
838 else | 845 else |
839 tmp = siEscapeString(d_str, optFieldSep); | 846 tmp = siEscapeString(d_str, optEscapeChars); |
840 #else | 847 #else |
841 (void) useConv; | 848 (void) useConv; |
842 tmp = siEscapeString(d_str, optFieldSep); | 849 tmp = siEscapeString(d_str, optEscapeChars); |
843 #endif | 850 #endif |
844 | 851 |
845 if ((str = siItemFormatStrPrint(fmt, opt, tmp, d_int)) != NULL) | 852 if ((str = siItemFormatStrPrint(fmt, opt, tmp, d_int)) != NULL) |
846 fputs(str, outFile); | 853 fputs(str, outFile); |
847 | 854 |
1002 } | 1009 } |
1003 } | 1010 } |
1004 | 1011 |
1005 if (optFieldOutput) | 1012 if (optFieldOutput) |
1006 { | 1013 { |
1007 if (shown && optOneLine) | 1014 if (shown && optOneLineFieldSep != NULL) |
1008 fprintf(outFile, "\n"); | 1015 fprintf(outFile, "\n"); |
1009 } | 1016 } |
1010 | 1017 |
1011 // Shutdown | 1018 // Shutdown |
1012 error: | 1019 error: |
1045 // Parse command line arguments | 1052 // Parse command line arguments |
1046 if (!th_args_process(argc, argv, optList, optListN, | 1053 if (!th_args_process(argc, argv, optList, optListN, |
1047 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) | 1054 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS)) |
1048 return -1; | 1055 return -1; |
1049 | 1056 |
1050 if (optOneLine) | 1057 if (optOneLineFieldSep != NULL) |
1051 { | 1058 { |
1052 // For one-line format, disable parsing and prefixes | 1059 // For one-line format, disable parsing and prefixes |
1053 optParsable = FALSE; | 1060 optParsable = FALSE; |
1054 optNoNamePrefix = TRUE; | 1061 optNoNamePrefix = TRUE; |
1062 | |
1063 // If no escape chars have been set, use the field separator(s) | |
1064 if (optEscapeChars == NULL) | |
1065 optEscapeChars = optOneLineFieldSep; | |
1055 } | 1066 } |
1056 | 1067 |
1057 if (optFieldOutput && optFormat.nitems == 0) | 1068 if (optFieldOutput && optFormat.nitems == 0) |
1058 { | 1069 { |
1059 // For standard field output, push standard items to format stack | 1070 // For standard field output, push standard items to format stack |