/[public]/psiconv/trunk/lib/psiconv/configuration.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/configuration.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 199 Revision 200
71 71
72 if (!(strcasecmp(var,"verbosity"))) { 72 if (!(strcasecmp(var,"verbosity"))) {
73 if ((value >= 1) && (value <= 4)) 73 if ((value >= 1) && (value <= 4))
74 (*config)->verbosity = value; 74 (*config)->verbosity = value;
75 else 75 else
76 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 76 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
77 "Verbosity should be between 1 and 5",filename,linenr); 77 "Verbosity should be between 1 and 5",filename,linenr);
78 } else if (!(strcasecmp(var,"color"))) { 78 } else if (!(strcasecmp(var,"color"))) {
79 if ((value == 0) || (value == 1)) 79 if ((value == 0) || (value == 1))
80 (*config)->color = value; 80 (*config)->color = value;
81 else 81 else
82 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 82 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
83 "Color should be 0 or 1",filename,linenr); 83 "Color should be 0 or 1",filename,linenr);
84 } else if (!(strcasecmp(var,"colordepth"))) { 84 } else if (!(strcasecmp(var,"colordepth"))) {
85 if ((value > 0) && (value <= 32)) 85 if ((value > 0) && (value <= 32))
86 (*config)->colordepth = value; 86 (*config)->colordepth = value;
87 else 87 else
88 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 88 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
89 "ColorDepth should be between 1 and 32",filename,linenr); 89 "ColorDepth should be between 1 and 32",filename,linenr);
90 } else if (!(strcasecmp(var,"redbits"))) { 90 } else if (!(strcasecmp(var,"redbits"))) {
91 if ((value >= 0) && (value <= 32)) 91 if ((value >= 0) && (value <= 32))
92 (*config)->redbits = value; 92 (*config)->redbits = value;
93 else 93 else
94 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 94 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
95 "RedBits should be between 1 and 32 or 0",filename,linenr); 95 "RedBits should be between 1 and 32 or 0",filename,linenr);
96 } else if (!(strcasecmp(var,"greenbits"))) { 96 } else if (!(strcasecmp(var,"greenbits"))) {
97 if ((value >= 0) && (value <= 32)) 97 if ((value >= 0) && (value <= 32))
98 (*config)->greenbits = value; 98 (*config)->greenbits = value;
99 else 99 else
100 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 100 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
101 "GreenBits should be between 1 and 32 or 0",filename,linenr); 101 "GreenBits should be between 1 and 32 or 0",filename,linenr);
102 } else if (!(strcasecmp(var,"bluebits"))) { 102 } else if (!(strcasecmp(var,"bluebits"))) {
103 if ((value >= 0) && (value <= 32)) 103 if ((value >= 0) && (value <= 32))
104 (*config)->bluebits = value; 104 (*config)->bluebits = value;
105 else 105 else
106 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 106 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
107 "BlueBits should be between 1 and 32 or 0",filename,linenr); 107 "BlueBits should be between 1 and 32 or 0",filename,linenr);
108 } else if (!(strcasecmp(var,"characterset"))) { 108 } else if (!(strcasecmp(var,"characterset"))) {
109 if ((value >= 0) && (value <= 1)) 109 if ((value >= 0) && (value <= 1))
110 psiconv_unicode_select_characterset(*config,value); 110 psiconv_unicode_select_characterset(*config,value);
111 else 111 else
112 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 112 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
113 "CharacterSet should be between 0 and 0", 113 "CharacterSet should be between 0 and 0",
114 filename,linenr); 114 filename,linenr);
115 } else if (!(strcasecmp(var,"unknownunicodechar"))) { 115 } else if (!(strcasecmp(var,"unknownunicodechar"))) {
116 if ((value >= 1) && (value < 0x10000)) 116 if ((value >= 1) && (value < 0x10000))
117 (*config)->unknown_unicode_char = value; 117 (*config)->unknown_unicode_char = value;
118 else 118 else
119 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 119 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
120 "UnknownUnicodeChar should be between 1 and 65535", 120 "UnknownUnicodeChar should be between 1 and 65535",
121 filename,linenr); 121 filename,linenr);
122 } else if (!(strcasecmp(var,"unknownepocchar"))) { 122 } else if (!(strcasecmp(var,"unknownepocchar"))) {
123 if ((value >= 1) && (value < 0x100)) 123 if ((value >= 1) && (value < 0x100))
124 (*config)->unknown_epoc_char = value; 124 (*config)->unknown_epoc_char = value;
125 else 125 else
126 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 126 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
127 "UnknownEPOCChar should be between 1 and 255", 127 "UnknownEPOCChar should be between 1 and 255",
128 filename,linenr); 128 filename,linenr);
129 } else if (sscanf(var,"char%d",&charnr) == strlen(var)) { 129 } else if (sscanf(var,"char%d",&charnr) == strlen(var)) {
130 if ((charnr < 0) || (charnr > 255)) 130 if ((charnr < 0) || (charnr > 255))
131 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 131 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
132 "CharXXX should have XXX between 0 and 255", 132 "CharXXX should have XXX between 0 and 255",
133 filename,linenr); 133 filename,linenr);
134 if ((value >= 1) && (value <= 0x10000)) 134 if ((value >= 1) && (value <= 0x10000))
135 (*config)->unicode_table[charnr] = value; 135 (*config)->unicode_table[charnr] = value;
136 else 136 else
137 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 137 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
138 "CharXXX should be between 1 and 65535", 138 "CharXXX should be between 1 and 65535",
139 filename,linenr); 139 filename,linenr);
140 } else { 140 } else {
141 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 141 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
142 "Unknown variable %s",filename,linenr,var); 142 "Unknown variable %s",filename,linenr,var);
143 } 143 }
144 psiconv_debug(*config,0,0,"Configuration file %s, line %d: " 144 psiconv_debug(*config,0,0,"Configuration file %s, line %d: "
145 "Set variable %s to %d",filename,linenr,var,value); 145 "Set variable %s to %d",filename,linenr,var,value);
146} 146}
162 return; 162 return;
163 eovar = sovar; 163 eovar = sovar;
164 while (line[eovar] && (((line[eovar] >= 'A') && (line[eovar] <= 'Z')) || 164 while (line[eovar] && (((line[eovar] >= 'A') && (line[eovar] <= 'Z')) ||
165 ((line[eovar] >= 'a') && (line[eovar] <= 'z')))) 165 ((line[eovar] >= 'a') && (line[eovar] <= 'z'))))
166 eovar ++; 166 eovar ++;
167 if (sovar == eovar) 167 if (sovar == eovar) {
168 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 168 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
169 "Syntax error (no variable found)",filename,linenr); 169 "Syntax error (no variable found)",filename,linenr);
170 return;
171 }
170 soval = eovar; 172 soval = eovar;
171 while (line[soval] && (line[soval] <= 32)) 173 while (line[soval] && (line[soval] <= 32))
172 soval ++; 174 soval ++;
173 if (line[soval] != '=') 175 if (line[soval] != '=') {
174 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 176 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
175 "Syntax error (no = token found)",filename,linenr); 177 "Syntax error (no = token found)",filename,linenr);
178 return;
179 }
176 soval ++; 180 soval ++;
177 while (line[soval] && (line[soval] <= 32)) 181 while (line[soval] && (line[soval] <= 32))
178 soval ++; 182 soval ++;
179 eoval = soval; 183 eoval = soval;
180 while (line[eoval] && ((line[eoval] >= '0') && (line[eovar] <= '9'))) 184 while (line[eoval] && ((line[eoval] >= '0') && (line[eovar] <= '9')))
181 eoval ++; 185 eoval ++;
182 if (eoval == soval) 186 if (eoval == soval) {
183 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 187 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
184 "Syntax error (no value found)",filename,linenr); 188 "Syntax error (no value found)",filename,linenr);
189 return;
190 }
185 if (soval - eoval > 7) 191 if (soval - eoval > 7) {
186 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 192 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
187 "Syntax error (value too large)",filename,linenr); 193 "Syntax error (value too large)",filename,linenr);
194 return;
195 }
188 eol = eoval; 196 eol = eoval;
189 while (line[eol] && (line[eol] < 32)) 197 while (line[eol] && (line[eol] < 32))
190 eol ++; 198 eol ++;
191 if (line[eol]) 199 if (line[eol]) {
192 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 200 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
193 "Syntax error (trailing garbage)",filename,linenr); 201 "Syntax error (trailing garbage)",filename,linenr);
202 return;
203 }
194 204
195 var = malloc(eovar - sovar + 1); 205 var = malloc(eovar - sovar + 1);
196 memcpy(var,line + sovar, eovar - sovar); 206 memcpy(var,line + sovar, eovar - sovar);
197 var[eovar-sovar] = 0; 207 var[eovar-sovar] = 0;
198 208
213 psiconv_progress(*config,0,0, 223 psiconv_progress(*config,0,0,
214 "Going to access configuration file %s",filename); 224 "Going to access configuration file %s",filename);
215 225
216 /* Try to open the file; it may fail, if it does not exist for example */ 226 /* Try to open the file; it may fail, if it does not exist for example */
217 if ((file = open(filename,O_RDONLY)) == -1) 227 if ((file = open(filename,O_RDONLY)) == -1)
218 return; 228 goto ERROR0;
219 229
220 /* Read the contents of the file into filebuffer. This may fail */ 230 /* Read the contents of the file into filebuffer. This may fail */
221 if (fstat(file,&stat_buf)) { 231 if (fstat(file,&stat_buf)) {
222 if (close(file)) 232 if (close(file))
223 psiconv_fatal(*config,0,0,"Configuration file %s: " 233 psiconv_error(*config,0,0,"Configuration file %s: "
224 "Couldn't close file",filename); 234 "Couldn't close file",filename);
225 return; 235 return;
226 } 236 }
227 237
228 filesize = stat_buf.st_size; 238 filesize = stat_buf.st_size;
229 if (!(filebuffer = malloc(filesize + 1))) 239 if (!(filebuffer = malloc(filesize + 1))) {
230 psiconv_fatal(*config,0,0,"Configuration file %s: " 240 psiconv_error(*config,0,0,"Configuration file %s: "
231 "Out of memory error",filename); 241 "Out of memory error",filename);
242 goto ERROR1;
243 }
244
232 filebuffer_ptr = filebuffer; 245 filebuffer_ptr = filebuffer;
233 bytes_left = filesize; 246 bytes_left = filesize;
234 bytes_read = 1; /* Dummy for the first time through the loop */ 247 bytes_read = 1; /* Dummy for the first time through the loop */
235 while ((bytes_read > 0) && bytes_left) { 248 while ((bytes_read > 0) && bytes_left) {
236 bytes_read = read(file,filebuffer_ptr,bytes_left); 249 bytes_read = read(file,filebuffer_ptr,bytes_left);
240 } 253 }
241 } 254 }
242 255
243 /* On NFS, the first read may fail and this is not fatal */ 256 /* On NFS, the first read may fail and this is not fatal */
244 if (bytes_left && (bytes_left != filesize)) { 257 if (bytes_left && (bytes_left != filesize)) {
245 psiconv_fatal(*config,0,0,"Configuration file %s: " 258 psiconv_error(*config,0,0,"Configuration file %s: "
246 "Couldn't read file into memory",filename); 259 "Couldn't read file into memory",filename);
260 goto ERROR2;
247 } 261 }
248 262
249 if (close(file)) 263 if (close(file)) {
250 psiconv_fatal(*config,0,0,"Configuration file %s: " 264 psiconv_error(*config,0,0,"Configuration file %s: "
251 "Couldn't close file",filename); 265 "Couldn't close file",filename);
266 file = -1;
267 goto ERROR2;
268 }
269 file = -1;
252 270
253 psiconv_progress(*config,0,0, 271 psiconv_progress(*config,0,0,
254 "Going to parse configuration file %s: ",filename); 272 "Going to parse configuration file %s: ",filename);
255 /* Now we walk through the file to isolate lines */ 273 /* Now we walk through the file to isolate lines */
256 linenr = 0; 274 linenr = 0;
261 eol = sol; 279 eol = sol;
262 while ((eol < filesize) && (filebuffer[eol] != 13) && 280 while ((eol < filesize) && (filebuffer[eol] != 13) &&
263 (filebuffer[eol] != 10) && (filebuffer[eol] != 0)) 281 (filebuffer[eol] != 10) && (filebuffer[eol] != 0))
264 eol ++; 282 eol ++;
265 283
266 if ((eol < filesize) && (filebuffer[eol] == 0)) 284 if ((eol < filesize) && (filebuffer[eol] == 0)) {
267 psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " 285 psiconv_error(*config,0,0,"Configuration file %s, line %d: "
268 "Unexpected character \000 found",filename,linenr); 286 "Unexpected character \000 found",filename,linenr);
287 goto ERROR2;
288 }
269 if ((eol < filesize + 1) && 289 if ((eol < filesize + 1) &&
270 (((filebuffer[eol] == 13) && (filebuffer[eol+1] == 10)) || 290 (((filebuffer[eol] == 13) && (filebuffer[eol+1] == 10)) ||
271 ((filebuffer[eol] == 10) && (filebuffer[eol+1] == 13)))) { 291 ((filebuffer[eol] == 10) && (filebuffer[eol+1] == 13)))) {
272 filebuffer[eol] = 0; 292 filebuffer[eol] = 0;
273 eol ++; 293 eol ++;
275 filebuffer[eol] = 0; 295 filebuffer[eol] = 0;
276 psiconv_config_parse_line(filename,linenr,filebuffer + sol,config); 296 psiconv_config_parse_line(filename,linenr,filebuffer + sol,config);
277 sol = eol+1; 297 sol = eol+1;
278 } 298 }
279 free(filebuffer); 299 free(filebuffer);
300 return;
301
302ERROR2:
303 free(filebuffer);
304ERROR1:
305 if ((file != -1) && close(file))
306 psiconv_error(*config,0,0,"Configuration file %s: "
307 "Couldn't close file",filename);
308ERROR0:
309 return;
280} 310}
281 311
282void psiconv_config_read(const char *extra_config_files, 312void psiconv_config_read(const char *extra_config_files,
283 psiconv_config *config) 313 psiconv_config *config)
284{ 314{

Legend:
Removed from v.199  
changed lines
  Added in v.200

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26