From 3c9cc7d383df019dacbd80480730723fe4b20b44 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sat, 11 Jul 2026 16:01:16 +0200 Subject: Infrastruktur hinzugefügt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 45 +++++++++++++++++++++++++++++++++++ .clang-tidy | 19 +++++++++++++++ .gitignore | 3 +++ compile_flags.txt | 4 ++++ config.mk | 2 ++ db-test.c | 66 --------------------------------------------------- makefile | 24 +++++++++++++++++++ src/db-test.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 167 insertions(+), 66 deletions(-) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .gitignore create mode 100644 compile_flags.txt create mode 100644 config.mk delete mode 100644 db-test.c create mode 100644 makefile create mode 100644 src/db-test.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..21efcac --- /dev/null +++ b/.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/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..0bceb5b --- /dev/null +++ b/.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/.gitignore b/.gitignore new file mode 100644 index 0000000..3a5e204 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +obj/ +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 @@ +-Wall +-Werror +-pedantic +-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 @@ +CFLAGS=-Wall -Werror -pedantic -std=c99 +LDFLAGS= diff --git a/db-test.c b/db-test.c deleted file mode 100644 index 2789ce0..0000000 --- a/db-test.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -typedef struct { - char username[20]; - char fullname[50]; - int age; -} user_type; - -int main(void) -{ - DB *db = dbopen("database.db", O_RDWR | O_CREAT, 0644, DB_BTREE, NULL); - if ( db != NULL ) { - fprintf(stderr, "Datenbank eröffnet...\n"); - -#if INSERT - user_type users[] = { - { "datengott", "Thomas Schmucker", 44 }, - { "user1", "Sabine Müller", 23 }, - { "sql-user", "SQL Database User", -1 } - }; - - for ( int i = 0; i != 3; ++i ) { - DBT data = { .data = &users[i], .size = sizeof(users[i]) }; - DBT key = { .data = &users[i].username, .size = sizeof(users[i].username) }; - - int res = db->put(db, &key, &data, 0); - if ( res == -1 ) { - fprintf(stderr, "failed to insert data!\n"); - } - } -#endif - -#if LOOKUP - { - DBT key = { .data = &users[0].username, .size = sizeof(users[0].username) }; - DBT data; - - int res = db->get(db, &key, &data, 0); - if ( res == 0 ) { - user_type *user = data.data; - printf("Fullname: %s, Age: %d\n", user->fullname, user->age); - } - } -#endif - - { - DBT key, data; - int err = db->seq(db, &key, &data, R_FIRST); - while ( !err ) { - user_type *user = data.data; - printf("Fullname: %s, Age: %d\n", user->fullname, user->age); - - err = db->seq(db, &key, &data, R_NEXT); - } - } - - db->close(db); - } - return EXIT_SUCCESS; -} diff --git a/makefile b/makefile new file mode 100644 index 0000000..da7631a --- /dev/null +++ b/makefile @@ -0,0 +1,24 @@ +include config.mk + +BIN=bin/db-test +OBJS=obj/db-test.o + +release: $(BIN) +release: CFLAGS+=-DNDEBUG -O2 + +debug: $(BIN) +debug: CFLAGS+=-g + +$(BIN): $(OBJS) | bin + cc $(LDFLAGS) $^ -o $@ + +obj/%.o: src/%.c | obj + cc $(CFLAGS) -c $< -o $@ + +bin obj: + mkdir -p $@ + +clean: + rm -rf bin obj + +.PHONY: release debug clean diff --git a/src/db-test.c b/src/db-test.c new file mode 100644 index 0000000..439ed79 --- /dev/null +++ b/src/db-test.c @@ -0,0 +1,70 @@ +#include +#include +#include + +#include +#include + +#define USERNAME_LENGTH 20 +#define FULLNAME_LENGTH 50 + +typedef struct { + char username[USERNAME_LENGTH]; + char fullname[FULLNAME_LENGTH]; + int age; +} user_type; + +int main(void) +{ + DB *db = dbopen("./database.db", O_RDWR | O_CREAT, 0644, DB_BTREE, NULL); // NOLINT + if ( db != NULL ) { + (void) fprintf(stderr, "Datenbank eröffnet...\n"); + +#if INSERT + user_type users[] = { + { "datengott", "Thomas Schmucker", 44 }, + { "user1", "Sabine Müller", 23 }, + { "sql-user", "SQL Database User", -1 } + }; + + for ( int i = 0; i != 3; ++i ) { + DBT data = { .data = &users[i], .size = sizeof(users[i]) }; + DBT key = { .data = &users[i].username, .size = sizeof(users[i].username) }; + + int res = db->put(db, &key, &data, 0); + if ( res == -1 ) { + fprintf(stderr, "failed to insert data!\n"); + } + } +#endif + +#if LOOKUP + { + DBT key = { .data = &users[0].username, .size = sizeof(users[0].username) }; + DBT data; + + int res = db->get(db, &key, &data, 0); + if ( res == 0 ) { + user_type *user = data.data; + printf("Fullname: %s, Age: %d\n", user->fullname, user->age); + } + } +#endif + + { + DBT key; + DBT data; + + int err = db->seq(db, &key, &data, R_FIRST); + while ( !err ) { + user_type *user = data.data; + printf("Fullname: %s, Age: %d\n", user->fullname, user->age); + + err = db->seq(db, &key, &data, R_NEXT); + } + } + + db->close(db); + } + return EXIT_SUCCESS; +} -- cgit v1.3