annotate sidinfo.c @ 85:4c0ecb078591

Rename various variables and functions and change relevant places to use the new th_ctx API.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 Feb 2016 23:18:58 +0200
parents c54d74312080
children 1e89b757f8a1
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
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
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"
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
8 #include "sidlib.h"
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
9
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
11 // Some constants
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
12 #define PSID_MAGIC_LEN 4
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
13 #define PSID_STR_LEN 32
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
14 #define PSID_BUFFER_SIZE (1024 * 16)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
17 // Flags for various information fields
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
18 enum
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
19 {
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
20 SIF_NONE = 0,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
21
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
22 SIF_TYPE = 0x00000001,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
23 SIF_VERSION = 0x00000002,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
24 SIF_DATA_OFFS = 0x00000004,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
25 SIF_LOAD_ADDR = 0x00000008,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
26 SIF_INIT_ADDR = 0x00000010,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
27 SIF_PLAY_ADDR = 0x00000020,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
28 SIF_SONGS = 0x00000040,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
29 SIF_START_SONG = 0x00000080,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
30 SIF_SPEEDS = 0x00000100,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
31 SIF_SID_NAME = 0x00000200,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
32 SIF_SID_AUTHOR = 0x00000400,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
33 SIF_SID_COPYRIGHT = 0x00000800,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
34 SIF_PLAYER_TYPE = 0x00001000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
35 SIF_PLAYSID_TUNE = 0x00002000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
36 SIF_VIDEO_CLOCK = 0x00004000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
37 SIF_SID_MODEL = 0x00008000,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
38
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
39 SIF_DATA_SIZE = 0x00100000,
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
40 SIF_HASH = 0x00200000,
51
485c8ed6d3fe Portability fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
41 SIF_FILENAME = 0x01000000,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
42
51
485c8ed6d3fe Portability fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
43 SIF_ALL = 0x0fffffff,
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
44 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
45
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
46
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
63
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
49 int cmd;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
50 char *str;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
51 char chr;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
52 } PSFStackItem;
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 {
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
57 int nitems, nallocated;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
58 PSFStackItem *items;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
59 } PSFStack;
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
60
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
61
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
62 typedef struct
6bbe11ae6bf5 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
63 {
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
64 uint32_t flag;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
65 char *name;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
66 char *lname;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
67 } PSFOption;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
68
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
69
45
ed8c803a948c Static constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
70 static const PSFOption optPSFlags[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
71 {
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
72 { SIF_FILENAME , "Filename" , NULL },
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
73 { SIF_TYPE , "Type" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
74 { SIF_VERSION , "Version" , NULL },
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
75 { SIF_PLAYER_TYPE , "PlayerType" , "Player type" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
76 { SIF_PLAYSID_TUNE , "PlayerCompat", "Player compatibility" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
77 { SIF_VIDEO_CLOCK , "VideoClock" , "Video clock speed" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
78 { SIF_SID_MODEL , "SIDModel" , "SID model" },
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
79
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
80 { SIF_DATA_OFFS , "DataOffs" , "Data offset" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
81 { SIF_DATA_SIZE , "DataSize" , "Data size" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
82 { SIF_LOAD_ADDR , "LoadAddr" , "Load address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
83 { SIF_INIT_ADDR , "InitAddr" , "Init address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
84 { SIF_PLAY_ADDR , "PlayAddr" , "Play address" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
85 { SIF_SONGS , "Songs" , "Songs" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
86 { SIF_START_SONG , "StartSong" , "Start song" },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
87 { SIF_SID_NAME , "Name" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
88 { SIF_SID_AUTHOR , "Author" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
89 { SIF_SID_COPYRIGHT , "Copyright" , NULL },
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
90 { SIF_HASH , "Hash" , NULL },
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
91
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
92 { SIF_ALL , "All" , NULL },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
93 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
94
45
ed8c803a948c Static constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
95 static const int noptPSFlags = sizeof(optPSFlags) / sizeof(optPSFlags[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
96
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 // Option variables
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
99 BOOL optParsable = FALSE,
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
100 optNoNamePrefix = FALSE,
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
101 optHexadecimal = FALSE,
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
102 optOneLine = FALSE;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
103 char *optFieldSep = NULL;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
104 uint32_t optFields = SIF_ALL;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
105 int optNFiles = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
106
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
107 PSFStack optFormat;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
108
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109
28
6240788fe172 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
110 // Define option arguments
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
111 static const th_optarg_t optList[] =
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
112 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
113 { 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
114 // { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115 { 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
116 { 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
117 { 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
118 { 3, 'f', "fields", "Show only specified field(s)", OPT_ARGREQ },
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
119 { 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
120 { 7, 'F', "format", "Use given format string (see below)", OPT_ARGREQ },
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 };
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122
44
7b137e4e817c Fix to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
123 static const int optListN = sizeof(optList) / sizeof(optList[0]);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
125
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126 void argShowHelp(void)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
127 {
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
128 int index, len;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
129
20
6058339ffe0e Update usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
130 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
131 th_args_help(stdout, optList, optListN, 0);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
132 printf(
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
133 "\n"
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
134 "Available fields:\n");
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
135
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
136 for (len = index = 0; index < noptPSFlags; index++)
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 const PSFOption *opt = &optPSFlags[index];
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
139 len += strlen(opt->name) + 3;
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
140 if (len >= 72)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
141 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
142 printf("\n");
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
143 len = 0;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
144 }
75
92a4065c41d0 Improve listing of available fields in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
145 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
146 }
58
5ea07110f0cf Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
147
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
148 printf(
61
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
149 "Example: %s -x -p -f hash,copyright somesidfile.sid\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
150 "\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
151 "Format strings for '-F' option are composed of @fields@ that\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
152 "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
153 "can be used: -F \"hash=@hash@\\ncopy=@copyright@\\n\"\n"
6916aaeda941 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
154 , th_prog_name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
156
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
157
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
158 int argMatchPSField(const char *field)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
159 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
160 int index, found = -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
161 for (index = 0; index < noptPSFlags; 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 const PSFOption *opt = &optPSFlags[index];
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
164 if (th_strcasecmp(opt->name, field) == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
165 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
166 if (found >= 0)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
167 return -2;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
168 found = index;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
169 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
170 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
171
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
172 return found;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
173 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
174
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
175
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
176 int argMatchPSFieldError(const char *field)
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 int found = argMatchPSField(field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
179 switch (found)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
180 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
181 case -1:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
182 THERR("No such field '%s'.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
183 break;
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 case -2:
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
186 THERR("Field '%s' is ambiguous.\n", field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
187 break;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
188 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
189 return found;
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
190 }
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
191
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
192
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
193 BOOL argParsePSField(char *opt, char *end, uint32_t *fields)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
194 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
195 // Trim whitespace
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
196 if (end != NULL)
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
197 while (end > opt && *end && th_isspace(*end)) end--;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
198
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
199 while (*opt && th_isspace(*opt)) opt++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
200
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
201 // Match field name
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
202 char *field = (end != NULL) ? th_strndup(opt, end - opt) : th_strdup(opt);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
203 int found = argMatchPSFieldError(field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
204 if (found >= 0)
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
205 *fields |= optPSFlags[found].flag;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
206
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
207 th_free(field);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
208 return FALSE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
209 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
210
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
211
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
212 BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
213 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
214 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
215 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
216 stack->nallocated += 16;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
217 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
218 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
219 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
220 return FALSE;
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 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
223
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
224 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
225 stack->nitems++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
226 return TRUE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
227 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
228
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
229
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
230 void siClearStack(PSFStack *stack)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
231 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
232 if (stack != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
233 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
234 if (stack->nitems > 0 && stack->items != NULL)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
235 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
236 int n;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
237 for (n = 0; n < stack->nitems; n++)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
238 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
239 if (stack->items[n].cmd == -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
240 th_free(stack->items[n].str);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
241 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
242 th_free(stack->items);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
243 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
244 memset(stack, 0, sizeof(PSFStack));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
245 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
246 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
247
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
248
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
249 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
250 // Parse a format string into a PSFStack structure
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
251 //
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
252 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
253 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
254 PSFStackItem item;
83
c54d74312080 Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
255 const char *start = NULL;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
256 int mode = 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
257
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
258 siClearStack(stack);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
259
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
260 while (mode != -1)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
261 switch (mode)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
262 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
263 case 0:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
264 if (*fmt == '@')
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 start = fmt + 1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
267 mode = 1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
268 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
269 else
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 start = fmt;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
272 mode = 2;
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 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
275 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
276
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
277 case 1:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
278 if (*fmt == '@')
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
279 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
280 if (fmt - start == 0)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
281 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
282 item.cmd = -2;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
283 item.str = NULL;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
284 item.chr = '@';
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
285 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
286 return FALSE;
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 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
289 {
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
290 char *field = th_strndup(start, fmt - start);
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
291 int ret = argMatchPSFieldError(field);
81
4904b2de4fca Oops, fix a 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
292 if (ret >= 0)
59
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 = ret;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
295 item.str = NULL;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
296 if (!siStackAddItem(stack, &item))
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
297 {
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
298 th_free(field);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
299 return FALSE;
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
300 }
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
301 }
78
9fb70b7b34ff Clean up error handling for field parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
302 th_free(field);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
303 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
304 mode = 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
305 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
306 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
307 if (*fmt == 0)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
308 mode = -1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
309 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
310 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
311
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
312 case 2:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
313 if (*fmt == 0 || *fmt == '@')
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 item.cmd = -1;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
316 item.str = th_strndup(start, fmt - start);
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
317 if (!siStackAddItem(stack, &item))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
318 return FALSE;
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
319
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
320 mode = (*fmt == 0) ? -1 : 0;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
321 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
322 else
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
323 fmt++;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
324 break;
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
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
327 return TRUE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
328 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
329
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
330
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
331 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
332 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
333 switch (optN)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
334 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
335 case 0:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
336 argShowHelp();
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
337 exit(0);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
338 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
339
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
340 case 1:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
341 th_verbosityLevel++;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
342 break;
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 case 2:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
345 optParsable = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
346 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
347
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
348 case 3:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
349 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
350 char *start = optArg;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
351 optFields = SIF_NONE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
352
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
353 while (*start)
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 char *end = strchr(start, ',');
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
356
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
357 if (!argParsePSField(start, end, &optFields))
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
358 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
359
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
360 if (!end)
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
361 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
362
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
363 start = end + 1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
364 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
365 }
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
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
368 case 4:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
369 optHexadecimal = TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
370 break;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
371
7
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
372 case 5:
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
373 optNoNamePrefix = TRUE;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
374 break;
36c43f085b28 Add NoPrefix option -n.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
375
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
376 case 6:
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
377 optOneLine = TRUE;
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
378 optFieldSep = optArg;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
379 break;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
380
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
381 case 7:
79
5709d0beb394 Avoid using a global variable here.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
382 if (!argParsePSFormatStr(&optFormat, optArg))
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
383 return FALSE;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
384 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
385
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
386 default:
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
387 THERR("Unknown option '%s'.\n", currArg);
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
388 return FALSE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
389 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
390
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
391 return TRUE;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
392 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
393
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
394
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
395 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
396 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
397 while (*str)
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
398 {
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
399 if (*str == '\\')
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
400 switch (*(++str))
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
401 {
82
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
402 case 'n': fputc('\n', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
403 case 'r': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
404 case 't': fputc('\r', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
405 case '\\': fputc('\\', outFile); break;
82679cccaa32 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
406 default: fputc(*str, outFile); break;
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
407 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
408 else
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
409 fputc(*str, outFile);
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
410
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
411 str++;
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 }
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
414
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
415
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
416 static void siPrintFieldPrefix(FILE *outFile, const char *name)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
417 {
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
418 if (!optNoNamePrefix && !optFormat.nitems)
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
419 fprintf(outFile, optParsable ? "%s=" : "%-20s : ", name);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
420 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
421
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
422
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
423 static void siPrintFieldSeparator(FILE *outFile)
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
424 {
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
425 if (!optFormat.nitems)
83
c54d74312080 Fix some warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
426 fputs(optOneLine ? optFieldSep : "\n", outFile);
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
427 }
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
428
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
429
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
430 static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const int xindex, const char *xfmt, const char *xaltfmt, ...)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
431 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
432 const PSFOption *opt = &optPSFlags[xindex];
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
433 if (optFormat.nitems || (optFields & opt->flag))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
434 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
435 va_list ap;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
436 const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
437
31
727c012d5de4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
438 siPrintFieldPrefix(outFile, (optParsable || opt->lname == NULL) ? opt->name : opt->lname);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
439
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
440 va_start(ap, xaltfmt);
57
c10c79c266d3 Remove useless code.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
441 vfprintf(outFile, fmt, ap);
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
442 va_end(ap);
3
dbe35d78e621 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
443
33
39d9df17c8b1 Add field separator argument to -l option.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
444 siPrintFieldSeparator(outFile);
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
445 *shown = TRUE;
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
446 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
447 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
448
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
449 #define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, xindex, xfmt, xaltfmt, __VA_ARGS__ )
9
c1fba4abf56f Make filename printing optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
450
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
451
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
452 static void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const int xindex)
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
453 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
454 switch (xindex)
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
455 {
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
456 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
457 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
458 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
459 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
460 case 4:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
461 if (psid->version >= 2)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
462 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
463 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
464 case 5:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
465 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
466 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
467 break;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
468 case 6:
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_model_str(psid->flags));
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
471 break;
35
79e6d08b473f Add more information fields, including SID model, video clock speed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
472
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
473 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
474 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
475 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
476 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
477 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
478 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
479 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
480 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
481 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
482 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
483
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
484 case 17:
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
485 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
486 const PSFOption *opt = &optPSFlags[xindex];
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
487 if (optFormat.nitems || (optFields & opt->flag))
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
488 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
489 siPrintFieldPrefix(outFile, "Hash");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
490 th_md5_print(outFile, psid->hash);
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
491 siPrintFieldSeparator(outFile);
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
492 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
493 }
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
494 break;
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
495 }
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
496 }
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
497
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
499 BOOL argHandleFile(char *filename)
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
500 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
501 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
502 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
503 FILE *outFile;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
504 int index;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
505 BOOL shown = FALSE;
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
506
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
507 optNFiles++;
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
508 outFile = stdout;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
509
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
510 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
511 {
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
512 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
513 return TRUE;
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
514 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
515
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
516 // 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
517 if (si_read_sid_file(inFile, &psid) != 0)
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
518 {
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
519 THERR("Error reading %s\n", filename);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
520 goto error;
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
521 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
522
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
523 // Output
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
524 if (optFormat.nitems)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
525 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
526 for (index = 0; index < optFormat.nitems; index++)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
527 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
528 PSFStackItem *item = &optFormat.items[index];
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
529 switch (item->cmd)
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
530 {
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
531 case -1:
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
532 siPrintStrEscapes(outFile, item->str);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
533 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
534
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
535 case -2:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
536 fputc(item->chr, outFile);
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
537 break;
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
538
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
539 default:
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
540 siPrintPSIDInformationField(outFile, filename, &psid, &shown, item->cmd);
62
0d01efc3c803 Factor escape printing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
541 break;
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
542 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
543 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
544 }
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
545 else
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
546 {
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
547 for (index = 0; index < noptPSFlags - 1; index++)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
548 siPrintPSIDInformationField(outFile, filename, &psid, &shown, index);
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
549
55
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
550 if (shown && optOneLine)
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
551 fprintf(outFile, "\n");
54b48086a1d0 Begin slight refactoring of how output is done.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
552 }
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
553
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
554 // Shutdown
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
555 error:
85
4c0ecb078591 Rename various variables and functions and change relevant places to use the
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
556 th_io_free(inFile);
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
557
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
558 return TRUE;
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
559 }
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
560
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
561
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 // Initialize
70
4779bbec2f28 Split some functionality into sidlib.[ch].
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
565 th_init("SIDInfo", "PSID/RSID information displayer", "0.6.1", NULL, NULL);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 th_verbosityLevel = 0;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
59
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
568 memset(&optFormat, 0, sizeof(optFormat));
718cdb563531 Initial implementation of -F format string option.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
569
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
570 // Parse command line arguments
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
571 if (!th_args_process(argc, argv, optList, optListN,
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
572 argHandleOpt, argHandleFile, OPTH_ONLY_OPTS))
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
573 return -1;
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
574
29
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
575 if (optOneLine)
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
576 {
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
577 optParsable = FALSE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
578 optNoNamePrefix = TRUE;
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
579 }
d4ec69beb160 Add one line output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
580
23
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
581 // Process files
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
582 if (!th_args_process(argc, argv, optList, optListN,
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
583 argHandleOpt, argHandleFile, OPTH_ONLY_OTHER))
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
584 return -2;
832c26cb1637 Improve option handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
585
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
586 if (optNFiles == 0)
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
587 {
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
588 argShowHelp();
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
589 THERR("No filename(s) specified.\n");
2
ffb795582a91 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
590 }
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
591
19
16cfbdf20eaf Handle multiple files.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
592 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 }