From: Lukas Krickl Date: Mon, 30 Sep 2024 15:17:15 +0000 (+0200) Subject: ulas: minor refactor of project structure X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=b7e395d761bee09d2715be3d7f79de3803b84246;p=ulas%2F.git ulas: minor refactor of project structure --- diff --git a/.clang-tidy b/.clang-tidy index 47cc1cf..42c3dd0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -22,10 +22,18 @@ Checks: "*, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -misc-no-recursion, -concurrency-mt-unsafe, - -clang-analyzer-unix.Malloc, + -hicpp-signed-bitwise, + -misc-include-cleaner, -modernize-macro-to-enum, - -hicpp-signed-bitwise + -hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix, + -readability-uppercase-literal-suffix, + -hicpp-function-size, + -readability-function-size, + -cert-env33-c " WarningsAsErrors: '' HeaderFilterRegex: '' FormatStyle: None + + + diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..0e17bae --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +Diagnostics: + UnusedIncludes: None diff --git a/.gitignore b/.gitignore index 383f6c3..c7e8574 100644 --- a/.gitignore +++ b/.gitignore @@ -60,5 +60,5 @@ dkms.conf compile_commands.json .cache/ .clang_complete -.clangd +# .clangd .session diff --git a/src/main.c b/src/main.c index d2a0212..e033a06 100644 --- a/src/main.c +++ b/src/main.c @@ -16,43 +16,6 @@ * register with -w syntax */ -#define ULAS_NAME "ulas" -#define ULAS_VER "0.0.1" - -// args without value -#define ULAS_OPTS "hvVpdA" - -// args with value -#define ULAS_OPTS_ARG "o:l:s:i:w:a:S:" - -#define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc); - -#define ULAS_INCPATHSMAX 256 - -char *incpaths[ULAS_INCPATHSMAX]; -unsigned long incpathslen = 0; - -void ulas_help(void) { - printf("%s\n", ULAS_NAME); - printf("Usage %s [-%s] [-o=path] [-i=path] [-l=path] [-a=initial-address] [-S=ulas|mlb] " - "[input]\n\n", - ULAS_NAME, ULAS_OPTS); - ULAS_HELP("h", "display this help and exit"); - ULAS_HELP("V", "display version info and exit"); - ULAS_HELP("v", "verbose output"); - ULAS_HELP("p", "Stop after preprocessor"); - ULAS_HELP("o=path", "Output file"); - ULAS_HELP("l=path", "Listing file"); - ULAS_HELP("s=path", "Symbols file"); - ULAS_HELP("i=path", "Add include search path"); - ULAS_HELP("a=initial-address", "Initial starting address"); - ULAS_HELP("A", "Print addresses in disassembler mode"); - ULAS_HELP("d", "Disassemble a file"); - ULAS_HELP("S", "Set the symbol format"); - ULAS_HELP("w=warning", "Toggle warnings: a=all, o=overflow"); -} - -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 warnings[255]; diff --git a/src/test.c b/src/test.c index b00742e..8410575 100644 --- a/src/test.c +++ b/src/test.c @@ -1,6 +1,10 @@ #include "ulas.h" #include #include +#include + +#define ULAS_TEST_OPTS "hV" +#define ULAS_TEST_OPTS_ARG "" #define ULAS_TOKMAX 64 #define TESTBEGIN(name) printf("[test %s]\n", (name)); @@ -433,8 +437,39 @@ void test_full_dasm(void) { TESTEND("testfulldasm"); } -int main(int arc, char **argv) { +void test_help(void) { + printf("%s tests\n", ULAS_NAME); + printf("Usage %s [%s]\n\n", ULAS_NAME, ULAS_TEST_OPTS); + ULAS_HELP("h", "display this help and exit"); + ULAS_HELP("V", "display version info and exit"); +} + +void test_getopt(int argc, char **argv, struct ulas_config *cfg) { + int c = 0; + while ((c = getopt(argc, argv, ULAS_TEST_OPTS ULAS_TEST_OPTS_ARG)) != -1) { + switch (c) { + case 'h': + test_help(); + exit(0); + break; + case 'V': + ulas_version(); + exit(0); + break; + case '?': + break; + default: + printf("%s: invalid option '%c'\nTry '%s -h' for more information.\n", + ULAS_NAME, c, ULAS_NAME); + exit(-1); + break; + } + } +} + +int main(int argc, char **argv) { TESTBEGIN("ulas test"); + test_getopt(argc, argv, &ulascfg); ulas_init(ulas_cfg_from_env()); /*if (!ulascfg.verbose) { diff --git a/src/ulas.c b/src/ulas.c index 0443018..a4dedf5 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -15,6 +15,32 @@ FILE *ulassymout = NULL; struct ulas_config ulascfg; struct ulas ulas; +char *incpaths[ULAS_INCPATHSMAX]; +unsigned long incpathslen = 0; + +void ulas_help(void) { + printf("%s\n", ULAS_NAME); + printf("Usage %s [-%s] [-o=path] [-i=path] [-l=path] [-a=initial-address] [-S=ulas|mlb] " + "[input]\n\n", + ULAS_NAME, ULAS_OPTS); + ULAS_HELP("h", "display this help and exit"); + ULAS_HELP("V", "display version info and exit"); + ULAS_HELP("v", "verbose output"); + ULAS_HELP("p", "Stop after preprocessor"); + ULAS_HELP("o=path", "Output file"); + ULAS_HELP("l=path", "Listing file"); + ULAS_HELP("s=path", "Symbols file"); + ULAS_HELP("i=path", "Add include search path"); + ULAS_HELP("a=initial-address", "Initial starting address"); + ULAS_HELP("A", "Print addresses in disassembler mode"); + ULAS_HELP("d", "Disassemble a file"); + ULAS_HELP("S", "Set the symbol format"); + ULAS_HELP("w=warning", "Toggle warnings: a=all, o=overflow"); +} + +void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); } + + void ulas_init(struct ulas_config cfg) { // init global cfg if (ulasin == NULL) { diff --git a/src/ulas.h b/src/ulas.h index e124ba9..9a7ea12 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -6,6 +6,22 @@ #include #include "archs.h" +#define ULAS_NAME "ulas" +#define ULAS_VER "0.0.1" + +// args without value +#define ULAS_OPTS "hvVpdA" + +// args with value +#define ULAS_OPTS_ARG "o:l:s:i:w:a:S:" + +#define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc); + +#define ULAS_INCPATHSMAX 256 + +extern char *incpaths[ULAS_INCPATHSMAX]; +extern unsigned long incpathslen; + // if this is used as a path use stdin or stdout instead #define ULAS_STDFILEPATH "-" #define ULAS_PATHSEP "/" @@ -603,4 +619,7 @@ const char *ulas_asmregstr(unsigned int reg); int ulas_intexpr(const char **line, unsigned long n, int *rc); char *ulas_strexpr(const char **line, unsigned long n, int *rc); +void ulas_help(void); +void ulas_version(void); + #endif