annotate sidinfo.c @ 125:ffccc712409a

Fix build.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Oct 2016 11:59:15 +0300
parents a2c2c63311de
children c1462b7880e8
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
108
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
3 * Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
73
2b2376f1b0cc Update copyright years. Yay. It's 2016!
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
4 * (C) Copyright 2014-2016 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"
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
9 #include "sidlib.h"
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
10 #include <iconv.h>
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
11
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
13 // Some constants
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
14 #define SET_DEF_CHARSET "utf-8"
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
15 #define SET_SLDB_FILENAME "Songlengths.txt"
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
16
121
a2c2c63311de Change in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
17
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
18 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
19 {
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
20 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
21 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
22 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
23 };
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
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 {
63
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
28 int cmd;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
29 char *str;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
30 char chr;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
31 int flags;
63
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
32 } PSFStackItem;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
33
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
34
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
35 typedef struct
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
36 {
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
37 int nitems, nallocated;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
38 PSFStackItem *items;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
39 } PSFStack;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
40
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
41
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
42 typedef struct
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
43 {
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
44 char *name;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
45 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
46 int type;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
47 } PSFOption;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
48
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
49
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
50 static const PSFOption optPSOptions[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
51 {
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
52 { "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
53 { "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
54 { "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
55 { "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
56 { "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
57 { "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
58 { "SIDModel" , "SID model" , OTYPE_STR },
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
59
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
60 { "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
61 { "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
62 { "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
63 { "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
64 { "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
65 { "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
66 { "StartSong" , "Start song" , OTYPE_INT },
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
67
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
68 { "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
69 { "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
70 { "Copyright" , 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
71 { "Hash" , NULL , OTYPE_OTHER },
55d99dc7c35c Prepare for some possible future enhancements by specifying a type for each data field.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
72
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 { "Songlengths" , "Song lengths" , OTYPE_OTHER },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
74 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
75
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
76 static const int noptPSOptions = sizeof(optPSOptions) / sizeof(optPSOptions[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
77
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
78
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
79 // Option variables
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
80 char *setHVSCPath = NULL,
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
81 *setSLDBPath = NULL;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
82 BOOL optParsable = FALSE,
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
83 optNoNamePrefix = FALSE,
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
84 optHexadecimal = FALSE,
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
85 optOneLine = FALSE,
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
86 optFieldOutput = TRUE;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
87 char *optFieldSep = NULL;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
88 int optNFiles = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
89
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
90 PSFStack optFormat;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
91
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
92 SIDLibSLDB *sidSLDB = NULL;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
93
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
94 BOOL setUseChConv;
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
95 iconv_t setChConv;
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
96
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
97
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
98 // Define option arguments
121
a2c2c63311de Change in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
99 static const th_optarg optList[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
100 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
101 { 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
102 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
103 { 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
104 { 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
105 { 6, 'l', "line", "Output in one line format, -l <field separator>", OPT_ARGREQ },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
106 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
107 { 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
108 { 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
109 { 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
110 { 9, 'S', "sldb", "Specify Songlengths.txt file (use -H if possible)", OPT_ARGREQ },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
112
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
113 static const int optListN = sizeof(optList) / sizeof(optList[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
116 void argShowHelp(void)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
117 {
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
118 int index, len;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119
20
6058339ffe0e Update usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
120 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
121 th_args_help(stdout, optList, optListN, 0);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 printf(
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
123 "\n"
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 "Available fields:\n");
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
125
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
126 for (len = index = 0; index < noptPSOptions; index++)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
128 const PSFOption *opt = &optPSOptions[index];
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
129 len += strlen(opt->name) + 3;
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
130 if (len >= 72)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
131 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 printf("\n");
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
133 len = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
134 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
135 printf("%s%s", opt->name, (index < noptPSOptions - 1) ? ", " : "\n\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
136 }
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
137
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
138 printf(
61
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
139 "Example: %s -x -p -f hash,copyright somesidfile.sid\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
140 "\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
141 "Format strings for '-F' option are composed of @fields@ that\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
142 "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
143 "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
144 "\n"
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
145 "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
146 "as STIL.txt and Songlengths.txt will be automatically used from there.\n"
61
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
147 , th_prog_name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
148 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
150
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
151 int argMatchPSField(const char *field)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
152 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
153 int index, found = -1;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
154 for (index = 0; index < noptPSOptions; index++)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
156 const PSFOption *opt = &optPSOptions[index];
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
157 if (th_strcasecmp(opt->name, field) == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
158 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
159 if (found >= 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
160 return -2;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
161 found = index;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
162 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
163 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
164
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
165 return found;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
166 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
167
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
168
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
169 int argMatchPSFieldError(const char *field)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
170 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
171 int found = argMatchPSField(field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
172 switch (found)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
173 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
174 case -1:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
175 THERR("No such field '%s'.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
176 break;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
177
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
178 case -2:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
179 THERR("Field '%s' is ambiguous.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
180 break;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
181 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
182 return found;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
183 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
184
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
185
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
186 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
187 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
188 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
189 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
190 stack->nallocated += 16;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
191 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
192 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
193 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
194 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
195 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
196 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
197
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
198 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
199 stack->nitems++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
200 return TRUE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
201 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
202
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
203
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
204 void siClearStack(PSFStack *stack)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
205 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
206 if (stack != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
207 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
208 if (stack->nitems > 0 && stack->items != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
209 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
210 int n;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
211 for (n = 0; n < stack->nitems; n++)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
212 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
213 if (stack->items[n].cmd == -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
214 th_free(stack->items[n].str);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
215 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
216 th_free(stack->items);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
217 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
218 memset(stack, 0, sizeof(PSFStack));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
219 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
220 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
221
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
222
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
223 BOOL argParsePSFields(PSFStack *stack, const char *fmt)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
224 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
225 const char *start = fmt;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
226 siClearStack(stack);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
227
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
228 while (*start)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
229 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
230 PSFStackItem item;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
231 const char *end = strchr(start, ',');
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
232 char *field = (end != NULL) ?
116
d062312ea850 Fix th_strndup_trim() usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
233 th_strndup_trim(start, end - start, TH_TRIM_BOTH) :
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
234 th_strdup_trim(start, TH_TRIM_BOTH);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
235
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
236 if (field != NULL)
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
237 {
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
238 int found = argMatchPSFieldError(field);
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
239 th_free(field);
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
240
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
241 if (found < 0)
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
242 return FALSE;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
243
118
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
244 item.cmd = found;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
245 item.str = NULL;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
246 if (!siStackAddItem(stack, &item))
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
247 return FALSE;
24583e5ca0b3 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
248 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
249
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
250 if (!end)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
251 break;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
252
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
253 start = end + 1;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
254 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
255
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
256 return TRUE;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
257 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
258
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
259
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
260 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
261 // Parse a format string into a PSFStack structure
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
262 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
263 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
264 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
265 PSFStackItem item;
83
c54d74312080 Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
266 const char *start = NULL;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
267 int mode = 0;
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
268 BOOL rval = TRUE;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
269
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
270 siClearStack(stack);
59
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 while (mode != -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
273 switch (mode)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
274 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
275 case 0:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
276 if (*fmt == '@')
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 start = fmt + 1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
279 mode = 1;
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 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
282 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
283 start = fmt;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
284 mode = 2;
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 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
287 break;
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 case 1:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
290 if (*fmt == '@')
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
291 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
292 if (fmt - start == 0)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
293 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
294 item.cmd = -2;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
295 item.str = NULL;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
296 item.chr = '@';
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
297 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
298 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
299 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
300 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
301 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
302 char *field = th_strndup_trim(start, fmt - start, TH_TRIM_BOTH);
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
303 int ret = argMatchPSFieldError(field);
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
304 th_free(field);
81
4904b2de4fca Oops, fix a 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
305 if (ret >= 0)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
306 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
307 item.cmd = ret;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
308 item.str = NULL;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
309 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
310 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
311 }
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
312 else
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
313 rval = FALSE;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
314 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
315 mode = 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
316 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
317 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
318 if (*fmt == 0)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
319 mode = -1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
320 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
321 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
322
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
323 case 2:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
324 if (*fmt == 0 || *fmt == '@')
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
325 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
326 item.cmd = -1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
327 item.str = th_strndup(start, fmt - start);
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
328 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
329 return FALSE;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
330
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
331 mode = (*fmt == 0) ? -1 : 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
332 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
333 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
334 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
335 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
336 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
337
113
cd97e7517e21 Simplify error handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
338 return rval;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
339 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
340
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
341
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
342 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
343 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
344 switch (optN)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
345 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
346 case 0:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
347 argShowHelp();
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
348 exit(0);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
349 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
350
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
351 case 1:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
352 th_verbosityLevel++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
353 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
354
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
355 case 2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
356 optParsable = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
357 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
358
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
359 case 3:
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
360 if (!argParsePSFields(&optFormat, optArg))
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
361 return FALSE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
362 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
363
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
364 case 4:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
365 optHexadecimal = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
366 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
367
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
368 case 5:
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
369 optNoNamePrefix = TRUE;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
370 break;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
371
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
372 case 6:
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
373 optOneLine = TRUE;
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
374 optFieldSep = optArg;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
375 break;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
376
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
377 case 7:
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
378 optFieldOutput = FALSE;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
379 if (!argParsePSFormatStr(&optFormat, optArg))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
380 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
381 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
382
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
383 case 8:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
384 setHVSCPath = th_strdup(optArg);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
385 break;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
386
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
387 case 9:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
388 setSLDBPath = th_strdup(optArg);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
389 break;
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
390
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
391 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
392 THERR("Unknown option '%s'.\n", currArg);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
393 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
394 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
395
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
396 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
397 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
398
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
399
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
400 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
401 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
402 while (*str)
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
403 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
404 if (*str == '\\')
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
405 switch (*(++str))
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
406 {
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
407 case 'n': fputc('\n', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
408 case 'r': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
409 case 't': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
410 case '\\': fputc('\\', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
411 default: fputc(*str, outFile); break;
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
412 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
413 else
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
414 fputc(*str, outFile);
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
415
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
416 str++;
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
417 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
418 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
419
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
420
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
421 static void siPrintFieldPrefix(FILE *outFile, const PSFOption *opt)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
422 {
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
423 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
424 if (!optNoNamePrefix && optFieldOutput)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
425 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
426 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
427
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
428
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
429 static void siPrintFieldSeparator(FILE *outFile)
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
430 {
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
431 if (optFieldOutput)
83
c54d74312080 Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
432 fputs(optOneLine ? optFieldSep : "\n", outFile);
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
433 }
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
434
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
435
125
ffccc712409a Fix build.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
436 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFOption *opt, const char *xfmt, const char *xaltfmt, ...)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
437 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
438 va_list ap;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
439 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
440
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
441 siPrintFieldPrefix(outFile, opt);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
442
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
443 va_start(ap, xaltfmt);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
444 vfprintf(outFile, fmt, ap);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
445 va_end(ap);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
446
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
447 siPrintFieldSeparator(outFile);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
448 *shown = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
449 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
450
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
451
125
ffccc712409a Fix build.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
452 #define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, opt, xfmt, xaltfmt, __VA_ARGS__ )
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
453
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
454
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
455 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
456 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
457 const PSFOption *opt = &optPSOptions[item->cmd];
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
458 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
459 {
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
460 case 0: PR("%s", NULL, filename); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
461 case 1: PR("%s", NULL, psid->magic); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
462 case 2: PR("%d.%d", NULL, (psid->version & 0xff), (psid->version >> 8)); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
463 case 3: PR("%s", NULL, (psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in"); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
464 case 4:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
465 if (psid->version >= 2)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
466 PR("%s", NULL, (psid->flags & PSF_PLAYSID_TUNE) ? "PlaySID" : "C64 compatible");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
467 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
468 case 5:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
469 if (psid->version >= 2)
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
470 PR("%s", NULL, si_get_sid_clock_str(psid->flags));
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
471 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
472 case 6:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
473 if (psid->version >= 2)
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
474 PR("%s", NULL, si_get_sid_model_str(psid->flags));
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
475 break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
476
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
477 case 7: PR("%d", "$%08x", psid->dataOffset); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
478 case 8: PR("%d", "$%08x", psid->dataSize); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
479 case 9: PR("%d", "$%04x", psid->loadAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
480 case 10: PR("%d", "$%04x", psid->initAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
481 case 11: PR("%d", "$%04x", psid->playAddress); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
482 case 12: PR("%d", "$%04x", psid->nSongs); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
483 case 13: PR("%d", "$%04x", psid->startSong); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
484 case 14: PR("%s", NULL, psid->sidName); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
485 case 15: PR("%s", NULL, psid->sidAuthor); break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
486 case 16: PR("%s", NULL, psid->sidCopyright); break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
487
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
488 case 17:
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
489 siPrintFieldPrefix(outFile, opt);
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
490 th_md5_print(outFile, psid->hash);
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
491 siPrintFieldSeparator(outFile);
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
492 break;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
493
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
494 case 18:
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
495 siPrintFieldPrefix(outFile, opt);
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
496 if (psid->lengths != NULL)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
497 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
498 int i;
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
499 for (i = 0; i < psid->lengths->nlengths; i++)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
500 {
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
501 int len = psid->lengths->lengths[i];
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
502 fprintf(outFile, "%d:%d%s", len / 60, len % 60,
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
503 (i < psid->lengths->nlengths - 1) ? " " : "");
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
504 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
505 }
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
506 siPrintFieldSeparator(outFile);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
507 break;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
508 }
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
509 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
510
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
512 BOOL argHandleFile(char *filename)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
513 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
514 static PSIDHeader psid;
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
515 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
516 FILE *outFile;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
517 int index;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
518 BOOL shown = FALSE;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
519
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
520 optNFiles++;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
521 outFile = stdout;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
522
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
523 if ((inFile = th_io_fopen(&th_stdio_io_ops, filename, "rb")) == NULL)
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
524 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
525 THERR("Could not open file '%s'.\n", filename);
27
4dd463eebb74 Fix argument handling when file does not exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
526 return TRUE;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
527 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
528
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
529 // Read PSID data
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
530 if (si_read_sid_file(inFile, &psid) != 0)
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
531 {
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
532 THERR("Error reading %s\n", filename);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
533 goto error;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
534 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
535
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
536 // Get songlength information, if any
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
537 if (sidSLDB != NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
538 psid.lengths = si_sldb_get_by_hash(sidSLDB, psid.hash);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
539
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
540 // Output
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
541 for (index = 0; index < optFormat.nitems; index++)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
542 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
543 PSFStackItem *item = &optFormat.items[index];
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
544 switch (item->cmd)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
545 {
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
546 case -1:
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
547 siPrintStrEscapes(outFile, item->str);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
548 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
549
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
550 case -2:
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
551 fputc(item->chr, outFile);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
552 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
553
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
554 default:
114
cc74a9871a44 Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
555 siPrintPSIDInformationField(outFile, filename, &psid, &shown, item);
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
556 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
557 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
558 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
559
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
560 if (optFieldOutput)
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
561 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
562 if (shown && optOneLine)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
563 fprintf(outFile, "\n");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
564 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
565
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
566 // Shutdown
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
567 error:
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
568 th_io_free(inFile);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
569
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
570 return TRUE;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
571 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
572
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
573
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 {
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
576 char *setLang = th_strdup(getenv("LANG"));
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
577
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 // Initialize
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
579 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 th_verbosityLevel = 0;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
582 memset(&optFormat, 0, sizeof(optFormat));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
583
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
584 // Initialize iconv, check if we have language/charset
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
585 if (setLang != NULL)
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
586 {
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
587 char *ptr = strchr(setLang, '.');
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
588 if (ptr != NULL) strcpy(setLang, ptr + 1);
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
589 }
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
590
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
591 setChConv = iconv_open("iso88591", setLang != NULL ? setLang : SET_DEF_CHARSET);
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
592 setUseChConv = setChConv != (iconv_t) -1;
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
593 th_free(setLang);
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
594
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
595 // Parse command line arguments
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
596 if (!th_args_process(argc, argv, optList, optListN,
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
597 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
598 return -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
599
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
600 if (optOneLine)
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
601 {
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
602 optParsable = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
603 optNoNamePrefix = TRUE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
604 }
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
605
111
c7ecf56d23e7 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
606 if (optFieldOutput && !optFormat.nitems)
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
607 {
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
608 PSFStackItem item;
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
609 int i;
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
610 memset(&item, 0, sizeof(item));
109
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
611 siClearStack(&optFormat);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
612 for (i = 0; i < noptPSOptions; i++)
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
613 {
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
614 item.cmd = i;
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
615 siStackAddItem(&optFormat, &item);
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
616 }
59b5b99f4280 Reimplement '-f' option differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
617 }
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
618
90
2ab9ab4b59eb Some fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
619 // Check paths
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
620 if (setHVSCPath != NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
621 {
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
622 if (setSLDBPath == NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
623 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
624 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
625
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
626 if (setSLDBPath != NULL)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
627 {
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
628 // Initialize SLDB
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
629 int ret = THERR_OK;
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
630 th_ioctx *ctx = NULL;
91
5ec395268fd3 Fix to comply with th_ioctx API change.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
631 if ((ctx = th_io_fopen(&th_stdio_io_ops, setSLDBPath, "r")) == NULL)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
632 {
106
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
633 THERR("Could not open SLDB '%s'.\n",
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
634 setSLDBPath);
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
635 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
636 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
637
115
6843261b4cd6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
638 THMSG(1, "Reading SLDB.\n");
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
639 if ((sidSLDB = si_sldb_new()) == NULL)
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
640 {
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
641 THERR("Could not allocate SLDB structure!\n");
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
642 goto err;
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
643 }
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
644
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
645 if ((ret = si_sldb_read(ctx, sidSLDB)) != THERR_OK)
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
646 {
106
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
647 THERR("Error parsing SLDB: %d, %s\n",
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
648 ret, th_error_str(ret));
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
649 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
650 }
90
2ab9ab4b59eb Some fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
651 th_io_close(ctx);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
652
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
653 if ((ret = si_sldb_build_index(sidSLDB)) != THERR_OK)
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
654 {
106
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
655 THERR("Error building SLDB index: %d, %s.\n",
9ff4f6da3db8 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
656 ret, th_error_str(ret));
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
657 goto err;
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
658 }
110
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
659
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
660 err:
e9dbedc4d5e4 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
661 th_io_close(ctx);
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
662 }
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
663
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
664 // Process files
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
665 if (!th_args_process(argc, argv, optList, optListN,
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
666 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER))
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
667 goto out;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
668
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
669 if (optNFiles == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
670 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
671 argShowHelp();
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
672 THERR("No filename(s) specified.\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
673 }
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
674
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
675 out:
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
676
120
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
677 if (setUseChConv)
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
678 iconv_close(setChConv);
ecbc8cabd6a2 Initial work on iconv support.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
679
89
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
680 th_free(setHVSCPath);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
681 th_free(setSLDBPath);
d9cb7c635e7b Implement initial SLDB support.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
682 si_sldb_free(sidSLDB);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
683 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 }