Ignore:
Timestamp:
Jun 20, 2008, 2:09:15 PM (15 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Last configuration file line was not handled
  • Added 'screensaver_timeout' to configuration file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/configuration.c

    r2463 r2464  
    3030    FILE *fp;
    3131    struct stat st;
    32     int size = 0, i = 0, total = 0, offset = 0;
     32    int size = 0, i = 0, total = 0, offset = 0, l = 1;
    3333    char *buffer = NULL;
    3434
     
    5353    }
    5454
    55     buffer = malloc(size);
     55    buffer = malloc(size + 1);
    5656    if(!buffer)
    5757    {
     
    6565        total+=i;
    6666    }
     67    buffer[total] = '\n';
    6768
    6869    fclose(fp);
     
    7576    {
    7677        offset+=i;
     78        l++;
    7779    }
    7880
     
    167169        line = realloc(line, l+1);
    168170        line[l] = 0;
     171
    169172        get_key_value(line, option);
    170173
     
    183186int get_key_value(char *line, struct option *option)
    184187{
    185     unsigned int i, o = 0, b=0;
     188    unsigned int i, o = 0, b=0, end_spaces = 0;
    186189    char *cur = NULL;
    187190    option->value = NULL;
     
    204207        if(line[i] == ' ' && !b) continue;
    205208
     209
    206210        if(line[i] == '=')
    207211        {
    208212            b = 0;
    209             cur[o] = 0;
     213            cur[o-end_spaces] = 0;
     214            cur = realloc(cur, (o-end_spaces)+1);
    210215            o = 0;
    211216            option->key = cur;
     
    214219        else
    215220        {
     221            if(line[i] == ' ') end_spaces++;
     222            else end_spaces = 0;
     223
    216224            cur = realloc(cur, o+2);
    217225            if(!cur)
     
    223231            o++;
    224232            b = 1;
     233
    225234        }
    226235    }
     
    228237    cur[o] = 0;
    229238    option->value = cur;
     239
     240
    230241    return 0;
    231242}
    232243
    233244
    234 #define IS_TOKEN(t) (!strncmp(option->key, t, strlen(t)))
    235 #define IS_VALUE(t) (!strncmp(option->value, t, strlen(t)))
     245#define IS_TOKEN(t) (!strncmp(option->key, t, strlen(option->key)))
     246#define IS_VALUE(t) (!strncmp(option->value, t, strlen(option->value)))
    236247
    237248
     
    265276            else                                       screen_list->mini = 0;
    266277
    267         } else if(IS_TOKEN("status"))
     278        } else if(IS_TOKEN("status_bar"))
    268279        {
    269280            if     (IS_VALUE("true") || IS_VALUE("1")) screen_list->status = 1;
    270281            else                                       screen_list->status = 0;
    271282
     283        } else if(IS_TOKEN("screensaver_timeout"))
     284        {
     285            screen_list->screensaver_timeout = atoi(option->value) * 1000000;
     286            if(!screen_list->screensaver_timeout) screen_list->screensaver_timeout-=1;
    272287        } else
    273288        {
Note: See TracChangeset for help on using the changeset viewer.