From 7d956c533e9fd7d3bbb9a4a8b7f89f0fe54d4bc3 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 13 Apr 2025 22:43:46 +0200 Subject: first draft --- .clang-format | 45 -------------------- .clang-tidy | 19 --------- .gitignore | 2 + config.mk | 3 -- contrib/csv-parser.py | 18 ++++++++ contrib/csv-parser.rb | 10 +++++ contrib/csv-perf.c | 46 +++++++++++++++++++++ contrib/csv-tutorial.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ contrib/seq-read.c | 20 +++++++++ csv-parser.py | 18 -------- csv-parser.rb | 10 ----- csv-perf.c | 46 --------------------- csv-tutorial.c | 106 ------------------------------------------------ lib/.clang-format | 45 ++++++++++++++++++++ lib/.clang-tidy | 19 +++++++++ lib/compile_flags.txt | 8 ++++ lib/config.mk | 4 ++ lib/makefile | 20 +++++++++ lib/src/csv.c | 74 ++++++++++++++++----------------- makefile | 32 +++++---------- seq-read.c | 20 --------- tests/.clang-format | 45 ++++++++++++++++++++ tests/.clang-tidy | 19 +++++++++ tests/compile_flags.txt | 8 ++++ tests/config.mk | 3 ++ tests/makefile | 24 +++++++++++ 26 files changed, 444 insertions(+), 326 deletions(-) delete mode 100644 .clang-format delete mode 100644 .clang-tidy delete mode 100644 config.mk create mode 100755 contrib/csv-parser.py create mode 100755 contrib/csv-parser.rb create mode 100644 contrib/csv-perf.c create mode 100644 contrib/csv-tutorial.c create mode 100644 contrib/seq-read.c delete mode 100755 csv-parser.py delete mode 100755 csv-parser.rb delete mode 100644 csv-perf.c delete mode 100644 csv-tutorial.c create mode 100644 lib/.clang-format create mode 100644 lib/.clang-tidy create mode 100644 lib/compile_flags.txt create mode 100644 lib/config.mk delete mode 100644 seq-read.c create mode 100644 tests/.clang-format create mode 100644 tests/.clang-tidy create mode 100644 tests/compile_flags.txt create mode 100644 tests/config.mk diff --git a/.clang-format b/.clang-format deleted file mode 100644 index b32bad6..0000000 --- a/.clang-format +++ /dev/null @@ -1,45 +0,0 @@ ---- -AccessModifierOffset: -4 -AlignConsecutiveAssignments: 'true' -AlignConsecutiveDeclarations: 'true' -AlignEscapedNewlines: Left -AlignTrailingComments: 'true' -AlwaysBreakAfterReturnType: TopLevelDefinitions -BreakBeforeBraces: Stroustrup -BreakConstructorInitializers: BeforeComma -BreakInheritanceList: BeforeComma -ColumnLimit: '0' -CompactNamespaces: 'false' -Cpp11BracedListStyle: 'false' -FixNamespaceComments: 'true' -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^.*(precomp|pch|stdafx)' - Priority: -1 - - Regex: '^<.*>' - Priority: 1 - - Regex: '^".*"' - Priority: 2 - - Regex: '.*' - Priority: 3 -IndentCaseLabels: 'false' -IndentPPDirectives: AfterHash -IndentWidth: '4' -IndentWrappedFunctionNames: 'false' -KeepEmptyLinesAtTheStartOfBlocks: 'false' -PointerAlignment: Right -SortIncludes: 'true' -SpaceAfterCStyleCast: 'true' -SpaceAfterTemplateKeyword: 'false' -SpaceBeforeAssignmentOperators: 'true' -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: 'false' -SpaceInEmptyParentheses: 'false' -SpacesInAngles: 'false' -SpacesInCStyleCastParentheses: 'false' -SpacesInConditionalStatement: 'true' -SpacesInParentheses: 'false' -Standard: Auto -TabWidth: '4' -UseTab: ForIndentation -... diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 0bceb5b..0000000 --- a/.clang-tidy +++ /dev/null @@ -1,19 +0,0 @@ ---- -Checks: "*, - -abseil-*, - -altera-*, - -android-*, - -fuchsia-*, - -google-*, - -llvm*, - -modernize-use-trailing-return-type, - -zircon-*, - -readability-else-after-return, - -readability-static-accessed-through-instance, - -readability-avoid-const-params-in-decls, - -cppcoreguidelines-non-private-member-variables-in-classes, - -misc-non-private-member-variables-in-classes, -" -WarningsAsErrors: '' -HeaderFilterRegex: '' -FormatStyle: none diff --git a/.gitignore b/.gitignore index 287f41c..98d5016 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.o +*.a *.csv +build/ csv-test csv-perf diff --git a/config.mk b/config.mk deleted file mode 100644 index 3c8fd05..0000000 --- a/config.mk +++ /dev/null @@ -1,3 +0,0 @@ -CC=cc -CFLAGS=-Wall -Wextra -Wsign-compare -Wsign-conversion -pedantic -std=c99 -O2 -CFLAGS-TEST=$(CFLAGS) -fsanitize=address -ggdb -fprofile-instr-generate -fcoverage-mapping diff --git a/contrib/csv-parser.py b/contrib/csv-parser.py new file mode 100755 index 0000000..9029321 --- /dev/null +++ b/contrib/csv-parser.py @@ -0,0 +1,18 @@ +#! /usr/local/bin/python3.7 + +import csv, time, sys + +with open(sys.argv[1]) as csv_file: + start = time.time() + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in csv_reader: + if line_count == 0: + line_count += 1 + else: + line_count += 1 + + end = time.time() + print(f'Processed {line_count} lines.') + print(end - start) + diff --git a/contrib/csv-parser.rb b/contrib/csv-parser.rb new file mode 100755 index 0000000..aaac877 --- /dev/null +++ b/contrib/csv-parser.rb @@ -0,0 +1,10 @@ +#! /usr/local/bin/ruby + +require 'csv' + +startTime = Time.now +CSV.read(ARGV[0]) +endTime = Time.now + +print(endTime-startTime) +puts "\n" diff --git a/contrib/csv-perf.c b/contrib/csv-perf.c new file mode 100644 index 0000000..1c0f7a3 --- /dev/null +++ b/contrib/csv-perf.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#include "csv.h" + +static int +test(FILE *f) +{ + int line = 0; + csv_t csv = { 0 }; + + while ( csv_read(&csv, f) ) { + ++line; + } + + return line; +} + +int +main(int argc, char *argv[]) +{ + if ( argc != 2 ) { + fprintf(stderr, "usage: %s testfile\n", argv[0]); + return EXIT_FAILURE; + } + + FILE *in = fopen(argv[1], "r"); + if ( in == NULL ) { + fprintf(stderr, "failed to open testfile...\n"); + return EXIT_FAILURE; + } + + clock_t start = clock(); + + int lines = test(in); + + clock_t end = clock(); + + fclose(in); + + printf("%d lines processed, duration: %.3lf sec\n", lines, ((double) (end - start)) / CLOCKS_PER_SEC); + + return EXIT_SUCCESS; +} diff --git a/contrib/csv-tutorial.c b/contrib/csv-tutorial.c new file mode 100644 index 0000000..9bdb7e6 --- /dev/null +++ b/contrib/csv-tutorial.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +#include "csv.h" + +bool +processFile(const char *filename) +{ + FILE *in = fopen(filename, "r"); + + if ( in == NULL ) { + return false; + } + + csv_t csv; + csv_init(&csv); + + while ( csv_read(&csv, in) ) { + const size_t nfields = csv_nfields(&csv); + // ... + } + csv_cleanup(&csv); + + (void) fclose(in); + return true; +} + +bool +processFile_options(const char *filename) +{ + FILE *in = fopen(filename, "r"); + + if ( in == NULL ) { + return false; + } + + csv_options_t csv_options = csv_default_options; + csv_options.field_delimiter = '"'; + csv_options.field_separator = ','; + + csv_t csv; + csv_init_opt(&csv, &csv_options); + + while ( csv_read(&csv, in) ) { + const size_t nfields = csv_nfields(&csv); + // ... + } + csv_cleanup(&csv); + + (void) fclose(in); + return true; +} + +static void +csvErrorHandler(csv_err_t err, void *cb_arg) +{ + longjmp(*((jmp_buf *) cb_arg), err); +} + +bool +processFile_error(const char *filename) +{ + FILE *in = fopen(filename, "r"); + + if ( in == NULL ) { + return false; + } + + csv_options_t csv_options = csv_default_options; + csv_options.field_delimiter = '"'; + csv_options.field_separator = ','; + + jmp_buf env; + csv_options.cb_error = csvErrorHandler; + csv_options.cb_error_arg = &env; + + csv_t csv; + csv_init_opt(&csv, &csv_options); + + switch ( setjmp(env) ) { + case CSV_ERR_OK: + while ( csv_read(&csv, in) ) { + const size_t nfields = csv_nfields(&csv); + // ... + } + break; + + case CSV_ERR_OUT_OF_MEMORY: + case CSV_ERR_OUT_OF_RANGE: + case CSV_ERR_IO_READ: + case CSV_ERR_IO_WRITE: + csv_cleanup(&csv); + break; + } + + (void) fclose(in); + return true; +} + +int +main(void) +{ + return EXIT_SUCCESS; +} diff --git a/contrib/seq-read.c b/contrib/seq-read.c new file mode 100644 index 0000000..90d201f --- /dev/null +++ b/contrib/seq-read.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int +main(void) +{ + clock_t start = clock(); + size_t sum = 0; + + for ( int ch; (ch = getc(stdin)) != EOF; ) { + sum += (unsigned char) ch; + } + + clock_t end = clock(); + + printf("Result: %zu, Duration: %.3lf sec\n", sum, ((double)(end - start)) / CLOCKS_PER_SEC); + + return EXIT_SUCCESS; +} diff --git a/csv-parser.py b/csv-parser.py deleted file mode 100755 index 9029321..0000000 --- a/csv-parser.py +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/local/bin/python3.7 - -import csv, time, sys - -with open(sys.argv[1]) as csv_file: - start = time.time() - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - if line_count == 0: - line_count += 1 - else: - line_count += 1 - - end = time.time() - print(f'Processed {line_count} lines.') - print(end - start) - diff --git a/csv-parser.rb b/csv-parser.rb deleted file mode 100755 index aaac877..0000000 --- a/csv-parser.rb +++ /dev/null @@ -1,10 +0,0 @@ -#! /usr/local/bin/ruby - -require 'csv' - -startTime = Time.now -CSV.read(ARGV[0]) -endTime = Time.now - -print(endTime-startTime) -puts "\n" diff --git a/csv-perf.c b/csv-perf.c deleted file mode 100644 index 1c0f7a3..0000000 --- a/csv-perf.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -#include "csv.h" - -static int -test(FILE *f) -{ - int line = 0; - csv_t csv = { 0 }; - - while ( csv_read(&csv, f) ) { - ++line; - } - - return line; -} - -int -main(int argc, char *argv[]) -{ - if ( argc != 2 ) { - fprintf(stderr, "usage: %s testfile\n", argv[0]); - return EXIT_FAILURE; - } - - FILE *in = fopen(argv[1], "r"); - if ( in == NULL ) { - fprintf(stderr, "failed to open testfile...\n"); - return EXIT_FAILURE; - } - - clock_t start = clock(); - - int lines = test(in); - - clock_t end = clock(); - - fclose(in); - - printf("%d lines processed, duration: %.3lf sec\n", lines, ((double) (end - start)) / CLOCKS_PER_SEC); - - return EXIT_SUCCESS; -} diff --git a/csv-tutorial.c b/csv-tutorial.c deleted file mode 100644 index 9bdb7e6..0000000 --- a/csv-tutorial.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include - -#include "csv.h" - -bool -processFile(const char *filename) -{ - FILE *in = fopen(filename, "r"); - - if ( in == NULL ) { - return false; - } - - csv_t csv; - csv_init(&csv); - - while ( csv_read(&csv, in) ) { - const size_t nfields = csv_nfields(&csv); - // ... - } - csv_cleanup(&csv); - - (void) fclose(in); - return true; -} - -bool -processFile_options(const char *filename) -{ - FILE *in = fopen(filename, "r"); - - if ( in == NULL ) { - return false; - } - - csv_options_t csv_options = csv_default_options; - csv_options.field_delimiter = '"'; - csv_options.field_separator = ','; - - csv_t csv; - csv_init_opt(&csv, &csv_options); - - while ( csv_read(&csv, in) ) { - const size_t nfields = csv_nfields(&csv); - // ... - } - csv_cleanup(&csv); - - (void) fclose(in); - return true; -} - -static void -csvErrorHandler(csv_err_t err, void *cb_arg) -{ - longjmp(*((jmp_buf *) cb_arg), err); -} - -bool -processFile_error(const char *filename) -{ - FILE *in = fopen(filename, "r"); - - if ( in == NULL ) { - return false; - } - - csv_options_t csv_options = csv_default_options; - csv_options.field_delimiter = '"'; - csv_options.field_separator = ','; - - jmp_buf env; - csv_options.cb_error = csvErrorHandler; - csv_options.cb_error_arg = &env; - - csv_t csv; - csv_init_opt(&csv, &csv_options); - - switch ( setjmp(env) ) { - case CSV_ERR_OK: - while ( csv_read(&csv, in) ) { - const size_t nfields = csv_nfields(&csv); - // ... - } - break; - - case CSV_ERR_OUT_OF_MEMORY: - case CSV_ERR_OUT_OF_RANGE: - case CSV_ERR_IO_READ: - case CSV_ERR_IO_WRITE: - csv_cleanup(&csv); - break; - } - - (void) fclose(in); - return true; -} - -int -main(void) -{ - return EXIT_SUCCESS; -} diff --git a/lib/.clang-format b/lib/.clang-format new file mode 100644 index 0000000..b32bad6 --- /dev/null +++ b/lib/.clang-format @@ -0,0 +1,45 @@ +--- +AccessModifierOffset: -4 +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: Left +AlignTrailingComments: 'true' +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBraces: Stroustrup +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +ColumnLimit: '0' +CompactNamespaces: 'false' +Cpp11BracedListStyle: 'false' +FixNamespaceComments: 'true' +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^.*(precomp|pch|stdafx)' + Priority: -1 + - Regex: '^<.*>' + Priority: 1 + - Regex: '^".*"' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: 'false' +IndentPPDirectives: AfterHash +IndentWidth: '4' +IndentWrappedFunctionNames: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +PointerAlignment: Right +SortIncludes: 'true' +SpaceAfterCStyleCast: 'true' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'false' +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInConditionalStatement: 'true' +SpacesInParentheses: 'false' +Standard: Auto +TabWidth: '4' +UseTab: ForIndentation +... diff --git a/lib/.clang-tidy b/lib/.clang-tidy new file mode 100644 index 0000000..0bceb5b --- /dev/null +++ b/lib/.clang-tidy @@ -0,0 +1,19 @@ +--- +Checks: "*, + -abseil-*, + -altera-*, + -android-*, + -fuchsia-*, + -google-*, + -llvm*, + -modernize-use-trailing-return-type, + -zircon-*, + -readability-else-after-return, + -readability-static-accessed-through-instance, + -readability-avoid-const-params-in-decls, + -cppcoreguidelines-non-private-member-variables-in-classes, + -misc-non-private-member-variables-in-classes, +" +WarningsAsErrors: '' +HeaderFilterRegex: '' +FormatStyle: none diff --git a/lib/compile_flags.txt b/lib/compile_flags.txt new file mode 100644 index 0000000..8b85c07 --- /dev/null +++ b/lib/compile_flags.txt @@ -0,0 +1,8 @@ +-Wall +-Wextra +-Wsign-compare +-Wsign-conversion +-pedantic +-std=c99 +-O2 +-Iinclude diff --git a/lib/config.mk b/lib/config.mk new file mode 100644 index 0000000..6b4ff86 --- /dev/null +++ b/lib/config.mk @@ -0,0 +1,4 @@ +BUILD_DIR=../build +ARFLAGS=rcs +CFLAGS=-Wall -Wextra -Wsign-compare -Wsign-conversion -pedantic -std=c99 -O2 -Iinclude -DNDEBUG + diff --git a/lib/makefile b/lib/makefile index e69de29..5c832ba 100644 --- a/lib/makefile +++ b/lib/makefile @@ -0,0 +1,20 @@ +include config.mk + +LIBRARY=$(BUILD_DIR)/libcsv.a +OBJS=$(BUILD_DIR)/csv.o + +$(LIBRARY): $(OBJS) + ar $(ARFLAGS) $@ $(OBJS) + +$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) + cc $(CFLAGS) -c $< -o $@ + +$(BUILD_DIR): + mkdir -p $@ + +compile_flags.txt: + echo "$(CFLAGS)" | tr ' ' '\n' > $@ + +.PHONY: clean +clean: + rm -f $(LIBRARY) $(OBJS) diff --git a/lib/src/csv.c b/lib/src/csv.c index e9c7464..ba78dbd 100644 --- a/lib/src/csv.c +++ b/lib/src/csv.c @@ -305,35 +305,35 @@ csv_read(csv_t *csv, FILE *in) csv_field_reset(&csv->csv_field); for ( int state = STATE_START_FIELD;; ) { - int ch; + int chr; switch ( state ) { case STATE_START_FIELD: csv_field_append(&csv->csv_field, csv->csv_string.pos, csv->csv_options); - ch = getc(in); - if ( ch == EOF ) { + chr = getc(in); + if ( chr == EOF ) { state = STATE_END_FILE; } - else if ( ch == '\r' ) { // test for CR.. - ch = getc(in); - if ( ch != '\n' ) { // ..LF - (void) ungetc(ch, in); + else if ( chr == '\r' ) { // test for CR.. + chr = getc(in); + if ( chr != '\n' ) { // ..LF + (void) ungetc(chr, in); } state = STATE_END_LINE; } - else if ( ch == '\n' ) { + else if ( chr == '\n' ) { state = STATE_END_LINE; } - else if ( ch == SEP ) { + else if ( chr == SEP ) { state = STATE_END_FIELD; } - else if ( ch == DELIM ) { + else if ( chr == DELIM ) { state = STATE_QUOTED_FIELD; } else { - if ( ch != '\0' ) { - csv_string_append(&csv->csv_string, ch, csv->csv_options); + if ( chr != '\0' ) { + csv_string_append(&csv->csv_string, chr, csv->csv_options); } state = STATE_SIMPLE_FIELD; } @@ -341,39 +341,39 @@ csv_read(csv_t *csv, FILE *in) case STATE_QUOTED_FIELD: do { - ch = getc(in); - if ( ch == EOF ) { + chr = getc(in); + if ( chr == EOF ) { state = STATE_END_FILE; } - else if ( ch == DELIM ) { - ch = getc(in); - if ( ch == EOF ) { + else if ( chr == DELIM ) { + chr = getc(in); + if ( chr == EOF ) { state = STATE_END_FILE; } - else if ( ch == DELIM ) { + else if ( chr == DELIM ) { csv_string_append(&csv->csv_string, DELIM, csv->csv_options); } - else if ( ch == SEP ) { + else if ( chr == SEP ) { state = STATE_END_FIELD; } - else if ( ch == '\r' ) { - ch = getc(in); - if ( ch != '\n' ) { - (void) ungetc(ch, in); + else if ( chr == '\r' ) { + chr = getc(in); + if ( chr != '\n' ) { + (void) ungetc(chr, in); } state = STATE_END_LINE; } - else if ( ch == '\n' ) { + else if ( chr == '\n' ) { state = STATE_END_LINE; } else { csv_string_append(&csv->csv_string, DELIM, csv->csv_options); - (void) ungetc(ch, in); // we have read too far... Put the character back! + (void) ungetc(chr, in); // we have read too far... Put the character back! } } else { - if ( ch != '\0' ) { - csv_string_append(&csv->csv_string, ch, csv->csv_options); + if ( chr != '\0' ) { + csv_string_append(&csv->csv_string, chr, csv->csv_options); } } } while ( state == STATE_QUOTED_FIELD ); @@ -381,26 +381,26 @@ csv_read(csv_t *csv, FILE *in) case STATE_SIMPLE_FIELD: do { - ch = getc(in); - if ( ch == EOF ) { + chr = getc(in); + if ( chr == EOF ) { state = STATE_END_FILE; } - else if ( ch == SEP ) { + else if ( chr == SEP ) { state = STATE_END_FIELD; } - else if ( ch == '\r' ) { - ch = getc(in); - if ( ch != '\n' ) { - (void) ungetc(ch, in); + else if ( chr == '\r' ) { + chr = getc(in); + if ( chr != '\n' ) { + (void) ungetc(chr, in); } state = STATE_END_LINE; } - else if ( ch == '\n' ) { + else if ( chr == '\n' ) { state = STATE_END_LINE; } else { - if ( ch != '\0' ) { - csv_string_append(&csv->csv_string, ch, csv->csv_options); + if ( chr != '\0' ) { + csv_string_append(&csv->csv_string, chr, csv->csv_options); } } } while ( state == STATE_SIMPLE_FIELD ); diff --git a/makefile b/makefile index 5b850c7..db36c5c 100644 --- a/makefile +++ b/makefile @@ -1,28 +1,16 @@ -include config.mk +.PHONY: all lib test tests clean -all: csv-test csv-perf seq-read csv-tutorial +all: lib -csv-test: csv-test.c csv.c csv.h - $(CC) $(CFLAGS-TEST) -DNDEBUG -o $@ csv-test.c csv.c - ./$@ +lib tests: + $(MAKE) -C $@ -coverage: csv-test - llvm-profdata merge -sparse default.profraw -o csv-test.profdata - llvm-cov show ./csv-test -instr-profile=csv-test.profdata - -csv-perf: csv-perf.c csv.o csv.h - $(CC) $(CFLAGS) -o $@ csv-perf.c csv.o - -seq-read: seq-read.c - $(CC) $(CFLAGS) -o $@ $< - -csv-tutorial: csv-tutorial.c csv.o csv.h - $(CC) $(CFLAGS) -o $@ csv-tutorial.c csv.o - -csv.o: csv.c csv.h - $(CC) $(CFLAGS) -DNDEBUG -o $@ -c $< +test: tests + build/tester clean: - rm -f csv-test csv-perf seq-read csv.o csv-tutorial + $(MAKE) -C lib clean + $(MAKE) -C tests clean + rm -rf build -.PHONY: all clean coverage +# Testdaten: https://excelbianalytics.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/ diff --git a/seq-read.c b/seq-read.c deleted file mode 100644 index 90d201f..0000000 --- a/seq-read.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -int -main(void) -{ - clock_t start = clock(); - size_t sum = 0; - - for ( int ch; (ch = getc(stdin)) != EOF; ) { - sum += (unsigned char) ch; - } - - clock_t end = clock(); - - printf("Result: %zu, Duration: %.3lf sec\n", sum, ((double)(end - start)) / CLOCKS_PER_SEC); - - return EXIT_SUCCESS; -} diff --git a/tests/.clang-format b/tests/.clang-format new file mode 100644 index 0000000..b32bad6 --- /dev/null +++ b/tests/.clang-format @@ -0,0 +1,45 @@ +--- +AccessModifierOffset: -4 +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: Left +AlignTrailingComments: 'true' +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBraces: Stroustrup +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +ColumnLimit: '0' +CompactNamespaces: 'false' +Cpp11BracedListStyle: 'false' +FixNamespaceComments: 'true' +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^.*(precomp|pch|stdafx)' + Priority: -1 + - Regex: '^<.*>' + Priority: 1 + - Regex: '^".*"' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: 'false' +IndentPPDirectives: AfterHash +IndentWidth: '4' +IndentWrappedFunctionNames: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +PointerAlignment: Right +SortIncludes: 'true' +SpaceAfterCStyleCast: 'true' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'false' +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInConditionalStatement: 'true' +SpacesInParentheses: 'false' +Standard: Auto +TabWidth: '4' +UseTab: ForIndentation +... diff --git a/tests/.clang-tidy b/tests/.clang-tidy new file mode 100644 index 0000000..0bceb5b --- /dev/null +++ b/tests/.clang-tidy @@ -0,0 +1,19 @@ +--- +Checks: "*, + -abseil-*, + -altera-*, + -android-*, + -fuchsia-*, + -google-*, + -llvm*, + -modernize-use-trailing-return-type, + -zircon-*, + -readability-else-after-return, + -readability-static-accessed-through-instance, + -readability-avoid-const-params-in-decls, + -cppcoreguidelines-non-private-member-variables-in-classes, + -misc-non-private-member-variables-in-classes, +" +WarningsAsErrors: '' +HeaderFilterRegex: '' +FormatStyle: none diff --git a/tests/compile_flags.txt b/tests/compile_flags.txt new file mode 100644 index 0000000..9352ecc --- /dev/null +++ b/tests/compile_flags.txt @@ -0,0 +1,8 @@ +-Wall +-Wextra +-Wsign-compare +-Wsign-conversion +-pedantic +-std=c99 +-O2 +-I../lib/include diff --git a/tests/config.mk b/tests/config.mk new file mode 100644 index 0000000..4b51d37 --- /dev/null +++ b/tests/config.mk @@ -0,0 +1,3 @@ +BUILD_DIR=../build +CFLAGS=-Wall -Wextra -Wsign-compare -Wsign-conversion -pedantic -std=c99 -O2 -I../lib/include +LDFLAGS=-L$(BUILD_DIR) -lcsv diff --git a/tests/makefile b/tests/makefile index e69de29..2300a19 100644 --- a/tests/makefile +++ b/tests/makefile @@ -0,0 +1,24 @@ +include config.mk + +TEST_RUNNER=$(BUILD_DIR)/tester +OBJS=$(BUILD_DIR)/csv-test.o + +$(TEST_RUNNER): $(OBJS) | libcsv + cc -o $@ $(LDFLAGS) $(OBJS) + +$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) + cc $(CFLAGS) -c $< -o $@ + +$(BUILD_DIR): + mkdir -p $@ + +.PHONY: libcsv +libcsv: + $(MAKE) -C ../lib + +compile_flags.txt: + echo "$(CFLAGS)" | tr ' ' '\n' > $@ + +.PHONY: clean +clean: + rm -f $(TEST_RUNNER) $(OBJS) -- cgit v1.3