Add initial project structure and files
This commit is contained in:
55
.gitignore
vendored
Normal file
55
.gitignore
vendored
Normal file
@@ -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
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -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.
|
||||||
43
Makefile
Normal file
43
Makefile
Normal file
@@ -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)
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -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.
|
||||||
BIN
bin/kvstore
Executable file
BIN
bin/kvstore
Executable file
Binary file not shown.
33
include/cli.h
Normal file
33
include/cli.h
Normal file
@@ -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
|
||||||
0
include/kv_store.h
Normal file
0
include/kv_store.h
Normal file
49
include/string.h
Normal file
49
include/string.h
Normal file
@@ -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
|
||||||
0
src/kv_store.c
Normal file
0
src/kv_store.c
Normal file
14
src/main.c
Normal file
14
src/main.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
11
src/string.c
Normal file
11
src/string.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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) {}
|
||||||
Reference in New Issue
Block a user