diff options
| -rw-r--r-- | include/ini.h | 3 | ||||
| -rw-r--r-- | src/delivery.c | 14 | ||||
| -rw-r--r-- | src/ini.c | 24 | 
3 files changed, 32 insertions, 9 deletions
diff --git a/include/ini.h b/include/ini.h index 7167cad..d7cf056 100644 --- a/include/ini.h +++ b/include/ini.h @@ -29,7 +29,7 @@  #define INIVAL_TO_LIST 1 << 1  /*! \union INIVal - * \brief Consolidation possible value types + * \brief Consolidate possible value types   */  union INIVal {      int as_int;                      ///< Integer @@ -52,6 +52,7 @@ union INIVal {  struct INIData {      char *key;                       ///< INI variable name      char *value;                     ///< INI variable value +    unsigned type_hint;  };  /*! \struct INISection diff --git a/src/delivery.c b/src/delivery.c index b1997f6..a55171a 100644 --- a/src/delivery.c +++ b/src/delivery.c @@ -54,7 +54,15 @@ static void conv_strlist(struct StrList **x, char *tok, union INIVal val) {      if (val.as_char_p) {          char *tplop = tpl_render(val.as_char_p);          if (tplop) { +            lstrip(tplop);              strip(tplop); +            // Special handler for space delimited lists +            if (strpbrk(tok, " ")) { +                // crunch all spaces +                normalize_space(tplop); +                // replace spaces with line feeds +                replace_text(tplop, " ", "\n", 0); +            }              strlist_append_tokenize((*x), tplop, tok);              guard_free(tplop);          } @@ -548,7 +556,7 @@ static int populate_delivery_ini(struct Delivery *ctx) {      conv_str(&ctx->conda.installer_baseurl, val);      ini_getval(ini, "conda", "conda_packages", INIVAL_TYPE_STR_ARRAY, &val); -    conv_strlist(&ctx->conda.conda_packages, LINE_SEP, val); +    conv_strlist(&ctx->conda.conda_packages, " "LINE_SEP, val);      for (size_t i = 0; i < strlist_count(ctx->conda.conda_packages); i++) {          char *pkg = strlist_item(ctx->conda.conda_packages, i); @@ -558,7 +566,7 @@ static int populate_delivery_ini(struct Delivery *ctx) {      }      ini_getval(ini, "conda", "pip_packages", INIVAL_TYPE_STR_ARRAY, &val); -    conv_strlist(&ctx->conda.pip_packages, LINE_SEP, val); +    conv_strlist(&ctx->conda.pip_packages, " "LINE_SEP, val);      for (size_t i = 0; i < strlist_count(ctx->conda.pip_packages); i++) {          char *pkg = strlist_item(ctx->conda.pip_packages, i); @@ -1201,7 +1209,7 @@ static const struct Test *requirement_from_test(struct Delivery *ctx, const char      result = NULL;      for (size_t i = 0; i < sizeof(ctx->tests) / sizeof(ctx->tests[0]); i++) { -        if (strstr(name, ctx->tests[i].name)) { +        if (ctx->tests[i].name && strstr(name, ctx->tests[i].name)) {              result = &ctx->tests[i];              break;          } @@ -292,13 +292,18 @@ int ini_write(struct INIFILE *ini, FILE **stream, unsigned mode) {                      char *render = NULL;                      if (mode == INI_WRITE_PRESERVE) {                          render = tpl_render(parts[p]); +                        replace_text(render, "\n", "\n    ", 0);                      } else {                          render = parts[p];                      }                      if (p == 0) {                          sprintf(outvalue, "%s" LINE_SEP, render);                      } else { -                        sprintf(outvalue + strlen(outvalue), "    %s" LINE_SEP, render); +                        if (!isspace(render[0])) { +                            sprintf(outvalue + strlen(outvalue), "    %s" LINE_SEP, render); +                        } else { +                            sprintf(outvalue + strlen(outvalue), "%s" LINE_SEP, render); +                        }                      }                      if (mode == INI_WRITE_PRESERVE) {                          guard_free(render); @@ -307,9 +312,9 @@ int ini_write(struct INIFILE *ini, FILE **stream, unsigned mode) {                  GENERIC_ARRAY_FREE(parts);                  strip(outvalue);                  strcat(outvalue, LINE_SEP); -                fprintf(*stream, "%s=%s%s", ini->section[x]->data[y]->key, parts_total > 1 ? LINE_SEP "    " : "", outvalue); +                fprintf(*stream, "%s = %s%s", ini->section[x]->data[y]->key, ini->section[x]->data[y]->type_hint || parts_total > 1 ? LINE_SEP "    " : "", outvalue);              } else { -                fprintf(*stream, "%s=%s", ini->section[x]->data[y]->key, ini->section[x]->data[y]->value); +                fprintf(*stream, "%s = %s", ini->section[x]->data[y]->key, ini->section[x]->data[y]->value);              }          }          fprintf(*stream, LINE_SEP); @@ -352,6 +357,13 @@ void ini_free(struct INIFILE **ini) {      guard_free((*ini));  } +static void ini_data_set_hint(struct INIFILE **ini, char *section_name, char *key, int hint) { +    struct INIData *data = ini_data_get(*ini, section_name, key); +    if (data) { +        data->type_hint = hint; +    } +} +  struct INIFILE *ini_open(const char *filename) {      FILE *fp;      char line[STASIS_BUFSIZ] = {0}; @@ -440,8 +452,10 @@ struct INIFILE *ini_open(const char *filename) {              ini_section_create(&ini, section_name);              // Record the name of the section. This is used until another section is found. +            memset(current_section, 0, sizeof(current_section));              strcpy(current_section, section_name);              guard_free(section_name); +            memset(line, 0, sizeof(line));              continue;          } @@ -473,6 +487,7 @@ struct INIFILE *ini_open(const char *filename) {              }              if (isempty(value)) {                  //printf("%s is probably long raw data\n", key); +                ini_data_set_hint(&ini, current_section, key, INIVAL_TYPE_STR_ARRAY);                  multiline_data = 1;                  no_data = 1;              } else { @@ -484,15 +499,14 @@ struct INIFILE *ini_open(const char *filename) {              strcpy(key, key_last);              strcpy(value, line);          } +        memset(line, 0, sizeof(line));          // Store key value pair in section's data array          if (strlen(key)) {              lstrip(key);              strip(key);              unquote(value); -            lstrip(value);              if (!multiline_data) { -                strip(value);                  reading_value = 0;                  ini_data_append(&ini, current_section, key, value);                  continue;  | 
