annotate sidinfo.c @ 191:d26bc1adfd14

Add internal directory reading and filename matching, plus optional subdirectory recursion via '-R' option.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jul 2018 16:46:08 +0300
parents 77eb019b7386
children c0849f47e10f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1 /*
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
2 * SIDInfo - PSID/RSID information displayer
171
d86ade7d0dfd Change copyright blurbs slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
3 * Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
169
da2fbfe18c60 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
4 * (C) Copyright 2014-2018 Tecnic Software productions (TNSP)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
5 */
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "th_args.h"
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
7 #include "th_string.h"
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
8 #include "th_file.h"
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
9 #include "th_datastruct.h"
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
10 #include "sidlib.h"
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
11 #include <sys/types.h>
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
12 #include <dirent.h>
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
13 #ifdef HAVE_ICONV
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
14 # include <iconv.h>
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
15 #endif
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
16
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
18 // Some constants
144
6418286a7e4c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
19 #define SET_DEF_CHARSET "utf-8"
163
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
20 #define SET_SLDB_FILENAME "Songlengths.md5"
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
21
121
a2c2c63311de Change in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
22
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
23 enum
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
24 {
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
25 OFMT_QUOTED = 0x0001,
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
26 OFMT_FORMAT = 0x0002,
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
27 };
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
28
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
29
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
30 enum
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
31 {
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
32 OTYPE_OTHER = 0,
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
33 OTYPE_STR = 1,
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
34 OTYPE_INT = 2,
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
35 };
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
36
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
63
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
40 int cmd;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
41 char *str;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
42 char chr;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
43 int flags;
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
44 char *fmt;
63
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
45 } PSFStackItem;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
46
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
47
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
48 typedef struct
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
49 {
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
50 int nitems, nallocated;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
51 PSFStackItem *items;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
52 } PSFStack;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
53
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
54
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
55 typedef struct
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
56 {
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
57 char *name;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
58 char *lname;
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
59 int type;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
60 } PSFOption;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
61
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
62
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
63 static const PSFOption optPSOptions[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
64 {
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
65 { "Filename" , NULL , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
66 { "Type" , NULL , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
67 { "Version" , NULL , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
68 { "PlayerType" , "Player type" , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
69 { "PlayerCompat" , "Player compatibility" , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
70 { "VideoClock" , "Video clock speed" , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
71 { "SIDModel" , "SID model" , OTYPE_STR },
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
72
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
73 { "DataOffs" , "Data offset" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
74 { "DataSize" , "Data size" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
75 { "LoadAddr" , "Load address" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
76 { "InitAddr" , "Init address" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
77 { "PlayAddr" , "Play address" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
78 { "Songs" , "Songs" , OTYPE_INT },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
79 { "StartSong" , "Start song" , OTYPE_INT },
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
80
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
81 { "SID2Model" , "2nd SID model" , OTYPE_INT },
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
82 { "SID3Model" , "3rd SID model" , OTYPE_INT },
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
83 { "SID2Addr" , "2nd SID address" , OTYPE_INT },
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
84 { "SID3Addr" , "3rd SID address" , OTYPE_INT },
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
85
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
86 { "Name" , NULL , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
87 { "Author" , NULL , OTYPE_STR },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
88 { "Copyright" , NULL , OTYPE_STR },
150
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
89 { "Hash" , NULL , OTYPE_STR },
112
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
90
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
91 { "Songlengths" , "Song lengths" , OTYPE_OTHER },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
92 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
93
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
94 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
95
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
96
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
97 // Option variables
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
98 char *setHVSCPath = NULL,
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
99 *setSLDBPath = NULL;
163
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
100 BOOL setSLDBNewFormat = FALSE,
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
101 optParsable = FALSE,
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
102 optNoNamePrefix = FALSE,
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
103 optHexadecimal = FALSE,
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
104 optFieldOutput = TRUE,
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
105 optRecurseDirs = FALSE;
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
106 char *optOneLineFieldSep = NULL,
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
107 *optEscapeChars = NULL;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
108 int optNFiles = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
110 PSFStack optFormat;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
111
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
112 SIDLibSLDB *sidSLDB = NULL;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
113
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
114 #ifdef HAVE_ICONV
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
115 BOOL setUseChConv;
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
116 iconv_t setChConv;
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
117 #endif
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
118
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
120 // Define option arguments
121
a2c2c63311de Change in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
121 static const th_optarg optList[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
123 { 0, '?', "help", "Show this help", OPT_NONE },
24
16d6b5029543 Disable verbose option for now, it does not do anything at the moment.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
124 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
173
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
125 {10, 0, "license", "Print out this program's license agreement", OPT_NONE },
177
6a73d17f0c34 Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
126
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 { 2, 'p', "parsable", "Output in script-parsable format", OPT_NONE },
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
128 { 5, 'n', "noprefix", "Output without field name prefix", OPT_NONE },
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
129 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ },
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
130 {11, 'e', "escape", "Escape these characters in fields (see note)", OPT_ARGREQ },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
131 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 { 4, 'x', "hex", "Use hexadecimal values", OPT_NONE },
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
133 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ },
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
134 { 8, 'H', "hvsc", "Specify path to HVSC documents directory", OPT_ARGREQ },
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
135 { 9, 'S', "sldb", "Specify Songlengths.txt file (use -H if possible)", OPT_ARGREQ },
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
136 {12, 'R', "recurse", "Recurse into sub-directories", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
137 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
138
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
139 static const int optListN = sizeof(optList) / sizeof(optList[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
140
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
141
173
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
142 void argShowLicense(void)
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
143 {
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
144 printf("%s - %s\n%s\n", th_prog_name, th_prog_desc, th_prog_author);
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
145 printf(
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
146 "\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
147 "Redistribution and use in source and binary forms, with or without\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
148 "modification, are permitted provided that the following conditions\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
149 "are met:\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
150 "\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
151 " 1. Redistributions of source code must retain the above copyright\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
152 " notice, this list of conditions and the following disclaimer.\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
153 "\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
154 " 2. Redistributions in binary form must reproduce the above copyright\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
155 " notice, this list of conditions and the following disclaimer in\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
156 " the documentation and/or other materials provided with the\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
157 " distribution.\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
158 "\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
159 " 3. The name of the author may not be used to endorse or promote\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
160 " products derived from this software without specific prior written\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
161 " permission.\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
162 "\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
163 "THIS SOFTWARE IS PROVIDED BY THE AUTHOR \"AS IS\" AND ANY EXPRESS OR\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
164 "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
165 "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
166 "ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
167 "INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
168 "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
169 "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
170 "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
171 "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
172 "IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
173 "POSSIBILITY OF SUCH DAMAGE.\n"
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
174 );
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
175 }
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
176
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
177
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
178 void argShowHelp(void)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
179 {
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
180 int index, len;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
181
20
6058339ffe0e Update usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
182 th_print_banner(stdout, th_prog_name, "[options] <sid filename> [sid filename #2 ..]");
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
183 th_args_help(stdout, optList, optListN, 0);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
184 printf(
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
185 "\n"
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
186 "Available fields:\n");
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
187
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
188 for (len = index = 0; index < noptPSOptions; index++)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
189 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
190 const PSFOption *opt = &optPSOptions[index];
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
191 len += strlen(opt->name) + 3;
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
192 if (len >= 72)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
193 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
194 printf("\n");
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
195 len = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
196 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
197 printf("%s%s", opt->name, (index < noptPSOptions - 1) ? ", " : "\n\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
198 }
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
199
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
200 printf(
61
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
201 "Example: %s -x -p -f hash,copyright somesidfile.sid\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
202 "\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
203 "Format strings for '-F' option are composed of @fields@ that\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
204 "are expanded to their value. Also, escape sequences \\r, \\n and \\t\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
205 "can be used: -F \"hash=@hash@\\ncopy=@copyright@\\n\"\n"
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
206 "\n"
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
207 "The -F fields can be further formatted via printf-style specifiers:\n"
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
208 "-F \"@copyright:'%%-30s'@\"\n"
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
209 "\n"
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
210 "When specifying HVSC path, it is preferable to use -H/--hvsc option,\n"
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
211 "as STIL.txt and Songlengths.txt will be automatically used from there.\n"
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
212 "\n"
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
213 "NOTE: One line output (-l <field separator>) also sets escape characters\n"
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
214 "(option -e <chars>), if escape characters have NOT been separately set.\n"
61
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
215 , th_prog_name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
216 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
217
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
218
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
219 int argMatchPSField(const char *field)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
220 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
221 int index, found = -1;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
222 for (index = 0; index < noptPSOptions; index++)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
223 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
224 const PSFOption *opt = &optPSOptions[index];
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
225 if (th_strcasecmp(opt->name, field) == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
226 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
227 if (found >= 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
228 return -2;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
229 found = index;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
230 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
231 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
232
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
233 return found;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
234 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
235
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
236
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
237 int argMatchPSFieldError(const char *field)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
238 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
239 int found = argMatchPSField(field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
240 switch (found)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
241 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
242 case -1:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
243 THERR("No such field '%s'.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
244 break;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
245
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
246 case -2:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
247 THERR("Field '%s' is ambiguous.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
248 break;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
249 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
250 return found;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
251 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
252
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
253
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
254 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
255 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
256 if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
257 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
258 stack->nallocated += 16;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
259 if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
260 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
261 THERR("Could not allocate memory for format item stack.\n");
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
262 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
263 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
264 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
265
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
266 memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
267 stack->nitems++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
268 return TRUE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
269 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
270
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
271
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
272 void siClearStack(PSFStack *stack)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
273 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
274 if (stack != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
275 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
276 if (stack->nitems > 0 && stack->items != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
277 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
278 int n;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
279 for (n = 0; n < stack->nitems; n++)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
280 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
281 if (stack->items[n].cmd == -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
282 th_free(stack->items[n].str);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
283 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
284 th_free(stack->items);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
285 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
286 memset(stack, 0, sizeof(PSFStack));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
287 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
288 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
289
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
290
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
291 BOOL argParsePSFields(PSFStack *stack, const char *fmt)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
292 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
293 const char *start = fmt;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
294 siClearStack(stack);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
295
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
296 while (*start)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
297 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
298 PSFStackItem item;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
299 const char *end = strchr(start, ',');
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
300 char *field = (end != NULL) ?
116
d062312ea850 Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
301 th_strndup_trim(start, end - start, TH_TRIM_BOTH) :
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
302 th_strdup_trim(start, TH_TRIM_BOTH);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
303
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
304 if (field != NULL)
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
305 {
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
306 int found = argMatchPSFieldError(field);
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
307 th_free(field);
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
308
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
309 if (found < 0)
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
310 return FALSE;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
311
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
312 item.cmd = found;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
313 item.str = NULL;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
314 if (!siStackAddItem(stack, &item))
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
315 return FALSE;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
316 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
317
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
318 if (!end)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
319 break;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
320
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
321 start = end + 1;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
322 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
323
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
324 return TRUE;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
325 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
326
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
327
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
328 #ifdef HAVE_ICONV
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
329 char *siConvertCharset(iconv_t ctx, const char *src)
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
330 {
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
331 size_t srcLeft = strlen(src) + 1;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
332 size_t outLeft = srcLeft * 2;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
333 char *outBuf, *outPtr;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
334 char *srcPtr = (char *) src;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
335
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
336 if ((outBuf = outPtr = th_malloc(outLeft + 1)) == NULL)
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
337 return NULL;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
338
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
339 while (srcLeft > 0)
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
340 {
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
341 size_t ret = iconv(ctx, &srcPtr, &srcLeft, &outPtr, &outLeft);
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
342 if (ret == (size_t) -1)
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
343 break;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
344 }
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
345
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
346 return outBuf;
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
347 }
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
348 #endif
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
349
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
350
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
351 int siItemFormatStrPutInt(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
352 const int value, const int f_radix, int f_flags, int f_width, int f_prec,
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
353 const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags))
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
354 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
355 char buf[64];
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
356 int f_len = 0, vret;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
357 BOOL f_neg = FALSE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
358
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
359 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, value,
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
360 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
361
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
362 if (vret == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
363 return 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
364
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
365 return th_vprintf_put_int_format(ctx, vputch, buf, f_flags, f_width, f_prec, f_len, vret, f_neg, f_unsig, f_alt);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
366 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
367
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
368
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
369 int siItemFormatStrPrintDo(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt,
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
370 const PSFOption *opt, const char *d_str, const int d_int)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
371 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
372 int ret = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
373
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
374 while (*fmt)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
375 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
376 if (*fmt != '%')
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
377 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
378 if ((ret = vputch(ctx, *fmt)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
379 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
380 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
381 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
382 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
383 int f_width = -1, f_prec = -1, f_flags = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
384 BOOL end = FALSE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
385
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
386 fmt++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
387
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
388 // Check for flags
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
389 while (!end)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
390 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
391 switch (*fmt)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
392 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
393 case '#':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
394 f_flags |= TH_PF_ALT;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
395 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
396
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
397 case '+':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
398 f_flags |= TH_PF_SIGN;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
399 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
400
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
401 case '0':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
402 f_flags |= TH_PF_ZERO;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
403 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
404
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
405 case '-':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
406 f_flags |= TH_PF_LEFT;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
407 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
408
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
409 case ' ':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
410 f_flags |= TH_PF_SPACE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
411 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
412
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
413 case '\'':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
414 f_flags |= TH_PF_GROUP;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
415 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
416
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
417 default:
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
418 end = TRUE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
419 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
420 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
421 if (!end) fmt++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
422 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
423
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
424 // Get field width
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
425 if (*fmt == '*')
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
426 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
427 return -101;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
428 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
429 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
430 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
431 f_width = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
432 while (th_isdigit(*fmt))
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
433 f_width = f_width * 10 + (*fmt++ - '0');
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
434 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
435
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
436 // Check for field precision
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
437 if (*fmt == '.')
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
438 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
439 fmt++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
440 if (*fmt == '*')
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
441 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
442 return -102;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
443 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
444 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
445 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
446 // If no digit after '.', precision is to be 0
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
447 f_prec = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
448 while (th_isdigit(*fmt))
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
449 f_prec = f_prec * 10 + (*fmt++ - '0');
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
450 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
451 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
452
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
453
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
454 // Check for length modifiers (only some are supported currently)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
455 switch (*fmt)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
456 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
457 case 0:
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
458 return -104;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
459
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
460 case 'o':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
461 if (opt->type != OTYPE_INT) return -120;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
462 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
463 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
464 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
465
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
466 case 'u':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
467 case 'i':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
468 case 'd':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
469 if (opt->type != OTYPE_INT) return -120;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
470 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 10, f_flags, f_width, f_prec, *fmt == 'u', NULL)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
471 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
472 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
473
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
474 case 'x':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
475 case 'X':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
476 if (opt->type != OTYPE_INT) return -120;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
477 if (*fmt == 'X')
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
478 f_flags |= TH_PF_UPCASE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
479 if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
480 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
481 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
482
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
483 case 's':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
484 if (opt->type != OTYPE_STR) return -121;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
485 if ((ret = th_vprintf_put_str(ctx, vputch, d_str, f_flags, f_width, f_prec)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
486 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
487 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
488
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
489 //case '%':
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
490 default:
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
491 if ((ret = vputch(ctx, *fmt)) == EOF)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
492 goto out;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
493 break;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
494 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
495 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
496 fmt++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
497 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
498
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
499 out:
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
500 return ret == EOF ? ret : ctx->ipos;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
501 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
502
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
503
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
504 static int siItemFormatStrPutCH(th_vprintf_ctx *ctx, const char ch)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
505 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
506 if (ctx->pos + 1 >= ctx->size)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
507 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
508 ctx->size += 64;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
509 if ((ctx->buf = th_realloc(ctx->buf, ctx->size)) == NULL)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
510 return EOF;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
511 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
512
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
513 ctx->buf[ctx->pos] = ch;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
514
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
515 ctx->pos++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
516 ctx->ipos++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
517 return ch;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
518 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
519
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
520
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
521 char * siItemFormatStrPrint(const char *fmt, const PSFOption *opt, const char *d_str, const int d_int)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
522 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
523 th_vprintf_ctx ctx;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
524
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
525 ctx.size = 128;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
526 ctx.buf = th_malloc(ctx.size);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
527 ctx.pos = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
528 ctx.ipos = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
529
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
530 if (ctx.buf == NULL)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
531 return NULL;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
532
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
533 if (siItemFormatStrPrintDo(&ctx, siItemFormatStrPutCH, fmt, opt, d_str, d_int) <= 0)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
534 goto err;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
535
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
536 if (siItemFormatStrPutCH(&ctx, 0) < 0)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
537 goto err;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
538
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
539 return ctx.buf;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
540
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
541 err:
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
542 th_free(ctx.buf);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
543 return NULL;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
544 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
545
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
546
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
547 static int siItemFormatStrPutCHNone(th_vprintf_ctx *ctx, const char ch)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
548 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
549 ctx->pos++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
550 ctx->ipos++;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
551 return ch;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
552 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
553
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
554
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
555 BOOL siItemFormatStrCheck(const char *fmt, const PSFOption *opt)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
556 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
557 th_vprintf_ctx ctx;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
558
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
559 memset(&ctx, 0, sizeof(ctx));
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
560
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
561 return siItemFormatStrPrintDo(&ctx, siItemFormatStrPutCHNone, fmt, opt, NULL, 0) >= 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
562 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
563
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
564
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
565 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
566 // Parse a format string into a PSFStack structure
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
567 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
568 BOOL argParsePSFormatStr(PSFStack *stack, const char *fmt)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
569 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
570 PSFStackItem item;
83
c54d74312080 Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
571 const char *start = NULL;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
572 int mode = 0;
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
573 BOOL rval = TRUE;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
574
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
575 siClearStack(stack);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
576
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
577 while (mode != -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
578 switch (mode)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
579 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
580 case 0:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
581 if (*fmt == '@')
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
582 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
583 start = fmt + 1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
584 mode = 1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
585 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
586 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
587 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
588 start = fmt;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
589 mode = 2;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
590 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
591 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
592 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
593
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
594 case 1:
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
595 if (*fmt != '@')
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
596 {
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
597 if (*fmt == 0)
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
598 mode = -1;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
599 fmt++;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
600 break;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
601 }
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
602
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
603 if (fmt - start == 0)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
604 {
177
6a73d17f0c34 Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 176
diff changeset
605 // "@@" sequence, just print out @
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
606 item.cmd = -2;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
607 item.str = NULL;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
608 item.chr = '@';
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
609 if (!siStackAddItem(stack, &item))
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
610 return FALSE;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
611 }
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
612 else
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
613 {
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
614 char *fopt = NULL, *pfield, *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
615 if ((pfield = strchr(field, ':')) != NULL)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
616 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
617 *pfield = 0;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
618 fopt = th_strdup_trim(pfield + 1, TH_TRIM_BOTH);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
619 }
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
620
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
621 int ret = argMatchPSFieldError(field);
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
622 if (ret >= 0)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
623 {
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
624 item.cmd = ret;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
625 item.flags = 0;
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
626 item.fmt = NULL;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
627 item.str = NULL;
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
628
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
629 if (fopt != NULL)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
630 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
631 if (siItemFormatStrCheck(fopt, &optPSOptions[item.cmd]))
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
632 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
633 item.flags |= OFMT_FORMAT;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
634 item.fmt = th_strdup(fopt);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
635 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
636 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
637 {
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
638 THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field);
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
639 rval = FALSE;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
640 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
641 }
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
642
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
643 if (!siStackAddItem(stack, &item))
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
644 rval = FALSE;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
645 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
646 else
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
647 rval = FALSE;
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
648
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
649 th_free(fopt);
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
650 th_free(field);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
651 }
143
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
652
e481947fd051 Improve format string parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
653 mode = 0;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
654 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
655 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
656
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
657 case 2:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
658 if (*fmt == 0 || *fmt == '@')
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
659 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
660 item.cmd = -1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
661 item.str = th_strndup(start, fmt - start);
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
662 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
663 return FALSE;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
664
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
665 mode = (*fmt == 0) ? -1 : 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
666 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
667 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
668 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
669 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
670 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
671
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
672 return rval;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
673 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
674
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
675
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
676 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
677 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
678 switch (optN)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
679 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
680 case 0:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
681 argShowHelp();
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
682 exit(0);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
683 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
684
173
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
685 case 10:
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
686 argShowLicense();
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
687 exit(0);
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
688 break;
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
689
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
690 case 1:
172
6dcf4ca1dce7 Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
691 th_verbosity++;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
692 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
693
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
694 case 2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
695 optParsable = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
696 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
697
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
698 case 3:
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
699 if (!argParsePSFields(&optFormat, optArg))
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
700 return FALSE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
701 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
702
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
703 case 4:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
704 optHexadecimal = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
705 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
706
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
707 case 5:
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
708 optNoNamePrefix = TRUE;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
709 break;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
710
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
711 case 6:
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
712 optOneLineFieldSep = optArg;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
713 break;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
714
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
715 case 7:
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
716 optFieldOutput = FALSE;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
717 if (!argParsePSFormatStr(&optFormat, optArg))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
718 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
719 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
720
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
721 case 8:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
722 setHVSCPath = th_strdup(optArg);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
723 break;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
724
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
725 case 9:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
726 setSLDBPath = th_strdup(optArg);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
727 break;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
728
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
729 case 11:
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
730 optEscapeChars = optArg;
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
731 break;
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
732
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
733 case 12:
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
734 optRecurseDirs = TRUE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
735 break;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
736
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
737 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
738 THERR("Unknown option '%s'.\n", currArg);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
739 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
740 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
741
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
742 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
743 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
744
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
745
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
746 static char * siEscapeString(const char *str, const char *esc)
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
747 {
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
748 if (str == NULL)
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
749 return NULL;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
750
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
751 if (esc == NULL)
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
752 return th_strdup(str);
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
753
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
754 size_t len = 0, size = strlen(str) + 1;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
755 char *buf = th_malloc(size);
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
756 if (buf == NULL)
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
757 return NULL;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
758
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
759 while (*str)
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
760 {
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
761 if (strchr(esc, *str) != NULL || *str == '\\')
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
762 {
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
763 if (!th_strbuf_putch(&buf, &size, &len, '\\'))
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
764 goto err;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
765 }
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
766 if (!th_strbuf_putch(&buf, &size, &len, *str))
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
767 goto err;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
768
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
769 str++;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
770 }
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
771
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
772 if (!th_strbuf_putch(&buf, &size, &len, 0))
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
773 goto err;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
774
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
775 return buf;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
776
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
777 err:
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
778 th_free(buf);
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
779 return NULL;
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
780 }
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
781
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
782
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
783 static void siPrintStrEscapes(FILE *outFile, const char *str)
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
784 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
785 while (*str)
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
786 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
787 if (*str == '\\')
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
788 switch (*(++str))
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
789 {
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
790 case 'n': fputc('\n', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
791 case 'r': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
792 case 't': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
793 case '\\': fputc('\\', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
794 default: fputc(*str, outFile); break;
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
795 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
796 else
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
797 fputc(*str, outFile);
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
798
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
799 str++;
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
800 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
801 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
802
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
803
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
804 static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
805 {
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
806 const char *name = (optParsable || opt->lname == NULL) ? opt->name : opt->lname;
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
807 if (!optNoNamePrefix && optFieldOutput)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
808 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
809 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
810
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
811
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
812 static void siPrintFieldSeparator(FILE *outFile)
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
813 {
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
814 if (optFieldOutput)
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
815 fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outFile);
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
816 }
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
817
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
818
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
819 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFStackItem *item, const char *d_str, const int d_int, const BOOL useConv)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
820 {
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
821 const PSFOption *opt = &optPSOptions[item->cmd];
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
822 char *fmt, *str, *tmp;
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
823
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
824 switch (opt->type)
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
825 {
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
826 case OTYPE_INT:
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
827 if (item->flags & OFMT_FORMAT)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
828 fmt = item->fmt;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
829 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
830 fmt = optHexadecimal ? "$%04x" : "%d";
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
831 break;
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
832
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
833 case OTYPE_STR:
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
834 if (item->flags & OFMT_FORMAT)
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
835 fmt = item->fmt;
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
836 else
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
837 fmt = "%s";
155
de75385f75e2 Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
838 break;
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
839
155
de75385f75e2 Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
840 default:
de75385f75e2 Simplify by removing few lines of duplicate code.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
841 return;
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
842 }
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
843
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
844 siPrintFieldPrefix(outFile, opt);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
845
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
846 #ifdef HAVE_ICONV
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
847 if (setUseChConv && d_str != NULL && useConv)
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
848 {
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
849 char *tmp2 = siConvertCharset(setChConv, d_str);
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
850 tmp = siEscapeString(tmp2, optEscapeChars);
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
851 th_free(tmp2);
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
852 }
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
853 else
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
854 tmp = siEscapeString(d_str, optEscapeChars);
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
855 #else
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
856 (void) useConv;
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
857 tmp = siEscapeString(d_str, optEscapeChars);
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
858 #endif
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
859
176
2e890e3d5684 Add functionality for escaping the separator characters (-l <str> option) in printed out string data.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
860 if ((str = siItemFormatStrPrint(fmt, opt, tmp, d_int)) != NULL)
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
861 fputs(str, outFile);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
862
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
863 siPrintFieldSeparator(outFile);
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
864 th_free(str);
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
865 th_free(tmp);
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
866
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
867 *shown = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
868 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
869
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
870
157
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
871 #define PRS(d_str, d_conv) siPrintPSIDInfoLine(outFile, shown, item, d_str, -1, d_conv)
8fc887cb56d0 Implement iconv support for converting from PSID de-facto latin-1/ISO-8859-*
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
872 #define PRI(d_int) siPrintPSIDInfoLine(outFile, shown, item, NULL, d_int, FALSE)
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
873
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
874
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
875 static void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const PSFStackItem *item)
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
876 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
877 const PSFOption *opt = &optPSOptions[item->cmd];
150
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
878 char tmp[128];
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
879
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
880 switch (item->cmd)
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
881 {
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
882 case 0: PRS(filename, FALSE); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
883 case 1: PRS(psid->magic, FALSE); break;
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
884 case 2:
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
885 snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8));
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
886 PRS(tmp, FALSE);
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
887 break;
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
888 case 3:
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
889 PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", FALSE);
146
263cd25749a1 Simplify data printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
890 break;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
891 case 4:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
892 if (psid->version >= 2)
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
893 PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", FALSE);
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
894 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
895 case 5:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
896 if (psid->version >= 2)
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
897 PRS(si_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), FALSE);
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
898 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
899 case 6:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
900 if (psid->version >= 2)
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
901 PRS(si_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), FALSE);
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
902 break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
903
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
904 case 7: PRI(psid->dataOffset); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
905 case 8: PRI(psid->dataSize); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
906 case 9: PRI(psid->loadAddress); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
907 case 10: PRI(psid->initAddress); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
908 case 11: PRI(psid->playAddress); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
909 case 12: PRI(psid->nSongs); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
910 case 13: PRI(psid->startSong); break;
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
911
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
912 case 14:
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
913 if (psid->version >= 3)
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
914 {
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
915 int flags = (psid->flags >> 6) & PSF_MODEL_MASK;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
916 if (flags == PSF_MODEL_UNKNOWN)
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
917 flags = (psid->flags >> 4) & PSF_MODEL_MASK;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
918
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
919 PRS(si_get_sid_model_str(flags), FALSE);
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
920 }
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
921 break;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
922 case 15:
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
923 if (psid->version >= 4)
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
924 {
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
925 int flags = (psid->flags >> 8) & PSF_MODEL_MASK;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
926 if (flags == PSF_MODEL_UNKNOWN)
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
927 flags = (psid->flags >> 4) & PSF_MODEL_MASK;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
928
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
929 PRS(si_get_sid_model_str(flags), FALSE);
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
930 }
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
931 break;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
932 case 16:
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
933 if (psid->version >= 3)
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
934 PRI(0xD000 | (psid->sid2Addr << 4));
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
935 break;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
936 case 17:
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
937 if (psid->version >= 4)
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
938 PRI(0xD000 | (psid->sid3Addr << 4));
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
939 break;
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
940
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
941 case 18: PRS(psid->sidName, TRUE); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
942 case 19: PRS(psid->sidAuthor, TRUE); break;
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
943 case 20: PRS(psid->sidCopyright, TRUE); break;
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
944
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
945 case 21:
140
9f96b37c4f75 Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
946 {
150
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
947 size_t i, k;
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
948 for (i = k = 0; i < TH_MD5HASH_LENGTH && k < sizeof(tmp) - 1; i++, k += 2)
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
949 sprintf(&tmp[k], "%02x", psid->hash[i]);
0288c4d138f7 Make the hash field also formattable.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
950
156
717d143612e2 Simplify things by having separate PRS/PRI macros for printing string and
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
951 PRS(tmp, FALSE);
140
9f96b37c4f75 Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
952 }
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
953 break;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
954
134
b9a3f93f69d1 Implement support for showing second and third SID chip addresses and models for PSID/RSID v3/v4 files.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
955 case 22:
142
da29f147afcb Better check for number of songlengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 141
diff changeset
956 if (psid->lengths != NULL && psid->lengths->nlengths > 0)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
957 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
958 int i;
140
9f96b37c4f75 Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
959 siPrintFieldPrefix(outFile, opt);
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
960 for (i = 0; i < psid->lengths->nlengths; i++)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
961 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
962 int len = psid->lengths->lengths[i];
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
963 fprintf(outFile, "%d:%d%s", len / 60, len % 60,
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
964 (i < psid->lengths->nlengths - 1) ? " " : "");
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
965 }
140
9f96b37c4f75 Don't print songlengths field if there are none.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
966 siPrintFieldSeparator(outFile);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
967 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
968 break;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
969 }
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
970 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
971
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
972
187
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
973 void siError(th_ioctx *fh, const int err, const char *msg)
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
974 {
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
975 (void) fh;
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
976 (void) err;
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
977 fprintf(stderr, "%s", msg);
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
978 }
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
979
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
980
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
981 BOOL siHandleSIDFile(const char *filename)
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
982 {
126
c1462b7880e8 Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
983 PSIDHeader *psid = NULL;
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
984 th_ioctx *inFile = NULL;
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
985 FILE *outFile;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
986 BOOL shown = FALSE;
186
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
987 int res;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
988
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
989 outFile = stdout;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
990
186
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
991 if ((res = th_io_fopen(&inFile, &th_stdio_io_ops, filename, "rb")) != THERR_OK)
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
992 {
186
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
993 THERR("Could not open file '%s': %s\n",
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
994 filename, th_error_str(res));
126
c1462b7880e8 Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
995 goto error;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
996 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
997
187
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
998 th_io_set_handlers(inFile, siError, NULL);
cf081a98dccd Improve error output.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
999
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1000 // Read PSID data
163
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
1001 if (!si_read_sid_file(inFile, &psid, setSLDBNewFormat))
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1002 goto error;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1003
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1004 // Get songlength information, if any
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1005 if (sidSLDB != NULL)
126
c1462b7880e8 Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1006 psid->lengths = si_sldb_get_by_hash(sidSLDB, psid->hash);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1007
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1008 // Output
147
f636c55c7cc4 Implement C printf-style format specifiers for -F option @fields@.
Matti Hamalainen <ccr@tnsp.org>
parents: 146
diff changeset
1009 for (int index = 0; index < optFormat.nitems; index++)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1010 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1011 PSFStackItem *item = &optFormat.items[index];
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1012 switch (item->cmd)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1013 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1014 case -1:
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1015 siPrintStrEscapes(outFile, item->str);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1016 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1017
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1018 case -2:
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1019 fputc(item->chr, outFile);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1020 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1021
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1022 default:
126
c1462b7880e8 Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1023 siPrintPSIDInformationField(outFile, filename, psid, &shown, item);
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1024 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1025 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1026 }
153
e3be2ae6120e Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
1027
188
489eb428cf65 Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
1028 if (optFieldOutput && shown)
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
1029 {
188
489eb428cf65 Add separator empty line between "files" when in normal output mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
1030 fprintf(outFile, "\n");
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
1031 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1032
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1033 // Shutdown
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1034 error:
126
c1462b7880e8 Make si_read_sid_file() to allocate the PSIDHeader struct itself, adjust
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1035 si_free_sid_file(psid);
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
1036 th_io_free(inFile);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1037
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1038 return TRUE;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1039 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1040
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1041
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1042 BOOL argHandleFileDir(const char *path, const char *filename, const char *pattern)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1043 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1044 th_stat_data sdata;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1045 char *npath;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1046 BOOL ret = TRUE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1047
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1048 if (filename != NULL)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1049 npath = th_strdup_printf("%s%c%s", path, TH_DIR_SEPARATOR, filename);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1050 else
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1051 npath = th_strdup(path);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1052
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1053 if (!th_stat_path(npath, &sdata))
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1054 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1055 THERR("File or path '%s' does not exist.\n", npath);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1056 ret = FALSE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1057 goto out;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1058 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1059
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1060 optNFiles++;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1061
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1062 if (sdata.flags & TH_IS_DIR)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1063 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1064 DIR *dirh;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1065 struct dirent *entry;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1066
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1067 // Check if recursion is disabled
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1068 if (!optRecurseDirs && optNFiles > 1)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1069 goto out;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1070
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1071 if ((dirh = opendir(npath)) == NULL)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1072 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1073 int err = th_get_error();
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1074 THERR("Could not open directory '%s': %s\n",
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1075 path, th_error_str(err));
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1076 ret = FALSE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1077 goto out;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1078 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1079
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1080 while ((entry = readdir(dirh)) != NULL)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1081 if (entry->d_name[0] != '.')
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1082 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1083 if (!argHandleFileDir(npath, entry->d_name, pattern))
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1084 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1085 ret = FALSE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1086 goto out;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1087 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1088 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1089
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1090 closedir(dirh);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1091 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1092 else
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1093 if (pattern == NULL || th_strmatch(filename, pattern))
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1094 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1095 siHandleSIDFile(npath);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1096 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1097
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1098 out:
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1099 th_free(npath);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1100 return ret;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1101 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1102
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1103
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1104 BOOL argHandleFile(char *path)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1105 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1106 char *pattern = NULL, *filename = NULL, *pt, *npath = th_strdup(path);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1107 BOOL ret;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1108
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1109 if (npath == NULL)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1110 return FALSE;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1111
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1112 // Check if we have path separators
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1113 if ((pt = strrchr(npath, '/')) != NULL ||
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1114 (pt = strrchr(npath, '\\')) != NULL)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1115 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1116 *pt++ = 0;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1117 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1118 else
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1119 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1120 th_free(npath);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1121 npath = th_strdup(".");
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1122 pt = strcmp(path, npath) != 0 ? path : NULL;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1123 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1124
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1125 // Check if we have glob pattern chars
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1126 if (pt != NULL && *pt != 0)
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1127 {
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1128 if (strchr(pt, '*') || strchr(pt, '?'))
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1129 pattern = th_strdup(pt);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1130 else
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1131 filename = th_strdup(pt);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1132 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1133
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1134 ret = argHandleFileDir(npath, filename, pattern);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1135
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1136 th_free(pattern);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1137 th_free(npath);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1138 th_free(filename);
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1139 return ret;
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1140 }
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1141
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1142
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1143 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1144 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1145 // Initialize
181
5bc837384177 Bump version again.
Matti Hamalainen <ccr@tnsp.org>
parents: 180
diff changeset
1146 th_init("SIDInfo", "PSID/RSID information displayer", "0.7.5",
173
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
1147 "By Matti 'ccr' Hamalainen (C) Copyright 2014-2018 TNSP",
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
1148 "This program is distributed under a 3-clause BSD -style license.");
23dcc2dc47a9 Add the license into the program itself, displayable via --license option.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
1149
172
6dcf4ca1dce7 Change to match th-libs' verbosity level changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
1150 th_verbosity = 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1151
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1152 memset(&optFormat, 0, sizeof(optFormat));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
1153
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1154 // Initialize iconv, check if we have language/charset
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1155 #ifdef HAVE_ICONV
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1156 char *setLang = th_strdup(getenv("LANG"));
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1157 if (setLang != NULL)
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1158 {
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1159 char *ptr = strchr(setLang, '.');
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1160 if (ptr != NULL) strcpy(setLang, ptr + 1);
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1161 }
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1162
129
abed2715ea68 Fix iconv initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
1163 setChConv = iconv_open(setLang != NULL ? setLang : SET_DEF_CHARSET, "iso88591");
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1164 setUseChConv = setChConv != (iconv_t) -1;
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1165 th_free(setLang);
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1166 #endif
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1167
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1168 // Parse command line arguments
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1169 if (!th_args_process(argc, argv, optList, optListN,
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1170 argHandleOpt, NULL, OPTH_ONLY_OPTS))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1171 return -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1172
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
1173 if (optOneLineFieldSep != NULL)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
1174 {
161
58fe784a6e48 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 158
diff changeset
1175 // For one-line format, disable parsing and prefixes
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
1176 optParsable = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
1177 optNoNamePrefix = TRUE;
180
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
1178
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
1179 // If no escape chars have been set, use the field separator(s)
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
1180 if (optEscapeChars == NULL)
6913c5dbbb58 Add separate escape characters option (-e <chars>), but make -l <separator>
Matti Hamalainen <ccr@tnsp.org>
parents: 177
diff changeset
1181 optEscapeChars = optOneLineFieldSep;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
1182 }
153
e3be2ae6120e Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
1183
161
58fe784a6e48 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 158
diff changeset
1184 if (optFieldOutput && optFormat.nitems == 0)
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1185 {
161
58fe784a6e48 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 158
diff changeset
1186 // For standard field output, push standard items to format stack
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
1187 PSFStackItem item;
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1188
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
1189 memset(&item, 0, sizeof(item));
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1190 siClearStack(&optFormat);
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1191
161
58fe784a6e48 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 158
diff changeset
1192 for (int i = 0; i < noptPSOptions; i++)
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1193 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1194 item.cmd = i;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1195 siStackAddItem(&optFormat, &item);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1196 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
1197 }
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
1198
90
2ab9ab4b59eb Some fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1199 // Check paths
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1200 if (setHVSCPath != NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1201 {
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1202 if (setSLDBPath == NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1203 setSLDBPath = th_strdup_printf("%s%c%s", setHVSCPath, TH_DIR_SEPARATOR, SET_SLDB_FILENAME);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1204 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1205
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1206 if (setSLDBPath != NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1207 {
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1208 // Initialize SLDB
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1209 int ret = THERR_OK;
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1210 th_ioctx *inFile = NULL;
186
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
1211 if ((ret = th_io_fopen(&inFile, &th_stdio_io_ops, setSLDBPath, "r")) != THERR_OK)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1212 {
186
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
1213 THERR("Could not open SLDB '%s': %s\n",
2f129ea15405 Adjust to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
1214 setSLDBPath, th_error_str(ret));
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1215 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1216 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1217
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
1218 THMSG(1, "Reading SLDB.\n");
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1219 if ((sidSLDB = si_sldb_new()) == NULL)
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1220 {
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1221 THERR("Could not allocate SLDB structure!\n");
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1222 goto err;
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1223 }
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1224
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1225 if ((ret = si_sldb_read(inFile, sidSLDB)) != THERR_OK)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1226 {
106
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
1227 THERR("Error parsing SLDB: %d, %s\n",
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
1228 ret, th_error_str(ret));
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1229 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1230 }
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1231 th_io_close(inFile);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1232
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1233 if ((ret = si_sldb_build_index(sidSLDB)) != THERR_OK)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1234 {
106
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
1235 THERR("Error building SLDB index: %d, %s.\n",
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
1236 ret, th_error_str(ret));
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1237 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1238 }
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1239
163
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
1240 setSLDBNewFormat = th_strrcasecmp(setSLDBPath, ".md5") != NULL;
179ffe97599c Implement support for the "new" MD5 format of SLDB.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
1241
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1242 err:
127
1786b9d77782 Rename a variable, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
1243 th_io_close(inFile);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1244 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1245
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
1246 // Process files
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
1247 if (!th_args_process(argc, argv, optList, optListN,
191
d26bc1adfd14 Add internal directory reading and filename matching, plus optional
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
1248 NULL, argHandleFile, OPTH_ONLY_OTHER))
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1249 goto out;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
1250
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1251 if (optNFiles == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1252 {
141
71725be55ed1 Do not show full help if no filenames are specified.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
1253 THERR("No filename(s) specified. Try --help.\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1254 }
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
1255
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1256 out:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1257
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1258 #ifdef HAVE_ICONV
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1259 if (setUseChConv)
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1260 iconv_close(setChConv);
135
b4b1aac8761c Add preprocessor guards around iconv stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1261 #endif
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1262
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1263 th_free(setHVSCPath);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1264 th_free(setSLDBPath);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
1265 si_sldb_free(sidSLDB);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
1266 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1267 }