--- psiconv/trunk/lib/psiconv/configuration.c 2004/02/04 14:37:53 199 +++ psiconv/trunk/lib/psiconv/configuration.c 2004/02/04 15:28:56 200 @@ -73,72 +73,72 @@ if ((value >= 1) && (value <= 4)) (*config)->verbosity = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Verbosity should be between 1 and 5",filename,linenr); } else if (!(strcasecmp(var,"color"))) { if ((value == 0) || (value == 1)) (*config)->color = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Color should be 0 or 1",filename,linenr); } else if (!(strcasecmp(var,"colordepth"))) { if ((value > 0) && (value <= 32)) (*config)->colordepth = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "ColorDepth should be between 1 and 32",filename,linenr); } else if (!(strcasecmp(var,"redbits"))) { if ((value >= 0) && (value <= 32)) (*config)->redbits = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "RedBits should be between 1 and 32 or 0",filename,linenr); } else if (!(strcasecmp(var,"greenbits"))) { if ((value >= 0) && (value <= 32)) (*config)->greenbits = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "GreenBits should be between 1 and 32 or 0",filename,linenr); } else if (!(strcasecmp(var,"bluebits"))) { if ((value >= 0) && (value <= 32)) (*config)->bluebits = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "BlueBits should be between 1 and 32 or 0",filename,linenr); } else if (!(strcasecmp(var,"characterset"))) { if ((value >= 0) && (value <= 1)) psiconv_unicode_select_characterset(*config,value); else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "CharacterSet should be between 0 and 0", filename,linenr); } else if (!(strcasecmp(var,"unknownunicodechar"))) { if ((value >= 1) && (value < 0x10000)) (*config)->unknown_unicode_char = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "UnknownUnicodeChar should be between 1 and 65535", filename,linenr); } else if (!(strcasecmp(var,"unknownepocchar"))) { if ((value >= 1) && (value < 0x100)) (*config)->unknown_epoc_char = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "UnknownEPOCChar should be between 1 and 255", filename,linenr); } else if (sscanf(var,"char%d",&charnr) == strlen(var)) { if ((charnr < 0) || (charnr > 255)) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "CharXXX should have XXX between 0 and 255", filename,linenr); if ((value >= 1) && (value <= 0x10000)) (*config)->unicode_table[charnr] = value; else - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "CharXXX should be between 1 and 65535", filename,linenr); } else { - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Unknown variable %s",filename,linenr,var); } psiconv_debug(*config,0,0,"Configuration file %s, line %d: " @@ -164,33 +164,43 @@ while (line[eovar] && (((line[eovar] >= 'A') && (line[eovar] <= 'Z')) || ((line[eovar] >= 'a') && (line[eovar] <= 'z')))) eovar ++; - if (sovar == eovar) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + if (sovar == eovar) { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Syntax error (no variable found)",filename,linenr); + return; + } soval = eovar; while (line[soval] && (line[soval] <= 32)) soval ++; - if (line[soval] != '=') - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + if (line[soval] != '=') { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Syntax error (no = token found)",filename,linenr); + return; + } soval ++; while (line[soval] && (line[soval] <= 32)) soval ++; eoval = soval; while (line[eoval] && ((line[eoval] >= '0') && (line[eovar] <= '9'))) eoval ++; - if (eoval == soval) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + if (eoval == soval) { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Syntax error (no value found)",filename,linenr); - if (soval - eoval > 7) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + return; + } + if (soval - eoval > 7) { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Syntax error (value too large)",filename,linenr); + return; + } eol = eoval; while (line[eol] && (line[eol] < 32)) eol ++; - if (line[eol]) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + if (line[eol]) { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Syntax error (trailing garbage)",filename,linenr); + return; + } var = malloc(eovar - sovar + 1); memcpy(var,line + sovar, eovar - sovar); @@ -215,20 +225,23 @@ /* Try to open the file; it may fail, if it does not exist for example */ if ((file = open(filename,O_RDONLY)) == -1) - return; + goto ERROR0; /* Read the contents of the file into filebuffer. This may fail */ if (fstat(file,&stat_buf)) { if (close(file)) - psiconv_fatal(*config,0,0,"Configuration file %s: " + psiconv_error(*config,0,0,"Configuration file %s: " "Couldn't close file",filename); return; } filesize = stat_buf.st_size; - if (!(filebuffer = malloc(filesize + 1))) - psiconv_fatal(*config,0,0,"Configuration file %s: " + if (!(filebuffer = malloc(filesize + 1))) { + psiconv_error(*config,0,0,"Configuration file %s: " "Out of memory error",filename); + goto ERROR1; + } + filebuffer_ptr = filebuffer; bytes_left = filesize; bytes_read = 1; /* Dummy for the first time through the loop */ @@ -242,13 +255,18 @@ /* On NFS, the first read may fail and this is not fatal */ if (bytes_left && (bytes_left != filesize)) { - psiconv_fatal(*config,0,0,"Configuration file %s: " + psiconv_error(*config,0,0,"Configuration file %s: " "Couldn't read file into memory",filename); + goto ERROR2; } - if (close(file)) - psiconv_fatal(*config,0,0,"Configuration file %s: " + if (close(file)) { + psiconv_error(*config,0,0,"Configuration file %s: " "Couldn't close file",filename); + file = -1; + goto ERROR2; + } + file = -1; psiconv_progress(*config,0,0, "Going to parse configuration file %s: ",filename); @@ -263,9 +281,11 @@ (filebuffer[eol] != 10) && (filebuffer[eol] != 0)) eol ++; - if ((eol < filesize) && (filebuffer[eol] == 0)) - psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " + if ((eol < filesize) && (filebuffer[eol] == 0)) { + psiconv_error(*config,0,0,"Configuration file %s, line %d: " "Unexpected character \000 found",filename,linenr); + goto ERROR2; + } if ((eol < filesize + 1) && (((filebuffer[eol] == 13) && (filebuffer[eol+1] == 10)) || ((filebuffer[eol] == 10) && (filebuffer[eol+1] == 13)))) { @@ -277,6 +297,16 @@ sol = eol+1; } free(filebuffer); + return; + +ERROR2: + free(filebuffer); +ERROR1: + if ((file != -1) && close(file)) + psiconv_error(*config,0,0,"Configuration file %s: " + "Couldn't close file",filename); +ERROR0: + return; } void psiconv_config_read(const char *extra_config_files,