Changeset 1422 in MondoRescue for branches/stable/mondo/src/lib/mr_conf.c


Ignore:
Timestamp:
May 9, 2007, 11:02:24 AM (17 years ago)
Author:
Bruno Cornec
Message:

mr_conf now handles # inside strings correctly (before they were considered as a comment which they are not !)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/lib/mr_conf.c

    r1264 r1422  
    6767/*"private" members declarations*/
    6868static size_t mr_conf_filesize(const char *name);
    69 static void mr_conf_error_msg(int error_code, const char *add_line);
     69#define mr_conf_error_msg(x, y) {mr_conf_error_msg_int(x, y, __LINE__,__FILE__);}
     70static void mr_conf_error_msg_int(int error_code, const char *add_line, int line, const char *file);
    7071static void mr_conf_remove_comments(void);
    7172static int mr_conf_check_int_flag(const int flag);
     
    284285    size_t i;                   /*iterator */
    285286    size_t k;                   /*conditioned iterator for tmp_buffer */
     287    bool found_quote = FALSE;
    286288
    287289    length = strlen(buffer);
     
    291293    i = 0;
    292294    while (i < length) {
    293         if (buffer[i] != MRCONF_COMM_CHAR) {
     295        /* Handle quotes */
     296        if (buffer[i] = '"') {
     297            if (found_quote) {
     298                found_quote = FALSE;
     299            } else {
     300                found_quote = TRUE;
     301            }
     302        if ((buffer[i] != MRCONF_COMM_CHAR) && (! found_quote)){
    294303            k++;
    295304            i++;
     
    306315    i = 0;
    307316    while (i < length) {
    308         if (buffer[i] != MRCONF_COMM_CHAR) {
     317        if (buffer[i] = '"') {
     318            if (found_quote) {
     319                found_quote = FALSE;
     320            } else {
     321                found_quote = TRUE;
     322            }
     323        if ((buffer[i] != MRCONF_COMM_CHAR) && (! found_quote)){
    309324            tmp_buf[k++] = buffer[i++];
    310325        } else {
     
    352367
    353368/*output error message*/
    354 static void mr_conf_error_msg(int error_code, const char *add_line) {
     369static void mr_conf_error_msg_int(int error_code, const char *add_line, int line, const char *file) {
    355370    if ((mr_conf_flags & MRCONF_FLAG_VERBOSE)) {    /*if verbose mode */
    356371        switch (error_code) {
    357372        case MRCONF_BAD_FILE:
    358             mr_msg(0,"%s %s %s\n", MRCONF_STR_ERROR, MRCONF_STR_BAD_FILE,
     373            mr_msg_int(0,line,file,"%s %s %s\n", MRCONF_STR_ERROR, MRCONF_STR_BAD_FILE,
    359374                   add_line);
    360375            break;
    361376
    362377        case MRCONF_READING_FAILED:
    363             mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_READING_FAILED);
     378            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_READING_FAILED);
    364379            break;
    365380
    366381        case MRCONF_FIELD_NOT_FOUND:
    367             mr_msg(0,"%s %s \"%s\"\n", MRCONF_STR_ERROR, MRCONF_STR_FIELD_NOT_FOUND, add_line);
    368             mr_msg(0,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_SET_TO_ZERO);
     382            mr_msg_int(0,line,file,"%s %s \"%s\"\n", MRCONF_STR_ERROR, MRCONF_STR_FIELD_NOT_FOUND, add_line);
     383            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_SET_TO_ZERO);
    369384            break;
    370385
    371386        case MRCONF_FIELD_NO_VALUE:
    372             mr_msg(0,"%s %s \"%s\"\n", MRCONF_STR_ERROR, MRCONF_STR_FIELD_NO_VALUE, add_line);
    373             mr_msg(0,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_IGNORE);
     387            mr_msg_int(0,line,file,"%s %s \"%s\"\n", MRCONF_STR_ERROR, MRCONF_STR_FIELD_NO_VALUE, add_line);
     388            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_IGNORE);
    374389            break;
    375390
    376391        case MRCONF_CLOSE_BUT_NOT_OPEN:
    377             mr_msg(0,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_CLOSE_BUT_NOT_OPEN);
     392            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_CLOSE_BUT_NOT_OPEN);
    378393            break;
    379394
    380395        case MRCONF_CALL_BUT_NOT_OPEN:
    381             mr_msg(0,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_CALL_BUT_NOT_OPEN);
     396            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_WARNING, MRCONF_STR_CALL_BUT_NOT_OPEN);
    382397            break;
    383398
    384399        case MRCONF_OPEN_OPENED:
    385             mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_OPEN_OPENED);
     400            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_OPEN_OPENED);
    386401            break;
    387402
    388403        case MRCONF_STRING_QUOTE:
    389             mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_STRING_QUOTE);
     404            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_STRING_QUOTE);
    390405            break;
    391406
    392407        default:
    393             mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_DEFAULT_ERROR);
    394             break;
    395         }
    396     }
    397 }
     408            mr_msg_int(0,line,file,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_DEFAULT_ERROR);
     409            break;
     410        }
     411    }
     412}
Note: See TracChangeset for help on using the changeset viewer.