Mercurial > hg > forks > yadex
annotate src/cfgfile.cc @ 80:2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Sep 2011 17:39:49 +0300 |
parents | a862fd9906ec |
children | 002bc70a3982 |
rev | line source |
---|---|
0 | 1 /* |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
2 * cfgfile.cc |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
3 * AYM 1998-09-30 |
0 | 4 */ |
5 | |
6 /* | |
7 This file is part of Yadex. | |
8 | |
9 Yadex incorporates code from DEU 5.21 that was put in the public domain in | |
10 1994 by Raphaël Quinet and Brendon Wyber. | |
11 | |
12 The rest of Yadex is Copyright © 1997-2003 André Majorel. | |
13 | |
14 This program is free software; you can redistribute it and/or modify it under | |
15 the terms of the GNU General Public License as published by the Free Software | |
16 Foundation; either version 2 of the License, or (at your option) any later | |
17 version. | |
18 | |
19 This program is distributed in the hope that it will be useful, but WITHOUT | |
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
21 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
22 | |
23 You should have received a copy of the GNU General Public License along with | |
24 this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
25 Place, Suite 330, Boston, MA 02111-1307, USA. | |
26 */ | |
27 | |
28 | |
29 #include "yadex.h" | |
30 | |
31 #include <sys/types.h> | |
32 #include <sys/stat.h> | |
33 | |
34 #include "cfgfile.h" | |
35 #include "gfx.h" | |
36 #include "help1.h" | |
37 #include "levels.h" | |
38 #include "locate.h" | |
39 #include "windim.h" | |
40 | |
41 | |
42 const char config_file_magic[] = "# Yadex configuration file version 4"; | |
43 | |
44 | |
45 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
46 * Description of the command line arguments and config file keywords |
0 | 47 */ |
48 typedef enum | |
49 { | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
50 // Boolean (toggle) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
51 // Receptacle is of type bool |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
52 // data_ptr is of type (bool *) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
53 OPT_BOOLEAN, |
0 | 54 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
55 // "yes", "no", "ask" |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
56 // Receptacle is of type confirm_t |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
57 // data_ptr is of type confirm_t |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
58 OPT_CONFIRM, |
0 | 59 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
60 // Integer number, |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
61 // Receptacle is of type int |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
62 // data_ptr is of type (int *) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
63 OPT_INTEGER, |
0 | 64 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
65 // Unsigned long integer |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
66 // Receptacle is of type unsigned |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
67 // data_ptr is of type (unsigned long *) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
68 OPT_UNSIGNED, |
0 | 69 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
70 // Window dimension, either integer (pixels) or integer% |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
71 // (percentage of total display dimension) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
72 // Receptacle is of type ... |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
73 // data_ptr is of type ... |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
74 OPT_WINDIM, |
0 | 75 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
76 // String |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
77 // Receptacle is of type (char[9]) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
78 // data_ptr is of type (char *) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
79 OPT_STRINGBUF8, |
0 | 80 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
81 // String |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
82 // Receptacle is of type (const char *) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
83 // data_ptr is of type (const char **) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
84 OPT_STRINGPTR, |
0 | 85 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
86 // String, but store in a list |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
87 // Receptacle is of type ?? |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
88 // data_ptr is of type ?? |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
89 OPT_STRINGPTRACC, |
0 | 90 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
91 // List of strings |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
92 // Receptacle is of type (const char *[]) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
93 // data_ptr is of type (const char ***) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
94 OPT_STRINGPTRLIST, |
0 | 95 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
96 // End of the options description |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
97 OPT_END |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
98 } OptionType; |
0 | 99 |
100 typedef struct | |
101 { | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
102 const char *long_name; // Command line arg. or keyword |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
103 const char *short_name; // Abbreviated command line argument |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
104 OptionType type; // Type of this option |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
105 const char *flags; // Flags for this option : |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
106 // "1" = process only on pass 1 of |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
107 // parse_command_line_options() |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
108 // "b" = BGI only (ignored ifndef Y_BGI) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
109 // "x" = X only (ignored ifndef Y_X11) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
110 const char *desc; // Description of the option |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
111 void *data_ptr; // Pointer to the data |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
112 } OptionDesc; |
0 | 113 |
114 /* The first option has neither long name nor short name. | |
115 It is used for "lonely" arguments (i.e. file names). */ | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
116 OptionDesc options[] = { |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
117 {NULL, NULL, OPT_STRINGPTRACC, NULL, "Patch wad file", &cfg.PatchWads }, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
118 {"autoscroll", NULL, OPT_BOOLEAN, NULL, "Enable autoscrolling", &cfg.autoscroll }, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
119 {"autoscroll_amp", NULL, OPT_UNSIGNED, NULL, "Amp. of scrolling (% of screen size)", &cfg.autoscroll_amp}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
120 {"autoscroll_edge", NULL, OPT_UNSIGNED, NULL, "Max. dist. to edge (pixels)", &cfg.autoscroll_edge}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
121 {NULL, "b", OPT_STRINGPTR, NULL, "Run benchmark and exit successfully", &cfg.bench}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
122 {"blindly_swap_sidedefs", NULL, OPT_BOOLEAN, NULL, "Blindly swap sidedefs on a linedef", &cfg.blindly_swap_sidedefs}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
123 {"config_file", "f", OPT_STRINGPTR, "1", "Config file", &cfg.config_file}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
124 {"copy_linedef_reuse_sidedefs",NULL,OPT_BOOLEAN, NULL, "Use same sidedefs as original linedef", &cfg.copy_linedef_reuse_sidedefs}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
125 {"debug", "d", OPT_BOOLEAN, NULL, "Debug mode", &cfg.Debug}, |
0 | 126 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
127 {"default_ceiling_height", NULL, OPT_INTEGER, NULL, "Default ceiling height", &cfg.def.ceiling_height}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
128 {"default_ceiling_texture", NULL, OPT_STRINGBUF8, NULL, "Default ceiling texture", cfg.def.ceiling_texture}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
129 {"default_floor_height", NULL, OPT_INTEGER, NULL, "Default floor height", &cfg.def.floor_height}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
130 {"default_floor_texture", NULL, OPT_STRINGBUF8, NULL, "Default floor texture", cfg.def.floor_texture}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
131 {"default_light_level", NULL, OPT_INTEGER, NULL, "Default light level", &cfg.def.light_level}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
132 {"cfg.def.lower_texture", NULL, OPT_STRINGBUF8, NULL, "Default lower texture", cfg.def.lower_texture}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
133 {"default_middle_texture", NULL, OPT_STRINGBUF8, NULL, "Default middle texture", cfg.def.middle_texture}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
134 {"default_thing", NULL, OPT_INTEGER, NULL, "Default thing number", &cfg.def.thing}, |
0 | 135 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
136 {"cfg.def.upper_texture", NULL, OPT_STRINGBUF8, NULL, "Default upper texture", cfg.def.upper_texture}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
137 {"digit_zoom_base", NULL, OPT_INTEGER, NULL, "[0]-[9]: base zoom factor (in %)", &cfg.digit_zoom_base}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
138 {"digit_zoom_step", NULL, OPT_INTEGER, NULL, "[0]-[9]: step between factors (in %)", &cfg.digit_zoom_step}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
139 {"double_click_timeout", NULL, OPT_INTEGER, NULL, "Max delay in ms between clicks", &cfg.double_click_timeout}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
140 {"expert", NULL, OPT_BOOLEAN, NULL, "Expert mode", &cfg.Expert}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
141 {"file", NULL, OPT_STRINGPTRLIST, NULL, "Patch wad file", &cfg.PatchWads}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
142 {"font", "fn", OPT_STRINGPTR, NULL, "(X11 only) Font name", &font_name}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
143 {"game", "g", OPT_STRINGPTR, NULL, "Game", &cfg.Game}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
144 {"grid_max", NULL, OPT_INTEGER, NULL, "Max grid step (map units)", &cfg.GridMax}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
145 {"grid_min", NULL, OPT_INTEGER, NULL, "Min grid step (map units)", &cfg.GridMin}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
146 {"grid_pixels_min", NULL, OPT_INTEGER, NULL, "Min grid step (pixels)", &cfg.grid_pixels_min}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
147 {"height", "h", OPT_WINDIM, "x", "(X11 only) Initial window height", &initial_window_height}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
148 {"help", "?", OPT_BOOLEAN, "1", "Show usage summary", &cfg.show_help}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
149 {"idle_sleep_ms", NULL, OPT_INTEGER, NULL, "ms to sleep before XPending()", &cfg.idle_sleep_ms}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
150 {"info_bar", NULL, OPT_BOOLEAN, NULL, "Show the info bar", &cfg.InfoShown}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
151 {"insert_vertex_split_linedef",NULL,OPT_CONFIRM, NULL, "Split ld after ins. vertex", &cfg.insert_vertex_split_linedef}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
152 {"insert_vertex_merge_vertices",NULL,OPT_CONFIRM, NULL, "Merge vertices after ins. vertex", &cfg.insert_vertex_merge_vertices}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
153 {"iwad1", "i1", OPT_STRINGPTR, NULL, "The name of the Doom/Ultimate D. iwad", &cfg.Iwad[0]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
154 {"iwad2", "i2", OPT_STRINGPTR, NULL, "The name of the Doom II/Final D. iwad", &cfg.Iwad[1]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
155 {"iwad3", "i3", OPT_STRINGPTR, NULL, "The name of the Heretic iwad", &cfg.Iwad[2]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
156 {"iwad4", "i4", OPT_STRINGPTR, NULL, "The name of the Hexen iwad", &cfg.Iwad[3]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
157 {"iwad5", "i5", OPT_STRINGPTR, NULL, "The name of the Strife iwad", &cfg.Iwad[4]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
158 {"iwad6", "i6", OPT_STRINGPTR, NULL, "The name of the Doom alpha 0.2 iwad", &cfg.Iwad[5]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
159 {"iwad7", "i7", OPT_STRINGPTR, NULL, "The name of the Doom alpha 0.4 iwad", &cfg.Iwad[6]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
160 {"iwad8", "i8", OPT_STRINGPTR, NULL, "The name of the Doom alpha 0.5 iwad", &cfg.Iwad[7]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
161 {"iwad9", "i9", OPT_STRINGPTR, NULL, "The name of the Doom press rel. iwad", &cfg.Iwad[8]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
162 {"iwad10", "i10",OPT_STRINGPTR, NULL, "The name of the Strife 1.0 iwad", &cfg.Iwad[9]}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
163 {"no_pixmap", "P", OPT_BOOLEAN, NULL, "(X11 only) Use no pixmap", &cfg.no_pixmap}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
164 {"pwad", "pw", OPT_STRINGPTRACC, NULL, "Pwad file to load", &cfg.PatchWads}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
165 {"quiet", "q", OPT_BOOLEAN, NULL, "Quiet mode", &cfg.Quiet}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
166 {"quieter", "qq", OPT_BOOLEAN, NULL, "Quieter mode", &cfg.Quieter}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
167 {"scroll_less", NULL, OPT_UNSIGNED, NULL, "Amp. of scrolling (% of screen size)", &cfg.scroll_less}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
168 {"scroll_more", NULL, OPT_UNSIGNED, NULL, "Amp. of scrolling (% of screen size)", &cfg.scroll_more}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
169 {"select0", "s0", OPT_BOOLEAN, NULL, "Automatic selection of 0th object", &cfg.Select0}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
170 {"sprite_scale", NULL, OPT_INTEGER, NULL, "Relative scale of sprites", &cfg.sprite_scale}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
171 {"swap_buttons", "sb", OPT_BOOLEAN, NULL, "Swap mouse buttons", &cfg.SwapButtons}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
172 {"text_dot", "td", OPT_BOOLEAN, NULL, "DrawScreenText debug flag", &cfg.text_dot}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
173 {"verbose", "v", OPT_BOOLEAN, "1", "Verbose mode", &cfg.verbose}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
174 {"welcome_message", NULL, OPT_BOOLEAN, NULL, "Print welcome message", &cfg.welcome_message}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
175 {"width", "w", OPT_WINDIM, "x", "(X11 only) Initial window width", &initial_window_width}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
176 {"zoom_default", "z", OPT_INTEGER, NULL, "Initial zoom factor", &cfg.zoom_default}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
177 {"zoom_step", NULL, OPT_INTEGER, NULL, "Step between zoom factors (in %)", &cfg.zoom_step}, |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
178 {"error_resiliency", "e", OPT_UNSIGNED, NULL, "Error resiliency of the WAD/map loader (0-4). See yadex.cfg for more info.", &cfg.error_res}, |
0 | 179 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
180 {NULL, NULL, OPT_END, NULL, NULL, NULL} |
0 | 181 }; |
182 | |
183 | |
184 typedef enum | |
185 { | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
186 CFG_PARSE_ = 0x00, |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
187 CFG_PARSE_MAGIC_ERROR = 0x01, |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
188 CFG_PARSE_MAGIC_WARN = 0x02, |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
189 CFG_PARSE_ANAL_NAME = 0x04, |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
190 CFG_PARSE_ANAL_SYNTAX = 0x08 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
191 } ConfigParseFlags; |
0 | 192 |
193 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
194 static void append_item_to_list(const char ***list, const char *item); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
195 static int parse_config_file(const char *filename, |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
196 ConfigParseFlags flags = CFG_PARSE_); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
197 static confirm_t confirm_e2i(const char *external); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
198 static const char *confirm_i2e(confirm_t internal); |
0 | 199 |
200 | |
201 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
202 * parse_config_file_default - parse the default config file(s) |
0 | 203 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
204 * Return non-zero if parse error occurred (i.e. at least |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
205 * one call to parse_config_file() returned non-zero), zero |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
206 * otherwise. |
0 | 207 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
208 int parse_config_file_default() |
0 | 209 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
210 int rc = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
211 int matches; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
212 const char *pathname; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
213 const char *name = "yadex.cfg"; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
214 Locate locate(yadex_etc_path, name, true); |
0 | 215 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
216 for (matches = 0; (pathname = locate.get_next()) != NULL; matches++) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
217 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
218 printf("Reading config file \"%s\".\n", pathname); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
219 int r = parse_config_file(pathname); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
220 if (r != 0) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
221 rc = 1; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
222 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
223 if (matches == 0) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
224 warn("%s: not found\n", name); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
225 return rc; |
0 | 226 } |
227 | |
228 | |
229 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
230 * parse_config_file_user - parse a user-specified config file |
0 | 231 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
232 * Return non-zero if the file couldn't be found or if |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
233 * parse error occurred (i.e. parse_config_file() returned |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
234 * non-zero), zero otherwise. |
0 | 235 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
236 int parse_config_file_user(const char *name) |
0 | 237 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
238 const char *pathname; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
239 Locate locate(yadex_etc_path, name, false); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
240 |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
241 pathname = locate.get_next(); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
242 if (pathname == NULL) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
243 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
244 err("%s: not found", name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
245 return 1; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
246 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
247 printf("Reading config file \"%s\".\n", pathname); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
248 return parse_config_file(pathname); |
0 | 249 } |
250 | |
251 | |
252 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
253 * parse_config_file - try to parse a config file by pathname. |
0 | 254 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
255 * If (flags & CFG_PARSE_MAGIC_ERROR) is true, the file must |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
256 * begin with config_file_magic on a line by itself or the |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
257 * function will exit immediately with a non-zero value. |
0 | 258 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
259 * If (flags & CFG_PARSE_MAGIC_WARN) is true, the file must |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
260 * begin with config_file_magic on a line by itself or the |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
261 * function will print a warning. |
0 | 262 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
263 * If (flags & CFG_PARSE_ANAL_NAME) is true, unknown |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
264 * variables name cause the function to return immediately |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
265 * with a non-zero value. Otherwise, unknown variables |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
266 * cause the line to be skipped with a warning and do not |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
267 * cause the return value to be non-zero. |
0 | 268 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
269 * If (flags & CFG_PARSE_ANAL_SYNTAX) is true, lines that |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
270 * do not follow the <name> = <value> syntax cause the |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
271 * function to emit an error message and return immediately |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
272 * with a non-zero value. Otherwise, such lines are simply |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
273 * ignored with a warning message and do not cause the |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
274 * return value to be non-zero. |
0 | 275 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
276 * Return 0 on success, <>0 on failure. |
0 | 277 */ |
278 #define RETURN_FAILURE do { rc = 1; goto byebye; } while (0) | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
279 static int parse_config_file(const char *filename, ConfigParseFlags flags) |
0 | 280 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
281 int rc = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
282 FILE *cfgfile; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
283 char line[1024]; |
0 | 284 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
285 cfgfile = fopen(filename, "r"); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
286 if (cfgfile == NULL) |
0 | 287 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
288 err("Can't open config file \"%s\" (%s)", filename, strerror(errno)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
289 RETURN_FAILURE; |
0 | 290 } |
291 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
292 /* The first line of the configuration file must |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
293 contain exactly config_file_magic. */ |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
294 if (fgets(line, sizeof line, cfgfile) == NULL |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
295 || memcmp(line, config_file_magic, sizeof config_file_magic - 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
296 || line[sizeof config_file_magic - 1] != '\n' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
297 || line[sizeof config_file_magic] != '\0') |
0 | 298 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
299 if (flags & CFG_PARSE_MAGIC_ERROR) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
300 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
301 err("%s(1): bad magic, not a valid Yadex configuration file", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
302 filename); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
303 err("Perhaps a leftover from a previous version of Yadex ?"); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
304 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
305 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
306 if (flags & CFG_PARSE_MAGIC_WARN) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
307 warn("%s(1): bad magic, perhaps from a different version of Yadex\n", filename); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
308 rewind(cfgfile); |
0 | 309 } |
310 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
311 // Execute one line on each iteration |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
312 for (unsigned lnum = 1; fgets(line, sizeof line, cfgfile) != NULL; lnum++) |
0 | 313 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
314 char *name = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
315 char *value = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
316 char *p = line; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
317 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
318 // Skip leading whitespace |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
319 while (isspace(*p)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
320 p++; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
321 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
322 // Skip comments |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
323 if (*p == '#') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
324 continue; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
325 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
326 // Remove trailing newline |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
327 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
328 size_t len = strlen(p); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
329 if (len >= 1 && p[len - 1] == '\n') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
330 p[len - 1] = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
331 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
332 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
333 // Skip empty lines |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
334 if (*p == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
335 continue; |
0 | 336 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
337 // Make <name> point on the <name> field |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
338 name = p; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
339 while (y_isident(*p)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
340 p++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
341 if (*p == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
342 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
343 if (flags & CFG_PARSE_ANAL_SYNTAX) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
344 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
345 err("%s(%u): expected an \"=\"", filename, lnum); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
346 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
347 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
348 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
349 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
350 warn("%s(%u): expected an \"=\", skipping\n", filename, lnum); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
351 goto next_line; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
352 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
353 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
354 if (*p == '=') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
355 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
356 // Mark the end of the option name |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
357 *p = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
358 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
359 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
360 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
361 // Mark the end of the option name |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
362 *p = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
363 p++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
364 // Skip blanks after the option name |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
365 while (isspace((unsigned char) *p)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
366 p++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
367 if (*p != '=') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
368 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
369 if (flags & CFG_PARSE_ANAL_SYNTAX) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
370 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
371 err("%s(%u,%d): expected an \"=\"", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
372 filename, lnum, 1 + (int) (p - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
373 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
374 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
375 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
376 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
377 warn("%s(%u,%d): expected an \"=\", skipping\n", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
378 filename, lnum, 1 + (int) (p - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
379 goto next_line; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
380 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
381 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
382 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
383 p++; |
0 | 384 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
385 /* First parameter : <value> points on the first character. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
386 Put a NUL at the end. If there is a second parameter, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
387 holler. */ |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
388 while (isspace((unsigned char) *p)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
389 p++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
390 value = p; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
391 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
392 unsigned char *p2 = (unsigned char *) value; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
393 while (*p2 != '\0' && !isspace(*p2)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
394 p2++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
395 if (*p2 != '\0') // There's trailing whitespace after 1st parameter |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
396 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
397 for (unsigned char *p3 = p2; *p3 != '\0'; p3++) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
398 if (!isspace(*p3)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
399 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
400 err("%s(%u,%d): extraneous argument", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
401 filename, lnum, 1 + (int) ((char *) p3 - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
402 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
403 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
404 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
405 *p2 = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
406 } |
0 | 407 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
408 for (const OptionDesc * o = options + 1;; o++) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
409 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
410 if (o->type == OPT_END) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
411 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
412 if (flags & CFG_PARSE_ANAL_NAME) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
413 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
414 err("%s(%u): invalid variable \"%s\"", filename, lnum, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
415 name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
416 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
417 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
418 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
419 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
420 warn("%s(%u): invalid variable \"%s\", skipping\n", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
421 filename, lnum, name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
422 goto next_line; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
423 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
424 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
425 if (!o->long_name || strcmp(name, o->long_name) != 0) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
426 continue; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
427 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
428 if (o->flags != NULL && strchr(o->flags, '1')) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
429 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
430 #if ! defined Y_X11 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
431 if (o->flags != NULL && strchr(o->flags, 'x')) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
432 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
433 #endif |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
434 switch (o->type) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
435 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
436 case OPT_BOOLEAN: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
437 if (!strcmp(value, "yes") || !strcmp(value, "true") |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
438 || !strcmp(value, "on") || !strcmp(value, "1")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
439 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
440 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
441 *((bool *) (o->data_ptr)) = true; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
442 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
443 else if (!strcmp(value, "no") || !strcmp(value, "false") |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
444 || !strcmp(value, "off") || !strcmp(value, "0")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
445 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
446 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
447 *((bool *) (o->data_ptr)) = false; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
448 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
449 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
450 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
451 err("%s(%u): invalid value for option %s: \"%s\"", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
452 filename, lnum, name, value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
453 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
454 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
455 break; |
0 | 456 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
457 case OPT_CONFIRM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
458 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
459 *((confirm_t *) o->data_ptr) = confirm_e2i(value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
460 break; |
0 | 461 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
462 case OPT_INTEGER: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
463 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
464 *((int *) (o->data_ptr)) = atoi(value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
465 break; |
0 | 466 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
467 case OPT_UNSIGNED: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
468 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
469 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
470 if (*value == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
471 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
472 err("%s(%u,%d): missing argument", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
473 filename, lnum, 1 + (int) (value - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
474 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
475 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
476 bool neg = false; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
477 if (value[0] == '-') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
478 neg = true; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
479 char *endptr; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
480 errno = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
481 *((unsigned long *) (o->data_ptr)) = |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
482 strtoul(value, &endptr, 0); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
483 if (*endptr != '\0' && !isspace(*endptr)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
484 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
485 err("%s(%u,%d): illegal character in unsigned integer", filename, lnum, 1 + (int) (endptr - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
486 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
487 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
488 /* strtoul() sets errno to ERANGE if overflow. In |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
489 addition, we don't want any non-zero negative |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
490 numbers. In terms of regexp, /^(0x)?0*$/i. */ |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
491 if (errno != 0 || neg && ! |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
492 (strspn(value + 1, "0") == strlen(value + 1) || value[1] == '0' && tolower(value[2]) == 'x' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
493 && strspn(value + 3, "0") == strlen(value + 3))) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
494 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
495 err("%s(%u,%d): unsigned integer out of range", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
496 filename, lnum, 1 + (int) (value - line)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
497 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
498 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
499 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
500 break; |
0 | 501 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
502 case OPT_WINDIM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
503 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
504 if (((Win_dim *) (o->data_ptr))->set(value)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
505 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
506 err("%s(%u): bad dimension spec \"%s\"", filename, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
507 lnum, value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
508 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
509 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
510 break; |
0 | 511 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
512 case OPT_STRINGBUF8: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
513 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
514 al_scps((char *) o->data_ptr, value, 8); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
515 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
516 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
517 case OPT_STRINGPTR: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
518 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
519 char *dup = (char *) GetMemory(strlen(value) + 1); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
520 strcpy(dup, value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
521 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
522 *((char **) (o->data_ptr)) = dup; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
523 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
524 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
525 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
526 case OPT_STRINGPTRACC: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
527 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
528 char *dup = (char *) GetMemory(strlen(value) + 1); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
529 strcpy(dup, value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
530 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
531 append_item_to_list((const char ***) o->data_ptr, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
532 dup); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
533 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
534 } |
0 | 535 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
536 case OPT_STRINGPTRLIST: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
537 while (*value != '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
538 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
539 char *v = value; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
540 while (*v != '\0' && !isspace((unsigned char) *v)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
541 v++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
542 char *dup = (char *) GetMemory(v - value + 1); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
543 memcpy(dup, value, v - value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
544 dup[v - value] = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
545 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
546 append_item_to_list((const char ***) o->data_ptr, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
547 dup); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
548 while (isspace(*v)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
549 v++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
550 value = v; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
551 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
552 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
553 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
554 default: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
555 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
556 nf_bug("%s(%u): unknown option type %d", |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
557 filename, lnum, (int) o->type); |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
558 RETURN_FAILURE; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
559 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
560 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
561 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
562 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
563 next_line:; |
0 | 564 } |
565 | |
566 byebye: | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
567 if (cfgfile != 0) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
568 fclose(cfgfile); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
569 return rc; |
0 | 570 } |
571 | |
572 | |
573 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
574 * parse_command_line_options |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
575 * If <pass> is set to 1, ignores all options except those |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
576 * that have the "1" flag. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
577 * Else, ignores all options that have the "1" flag. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
578 * If an error occurs, report it with err() |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
579 * and returns non-zero. Else, returns 0. |
0 | 580 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
581 int parse_command_line_options(int argc, const char *const *argv, int pass) |
0 | 582 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
583 const OptionDesc *o; |
0 | 584 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
585 while (argc > 0) |
0 | 586 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
587 int ignore; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
588 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
589 // Which option is this ? |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
590 if (**argv != '-' && **argv != '+') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
591 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
592 o = options; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
593 argc++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
594 argv--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
595 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
596 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
597 for (o = options + 1;; o++) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
598 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
599 if (o->type == OPT_END) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
600 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
601 err("invalid option: \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
602 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
603 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
604 if (o->short_name && !strcmp(argv[0] + 1, o->short_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
605 || o->long_name && !strcmp(argv[0] + 1, o->long_name)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
606 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
607 } |
0 | 608 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
609 // If this option has the "1" flag but pass is not 1 |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
610 // or it doesn't but pass is 1, ignore it. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
611 ignore = (o->flags != NULL && strchr(o->flags, '1')) != (pass == 1); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
612 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
613 switch (o->type) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
614 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
615 case OPT_BOOLEAN: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
616 if (argv[0][0] == '-') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
617 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
618 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
619 *((bool *) (o->data_ptr)) = true; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
620 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
621 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
622 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
623 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
624 *((bool *) (o->data_ptr)) = false; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
625 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
626 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
627 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
628 case OPT_CONFIRM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
629 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
630 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
631 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
632 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
633 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
634 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
635 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
636 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
637 *((confirm_t *) o->data_ptr) = confirm_e2i(argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
638 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
639 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
640 case OPT_INTEGER: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
641 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
642 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
643 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
644 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
645 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
646 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
647 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
648 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
649 *((int *) (o->data_ptr)) = atoi(argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
650 break; |
0 | 651 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
652 case OPT_UNSIGNED: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
653 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
654 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
655 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
656 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
657 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
658 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
659 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
660 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
661 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
662 const char *value = argv[0]; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
663 if (*value == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
664 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
665 err("not an unsigned integer \"%s\"", value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
666 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
667 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
668 bool neg = false; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
669 if (*value == '-') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
670 neg = true; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
671 char *endptr; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
672 errno = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
673 *((unsigned long *) (o->data_ptr)) = |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
674 strtoul(value, &endptr, 0); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
675 while (*endptr != '\0' && isspace(*endptr)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
676 endptr++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
677 if (*endptr != '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
678 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
679 err("illegal characters in unsigned int \"%s\"", endptr); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
680 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
681 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
682 /* strtoul() sets errno to ERANGE if overflow. In |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
683 addition, we don't want any non-zero negative |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
684 numbers. In terms of regexp, /^(0x)?0*$/i. */ |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
685 if (errno != 0 |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
686 || neg |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
687 && ! |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
688 (strspn(value + 1, "0") == strlen(value + 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
689 || value[1] == '0' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
690 && tolower(value[2]) == 'x' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
691 && strspn(value + 3, "0") == strlen(value + 3))) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
692 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
693 err("unsigned integer out of range \"%s\"", value); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
694 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
695 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
696 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
697 break; |
0 | 698 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
699 case OPT_WINDIM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
700 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
701 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
702 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
703 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
704 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
705 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
706 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
707 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
708 if (((Win_dim *) (o->data_ptr))->set(argv[0])) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
709 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
710 err("bad dimension spec \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
711 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
712 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
713 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
714 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
715 case OPT_STRINGBUF8: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
716 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
717 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
718 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
719 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
720 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
721 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
722 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
723 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
724 al_scps((char *) o->data_ptr, argv[0], 8); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
725 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
726 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
727 case OPT_STRINGPTR: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
728 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
729 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
730 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
731 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
732 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
733 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
734 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
735 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
736 *((const char **) (o->data_ptr)) = argv[0]; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
737 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
738 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
739 case OPT_STRINGPTRACC: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
740 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
741 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
742 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
743 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
744 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
745 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
746 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
747 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
748 append_item_to_list((const char ***) o->data_ptr, argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
749 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
750 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
751 case OPT_STRINGPTRLIST: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
752 if (argc <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
753 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
754 err("missing argument after \"%s\"", argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
755 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
756 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
757 while (argc > 1 && argv[1][0] != '-' && argv[1][0] != '+') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
758 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
759 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
760 argc--; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
761 if (o->data_ptr && !ignore) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
762 append_item_to_list((const char ***) o->data_ptr, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
763 argv[0]); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
764 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
765 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
766 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
767 default: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
768 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
769 nf_bug("unknown option type (%d)", (int) o->type); |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
770 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
771 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
772 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
773 argv++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
774 argc--; |
0 | 775 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
776 return 0; |
0 | 777 } |
778 | |
779 | |
780 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
781 * dump_parameters |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
782 * Print a list of the parameters with their current value. |
0 | 783 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
784 void dump_parameters(FILE * fp) |
0 | 785 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
786 const OptionDesc *o; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
787 int desc_maxlen = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
788 int name_maxlen = 0; |
0 | 789 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
790 for (o = options + 1; o->type != OPT_END; o++) |
0 | 791 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
792 int len = strlen(o->desc); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
793 desc_maxlen = al_amax(desc_maxlen, len); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
794 if (o->long_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
795 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
796 len = strlen(o->long_name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
797 name_maxlen = al_amax(name_maxlen, len); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
798 } |
0 | 799 } |
800 | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
801 for (o = options + 1; o->type != OPT_END; o++) |
0 | 802 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
803 if (!o->long_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
804 continue; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
805 fprintf(fp, "%-*s %-*s ", name_maxlen, o->long_name, desc_maxlen, |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
806 o->desc); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
807 if (o->type == OPT_BOOLEAN) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
808 fprintf(fp, "%s", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
809 *((bool *) o->data_ptr) ? "enabled" : "disabled"); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
810 else if (o->type == OPT_CONFIRM) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
811 fputs(confirm_i2e(*((confirm_t *) o->data_ptr)), fp); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
812 else if (o->type == OPT_STRINGBUF8) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
813 fprintf(fp, "\"%s\"", (char *) o->data_ptr); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
814 else if (o->type == OPT_STRINGPTR) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
815 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
816 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
817 fprintf(fp, "\"%s\"", *((char **) o->data_ptr)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
818 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
819 fprintf(fp, "--none--"); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
820 } |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
821 else if (o->type == OPT_INTEGER) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
822 fprintf(fp, "%d", *((int *) o->data_ptr)); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
823 else if (o->type == OPT_UNSIGNED) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
824 fprintf(fp, "%lu", *((unsigned long *) o->data_ptr)); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
825 else if (o->type == OPT_WINDIM) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
826 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
827 char buf[50]; // Much slack |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
828 ((Win_dim *) (o->data_ptr))->string(buf, sizeof buf); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
829 fputs(buf, fp); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
830 } |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
831 else if (o->type == OPT_STRINGPTRACC |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
832 || o->type == OPT_STRINGPTRLIST) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
833 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
834 if (o->data_ptr) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
835 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
836 char **list; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
837 for (list = *((char ***) o->data_ptr); list && *list; list++) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
838 fprintf(fp, "\"%s\" ", *list); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
839 if (list == *((char ***) o->data_ptr)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
840 fprintf(fp, "--none--"); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
841 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
842 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
843 fprintf(fp, "--none--"); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
844 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
845 fputc('\n', fp); |
0 | 846 } |
847 } | |
848 | |
849 | |
850 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
851 * dump_command_line_options |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
852 * Print a list of all command line options (usage message). |
0 | 853 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
854 void dump_command_line_options(FILE * fd) |
0 | 855 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
856 const OptionDesc *o; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
857 int desc_maxlen = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
858 int name_maxlen = 0; |
0 | 859 |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
860 for (o = options + 1; o->type != OPT_END; o++) |
0 | 861 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
862 int len; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
863 if (!o->short_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
864 continue; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
865 len = strlen(o->desc); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
866 desc_maxlen = al_amax(desc_maxlen, len); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
867 if (o->long_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
868 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
869 len = strlen(o->long_name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
870 name_maxlen = al_amax(name_maxlen, len); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
871 } |
0 | 872 } |
873 | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
874 for (o = options; o->type != OPT_END; o++) |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
875 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
876 if (!o->short_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
877 continue; |
0 | 878 #if ! defined Y_X11 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
879 if (o->flags && strchr(o->flags, 'x')) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
880 continue; |
0 | 881 #endif |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
882 if (o->short_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
883 fprintf(fd, " -%-3s ", o->short_name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
884 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
885 fprintf(fd, " "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
886 if (o->long_name) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
887 fprintf(fd, "-%-*s ", name_maxlen, o->long_name); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
888 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
889 fprintf(fd, "%*s", name_maxlen + 2, ""); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
890 switch (o->type) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
891 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
892 case OPT_BOOLEAN: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
893 fprintf(fd, " "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
894 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
895 case OPT_CONFIRM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
896 fprintf(fd, "yes|no|ask "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
897 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
898 case OPT_STRINGBUF8: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
899 case OPT_STRINGPTR: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
900 case OPT_STRINGPTRACC: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
901 fprintf(fd, "<string> "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
902 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
903 case OPT_INTEGER: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
904 fprintf(fd, "<integer> "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
905 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
906 case OPT_UNSIGNED: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
907 fprintf(fd, "<unsigned> "); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
908 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
909 case OPT_WINDIM: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
910 fprintf(fd, "<integer>[%%]"); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
911 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
912 case OPT_STRINGPTRLIST: |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
913 fprintf(fd, "<string> ..."); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
914 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
915 case OPT_END:; // This line is here only to silence a GCC warning. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
916 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
917 fprintf(fd, " %s\n", o->desc); |
0 | 918 } |
919 } | |
920 | |
921 | |
922 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
923 * confirm_e2i |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
924 * Convert the external representation of a confirmation |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
925 * flag ("yes", "no", "ask", "ask_once") to the internal |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
926 * representation (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE or |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
927 * '\0' if none). |
0 | 928 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
929 static confirm_t confirm_e2i(const char *external) |
0 | 930 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
931 if (external != NULL) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
932 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
933 if (!strcmp(external, "yes")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
934 return YC_YES; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
935 if (!strcmp(external, "no")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
936 return YC_NO; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
937 if (!strcmp(external, "ask")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
938 return YC_ASK; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
939 if (!strcmp(external, "ask_once")) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
940 return YC_ASK_ONCE; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
941 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
942 return YC_ASK; |
0 | 943 } |
944 | |
945 | |
946 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
947 * confirm_i2e |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
948 * Convert the internal representation of a confirmation |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
949 * flag (YC_YES, YC_NO, YC_ASK, YC_ASK_ONCE) to the external |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
950 * representation ("yes", "no", "ask", "ask_once" or "?"). |
0 | 951 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
952 static const char *confirm_i2e(confirm_t internal) |
0 | 953 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
954 if (internal == YC_YES) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
955 return "yes"; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
956 if (internal == YC_NO) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
957 return "no"; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
958 if (internal == YC_ASK) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
959 return "ask"; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
960 if (internal == YC_ASK_ONCE) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
961 return "ask_once"; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
962 return "?"; |
0 | 963 } |
964 | |
965 | |
966 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
967 * append_item_to_list |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
968 * Append a string to a null-terminated string list |
0 | 969 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
970 static void append_item_to_list(const char ***list, const char *item) |
0 | 971 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
972 int i; |
0 | 973 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
974 i = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
975 if (*list != 0) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
976 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
977 // Count the number of elements in the list (last = null) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
978 while ((*list)[i] != 0) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
979 i++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
980 // Expand the list |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
981 *list = (const char **) ResizeMemory(*list, (i + 2) * sizeof **list); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
982 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
983 else |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
984 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
985 // Create a new list |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
986 *list = (const char **) GetMemory(2 * sizeof **list); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
987 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
988 // Append the new element |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
989 (*list)[i] = item; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
990 (*list)[i + 1] = 0; |
0 | 991 } |
992 | |
993 | |
994 #include <string> | |
995 #include <vector> | |
996 | |
997 const size_t MAX_TOKENS = 10; | |
998 | |
999 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1000 * word_splitting - perform word splitting on a string |
0 | 1001 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1002 int word_splitting(std::vector < std::string > &tokens, const char *string) |
0 | 1003 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1004 size_t ntokens = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1005 const char *iptr = string; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1006 const char *token_start = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1007 bool in_token = false; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1008 bool quoted = false; |
0 | 1009 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1010 /* break the line into whitespace-separated tokens. |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1011 whitespace can be enclosed in double quotes. */ |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1012 for (;; iptr++) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1013 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1014 if (*iptr == '\n' || *iptr == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1015 break; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1016 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1017 else if (*iptr == '"') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1018 quoted = !quoted; |
0 | 1019 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1020 // "#" at the beginning of a token |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1021 else if (!in_token && !quoted && *iptr == '#') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1022 break; |
0 | 1023 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1024 // First character of token |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1025 else if (!in_token && (quoted || !isspace(*iptr))) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1026 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1027 ntokens++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1028 if (ntokens > MAX_TOKENS) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1029 return 2; // Too many tokens |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1030 in_token = true; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1031 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1032 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1033 // First space between two tokens |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1034 else if (in_token && !quoted && isspace(*iptr)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1035 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1036 tokens.push_back(std::string(token_start, iptr - token_start)); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1037 in_token = false; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1038 } |
0 | 1039 } |
1040 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1041 if (in_token) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1042 tokens.push_back(std::string(token_start, iptr - token_start)); |
0 | 1043 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1044 if (quoted) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1045 return 1; // Unmatched double quote |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
1046 return 0; |
0 | 1047 } |