Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 699530 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/utils.c (-3 / +60 lines)
Lines 489-502 shell_parser_set_variable (ShellParser *parser, Link Here
489
    if (found_entry != NULL) {
489
    if (found_entry != NULL) {
490
        g_free (found_entry->string);
490
        g_free (found_entry->string);
491
        found_entry->string = g_strdup_printf ("%s=%s", variable, quoted_value);
491
        found_entry->string = g_strdup_printf ("%s=%s", variable, quoted_value);
492
        g_free (found_entry->unquoted_value);
493
        found_entry->unquoted_value = g_strdup_printf ("%s=%s", variable,
494
                                                                value);
492
        ret = TRUE;
495
        ret = TRUE;
493
    } else {
496
    } else {
494
        if (add_if_unset) {
497
        if (add_if_unset) {
498
            GList *appended;
499
            GList *last = g_list_last (parser->entry_list);
500
            struct ShellEntry *last_entry = (struct ShellEntry *)last->data;
501
            if (last_entry != NULL &&
502
                last_entry->type != SHELL_ENTRY_TYPE_SEPARATOR &&
503
                last_entry->type != SHELL_ENTRY_TYPE_COMMENT) {
504
                last_entry = g_new0 (struct ShellEntry, 1);
505
                last_entry->type = SHELL_ENTRY_TYPE_SEPARATOR;
506
                last_entry->string = g_strdup ("\n");
507
                appended = g_new0 (GList, 1);
508
                appended->prev = last;
509
                appended->next = NULL;
510
                appended->data = (gpointer)last_entry;
511
                last->next = appended;
512
                last = appended;
513
            }
495
            found_entry = g_new0 (struct ShellEntry, 1);
514
            found_entry = g_new0 (struct ShellEntry, 1);
496
            found_entry->type = SHELL_ENTRY_TYPE_ASSIGNMENT;
515
            found_entry->type = SHELL_ENTRY_TYPE_ASSIGNMENT;
497
            found_entry->variable = g_strdup (variable);
516
            found_entry->variable = g_strdup (variable);
498
            found_entry->string = g_strdup_printf ("%s=%s", variable, quoted_value);
517
            found_entry->unquoted_value = g_strdup (value);
499
            parser->entry_list = g_list_append (parser->entry_list, found_entry);
518
            found_entry->string = g_strdup_printf ("%s=%s", variable,
519
                                                            quoted_value);
520
            appended = g_new0 (GList ,1);
521
            appended->prev = last;
522
            appended->next = NULL;
523
            appended->data = (gpointer)found_entry;
524
            last->next = appended;
500
            ret = TRUE;
525
            ret = TRUE;
501
        }
526
        }
502
    }
527
    }
Lines 527-532 shell_parser_clear_variable (ShellParser *parser, Link Here
527
            curr->prev = NULL;
552
            curr->prev = NULL;
528
            curr->next = NULL;
553
            curr->next = NULL;
529
            g_list_free_full (curr, (GDestroyNotify)shell_entry_free);
554
            g_list_free_full (curr, (GDestroyNotify)shell_entry_free);
555
            /* for a normal variable assignment, there is a separator
556
             * before and a separator after, so that we need to remove
557
             * one (otherwise, after a while, the file while have a lot
558
             * of blank lines!), but we need to choose which one. Things are
559
             * slightly more complicated, because one or both separators
560
             * may be comments, which we do not want to remove, and also,
561
             * we may be at the end or the beginning of the file:
562
             *   - if we are at the beginning of the file, remove next,
563
             *     except if next is a comment
564
             *   - if we are at the end of file or if next is a comment,
565
             *     remove prev, except if prev is a comment
566
             *   - if the preceding is a comment, remove next,
567
             *     except if it is a comment
568
             *   - it may happen that both prev and next are NULL, in which
569
             *     case, we do not remove anything.
570
             * Summary: if next is a separator, remove it, else, if prev
571
             * is a separator, remove it.
572
             */
573
            if (next != NULL &&
574
                ((struct ShellEntry*)next->data)->type ==
575
                                    SHELL_ENTRY_TYPE_SEPARATOR) {
576
                GList *next_next = next->next;
577
                next->prev = next->next = NULL;
578
                g_list_free_full (next, (GDestroyNotify)shell_entry_free);
579
                next = next_next;
580
            } else if (prev != NULL &&
581
                       ((struct ShellEntry*)next->data)->type ==
582
                                    SHELL_ENTRY_TYPE_SEPARATOR) {
583
                GList *prev_prev=prev->prev;
584
                prev->prev = prev->next = NULL;
585
                g_list_free_full (prev, (GDestroyNotify)shell_entry_free);
586
                prev = prev_prev;
587
            }
530
            if (prev != NULL)
588
            if (prev != NULL)
531
                prev->next = next;
589
                prev->next = next;
532
            if (next != NULL)
590
            if (next != NULL)
533
- 

Return to bug 699530