349
349
iniParseLine (char *line, char **optionName, char **optionValue)
354
char tmpName[MAX_OPTION_LENGTH];
355
char tmpValue[MAX_OPTION_LENGTH];
357
354
if (line[0] == '\0' || line[0] == '\n')
360
while (pos < strlen(line))
362
if (!splitPos && line[pos] == '=')
364
if (line[pos] == '\n')
372
if (splitPos && endPos)
378
for (i=0; i < splitPos; i++)
379
tmpName[i] = line[i];
380
tmpName[splitPos] = '\0';
382
for (i=splitPos+1; i<endPos; i++)
383
tmpValue[i - (splitPos+1)] = line[i];
384
tmpValue[endPos - (splitPos+1)] = '\0';
386
*optionName = strdup (tmpName);
387
*optionValue = strdup (tmpValue);
357
split_pos = strchr(line, '=');
361
length = strlen(line) - strlen(split_pos);
362
*optionName = strndup(line, length);
364
*optionValue = strndup(split_pos, strlen(split_pos)-1);
398
370
csvToList (char *csv, CompListValue *list, CompOptionType type)
400
char *csvtmp, *split, *item = NULL;
401
int count = 1, i, itemLength;
372
char *splitStart = NULL;
373
char *splitEnd = NULL;
403
379
if (csv[0] == '\0')
405
381
list->nValue = 0;
409
csvtmp = strdup (csv);
410
csvtmp = strchr (csv, ',');
414
csvtmp++; /* avoid the comma */
416
csvtmp = strchr (csvtmp, ',');
385
int length = strlen(csv);
387
for (i = 0; csv[i] != '\0'; i++)
388
if (csv[i] == ',' && i != length-1)
419
392
list->value = malloc (sizeof (CompOptionValue) * count);
422
for (i=0; i<count; i++)
395
for (i = 0; i < count; i++)
424
split = strchr (csv, ',');
397
splitEnd = strchr(splitStart, ',');
428
itemLength = strlen(csv) - strlen(split);
429
item = realloc (item, sizeof (char) * (itemLength+1));
430
strncpy (item, csv, itemLength);
431
item[itemLength] = '\0';
432
csv += itemLength + 1;
401
itemLength = strlen(splitStart) - strlen(splitEnd);
402
item = strndup(splitStart, itemLength);
437
itemLength = strlen(csv);
438
item = realloc (item, sizeof (char) * (itemLength+1));
439
strncpy (item, csv, itemLength);
440
item[itemLength] = '\0';
406
item = strdup(splitStart);
445
411
case CompOptionTypeString:
446
list->value[i].s = strdup (item);
413
list->value[i].s = strdup (item);
448
415
case CompOptionTypeBool:
449
416
if (item[0] != '\0')
689
658
IniAction action;
690
659
action.realOptionName = NULL;
691
Bool continueReading = FALSE;
692
while (fgets (&tmp[0], MAX_OPTION_LENGTH, optionFile) != NULL)
660
Bool continueReading;
661
while (fgets (tmp, MAX_OPTION_LENGTH, optionFile) != NULL)
664
continueReading = FALSE;
696
if (!iniParseLine (&tmp[0], &optionName, &optionValue))
666
if (!iniParseLine (tmp, &optionName, &optionValue))
699
669
"Ignoring line '%s' in %s %i\n", tmp, plugin, screen);
712
682
case CompOptionTypeBool:
714
684
value.b = (Bool) atoi (optionValue);
716
686
case CompOptionTypeInt:
718
688
value.i = atoi (optionValue);
720
690
case CompOptionTypeFloat:
722
692
value.f = atof (optionValue);
724
694
case CompOptionTypeString:
726
696
value.s = strdup (optionValue);
728
698
case CompOptionTypeColor:
729
hv = stringToColor (optionValue, value.c);
699
hasValue = stringToColor (optionValue, value.c);
731
701
case CompOptionTypeList:
732
hv = csvToList (optionValue, &value.list, value.list.type);
702
hasValue = csvToList (optionValue, &value.list, value.list.type);
734
704
case CompOptionTypeMatch:
736
706
matchInit (&value.match);
737
707
matchAddFromString (&value.match, optionValue);
780
750
if (action.realOptionName &&
781
751
!continueReading)
783
o = compFindOption (option, nOption, action.realOptionName, 0);
753
CompOption *realOption = compFindOption (option, nOption, action.realOptionName, 0);
756
value = realOption->value;
788
758
value.action.type = action.a.type;
789
759
value.action.key = action.a.key;
811
781
free(action.realOptionName);
812
782
action.realOptionName = NULL;
814
/* we missed the current line because we exited it in the first call */
815
if (!o && action.valueMasks == ACTION_VALUES_ALL)
817
action.valueMasks = 0;
784
/* we missed the current line because we exited it in the first call.
785
we also need to check wether we have a incomplete options here,
786
because otherwise parsing the last line again, would cause real
788
if (!o && action.valueMasks != ACTION_VALUES_ALL)
818
789
parseAction(d, optionName, optionValue, &action);
822
action.valueMasks = 0;