Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ dkms.conf

bin
build
temp
temp
.idea
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/split.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "split.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

bool open = false;
#define mark_open_close(open) if (open == true) open = false; else open = true;
#include "config.h"
#include "log.h"

Expand All @@ -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++;
}
Expand Down
3 changes: 1 addition & 2 deletions src/split.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef SPLIT_H
#define SPLIT_H

#include <stdbool.h>
#define FILE_NAME_SUFFIX_BUFFER 128

#include "config.h"

// Splits a CSV file based on the given config.
Expand Down