diff options
| -rw-r--r-- | .clang-format | 45 | ||||
| -rw-r--r-- | .clang-tidy | 19 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | compile_flags.txt | 4 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | makefile | 24 | ||||
| -rw-r--r-- | src/db-test.c (renamed from db-test.c) | 16 |
7 files changed, 107 insertions, 6 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..21efcac --- /dev/null +++ b/.clang-format | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | --- | ||
| 2 | AccessModifierOffset: -4 | ||
| 3 | AlignConsecutiveAssignments: 'true' | ||
| 4 | AlignConsecutiveDeclarations: 'true' | ||
| 5 | AlignEscapedNewlines: Left | ||
| 6 | AlignTrailingComments: 'true' | ||
| 7 | AlwaysBreakAfterReturnType: TopLevelDefinitions | ||
| 8 | BreakBeforeBraces: Stroustrup | ||
| 9 | BreakConstructorInitializers: BeforeComma | ||
| 10 | BreakInheritanceList: BeforeComma | ||
| 11 | ColumnLimit: '0' | ||
| 12 | CompactNamespaces: 'false' | ||
| 13 | Cpp11BracedListStyle: 'false' | ||
| 14 | FixNamespaceComments: 'true' | ||
| 15 | IncludeBlocks: Regroup | ||
| 16 | IncludeCategories: | ||
| 17 | - Regex: '^.*(precomp|pch|stdafx)' | ||
| 18 | Priority: -1 | ||
| 19 | - Regex: '^<.*>' | ||
| 20 | Priority: 1 | ||
| 21 | - Regex: '^".*"' | ||
| 22 | Priority: 2 | ||
| 23 | - Regex: '.*' | ||
| 24 | Priority: 3 | ||
| 25 | IndentCaseLabels: 'false' | ||
| 26 | IndentPPDirectives: AfterHash | ||
| 27 | IndentWidth: '4' | ||
| 28 | IndentWrappedFunctionNames: 'false' | ||
| 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' | ||
| 30 | PointerAlignment: Right | ||
| 31 | SortIncludes: 'true' | ||
| 32 | SpaceAfterCStyleCast: 'true' | ||
| 33 | SpaceAfterTemplateKeyword: 'false' | ||
| 34 | SpaceBeforeAssignmentOperators: 'true' | ||
| 35 | SpaceBeforeParens: ControlStatements | ||
| 36 | SpaceBeforeRangeBasedForLoopColon: 'false' | ||
| 37 | SpaceInEmptyParentheses: 'false' | ||
| 38 | SpacesInAngles: 'false' | ||
| 39 | SpacesInCStyleCastParentheses: 'false' | ||
| 40 | SpacesInConditionalStatement: 'true' | ||
| 41 | SpacesInParentheses: 'false' | ||
| 42 | Standard: Auto | ||
| 43 | TabWidth: '4' | ||
| 44 | UseTab: ForIndentation | ||
| 45 | ... | ||
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..0bceb5b --- /dev/null +++ b/.clang-tidy | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | --- | ||
| 2 | Checks: "*, | ||
| 3 | -abseil-*, | ||
| 4 | -altera-*, | ||
| 5 | -android-*, | ||
| 6 | -fuchsia-*, | ||
| 7 | -google-*, | ||
| 8 | -llvm*, | ||
| 9 | -modernize-use-trailing-return-type, | ||
| 10 | -zircon-*, | ||
| 11 | -readability-else-after-return, | ||
| 12 | -readability-static-accessed-through-instance, | ||
| 13 | -readability-avoid-const-params-in-decls, | ||
| 14 | -cppcoreguidelines-non-private-member-variables-in-classes, | ||
| 15 | -misc-non-private-member-variables-in-classes, | ||
| 16 | " | ||
| 17 | WarningsAsErrors: '' | ||
| 18 | HeaderFilterRegex: '' | ||
| 19 | FormatStyle: none | ||
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a5e204 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | bin/ | ||
| 2 | obj/ | ||
| 3 | database.db | ||
diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..d87afcf --- /dev/null +++ b/compile_flags.txt | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | -Wall | ||
| 2 | -Werror | ||
| 3 | -pedantic | ||
| 4 | -std=c99 | ||
diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..ed945d9 --- /dev/null +++ b/config.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | CFLAGS=-Wall -Werror -pedantic -std=c99 | ||
| 2 | LDFLAGS= | ||
diff --git a/makefile b/makefile new file mode 100644 index 0000000..da7631a --- /dev/null +++ b/makefile | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | include config.mk | ||
| 2 | |||
| 3 | BIN=bin/db-test | ||
| 4 | OBJS=obj/db-test.o | ||
| 5 | |||
| 6 | release: $(BIN) | ||
| 7 | release: CFLAGS+=-DNDEBUG -O2 | ||
| 8 | |||
| 9 | debug: $(BIN) | ||
| 10 | debug: CFLAGS+=-g | ||
| 11 | |||
| 12 | $(BIN): $(OBJS) | bin | ||
| 13 | cc $(LDFLAGS) $^ -o $@ | ||
| 14 | |||
| 15 | obj/%.o: src/%.c | obj | ||
| 16 | cc $(CFLAGS) -c $< -o $@ | ||
| 17 | |||
| 18 | bin obj: | ||
| 19 | mkdir -p $@ | ||
| 20 | |||
| 21 | clean: | ||
| 22 | rm -rf bin obj | ||
| 23 | |||
| 24 | .PHONY: release debug clean | ||
diff --git a/db-test.c b/src/db-test.c index 2789ce0..439ed79 100644 --- a/db-test.c +++ b/src/db-test.c | |||
| @@ -1,22 +1,24 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 4 | #include <limits.h> | 3 | #include <limits.h> |
| 5 | 4 | ||
| 6 | #include <db.h> | 5 | #include <db.h> |
| 7 | #include <fcntl.h> | 6 | #include <fcntl.h> |
| 8 | 7 | ||
| 8 | #define USERNAME_LENGTH 20 | ||
| 9 | #define FULLNAME_LENGTH 50 | ||
| 10 | |||
| 9 | typedef struct { | 11 | typedef struct { |
| 10 | char username[20]; | 12 | char username[USERNAME_LENGTH]; |
| 11 | char fullname[50]; | 13 | char fullname[FULLNAME_LENGTH]; |
| 12 | int age; | 14 | int age; |
| 13 | } user_type; | 15 | } user_type; |
| 14 | 16 | ||
| 15 | int main(void) | 17 | int main(void) |
| 16 | { | 18 | { |
| 17 | DB *db = dbopen("database.db", O_RDWR | O_CREAT, 0644, DB_BTREE, NULL); | 19 | DB *db = dbopen("./database.db", O_RDWR | O_CREAT, 0644, DB_BTREE, NULL); // NOLINT |
| 18 | if ( db != NULL ) { | 20 | if ( db != NULL ) { |
| 19 | fprintf(stderr, "Datenbank eröffnet...\n"); | 21 | (void) fprintf(stderr, "Datenbank eröffnet...\n"); |
| 20 | 22 | ||
| 21 | #if INSERT | 23 | #if INSERT |
| 22 | user_type users[] = { | 24 | user_type users[] = { |
| @@ -50,7 +52,9 @@ int main(void) | |||
| 50 | #endif | 52 | #endif |
| 51 | 53 | ||
| 52 | { | 54 | { |
| 53 | DBT key, data; | 55 | DBT key; |
| 56 | DBT data; | ||
| 57 | |||
| 54 | int err = db->seq(db, &key, &data, R_FIRST); | 58 | int err = db->seq(db, &key, &data, R_FIRST); |
| 55 | while ( !err ) { | 59 | while ( !err ) { |
| 56 | user_type *user = data.data; | 60 | user_type *user = data.data; |
