~smspillaz/compiz-core/compiz-core.fix_939228

« back to all changes in this revision

Viewing changes to plugins/ini.c

  • Committer: Mike Dransfield
  • Date: 2007-04-15 14:19:21 UTC
  • mfrom: (1094.1.50)
  • Revision ID: git-v1:499ec5365265f55edebb9b4276784612b341a8e7
Merge branch 'master' of git://git.freedesktop.org/git/xorg/app/compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
330
330
    if (fn)
331
331
    {
332
332
        sprintf (fn, "%s-%s%s",
333
 
                 plugin?plugin:CORE_NAME, screenStr, FILE_SUFFIX);
 
333
                 plugin ? plugin : CORE_NAME, screenStr, FILE_SUFFIX);
334
334
 
335
335
        *filename = strdup (fn);
336
336
 
348
348
static Bool
349
349
iniParseLine (char *line, char **optionName, char **optionValue)
350
350
{
351
 
    int  pos = 0;
352
 
    int  splitPos = 0;
353
 
    int  endPos = 0;
354
 
    char tmpName[MAX_OPTION_LENGTH];
355
 
    char tmpValue[MAX_OPTION_LENGTH];
 
351
    char *split_pos;
 
352
    int length;
356
353
 
357
354
    if (line[0] == '\0' || line[0] == '\n')
358
355
        return FALSE;
359
356
 
360
 
    while (pos < strlen(line))
361
 
    {
362
 
        if (!splitPos && line[pos] == '=')
363
 
            splitPos = pos;
364
 
        if (line[pos] == '\n')
365
 
        {
366
 
            endPos = pos;
367
 
            break;
368
 
        }
369
 
        pos++;
370
 
    }
371
 
 
372
 
    if (splitPos && endPos)
373
 
    {
374
 
        tmpName[0] = '\0';
375
 
        tmpValue[0] = '\0';
376
 
 
377
 
        int i;
378
 
        for (i=0; i < splitPos; i++)
379
 
            tmpName[i] = line[i];
380
 
        tmpName[splitPos] = '\0';
381
 
 
382
 
        for (i=splitPos+1; i<endPos; i++)
383
 
            tmpValue[i - (splitPos+1)] = line[i];
384
 
        tmpValue[endPos - (splitPos+1)] = '\0';
385
 
 
386
 
        *optionName = strdup (tmpName);
387
 
        *optionValue = strdup (tmpValue);
388
 
    }
389
 
    else
390
 
    {
 
357
    split_pos = strchr(line, '=');
 
358
    if (!split_pos)
391
359
        return FALSE;
392
 
    }
 
360
 
 
361
    length = strlen(line) - strlen(split_pos);
 
362
    *optionName = strndup(line, length);
 
363
    split_pos++;
 
364
    *optionValue = strndup(split_pos, strlen(split_pos)-1);
393
365
 
394
366
    return TRUE;
395
367
}
397
369
static Bool
398
370
csvToList (char *csv, CompListValue *list, CompOptionType type)
399
371
{
400
 
    char *csvtmp, *split, *item = NULL;
401
 
    int  count = 1, i, itemLength;
 
372
    char *splitStart = NULL;
 
373
    char *splitEnd = NULL;
 
374
    char *item = NULL;
 
375
    int itemLength;
 
376
    int count;
 
377
    int i;
402
378
 
403
379
    if (csv[0] == '\0')
404
380
    {
405
381
        list->nValue = 0;
406
382
        return FALSE;
407
383
    }
408
 
 
409
 
    csvtmp = strdup (csv);
410
 
    csvtmp = strchr (csv, ',');
411
 
 
412
 
    while (csvtmp)
413
 
    {
414
 
        csvtmp++;  /* avoid the comma */
415
 
        count++;
416
 
        csvtmp = strchr (csvtmp, ',');
417
 
    }
418
 
 
 
384
 
 
385
    int length = strlen(csv);
 
386
    count = 1;
 
387
    for (i = 0; csv[i] != '\0'; i++)
 
388
        if (csv[i] == ',' && i != length-1)
 
389
            count++;
 
390
 
 
391
    splitStart = csv;
419
392
    list->value = malloc (sizeof (CompOptionValue) * count);
420
393
    if (list->value)
421
394
    {
422
 
        for (i=0; i<count; i++)
 
395
        for (i = 0; i < count; i++)
423
396
        {
424
 
            split = strchr (csv, ',');
425
 
            if (split)
 
397
            splitEnd = strchr(splitStart, ',');
 
398
 
 
399
            if (splitEnd)
426
400
            {
427
 
                /* > 1 value */
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);
433
403
            }
434
 
            else
 
404
            else // last value
435
405
            {
436
 
                /* 1 value only */
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);
441
407
            }
442
408
 
443
409
            switch (type)
444
410
            {
445
411
                case CompOptionTypeString:
446
 
                    list->value[i].s = strdup (item);
 
412
                    if (item[0] != '\0')
 
413
                        list->value[i].s = strdup (item);
447
414
                    break;
448
415
                case CompOptionTypeBool:
449
416
                    if (item[0] != '\0')
464
431
                default:
465
432
                    break;
466
433
            }
 
434
 
 
435
            splitStart = ++splitEnd;
 
436
            if (item)
 
437
                free(item);
467
438
        }
468
439
        list->nValue = count;
469
440
    }
470
441
 
471
 
    if (item)
472
 
        free (item);
473
 
 
474
442
    return TRUE;
475
443
}
476
444
 
543
511
        action->a.bell = FALSE;
544
512
        action->a.edgeMask = 0;
545
513
        action->a.edgeButton = 0;
 
514
        action->valueMasks = 0;
546
515
    }
547
516
    /* detect a new option (might happen when the options are incomplete) */
548
517
    else if (action->valueMasks != ACTION_VALUES_ALL)
639
608
    CompScreen *s = NULL;
640
609
    CompPlugin *p = NULL;
641
610
    Bool status = FALSE;
642
 
    Bool hv = FALSE;
 
611
    Bool hasValue = FALSE;
643
612
    CompOptionValue value;
644
613
 
645
614
    if (plugin)
688
657
 
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)
693
662
    {
694
663
        status = FALSE;
 
664
        continueReading = FALSE;
695
665
 
696
 
        if (!iniParseLine (&tmp[0], &optionName, &optionValue))
 
666
        if (!iniParseLine (tmp, &optionName, &optionValue))
697
667
        {
698
668
            fprintf(stderr,
699
669
                    "Ignoring line '%s' in %s %i\n", tmp, plugin, screen);
710
680
                switch (o->type)
711
681
                {
712
682
                case CompOptionTypeBool:
713
 
                    hv = TRUE;
 
683
                    hasValue = TRUE;
714
684
                    value.b = (Bool) atoi (optionValue);
715
685
                        break;
716
686
                case CompOptionTypeInt:
717
 
                    hv = TRUE;
 
687
                    hasValue = TRUE;
718
688
                    value.i = atoi (optionValue);
719
689
                        break;
720
690
                case CompOptionTypeFloat:
721
 
                    hv = TRUE;
 
691
                    hasValue = TRUE;
722
692
                    value.f = atof (optionValue);
723
693
                        break;
724
694
                case CompOptionTypeString:
725
 
                    hv = TRUE;
 
695
                    hasValue = TRUE;
726
696
                    value.s = strdup (optionValue);
727
697
                        break;
728
698
                case CompOptionTypeColor:
729
 
                    hv = stringToColor (optionValue, value.c);
 
699
                    hasValue = stringToColor (optionValue, value.c);
730
700
                        break;
731
701
                case CompOptionTypeList:
732
 
                    hv = csvToList (optionValue, &value.list, value.list.type);
 
702
                    hasValue = csvToList (optionValue, &value.list, value.list.type);
733
703
                        break;
734
704
                case CompOptionTypeMatch:
735
 
                    hv = TRUE;
 
705
                    hasValue = TRUE;
736
706
                    matchInit (&value.match);
737
707
                    matchAddFromString (&value.match, optionValue);
738
708
                        break;
740
710
                        break;
741
711
                }
742
712
 
743
 
                if (hv)
 
713
                if (hasValue)
744
714
                {
745
715
                    if (plugin && p)
746
716
                    {
780
750
            if (action.realOptionName &&
781
751
                !continueReading)
782
752
            {
783
 
                o = compFindOption (option, nOption, action.realOptionName, 0);
784
 
                if (o)
 
753
                CompOption *realOption = compFindOption (option, nOption, action.realOptionName, 0);
 
754
                if (realOption)
785
755
                {
786
 
                    value = o->value;
 
756
                    value = realOption->value;
787
757
 
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;
813
783
 
814
 
                    /* we missed the current line because we exited it in the first call */
815
 
                    if (!o && action.valueMasks == ACTION_VALUES_ALL)
816
 
                    {
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
 
787
                       trouble. ;-) */
 
788
                    if (!o && action.valueMasks != ACTION_VALUES_ALL)
818
789
                        parseAction(d, optionName, optionValue, &action);
819
 
                    }
820
 
                    else
821
 
                    {
822
 
                        action.valueMasks = 0;
823
 
                    }
824
790
                }
825
791
            }
826
792
        }
830
796
            free (optionName);
831
797
        if (optionValue)
832
798
            free (optionValue);
833
 
        continueReading = FALSE;
834
799
    } 
835
800
 
836
801
    return TRUE;