diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 11:59:26 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-10-31 11:59:26 -0400 |
commit | 69c09a2c75f3992b7cda8f52ce5352f797e1d9fa (patch) | |
tree | 1f55dac1ba2299a5e34728d03c49dfc99d54a057 /src | |
parent | 17178535cc9df5e834dfd43e3b2b919e02e5798d (diff) | |
download | stasis-69c09a2c75f3992b7cda8f52ce5352f797e1d9fa.tar.gz |
Only truncate value when length is greater than zero
* Remove unused code/comments
Diffstat (limited to 'src')
-rw-r--r-- | src/ini.c | 73 |
1 files changed, 6 insertions, 67 deletions
@@ -4,71 +4,6 @@ #include <ctype.h> #include "ohmycal.h" #include "ini.h" -/* -char *strip(char *s) { - size_t len = strlen(s) + 1; - while (--len) { - if (isalnum(s[len])) { - break; - } - if (isblank(s[len])) { - s[len] = '\0'; - } - } - return s; -} - */ - -/* -char *lstrip(char *s) { - size_t i = 0; - char *end = NULL; - do { - end = &s[i]; - if (!isblank(*end)) { - break; - } - i++; - } while (1); - if (i) { - size_t len = strlen(end); - memmove(s, end, len); - if (strlen(s)) { - s[len] = '\0'; - } - } - return s; -} - */ - -/* -int startswith(const char *s1, char *s2) { - size_t i; - for (i = 0; i < strlen(s2); i++) { - if (s1[i] != s2[i]) { - return 0; - } - } - return 1; -} -*/ - -/* -int endswith(const char *s1, char *s2) { - size_t s2x, s1x; - for (s2x = strlen(s2), s1x = strlen(s1); s2x >= 0; s2x--, s1x--) { - char *s1p = &s1[s1x]; - char *s2p = &s2[s2x]; - if (s1[s1x] != s2[s2x]) { - return 0; - } - if (s2x == 0) { - break; - } - } - return 1; -} - */ struct INIFILE *ini_init() { struct INIFILE *ini; @@ -374,7 +309,9 @@ struct INIFILE *ini_open(const char *filename) { key = strndup(line, key_len); key_last = key; strcpy(value, &operator[1]); - value[strlen(value) - 1] = '\0'; + if (strlen(value)) { + value[strlen(value) - 1] = '\0'; + } } else if (!key && !strlen(value) && ! (startswith(line, " ") || startswith(line, "\t"))) { fprintf(stderr, "NO OPERATOR OR INDENT: %zu:'%s'\n", i, line); struct INISection *section = ini_section_search(&ini, current_section); @@ -391,7 +328,9 @@ struct INIFILE *ini_open(const char *filename) { key = key_last; strcpy(value, line); if (endswith(value, "\n")) { - value[strlen(value) - 1] = '\n'; + if (strlen(value)) { + value[strlen(value) - 1] = '\n'; + } } } |