commit:     591aea28215a8b5ad8660184dc6f6f15ff0c18b4
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Thu Nov  5 15:29:33 2015 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Nov  5 17:20:57 2015 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=591aea28

librc: Remove redundant code from rc_config_load

 src/librc/librc-misc.c | 61 +-------------------------------------------------
 1 file changed, 1 insertion(+), 60 deletions(-)

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 1eedc96..2c73663 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -378,71 +378,12 @@ rc_config_load(const char *file)
 {
        RC_STRINGLIST *list;
        RC_STRINGLIST *config;
-       char *token;
        RC_STRING *line;
-       RC_STRING *cline;
-       size_t i = 0;
-       bool replaced;
-       char *entry;
-       char *newline;
-       char *p;
 
        list = rc_config_list(file);
        config = rc_stringlist_new();
        TAILQ_FOREACH(line, list, entries) {
-               /* Get entry */
-               p = line->value;
-               if (! p)
-                       continue;
-               if (strncmp(p, "export ", 7) == 0)
-                       p += 7;
-               if (! (token = strsep(&p, "=")))
-                       continue;
-
-               entry = xstrdup(token);
-               /* Preserve shell coloring */
-               if (*p == '$')
-                       token = line->value;
-               else
-                       do {
-                               /* Bash variables are usually quoted */
-                               token = strsep(&p, "\"\'");
-                       } while (token && *token == '\0');
-
-               /* Drop a newline if that's all we have */
-               if (token) {
-                       i = strlen(token) - 1;
-                       if (token[i] == '\n')
-                               token[i] = 0;
-
-                       i = strlen(entry) + strlen(token) + 2;
-                       newline = xmalloc(sizeof(char) * i);
-                       snprintf(newline, i, "%s=%s", entry, token);
-               } else {
-                       i = strlen(entry) + 2;
-                       newline = xmalloc(sizeof(char) * i);
-                       snprintf(newline, i, "%s=", entry);
-               }
-
-               replaced = false;
-               /* In shells the last item takes precedence, so we need to 
remove
-                  any prior values we may already have */
-               TAILQ_FOREACH(cline, config, entries) {
-                       i = strlen(entry);
-                       if (strncmp(entry, cline->value, i) == 0 && 
cline->value[i] == '=') {
-                               /* We have a match now - to save time we 
directly replace it */
-                               free(cline->value);
-                               cline->value = newline;
-                               replaced = true;
-                               break;
-                       }
-               }
-
-               if (!replaced) {
-                       rc_stringlist_add(config, newline);
-                       free(newline);
-               }
-               free(entry);
+               rc_config_set_value(config, line->value);
        }
        rc_stringlist_free(list);
 

Reply via email to