From 7ace8bda1e0f1dc5600522222b1adbc62c5ef6e2 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 4 Nov 2023 21:28:52 +0100 Subject: [PATCH 1/1] Initial commit --- .clang-format | 1 + .clang-tidy | 29 +++++++++++++++++++++++ .gitattributes | 1 + .gitignore | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 18 +++++++++++++++ README.md | 29 +++++++++++++++++++++++ doc/ulas.man | 30 ++++++++++++++++++++++++ include/ulas.h | 15 ++++++++++++ makefile | 52 +++++++++++++++++++++++++++++++++++++++++ scrips/bear.sh | 4 ++++ scrips/init.sh | 32 +++++++++++++++++++++++++ scrips/run.sh | 4 ++++ scrips/test.sh | 4 ++++ src/main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ src/test.c | 12 ++++++++++ src/ulas.c | 5 ++++ 16 files changed, 358 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 doc/ulas.man create mode 100644 include/ulas.h create mode 100644 makefile create mode 100755 scrips/bear.sh create mode 100755 scrips/init.sh create mode 100755 scrips/run.sh create mode 100755 scrips/test.sh create mode 100644 src/main.c create mode 100644 src/test.c create mode 100644 src/ulas.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ac7dcd1 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +SortIncludes: false diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e8c0c33 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,29 @@ +--- +Checks: "*, + -abseil-*, + -llvm*, + -google*, + -modernize-use-trailing-return-type, + -readability-else-after-return, + -readability-static-accessed-through-instance, + -readability-avoid-const-params-in-decls, + -misc-unused-parameters, + -bugprone-easily-swappable-parameters, + -cert-err33-c, + -readability-identifier-length, + -altera-unroll-loops, + -cppcoreguidelines-avoid-non-const-global-variables, + -altera-struct-pack-align, + -cppcoreguidelines-avoid-magic-numbers, + -readability-magic-numbers, + -cert-err34-c, + -readability-function-cognitive-complexity, + -altera-id-dependent-backward-branch, + -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, + -misc-no-recursion, + -concurrency-mt-unsafe +" +WarningsAsErrors: '' +HeaderFilterRegex: '' +FormatStyle: None + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..909c473 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# Build directory +bin/ +obj/ + + 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 +vgcore.* + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +compile_commands.json +.cache/ +.clang_complete +.clangd + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0702b7d --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Copyright 2020 Lukas Krickl (lukas@krickl.dev) + +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/README.md b/README.md new file mode 100644 index 0000000..031a1e7 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# ulas + +## Table of content + +- [Installation](#Installation) +- [Usage](#Usage) +- [License](#License) +- [Contributing](#Contributing) +- [TODO](#TODO) + +## Installation + +To build this program you will require a recent C compiler, make, `libargtable2` and `libcmocka` for unit tests. + +```sh +premake gmake # to build gnu make file +make # to compile all targets +``` + +## Usage + +1) Rename `ulas` to the project's name in all files and folders + +## License + +This program is distributed under the terms of the MIT License. + +## Contributing + diff --git a/doc/ulas.man b/doc/ulas.man new file mode 100644 index 0000000..9360001 --- /dev/null +++ b/doc/ulas.man @@ -0,0 +1,30 @@ +.\" Manpage for ulas. +.\" Contact lukas@krickl.dev to correct errors or typos. + +.TH man 8 "21 August 2023" "0.0.1" "ulas manual" + +.SH NAME + ulas +.SH SYNOPSIS + ulas [-v] [--help] [--version] +.SH DESCRIPTION + ulas + + --help + display this help and exit + --version + display version info and exit + -v, --verbose + verbose output + +.SH EXAMPLES + +.SH SEE ALSO + +.SH BUGS + +.SH AUTHOR + Lukas Krickl (lukas@krickl.dev) + +.SH COPYRIGHT + Copyright 2023 Lukas Krickl (lukas@krickl.dev) diff --git a/include/ulas.h b/include/ulas.h new file mode 100644 index 0000000..03bca6b --- /dev/null +++ b/include/ulas.h @@ -0,0 +1,15 @@ +#ifndef ULASH__ +#define ULASH__ + +#include + +struct ulas_config { + char **argv; + int argc; + + bool verbose; +}; + +int ulas_main(struct ulas_config *cfg); + +#endif diff --git a/makefile b/makefile new file mode 100644 index 0000000..336b96f --- /dev/null +++ b/makefile @@ -0,0 +1,52 @@ +NAME=ulas +IDIR=./include +SDIR=./src +CC=gcc +DBGCFLAGS=-g -fsanitize=address +DBGLDFLAGS=-fsanitize=address +CFLAGS=-I$(IDIR) -Wall -pedantic $(DBGCFLAGS) -std=gnu99 +LIBS= +TEST_LIBS= +LDFLAGS=$(DBGLDFLAGS) $(LIBS) + +ODIR=obj +TEST_ODIR=obj/test +BDIR=bin +BNAME=$(NAME) +MAIN=main.o +TEST_MAIN=test.o +TEST_BNAME=testulas + +BIN_INSTALL_DIR=/usr/local/bin +MAN_INSTALL_DIR=/usr/local/man + +_OBJ = $(MAIN) ulas.o +OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) + +all: bin test + +$(ODIR)/%.o: src/%.c + mkdir -p $(@D) + $(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS) + +bin: $(OBJ) + mkdir -p $(BDIR) + $(CC) -o $(BDIR)/$(BNAME) $^ $(CFLAGS) $(LDFLAGS) + +test: + echo "building tests" + make bin MAIN=$(TEST_MAIN) BNAME=$(TEST_BNAME) ODIR=$(TEST_ODIR) LIBS=$(TEST_LIBS) + +.PHONY: clean + +clean: + rm -f ./$(ODIR)/*.o + rm -f ./$(TEST_ODIR)/*.o + rm -f ./$(BDIR)/$(BNAME) + rm -f ./$(BDIR)/$(TEST_BNAME) + +.PHONY: install + +install: + cp ./$(BDIR)/$(BNAME) $(BIN_INSTALL_DIR) + cp ./doc/$(BNAME).man $(MAN_INSTALL_DIR) diff --git a/scrips/bear.sh b/scrips/bear.sh new file mode 100755 index 0000000..445b696 --- /dev/null +++ b/scrips/bear.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# generate clang build commands +bear -- make SHELL="sh -x -e" --always-make diff --git a/scrips/init.sh b/scrips/init.sh new file mode 100755 index 0000000..9163866 --- /dev/null +++ b/scrips/init.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# rename to project specific values +NAME="ulas" +CONST="ULAS" +STRUCT="ulas" +FN="ulas" + +# will be replaced +ULAS_NAME="ulas" +ULAS_STRUCT="ulas" +ULAS_CONST="ULAS" +ULAS_FN="ulas" + +function replace() { + echo "Replacing $1 with $2" + find ./ -type f -name '*.c' -exec sed -i "s/$1/$2/g" {} \; + find ./ -type f -name '*.h' -exec sed -i "s/$1/$2/g" {} \; + find ./ -type f -name '*.md' -exec sed -i "s/$1/$2/g" {} \; + find ./ -type f -name 'makefile' -exec sed -i "s/$1/$2/g" {} \; + find ./ -type f -name '*.sh' -exec sed -i "s/$1/$2/g" {} \; + find ./doc/ -type f -name '*' -exec sed -i "s/$1/$2/g" {} \; +} + +replace $ULAS_NAME $NAME +replace $ULAS_CONST $CONST +replace $ULAS_STRUCT $STRUCT +replace $ULAS_FN $FN + +mv "include/$ULAS_NAME.h" "include/$NAME.h" +mv "src/$ULAS_NAME.c" "src/$NAME.c" +mv "doc/$ULAS_NAME.man" "doc/$NAME.man" diff --git a/scrips/run.sh b/scrips/run.sh new file mode 100755 index 0000000..16552dc --- /dev/null +++ b/scrips/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +make && ./bin/ulas "$@" + diff --git a/scrips/test.sh b/scrips/test.sh new file mode 100755 index 0000000..896784d --- /dev/null +++ b/scrips/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +make && ./bin/testulas + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..79e49a3 --- /dev/null +++ b/src/main.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include "ulas.h" +#include + +#define ULAS_NAME "ulas" +#define ULAS_VER "0.0.1" + +void ulas_help(void) { + printf("%s\n", ULAS_NAME); + printf("Usage %s [-h] [-V] [-v]\n\n", ULAS_NAME); + printf("\t-h\tdisplay this help and exit\n"); + printf("\t-V\tdisplay version info and exit\n"); + printf("\t-v\tverbose output\n"); +} + +void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); } + +void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) { + int c = 0; + while ((c = getopt(argc, argv, "hvV")) != -1) { + switch (c) { + case 'h': + ulas_help(); + exit(0); + break; + case 'V': + ulas_version(); + exit(0); + break; + case 'v': + cfg->verbose = true; + break; + case '?': + break; + default: + printf("%s: invalid option '%c'\nTry '%s -h' for more information.\n", + ULAS_NAME, c, ULAS_NAME); + exit(-1); + break; + } + } + + cfg->argc = argc - optind; + cfg->argv = argv + optind; +} + +int main(int argc, char **argv) { + // map args to cfg here + struct ulas_config cfg; + memset(&cfg, 0, sizeof(cfg)); + + ulas_getopt(argc, argv, &cfg); + + int res = ulas_main(&cfg); + + return res; +} diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..da0b381 --- /dev/null +++ b/src/test.c @@ -0,0 +1,12 @@ +#include + +void null_test_success(void) { + puts("[null test]"); + puts("[null test ok]"); +} + +int main(int arc, char **argv) { + null_test_success(); + + return 0; +} diff --git a/src/ulas.c b/src/ulas.c new file mode 100644 index 0000000..159a094 --- /dev/null +++ b/src/ulas.c @@ -0,0 +1,5 @@ +#include "ulas.h" + +int ulas_main(struct ulas_config *cfg) { + return 0; +} -- 2.30.2