From 2eb38da4e6f87e763b5edd89671a8894ad619f98 Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 28 Aug 2023 12:56:34 -0600 Subject: [PATCH 1/4] Structural Repair --- Makefile | 18 +- chad.mk | 6 +- config.mk | 18 -- BUGS.md => document/BUGS.md | 0 TODO => document/TODO | 0 {docs => document}/possible_messages.list | 0 {source => include}/chad.h | 0 {source => include}/hl.h | 0 {source => include}/regex.h | 0 {source => include}/terminal_hl.h | 0 {source => include}/vector.h | 0 tests/comment.input | 1 - tests/main.c | 321 ------------------------------ tests/regex_tester.cpp | 76 ------- tests/test.input | 1 - tests/vector.c | 135 ------------- 16 files changed, 18 insertions(+), 558 deletions(-) delete mode 100644 config.mk rename BUGS.md => document/BUGS.md (100%) rename TODO => document/TODO (100%) rename {docs => document}/possible_messages.list (100%) rename {source => include}/chad.h (100%) rename {source => include}/hl.h (100%) rename {source => include}/regex.h (100%) rename {source => include}/terminal_hl.h (100%) rename {source => include}/vector.h (100%) delete mode 100644 tests/comment.input delete mode 100644 tests/main.c delete mode 100644 tests/regex_tester.cpp delete mode 100644 tests/test.input delete mode 100644 tests/vector.c diff --git a/Makefile b/Makefile index c698c95..544c1af 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,20 @@ -include config.mk +TARGET:=hl + +CFLAGS:=-std=c99 +CPPFLAGS:=-Isyntax -Iinclude -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 + +DEBUG=1 + +ifeq (${DEBUG},1) + CFLAGS += -Og -ggdb -pg -fno-inline +else + CFLAGS += -O2 -flto=auto +endif + +PREFIX:=/usr/bin + +USER=$(shell whoami) + include chad.mk SRC.dir:=source diff --git a/chad.mk b/chad.mk index c4ce45a..5488edb 100644 --- a/chad.mk +++ b/chad.mk @@ -1,7 +1,3 @@ -# - ARGS : default flags to test the program with - -# Programs to check warnings for as defined by the chad standard - ARGS:=${TARGET} < source/main.c GCC:=gcc @@ -16,6 +12,6 @@ VALGRIND:=valgrind VALGRIND.flags:=--track-origins=yes --leak-check=full --show-leak-kinds=all chad_test: - ${CLANG} ${CPPFLAGS} ${D.versions} ${CLANG.warnings} ${SRC} -o ${TARGET} + ${CLANG} ${CPPFLAGS} ${D.versions} ${CLANG.warnings} ${SRC} -o ${TARGET} ${GCC} ${CPPFLAGS} ${D.versions} ${GCC.debug} ${GCC.warnings} ${SRC} -o ${TARGET} ${VALGRIND} ${VALGRIND.flags} $(shell pwd)/${TARGET} ${ARGS} diff --git a/config.mk b/config.mk deleted file mode 100644 index 0a3f5c1..0000000 --- a/config.mk +++ /dev/null @@ -1,18 +0,0 @@ -# - TARGET : output program name - -TARGET:=hl - -CFLAGS:=-std=c99 -CPPFLAGS:=-Isyntax/ -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 - -DEBUG=1 - -ifeq (${DEBUG},1) - CFLAGS += -Og -ggdb -pg -fno-inline -else - CFLAGS += -O2 -flto=auto -endif - -PREFIX:=/usr/bin - -USER=$(shell whoami) diff --git a/BUGS.md b/document/BUGS.md similarity index 100% rename from BUGS.md rename to document/BUGS.md diff --git a/TODO b/document/TODO similarity index 100% rename from TODO rename to document/TODO diff --git a/docs/possible_messages.list b/document/possible_messages.list similarity index 100% rename from docs/possible_messages.list rename to document/possible_messages.list diff --git a/source/chad.h b/include/chad.h similarity index 100% rename from source/chad.h rename to include/chad.h diff --git a/source/hl.h b/include/hl.h similarity index 100% rename from source/hl.h rename to include/hl.h diff --git a/source/regex.h b/include/regex.h similarity index 100% rename from source/regex.h rename to include/regex.h diff --git a/source/terminal_hl.h b/include/terminal_hl.h similarity index 100% rename from source/terminal_hl.h rename to include/terminal_hl.h diff --git a/source/vector.h b/include/vector.h similarity index 100% rename from source/vector.h rename to include/vector.h diff --git a/tests/comment.input b/tests/comment.input deleted file mode 100644 index ee7d88c..0000000 --- a/tests/comment.input +++ /dev/null @@ -1 +0,0 @@ -/* a */ diff --git a/tests/main.c b/tests/main.c deleted file mode 100644 index f599c2b..0000000 --- a/tests/main.c +++ /dev/null @@ -1,321 +0,0 @@ -// @COMPILECMD gcc $@ -o test -#include - -signed main(){ - printf("Warning: .drectve `TEST_STRING' unrecognized\n"); - printf("Warning: corrupt .drectve at end of def file\n"); - printf("TEST_STRING:10: Warning: path components stripped from TEST_STRING, 'TEST_STRING'\n"); - printf("ld: TEST_STRING:10: TEST_STRING\n"); - printf("ld: bfd_hash_table_init of cref table failed: 404\n"); - printf("ld: cref_hash_lookup failed: 404\n"); - printf("ld: cref alloc failed: 404\n"); - printf("ld: symbol `%T' missing from main hash table\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("ld: symbol `%T' missing from main hash table\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("testfile.c: could not read relocs: 404\n"); - printf("testfile.c: could not read relocs: 404\n"); - printf("testfile.c:102: prohibited cross reference from TEST_STRING to `%T' in TEST_STRING\n"); - printf("ld: Different relocs used in set TEST_STRING\n"); - printf("ld: Different object file formats composing set TEST_STRING\n"); - printf("ld: TEST_STRING does not support reloc TEST_STRING for set TEST_STRING\n"); - printf("ld: Special section TEST_STRING does not support reloc TEST_STRING for set TEST_STRING\n"); - printf("ld: TEST_STRING does not support reloc TEST_STRING for set TEST_STRING\n"); - printf("ld: Unsupported size 10 for set TEST_STRING\n"); - printf("ld: unrecognised emulation mode: TEST_STRING\n"); - printf("Supported emulations: "); - printf("\n"); - printf("ld: bfd_hash_allocate failed creating symbol TEST_STRING\n"); - printf("ld: bfd_hash_lookup failed creating symbol TEST_STRING\n"); - printf("ld: warning: address of `TEST_STRING' "); - printf("TEST_STRING %% by zero\n"); - printf("TEST_STRING / by zero\n"); - printf("ld: bfd_link_hash_lookup failed: 404\n"); - printf("TEST_STRING: unresolvable symbol `TEST_STRING'"); - printf("TEST_STRING: undefined symbol `TEST_STRING'"); - printf("TEST_STRING: undefined section `TEST_STRING'"); - printf("TEST_STRING: undefined section `TEST_STRING'"); - printf("TEST_STRING: undefined section `TEST_STRING'"); - printf("TEST_STRING: undefined MEMORY region `TEST_STRING'"); - printf("TEST_STRING: undefined MEMORY region `TEST_STRING'"); - printf("TEST_STRING: unknown constant `TEST_STRING' referenced in expression\n"); - printf("ld: TEST_STRING\n"); - printf("TEST_STRING can not PROVIDE assignment to"); - printf("TEST_STRING invalid assignment to"); - printf("TEST_STRING assignment to location counter"); - printf("TEST_STRING cannot move location counter backwards"); - printf("ld:TEST_STRING: hash creation failed\n"); - printf("TEST_STRING: nonconstant expression for TEST_STRING\n"); - printf("TEST_STRING: nonconstant expression for TEST_STRING\n"); - printf("TEST_STRING: nonconstant expression for TEST_STRING\n"); - printf("ld: can not create hash table: 404\n"); - printf("ld: invalid BFD target `TEST_STRING'\n"); - printf("ld: skipping incompatible TEST_STRING "); - printf("ld: attempted static link of dynamic object `TEST_STRING'\n"); - printf("ld: skipping incompatible TEST_STRING "); - printf("ld: cannot find TEST_STRING (TEST_STRING): 404\n"); - printf("ld: cannot find TEST_STRING: 404\n"); - printf("ld: cannot find TEST_STRING inside TEST_STRING\n"); - printf("ld: cannot find TEST_STRING\n"); - printf("ld: cannot open linker script file TEST_STRING: 404\n"); - printf("ld: cannot represent machine `TEST_STRING'\n"); - printf("ld: unrecognised keyword in MRI style script 'TEST_STRING'\n"); - printf("ld:TEST_STRING: unknown phdr type `TEST_STRING' (try integer literal)\n"); - printf("ld:TEST_STRING: PHDRS syntax error at `TEST_STRING'\n"); - printf("ld:TEST_STRING: file format not recognized; treating as linker script\n"); - printf("ld:TEST_STRING: TEST_STRING in TEST_STRING\n"); - printf("ld:TEST_STRING: TEST_STRING\n"); - printf("ld: can not create hash table: 404\n"); - printf("ld:TEST_STRING: warning: redeclaration of memory region `TEST_STRING'\n"); - printf("ld:TEST_STRING: warning: memory region `TEST_STRING' not declared\n"); - printf("ld:TEST_STRING: error: alias for default memory region\n"); - printf("ld: Illegal use of `TEST_STRING' section\n"); - printf("ld: output format TEST_STRING cannot represent section"); - printf("testfile.c: file not recognized: 404\n"); - printf("testfile.c: matching formats:"); - printf(" TEST_STRING"); - printf("\n"); - printf("testfile.c: file not recognized: 404\n"); - printf("testfile.c: member testfile.c in archive is not an object\n"); - printf("testfile.c: error adding symbols: 404\n"); - printf("testfile.c: error adding symbols: 404\n"); - printf("ld: warning: could not find any targets"); - printf("ld: target TEST_STRING not found\n"); - printf("ld: cannot open output file TEST_STRING: 404\n"); - printf("ld:TEST_STRING: can not make object file: 404\n"); - printf("ld:TEST_STRING: can not set architecture: 404\n"); - printf("ld: can not create hash table: 404\n"); - printf("ld: warning: TEST_STRING contains output sections;"); - printf(""); - printf("ld: bfd_link_hash_lookup failed: 404\n"); - printf("ld: required symbol `TEST_STRING' not defined\n"); - printf("ld: TEST_STRING not found for insert\n"); - printf("ld: section TEST_STRING VMA wraps around address space\n"); - printf("ld: section TEST_STRING LMA wraps around address space\n"); - printf("ld: section TEST_STRING LMA [%V,%V]"); - printf("ld: section TEST_STRING VMA [%V,%V]"); - printf("ld: region `TEST_STRING' overflowed by 12345 bytes\n"); - printf("ld: address 0x%v of testfile.c section `TEST_STRING'"); - printf("ld: testfile.c section `TEST_STRING' will not fit in region `TEST_STRING'\n"); - printf("ld: invalid data statement\n"); - printf("ld: invalid reloc statement\n"); - printf("ld: gc-sections requires either an entry or "); - printf("ld:TEST_STRING: can't set start address\n"); - printf("ld: can't set start address\n"); - printf("ld: warning: cannot find entry symbol TEST_STRING;"); - printf("ld: can't set start address\n"); - printf("ld: warning: cannot find entry symbol TEST_STRING;"); - printf("ld: Relocatable linking with relocations from"); - printf("ld: TEST_STRING architecture of input file `testfile.c'"); - printf("ld: failed to merge target specific data"); - printf("ld: Could not define common symbol `%T': 404\n"); - printf("ld: error: unplaced orphan section `.text' from `testfile.c'.\n"); - printf("ld: warning: orphan section `.text' from `testfile.c' being "); - printf("ld: invalid character %c (10) in flags\n"); - printf("ld:TEST_STRING: error: align with input and explicit align specified\n"); - printf("ld: Failed to create hash table\n"); - printf("ld: TEST_STRING: plugin reported error after all symbols read\n"); - printf("ld: multiple STARTUP files\n"); - printf("ld:TEST_STRING: section has both a load address and a load region\n"); - printf("ld:TEST_STRING: PHDRS and FILEHDR are not supported"); - printf("ld: no sections assigned to phdrs\n"); - printf("ld: bfd_record_phdr failed: 404\n"); - printf("ld: section `TEST_STRING' assigned to non-existent phdr `TEST_STRING'\n"); - printf("ld: unknown language `TEST_STRING' in version information\n"); - printf("ld: anonymous version tag cannot be combined"); - printf("ld: duplicate version tag `TEST_STRING'\n"); - printf("ld: duplicate expression `TEST_STRING'"); - printf("ld: duplicate expression `TEST_STRING'"); - printf("ld: duplicate expression `TEST_STRING'"); - printf("ld: duplicate expression `TEST_STRING'"); - printf("ld: unable to find version dependency `TEST_STRING'\n"); - printf("ld: unable to read .exports section contents\n"); - printf("ld: invalid origin for memory region TEST_STRING\n"); - printf("ld: invalid length for memory region TEST_STRING\n"); - printf("ld: unknown feature `TEST_STRING'\n"); - printf(":includes nested too deeply\n"); - printf(": macros nested too deeply\n"); - printf("ld: read in flex scanner failed\n"); - printf( "ld: EOF in comment\n"); - printf("TEST_STRING: file not recognized: 404\n"); - printf("ld:TEST_STRING: ignoring invalid character `TEST_STRING'TEST_STRING\n"); - printf("ld: can't set BFD default target to `TEST_STRING': 404\n"); - printf("ld: no input files\n"); - printf("ld: cannot open map file TEST_STRING: 404\n"); - printf("ld: link errors found, deleting executable `TEST_STRING'\n"); - printf("testfile.c: final close failed: 404\n"); - printf("ld: unable to open for source of copy `TEST_STRING'\n"); - printf("ld: unable to open for destination of copy `TEST_STRING'\n"); - printf("ld: Error writing file `TEST_STRING'\n"); - printf("ld: Error closing file `TEST_STRING'\n"); - printf("ld: missing argument to -m\n"); - printf("ld: bfd_hash_table_init failed: 404\n"); - printf("ld: bfd_hash_lookup failed: 404\n"); - printf("ld: bfd_hash_table_init failed: 404\n"); - printf("ld: bfd_hash_lookup failed: 404\n"); - printf("ld: bfd_hash_table_init failed: 404\n"); - printf("ld: bfd_hash_lookup failed: 404\n"); - printf("ld: error: duplicate retain-symbols-file\n"); - printf("ld: TEST_STRING: 404\n"); - printf("ld: bfd_hash_table_init failed: 404\n"); - printf("ld: bfd_hash_lookup for insertion failed: 404\n"); - printf("ld: `-retain-symbols-file' overrides `-s' and `-S'\n"); - printf("testfile.c:102: multiple definition of `%T'\n"); - printf("10: first defined here\n"); - printf("ld: Disabling relaxation: it will not work with multiple definitions\n"); - printf("testfile.c: warning: definition of `%T' overriding common\n"); - printf("testfile.c: warning: common is here\n"); - printf("testfile.c: warning: common of `%T' overridden by definition\n"); - printf("testfile.c: warning: defined here\n"); - printf("testfile.c: warning: common of `%T' overridden by larger common\n"); - printf("testfile.c: warning: larger common is here\n"); - printf("testfile.c: warning: common of `%T' overriding smaller common\n"); - printf("testfile.c: warning: smaller common is here\n"); - printf("testfile.c: warning: multiple common of `%T'\n"); - printf("testfile.c: warning: previous common is here\n"); - printf("ld: warning: global constructor TEST_STRING used\n"); - printf("ld: warning: global constructor TEST_STRING used\n"); - printf("ld: BFD backend error: BFD_RELOC_CTOR unsupported\n"); - printf("ld: bfd_link_hash_lookup failed: 404\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("testfile.c:102: TEST_STRINGTEST_STRING\n"); - printf("ld: TEST_STRINGTEST_STRING\n"); - printf("testfile.c: TEST_STRINGTEST_STRING\n"); - printf("testfile.c: TEST_STRINGTEST_STRING\n"); - printf("testfile.c: could not read relocs: 404\n"); - printf("testfile.c: could not read relocs: 404\n"); - printf("testfile.c:102: TEST_STRINGTEST_STRING\n"); - printf("testfile.c:102: undefined reference to `%T'\n"); - printf("testfile.c:102: warning: undefined reference to `%T'\n"); - printf("10: more undefined references to `%T' follow\n"); - printf("10: warning: more undefined references to `%T' follow\n"); - printf(""); - printf("testfile.c: undefined reference to `%T'\n"); - printf("testfile.c: warning: undefined reference to `%T'\n"); - printf("testfile.c: more undefined references to `%T' follow\n"); - printf("testfile.c: warning: more undefined references to `%T' follow\n"); - printf(""); - printf("%H:"); - printf(" additional relocation overflows omitted from the output\n"); - printf(" relocation truncated to fit: "); - printf(" relocation truncated to fit: "); - printf(" relocation truncated to fit: TEST_STRING against `%T'"); - printf("+%v"); - printf("\n"); - printf("%H: dangerous relocation: TEST_STRING\n"); - printf("%H: reloc refers to symbol `%T' which is not being output\n"); - printf("testfile.c: reference to TEST_STRING\n"); - printf("testfile.c: definition of TEST_STRING\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("ld: internal error TEST_STRING 10\n"); - printf("ld: internal error: aborting at TEST_STRING:10 in TEST_STRING\n"); - printf("ld: internal error: aborting at TEST_STRING:10\n"); - printf("ld: please report this bug\n"); - printf("ld: bfd_new_link_order failed\n"); - printf("ld: bfd_new_link_order failed\n"); - printf("ld: TEST_STRING: missing argument\n"); - printf("ld: TEST_STRING: missing argument\n"); - printf("ld: unrecognized option 'TEST_STRING'\n"); - printf("ld: unrecognized option 'TEST_STRING'\n"); - printf("ld: use the --help option for usage information\n"); - printf("ld: use the --help option for usage information\n"); - printf("ld: unrecognized -a option `TEST_STRING'\n"); - printf("ld: unrecognized -a option `TEST_STRING'\n"); - printf("ld: unrecognized -assert option `TEST_STRING'\n"); - printf("ld: unrecognized -assert option `TEST_STRING'\n"); - printf("ld: unknown demangling style `TEST_STRING'\n"); - printf("ld: unknown demangling style `TEST_STRING'\n"); - printf("ld: invalid number `TEST_STRING'\n"); - printf("ld: invalid number `TEST_STRING'\n"); - printf("ld: bad --unresolved-symbols option: TEST_STRING\n"); - printf("ld: bad --unresolved-symbols option: TEST_STRING\n"); - printf("ld: bad -plugin-opt option\n"); - printf("ld: bad -plugin-opt option\n"); - printf("ld: unrecognised option: TEST_STRING\n"); - printf("ld: unrecognised option: TEST_STRING\n"); - printf("ld: -r and TEST_STRING may not be used together\n"); - printf("ld: -r and TEST_STRING may not be used together\n"); - printf("ld: -r and -shared may not be used together\n"); - printf("ld: -r and -shared may not be used together\n"); - printf("ld: -shared not supported\n"); - printf("ld: -shared not supported\n"); - printf("ld: -r and -pie may not be used together\n"); - printf("ld: -r and -pie may not be used together\n"); - printf("ld: -pie not supported\n"); - printf("ld: -pie not supported\n"); - printf("ld: SONAME must not be empty string; keeping previous one\n"); - printf("ld: SONAME must not be empty string; keeping previous one\n"); - printf("ld: invalid common section sorting option: TEST_STRING\n"); - printf("ld: invalid common section sorting option: TEST_STRING\n"); - printf("ld: invalid section sorting option: TEST_STRING\n"); - printf("ld: invalid section sorting option: TEST_STRING\n"); - printf("ld: invalid argument to option"); - printf("ld: invalid argument to option"); - printf("ld: missing argument(s) to option"); - printf("ld: missing argument(s) to option"); - printf("ld: -r and TEST_STRING may not be used together\n"); - printf("ld: -r and TEST_STRING may not be used together\n"); - printf("ld: invalid number `TEST_STRING'\n"); - printf("ld: invalid number `TEST_STRING'\n"); - printf("ld: group ended before it began (--help for usage)\n"); - printf("ld: group ended before it began (--help for usage)\n"); - printf("ld: --hash-size needs a numeric argument\n"); - printf("ld: --hash-size needs a numeric argument\n"); - printf("ld: no state pushed before popping\n"); - printf("ld: no state pushed before popping\n"); - printf("ld: invalid argument to option"); - printf("ld: invalid argument to option"); - printf("ld: SONAME must not be empty string; ignored\n"); - printf("ld: SONAME must not be empty string; ignored\n"); - printf("ld: -F may not be used without -shared\n"); - printf("ld: -F may not be used without -shared\n"); - printf("ld: -f may not be used without -shared\n"); - printf("ld: -f may not be used without -shared\n"); - printf("ld: invalid hex number `TEST_STRING'\n"); - printf("ld: invalid hex number `TEST_STRING'\n"); - printf("ld: unknown format type TEST_STRING\n"); - printf("ld: Unsupported PEI architecture: TEST_STRING\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("ld: Cannot export TEST_STRING: invalid export name\n"); - printf("ld: Error, duplicate EXPORT with ordinals: TEST_STRING (10 vs 10)\n"); - printf("ld: Warning, duplicate EXPORT: TEST_STRING\n"); - printf("ld: Cannot export TEST_STRING: symbol not defined\n"); - printf("ld: Cannot export TEST_STRING: symbol wrong type (10 vs 10)\n"); - printf("ld: Cannot export TEST_STRING: symbol not found\n"); - printf("ld: can not create BFD: 404\n"); - printf("ld: can not create .edata section: 404\n"); - printf("ld: can not create .reloc section: 404\n"); - printf("ld: Error: ordinal used twice: 10 (TEST_STRING vs TEST_STRING)\n"); - printf("ld: Error: export ordinal too large: 10\n"); - printf("DJ: zero vma section reloc detected: `TEST_STRING' #10 f=10\n"); - printf("testfile.c: could not read symbols: 404\n"); - printf("ld: Error: 10-bit reloc in dll\n"); - printf("ld: Can't open output def file TEST_STRING\n"); - printf("ld: Error closing file `TEST_STRING'\n"); - printf("ldtestfile.c:102: variable '%T' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.\n"); - printf("ld: Can't open .lib file: TEST_STRING\n"); - printf("ld: bfd_openr TEST_STRING: 404\n"); - printf("ld: TEST_STRING(TEST_STRING): can't find member in non-archive file"); - printf("ld: TEST_STRING(TEST_STRING): can't find member in archive"); - printf("ld: bfd_set_archive_head: 404\n"); - printf("ld: bfd_close TEST_STRING: 404\n"); - printf("ld: addsym TEST_STRING: 404\n"); - printf("ld: open TEST_STRING: 404\n"); - printf("ld: TEST_STRING: this doesn't appear to be a DLL\n"); - printf("ld: Error: can't use long section names on this arch\n"); - printf("ld: TEST_STRING: error loading plugin: TEST_STRING\n"); - printf("ld: TEST_STRING: duplicated plugin\n"); - printf("could not create dummy IR bfd: 404\n"); - printf("ld: TEST_STRING: non-ELF symbol in ELF BFD!\n"); - printf("ld: unknown ELF symbol visibility: 10!\n"); - printf("ld: unsupported input file size: TEST_STRING (12345 bytes)\n"); - printf("ld: TEST_STRING: plugin symbol table corrupt (sym type 10)\n"); - printf("ld: testfile.c: symbol `TEST_STRING' "); - printf("ld: TEST_STRING: error loading plugin: TEST_STRING\n"); - printf("ld: TEST_STRING: plugin error: 10\n"); - printf("ld: plugin_strdup failed to allocate memory: TEST_STRING\n"); - printf("ld: plugin failed to allocate memory for input: TEST_STRING\n"); - printf("ld: TEST_STRING: plugin reported error claiming file\n"); - - return 0; -} diff --git a/tests/regex_tester.cpp b/tests/regex_tester.cpp deleted file mode 100644 index b3ccf06..0000000 --- a/tests/regex_tester.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// @COMPILECMD g++ $@ -o regtest -O0 -ggdb -pg -fno-inline -#include -#include "regex.hpp" - -#define TEST(a, b, expected) do { \ - r = regex_compile(a); \ - bool result = regex_search(r, b); \ - bool passed = (result == expected); \ - if (passed) { printf("Success. - "); } else { printf("Failiour. - "); } \ - printf("%s vs %s: Result = %d, Expected = %d\n", #a, #b, result, expected); \ - ++num_tests; \ - if (passed) { ++passed_tests; } \ -} while(0) - -signed main() { - int num_tests = 0; - int passed_tests = 0; - regex_t * r; - - TEST(R"del(abc)del","abc",true); - TEST(R"del(efg1)del","efg1",true); - TEST(R"del(nig)del","ger",false); - - puts(""); - - TEST(R"del(ab+c)del","abc",true); - TEST(R"del(ef+g1)del","effffg1",true); - TEST(R"del(ni*g?)del","ngg",false); - - puts(""); - - TEST(R"del(ne.)del","net",true); - TEST(R"del(ne.)del","ne",false); - TEST(R"del(ne.+)del","neoo",true); - - puts(""); - - TEST(R"del(ne.)del","ne\t",true); - TEST(R"del(ne\t)del","ne",false); - TEST(R"del(ne\t)del","ne\t",true); - - puts(""); - - TEST(R"del(\sa)del"," a",true); - TEST(R"del(\wi)del","hi",true); - TEST(R"del(\w+)del","asd",true); - - puts(""); - - TEST(R"del([A-Za-z]+)del","HelloWorld",true); - TEST(R"del([A-Za-z]+g)del","HelloWorldg",true); - TEST(R"del([A-Za-z]+g)del","g",false); - - puts(""); - - TEST(R"del(a+a)del","aaa",true); - TEST(R"del(a+a)del","aa",true); - TEST(R"del(a+a)del","a",false); - - //++num_tests; TEST(R"del(\d{3})del","123",true); - //++num_tests; TEST(R"del(^\w+@\w+\.\w+$)del","example@email.com",true); - - //++num_tests; TEST(R"del(\b\w+\b)del","This is a test",true); - //++num_tests; TEST(R"del(^[A-Za-z]+\s\d+)del","OpenAI 123",true); - //++num_tests; TEST(R"del([0-9]{4}-[0-9]{2}-[0-9]{2})del","2023-08-22",true); - - //++num_tests; TEST(R"del(^[^abc]+$)del","def123",true); - //++num_tests; TEST(R"del(\b\d{5}\b)del","12345 67890",true); - //++num_tests; TEST(R"del(^[A-Z][a-z]+$)del","OpenAI",true); - - //++num_tests; TEST(R"del(\d{3}-\d{2}-\d{4})del","123-45-6789",true); - //++num_tests; TEST(R"del(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})del","192.168.1.1",true); - //++num_tests; TEST(R"del(^\w{8,12})del","Password123", false); - - printf("\nPassed %d out of %d tests.\n", passed_tests, num_tests); -} diff --git a/tests/test.input b/tests/test.input deleted file mode 100644 index efe9836..0000000 --- a/tests/test.input +++ /dev/null @@ -1 +0,0 @@ -while diff --git a/tests/vector.c b/tests/vector.c deleted file mode 100644 index b60d6cb..0000000 --- a/tests/vector.c +++ /dev/null @@ -1,135 +0,0 @@ -// @COMPILECMD gcc $@ -o vector.out -#include -#include -#include - -typedef struct { - char * data; - size_t element_size; - size_t element_count; -} vector_t; - -typedef struct { - int a; - int b; - char * c; -} example_t; - -extern void vector_init(vector_t * vector, - size_t element_size, - size_t element_count); - -extern void vector_push(vector_t * vector, - void * data); - -extern void vector_pop(vector_t * vector); - -extern void * vector_get(vector_t * vector, - size_t element); - -extern void vector_set(vector_t * vector, - void * data, - size_t element); - -extern void vector_free(vector_t * vector); - -extern void example_print(example_t * example); - -void vector_init(vector_t * vector, - size_t element_size, - size_t element_count) { - vector->data = NULL; - vector->element_size = element_size; - vector->element_count = element_count; - - vector->data = malloc(vector->element_size * vector->element_count); - - if ((! vector->data) && (vector->element_count)) { - // Handle or output error somehow? - puts("vector_init"); - exit(EXIT_FAILURE); - } - - memset(vector->data, - 0, - vector->element_size * vector->element_count); -} - -void vector_push(vector_t * vector, - void * data) { - ++vector->element_count; - - vector->data = realloc(vector->data, - vector->element_size * vector->element_count); - - if (! vector->data) { - // Handle or output error somehow? - puts("vector_push"); - exit(EXIT_FAILURE); - } - - memcpy(&vector->data[(vector->element_count - 1) * vector->element_size], - data, - vector->element_size); -} - -void vector_pop(vector_t * vector) { - (void) vector; -} - -void * vector_get(vector_t * vector, - size_t element) { - if (element >= vector->element_count) { - // Handle or output error somehow? - puts("vector_get"); - exit(EXIT_FAILURE); - } - - return &vector->data[vector->element_size * element]; -} - -void vector_set(vector_t * vector, - void * data, - size_t element) { - if (element >= vector->element_count) { - // Handle or output error somehow? - puts("vector_set"); - exit(EXIT_FAILURE); - } - - memcpy(&vector->data[vector->element_size * element], - data, - vector->element_size); -} - -void vector_free(vector_t * vector) { - free(vector->data); -} - -void example_print(example_t * example) { - printf("a : %+i\n", example->a); - printf("b : %+i\n", example->b); - printf("c : %2s\n", example->c); -} - -int main(void) { - vector_t vector; - - example_t x = { 1, -1, "A" }, - y = { 2, -2, "B" }, - z = { 3, -3, "C" }; - - vector_init(&vector, sizeof(example_t), 10); - - vector_set(&vector, &x, 0); - vector_set(&vector, &y, 1); - vector_set(&vector, &z, 2); - - example_print(vector_get(&vector, 0)); - example_print(vector_get(&vector, 1)); - example_print(vector_get(&vector, 2)); - - vector_free(&vector); - - return (EXIT_SUCCESS); -} From 18b6128e606a53043d1cecf680a54386d7b7da5c Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 28 Aug 2023 13:03:03 -0600 Subject: [PATCH 2/4] Relocate syntax/ --- Makefile | 2 +- {syntax => include/syntax}/c.h | 0 source/main.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename {syntax => include/syntax}/c.h (100%) diff --git a/Makefile b/Makefile index 544c1af..816bb8c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ TARGET:=hl CFLAGS:=-std=c99 -CPPFLAGS:=-Isyntax -Iinclude -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 +CPPFLAGS:=-Iinclude -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 DEBUG=1 diff --git a/syntax/c.h b/include/syntax/c.h similarity index 100% rename from syntax/c.h rename to include/syntax/c.h diff --git a/source/main.c b/source/main.c index 2b6ad6a..7ba4529 100644 --- a/source/main.c +++ b/source/main.c @@ -40,7 +40,7 @@ int main(int argc, // Highlight init terminal_hl_init(); // - #include "c.h" + #include "syntax/c.h" // render_string(buffer, "cterm"); From 08c9f81f4d7aa3255b105f0f8d8944e22fff64ff Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 28 Aug 2023 13:58:20 -0600 Subject: [PATCH 3/4] chad.h gets cucked --- include/chad.h | 27 +-------------------------- include/hl.h | 4 ++-- include/regex.h | 3 ++- include/terminal_hl.h | 25 +++++++++++++++++++++++++ include/vector.h | 5 +---- source/main.c | 9 ++------- source/regex.c | 3 +-- source/vector.c | 5 +++++ 8 files changed, 39 insertions(+), 42 deletions(-) diff --git a/include/chad.h b/include/chad.h index 474186a..02935aa 100644 --- a/include/chad.h +++ b/include/chad.h @@ -2,32 +2,7 @@ #include -#define UNUSED(x) ((void)x) - -// Terminal manipulation -#define TERMINAL_RESET "\033[0m" - -#define TERMINAL_COLOR_FG_BLACK "\033[30m" -#define TERMINAL_COLOR_FG_RED "\033[31m" -#define TERMINAL_COLOR_FG_GREEN "\033[32m" -#define TERMINAL_COLOR_FG_YELLOW "\033[33m" -#define TERMINAL_COLOR_FG_BLUE "\033[34m" -#define TERMINAL_COLOR_FG_MAGENTA "\033[35m" -#define TERMINAL_COLOR_FG_CYAN "\033[36m" -#define TERMINAL_COLOR_FG_WHITE "\033[37m" - -#define TERMINAL_COLOR_BG_BLACK "\033[40m" -#define TERMINAL_COLOR_BG_RED "\033[41m" -#define TERMINAL_COLOR_BG_GREEN "\033[42m" -#define TERMINAL_COLOR_BG_YELLOW "\033[43m" -#define TERMINAL_COLOR_BG_BLUE "\033[44m" -#define TERMINAL_COLOR_BG_MAGENTA "\033[45m" -#define TERMINAL_COLOR_BG_CYAN "\033[46m" -#define TERMINAL_COLOR_BG_WHITE "\033[47m" - -#define TERMINAL_STYLE_BOLD "\033[1m" -#define TERMINAL_STYLE_ITALICS "\033[3m" -#define TERMINAL_STYLE_REVERSE "\033[7m" +#define UNUSED(x) ((void)x) /* much like this header */ #define CHAD_H #endif diff --git a/include/hl.h b/include/hl.h index 8735177..d5476d7 100644 --- a/include/hl.h +++ b/include/hl.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "chad.h" #include "regex.h" @@ -248,8 +249,7 @@ int token_fits(const token_t * const token, const char * const to, const int string_offset, int * match_offset) { - UNUSED(match_offset); - + UNUSED(match_offset); //return regex_match(pattern, to, string_offset, match_offset); return regex_match(token->syntax, to + string_offset); } diff --git a/include/regex.h b/include/regex.h index 0049fcc..2628255 100644 --- a/include/regex.h +++ b/include/regex.h @@ -1,7 +1,8 @@ #ifndef REGEX_H #define REGEX_H -#include "chad.h" +#include + #include "vector.h" extern bool is_case_on; diff --git a/include/terminal_hl.h b/include/terminal_hl.h index 5fe1947..660e6a8 100644 --- a/include/terminal_hl.h +++ b/include/terminal_hl.h @@ -1,5 +1,30 @@ #include "hl.h" +// Terminal manipulation +#define TERMINAL_RESET "\033[0m" + +#define TERMINAL_COLOR_FG_BLACK "\033[30m" +#define TERMINAL_COLOR_FG_RED "\033[31m" +#define TERMINAL_COLOR_FG_GREEN "\033[32m" +#define TERMINAL_COLOR_FG_YELLOW "\033[33m" +#define TERMINAL_COLOR_FG_BLUE "\033[34m" +#define TERMINAL_COLOR_FG_MAGENTA "\033[35m" +#define TERMINAL_COLOR_FG_CYAN "\033[36m" +#define TERMINAL_COLOR_FG_WHITE "\033[37m" + +#define TERMINAL_COLOR_BG_BLACK "\033[40m" +#define TERMINAL_COLOR_BG_RED "\033[41m" +#define TERMINAL_COLOR_BG_GREEN "\033[42m" +#define TERMINAL_COLOR_BG_YELLOW "\033[43m" +#define TERMINAL_COLOR_BG_BLUE "\033[44m" +#define TERMINAL_COLOR_BG_MAGENTA "\033[45m" +#define TERMINAL_COLOR_BG_CYAN "\033[46m" +#define TERMINAL_COLOR_BG_WHITE "\033[47m" + +#define TERMINAL_STYLE_BOLD "\033[1m" +#define TERMINAL_STYLE_ITALICS "\033[3m" +#define TERMINAL_STYLE_REVERSE "\033[7m" + typedef struct { char * attribute; char * foreground_color; diff --git a/include/vector.h b/include/vector.h index 613c57c..170e56b 100644 --- a/include/vector.h +++ b/include/vector.h @@ -1,10 +1,7 @@ #ifndef VECTOR_H #define VECTOR_H -#include -#include -#include -#include +#include // TODO: Handle error warnings? // TODO: Implement more useful functions? diff --git a/source/main.c b/source/main.c index 7ba4529..43359e5 100644 --- a/source/main.c +++ b/source/main.c @@ -7,6 +7,7 @@ #include #include #include + #include "terminal_hl.h" #define ALLOCATION_CHUNK (10UL) @@ -14,18 +15,12 @@ static char * buffer = NULL; static size_t buffer_size = 0; -int main(int argc, - char * * argv) { - UNUSED(argc); - UNUSED(argv); - +int main(void) { // Buffer init buffer = realloc(buffer, ALLOCATION_CHUNK); do { if (!((buffer_size + 1) % ALLOCATION_CHUNK)) { - /* Linear incremental reallocation (advanced)! - */ size_t chunks = (buffer_size + 1) / ALLOCATION_CHUNK; buffer = realloc(buffer, ++chunks * ALLOCATION_CHUNK); } diff --git a/source/regex.c b/source/regex.c index 9d01efa..d5f63eb 100644 --- a/source/regex.c +++ b/source/regex.c @@ -7,6 +7,7 @@ #include #include #include +#include // ------------------ // ### Char tests ### @@ -32,8 +33,6 @@ bool is_magic(const char c) { return false; } - - // ---------------------- // ### Internal Types ### // ---------------------- diff --git a/source/vector.c b/source/vector.c index 564cadb..3cfe9f8 100644 --- a/source/vector.c +++ b/source/vector.c @@ -4,6 +4,11 @@ #include "vector.h" +#include +#include +#include +#include + void vector_init(vector_t * vector, size_t element_size, size_t element_count) { From 9a5bd3be4295cc1b2b65482ed82b55b0e57fa8b4 Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 28 Aug 2023 16:19:40 -0600 Subject: [PATCH 4/4] Fix all the warnings --- include/hl.h | 31 ++++++++++++++++++------------- include/terminal_hl.h | 26 +++++++++++++------------- source/regex.c | 16 ++++++++-------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/hl.h b/include/hl.h index d5476d7..91ced6a 100644 --- a/include/hl.h +++ b/include/hl.h @@ -21,9 +21,9 @@ typedef enum { REGION } token_type_t; -typedef void (*attribute_callback_t) (const char * const string, - const int length, - void * const attributes); +typedef void (*attribute_callback_t) (const char * string, + const int length, + void * attributes); typedef struct { char * key; @@ -58,14 +58,19 @@ extern int append_token(token_t * token); extern token_t * new_symbol_token(const char * const c, hl_group_t * const g); + extern int new_symbol_tokens(const char * const * symbols, - hl_group_t * const g); -extern int new_char_tokens(const char * characters, - hl_group_t * const g); + hl_group_t * const g); + +extern int new_char_tokens(const char * str, + hl_group_t * const g); + extern token_t * new_keyword_token(const char * const word, - hl_group_t * const g); + hl_group_t * const g); + extern int new_keyword_tokens(const char * const * words, - hl_group_t * const g); + hl_group_t * const g); + extern token_t * new_token(const char * const word, const token_type_t t, hl_group_t * const g); @@ -146,7 +151,7 @@ int new_symbol_tokens(const char * const * symbols, return i; } -int new_char_tokens(const char * characters, +int new_char_tokens(const char * str, hl_group_t * const g) { int i = 0; @@ -154,7 +159,7 @@ int new_char_tokens(const char * characters, buffer[0] = '\\'; buffer[2] = '\0'; - for(const char * s = characters; *s != '\0'; s++) { + for(const char * s = str; *s != '\0'; s++) { buffer[1] = *s; if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) { ++i; @@ -202,9 +207,9 @@ int new_keyword_tokens(const char * const * words, return i; } -token_t * new_region_token(const char * const * start, - const char * const * end, - hl_group_t * const g) { +token_t * new_region_token(const char * start, + const char * end, + hl_group_t * g) { char buffer[100]; buffer[0] = '\0'; strcat(buffer, start); diff --git a/include/terminal_hl.h b/include/terminal_hl.h index 660e6a8..6bbff84 100644 --- a/include/terminal_hl.h +++ b/include/terminal_hl.h @@ -26,9 +26,9 @@ #define TERMINAL_STYLE_REVERSE "\033[7m" typedef struct { - char * attribute; - char * foreground_color; - char * background_color; + const char * attribute; + const char * foreground_color; + const char * background_color; } terminal_hl_t; extern display_t * cterm; @@ -47,7 +47,7 @@ display_t * cterm = &(display_t) { void cterm_render_callback(const char * const string, const int length, void * const attributes) { - if(!length){ + if (!length) { fputs(TERMINAL_STYLE_BOLD, stdout); putchar(*string); fputs(TERMINAL_RESET, stdout); @@ -68,16 +68,16 @@ void cterm_render_callback(const char * const string, } -void fun(const char * const attribute, - const char * const color, - hl_group_t * * group){ - terminal_hl_t * t = (terminal_hl_t *)malloc(sizeof(terminal_hl_t)); - t->attribute = attribute; - t->foreground_color = color;; - t->background_color = NULL; +void fun(const char * attribute, + const char * color, + hl_group_t * * group){ + terminal_hl_t * t = (terminal_hl_t *) malloc(sizeof(terminal_hl_t)); + t->attribute = attribute; + t->foreground_color = color; + t->background_color = NULL; (*group) = (hl_group_t *)malloc(sizeof(hl_group_t)); - (*group)->link = NULL; - (*group)->attributes = (void*)t; + (*group)->link = NULL; + (*group)->attributes = (void*)t; } int terminal_hl_init(void) { diff --git a/source/regex.c b/source/regex.c index d5f63eb..32464b6 100644 --- a/source/regex.c +++ b/source/regex.c @@ -343,17 +343,17 @@ static int compile_range(const char * const range, return ((s - range) + 1); } -void filter_blacklist(const char * const whitelist, - const char * const blacklist, - char * const filtered) { - for (char * black_pointer = blacklist; *black_pointer != '\0'; black_pointer++) { - for(char * white_pointer = blacklist; *white_pointer != '\0'; white_pointer++) { - if (*black_pointer == *white_pointer) { +void filter_blacklist(const char * whitelist, + const char * blacklist, + char * filtered) { + for (; *blacklist != '\0'; blacklist++) { + for(; *whitelist != '\0'; whitelist++) { + if (*blacklist == *whitelist) { goto long_continue; } } - strncat(filtered, black_pointer, 1); - long_continue: + strncat(filtered, blacklist, 1); + long_continue:; } }