commit f97528f2f07d4285897527dfd8575155aba56a81 Author: Spencer Jones Date: Thu Dec 18 17:01:21 2025 -0700 Add initial project structure and files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..845cda6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,55 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# debug information files +*.dwo diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2b53484 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Spencer Jones + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4819974 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +# kvstore - A simple key-value store CLI application +# Build with: make +# Run with: make run +# Clean with: make clean + +# ===== PROJECT CONFIGURATION ===== +TARGET = kvstore +CC = clang +CPPFLAGS = -I include +CFLAGS = -Wall -Wextra + +# ===== LINKER ===== +LDFLAGS = +LIBS = + +# ===== DIRECTORIES ===== +SRC_DIR = src +BUILD_DIR = build +BIN_DIR = bin + +# ===== SOURCE AND OBJECT FILES ===== +SRCS = $(wildcard $(SRC_DIR)/*.c) +OBJS = $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) +TARGET_PATH = $(BIN_DIR)/$(TARGET) + +# ===== COMPILATION PATTERN RULE ===== +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +# ===== LINKING RULES ===== +$(TARGET_PATH): $(OBJS) | $(BIN_DIR) + $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ + +# ===== CONVENIENCE TARGETS ===== +.PHONY: all clean run + +all: $(TARGET_PATH) + +run: $(TARGET_PATH) + ./$(TARGET_PATH) + +clean: + rm -f $(BUILD_DIR)/*.o $(TARGET_PATH) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e230b85 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# C Learning Project: Key-Value store + +The purpose of this project is to learn c development from first principles using clang and make with the loose goal of creating an RDBMS. diff --git a/bin/kvstore b/bin/kvstore new file mode 100755 index 0000000..dc5ef07 Binary files /dev/null and b/bin/kvstore differ diff --git a/include/cli.h b/include/cli.h new file mode 100644 index 0000000..36c0bfd --- /dev/null +++ b/include/cli.h @@ -0,0 +1,33 @@ +#ifndef CLI_H +#define CLI_H + +/* + * Result structure containing command status and message + */ +typedef struct { + int success; // 0 for failure, 1 for success + char *message; // Result or error message +} cli_result_t; + +/* + * cli_print_help - Prints the cli's usage text to stdout. + */ +void cli_print_help(void); + +/* + * cli_execute - Parse arguments and execute the command + * @argc: Argument count + * @argv: Argument array + * + * Returns: cli_result_t with status and message. + * Caller must free message with string_free(). + */ +cli_result_t cli_execute(int argc, char *argv[]); + +/* + * cli_print_result - Print a result to stdout + * @result: Result structure from cli_execute + */ +void cli_print_result(const cli_result_t *result); + +#endif diff --git a/include/kv_store.h b/include/kv_store.h new file mode 100644 index 0000000..e69de29 diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..48ae0cf --- /dev/null +++ b/include/string.h @@ -0,0 +1,49 @@ +#ifndef STRING_H +#define STRING_H + +/* + * string_copy - Allocate and copy a string + * @src: Source string to copy + * + * Returns: Newly allocated copy of src, or NULL on failure. + * Caller must free the returned pointer. + */ +char *string_copy(const char *src); + +/* + * string_compare - Compare two strings + * @str1: First string + * @str2: Second string + * + * Returns: 0 if equal, negative if str1 < str2, positive if str1 > str2. + */ +int string_compare(const char *str1, const char *str2); + +/* + * string_trim - Allocate and return a trimmed copy of a string + * @str: String to trim + * + * Returns: Newly allocated copy of str with leading and trailing whitespace + * removed, or NULL on failure. Caller must free the returned pointer. + */ +char *string_trim(const char *str); + +/* + * string_search - Search if a string contains a different string. + * @src: Source string to search + * @search: String to search for + * + * Returns: -1 if not found, zero-based index of the searched string if found. + * Returns -1 if search string is empty or NULL. + */ +int string_search(const char *src, const char *search); + +/* + * string_free - Free a string allocated by string functions + * @str: String to free (NULL-safe) + * + * Safe to call with NULL; does nothing in that case. + */ +void string_free(const char *str); + +#endif diff --git a/src/cli.c b/src/cli.c new file mode 100644 index 0000000..e69de29 diff --git a/src/kv_store.c b/src/kv_store.c new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..26d0efe --- /dev/null +++ b/src/main.c @@ -0,0 +1,14 @@ +#include + +int main(int argc, char *argv[]) { + printf("KVStore - Key-Value Store\n"); + + if (argc > 1) { + printf("Number of arguments: %d\n", argc - 1); + for (int i = 1; i < argc; i++) { + printf("Argument %d: %s\n", i, argv[i]); + } + } + + return 0; +} diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..ae6230e --- /dev/null +++ b/src/string.c @@ -0,0 +1,11 @@ +#include + +char *string_copy(const char *src) { return NULL; } + +int string_compare(const char *str1, const char *str2) { return -1; } + +char *string_trim(const char *str) { return NULL; } + +int string_search(const char *src, const char *search) { return -1; } + +void string_free(const char *str) {}