diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-13 16:13:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-13 16:13:06 +0200 |
commit | 9566646cd54a34c0dfe2dbdd89ee3858372a6c28 (patch) | |
tree | 1aa3942cb421b2fc90426b8e0984120511128a9d | |
parent | ae0520e57267dbd866fc8cd25f66f4e6af2ac118 (diff) |
Move string utils to their own file
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | src/main.c | 46 | ||||
-rw-r--r-- | src/rss.c | 3 | ||||
-rw-r--r-- | src/stringutils.c | 47 | ||||
-rw-r--r-- | src/stringutils.h | 9 |
5 files changed, 61 insertions, 46 deletions
@@ -5,4 +5,4 @@ CFLAGS="-O0 -g3 -Wall -Wextra -Werror" #LIBS="-lcurl" LIBS="" #gcc -musl-gcc -static src/main.c src/program.c src/alloc.c src/buffer.c src/fileutils.c src/transmission.c src/rss.c src/download.c -o automedia $CFLAGS $LIBS +musl-gcc -static src/main.c src/program.c src/alloc.c src/buffer.c src/fileutils.c src/transmission.c src/rss.c src/download.c src/stringutils.c -o automedia $CFLAGS $LIBS @@ -2,6 +2,7 @@ #include "fileutils.h" #include "transmission.h" #include "fileutils.h" +#include "stringutils.h" #include "rss.h" #include "json.h" @@ -184,51 +185,6 @@ static int compare_downloaded_item(const void *a, const void *b) { return list_data_a->timestamp - list_data_b->timestamp; } -static void string_replace(char *str, char old, char new) { - for(;;) { - char c = *str; - if(c == old) - *str = new; - else if(c == '\0') - break; - ++str; - } -} - -static char* lstrip(char *str) { - for(;;) { - char c = *str; - if(c != ' ' && c != '\t' && c != '\n') - break; - else if(c == '\0') - break; - ++str; - } - return str; -} - -static void rstrip(char *str) { - int len = strlen(str); - if(len == 0) - return; - - char *p = str + len - 1; - while(p != str) { - char c = *p; - if(c != ' ' && c != '\t' && c != '\n') - break; - --p; - } - - p[1] = '\0'; -} - -static char* strip(char *str) { - str = lstrip(str); - rstrip(str); - return str; -} - static void command_add(int argc, char **argv, char *rss_config_dir, char *html_config_dir) { if(argc < 2) usage_add(); @@ -170,6 +170,9 @@ int add_rss(const char *name, const char *url, const char *rss_config_dir, const } fprintf(stderr, "rss title: |%s|\n", rss_title); + /*if(!name) + name = rss_title*/ + cleanup: buffer_deinit(&buffer); return result; diff --git a/src/stringutils.c b/src/stringutils.c new file mode 100644 index 0000000..172d40d --- /dev/null +++ b/src/stringutils.c @@ -0,0 +1,47 @@ +#include "stringutils.h" +#include <string.h> + +void string_replace(char *str, char old_char, char new_char) { + for(;;) { + char c = *str; + if(c == old_char) + *str = new_char; + else if(c == '\0') + break; + ++str; + } +} + +char* lstrip(char *str) { + for(;;) { + char c = *str; + if(c != ' ' && c != '\t' && c != '\n') + break; + else if(c == '\0') + break; + ++str; + } + return str; +} + +void rstrip(char *str) { + int len = strlen(str); + if(len == 0) + return; + + char *p = str + len - 1; + while(p != str) { + char c = *p; + if(c != ' ' && c != '\t' && c != '\n') + break; + --p; + } + + p[1] = '\0'; +} + +char* strip(char *str) { + str = lstrip(str); + rstrip(str); + return str; +}
\ No newline at end of file diff --git a/src/stringutils.h b/src/stringutils.h new file mode 100644 index 0000000..a14d76c --- /dev/null +++ b/src/stringutils.h @@ -0,0 +1,9 @@ +#ifndef STRINGUTILS_H +#define STRINGUTILS_H + +void string_replace(char *str, char old_char, char new_char); +char* lstrip(char *str); +void rstrip(char *str); +char* strip(char *str); + +#endif |