diff --git a/.gitignore b/.gitignore index 2c19aa0..2fc4e48 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,5 @@ dkms.conf bin build -temp \ No newline at end of file +temp +.idea diff --git a/Makefile b/Makefile index a720be5..54d6c19 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CC = gcc LD = gcc CFLAG = -Wall -O3 +# CFLAG = -Wall -g3 # use for debugging PROG_NAME = csv-split FILES_EXIST = ./scripts/files_exist.sh diff --git a/src/flags.c b/src/flags.c index 4866237..0274aa9 100644 --- a/src/flags.c +++ b/src/flags.c @@ -67,7 +67,7 @@ static size_t parse_flag_by_index( return *at += 2; // Read extra argument. case EXCLUDE_HEADERS: cfg->exclude_headers = 1; return *at += 1; case LINE_COUNT: - if (at + 1 == argc) { + if (*(at + 1) == argc) { ERR_LOG("Expected line count. Use --help to learn more.\n"); exit(PARSE_ERR); } @@ -90,7 +90,7 @@ static size_t parse_flag_by_index( cfg->delimiter = argv[arg_at][0]; return *at += 2; case REMOVE_COLUMNS: - if (at + 1 == argc) { // Any string will be treated as a file name, as + if (*(at + 1) == argc) { // Any string will be treated as a file name, as // lon as it's there. ERR_LOG("Expected file name. Use --help to learn more.\n"); exit(PARSE_ERR); diff --git a/src/split.c b/src/split.c index 7b76e74..28c809b 100644 --- a/src/split.c +++ b/src/split.c @@ -1,10 +1,12 @@ #include "split.h" +#include #include #include #include #include - +bool open = false; +#define mark_open_close(open) if (open == true) open = false; else open = true; #include "config.h" #include "log.h" @@ -13,8 +15,13 @@ static size_t strsub(char *str, const char old, const char new) { size_t count = 0; char *p; + const char ENCLOSED = '"'; + open = false; //safety measure for (p = str; *p != '\0'; p++) { - if (*p == old) { + if (*p == ENCLOSED) { //quick fix for handling enclosed columns + mark_open_close(open); + } + if (*p == old && open == false) { *p = new; count++; } diff --git a/src/split.h b/src/split.h index 39812b5..fec020a 100644 --- a/src/split.h +++ b/src/split.h @@ -1,8 +1,7 @@ #ifndef SPLIT_H #define SPLIT_H - +#include #define FILE_NAME_SUFFIX_BUFFER 128 - #include "config.h" // Splits a CSV file based on the given config.