ulas: minor refactor of project structure
authorLukas Krickl <lukas@krickl.dev>
Mon, 30 Sep 2024 15:17:15 +0000 (17:17 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 30 Sep 2024 15:17:15 +0000 (17:17 +0200)
.clang-tidy
.clangd [new file with mode: 0644]
.gitignore
src/main.c
src/test.c
src/ulas.c
src/ulas.h

index 47cc1cf2c035ecf34cebf969192e25dcefad23c0..42c3dd0e0deb6fde64ddebaa60d812cbc2d477d1 100644 (file)
@@ -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 (file)
index 0000000..0e17bae
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,2 @@
+Diagnostics:
+  UnusedIncludes: None 
index 383f6c348499cea60a32c80d665e228b61324948..c7e8574fd7db157791cb3513e156f8046b1bafdc 100644 (file)
@@ -60,5 +60,5 @@ dkms.conf
 compile_commands.json
 .cache/
 .clang_complete
-.clangd
+.clangd
 .session
index d2a0212c88bc1357f86ce92b30e22e09522754c9..e033a06940378abfe8987a615eb30c5acaac85ef 100644 (file)
  * 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];
index b00742e5dd1f3cb873c302049b2bb0185866ee13..8410575fc590cf3720845073ea297311922c1716 100644 (file)
@@ -1,6 +1,10 @@
 #include "ulas.h"
 #include <stdio.h>
 #include <assert.h>
+#include <unistd.h>
+
+#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) {
index 0443018caa36ce08d183f677d74cb12508bf1a36..a4dedf56b3dcc4c5c985b358539bb3e9cbd7c141 100644 (file)
@@ -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) {
index e124ba9c9a80458cfdfc46d9e2cdda260cd0a2af..9a7ea12193220bb1715cd22171dc15219132c9f7 100644 (file)
@@ -6,6 +6,22 @@
 #include <string.h>
 #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