From: Emil Date: Mon, 28 Aug 2023 18:56:34 +0000 (-0600) Subject: Structural Repair X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=2eb38da4e6f87e763b5edd89671a8894ad619f98;p=public-libhl.git Structural Repair --- diff --git a/BUGS.md b/BUGS.md deleted file mode 100644 index 75fcd02..0000000 --- a/BUGS.md +++ /dev/null @@ -1,2 +0,0 @@ -## Bugs - + "\<" and "\>" are not yet implemented; they actually signal complex regexes, there should be a regex preprocessor replacing them 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/TODO b/TODO deleted file mode 100644 index 2bf3b11..0000000 --- a/TODO +++ /dev/null @@ -1,5 +0,0 @@ - > Complete C syntax hearer - > Add Ada syntax header - > Figure out what the fuck to do about offset when regex_search()-ing - > Binary search when looking up delta_table - > valgrind 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/docs/possible_messages.list b/docs/possible_messages.list deleted file mode 100644 index 106c91e..0000000 --- a/docs/possible_messages.list +++ /dev/null @@ -1,314 +0,0 @@ -(_("Warning: .drectve `%s' unrecognized\n"), param); -(_("Warning: corrupt .drectve at end of def file\n")); -("%s:%d: Warning: path components stripped from %s, '%s'\n", -("%P: %s:%d: %s\n", -(_("%X%P: bfd_hash_table_init of cref table failed: %E\n")); -(_("%X%P: cref_hash_lookup failed: %E\n")); -(_("%X%P: cref alloc failed: %E\n")); -("%P: symbol `%T' missing from main hash table\n", -(_("%B%F: could not read symbols: %E\n"), abfd); -(_("%P: symbol `%T' missing from main hash table\n"), -(_("%B%F: could not read symbols: %E\n"), abfd); -(_("%B%F: could not read relocs: %E\n"), abfd); -(_("%B%F: could not read relocs: %E\n"), abfd); -(_("%X%C: prohibited cross reference from %s to `%T' in %s\n"), -(_("%P%X: Different relocs used in set %s\n"), -(_("%P%X: Different object file formats composing set %s\n"), -(_("%P%X: %s does not support reloc %s for set %s\n"), -(_("%P%X: Special section %s does not support reloc %s for set %s\n"), -(_("%P%X: %s does not support reloc %s for set %s\n"), -(_("%P%X: Unsupported size %d for set %s\n"), -(_("%P: unrecognised emulation mode: %s\n"), target); -(_("Supported emulations: ")); -("%F\n"); -(_("%P%F: bfd_hash_allocate failed creating symbol %s\n"), name); -(_("%P%F: bfd_hash_lookup failed creating symbol %s\n"), name); -(_("%P: warning: address of `%s' " -(_("%F%S %% by zero\n"), tree->binary.rhs); -(_("%F%S / by zero\n"), tree->binary.rhs); -(_("%P%F: bfd_link_hash_lookup failed: %E\n")); -(_("%X%S: unresolvable symbol `%s'" -(_("%F%S: undefined symbol `%s'" -(_("%F%S: undefined section `%s'" -(_("%F%S: undefined section `%s'" -(_("%F%S: undefined section `%s'" -(_("%F%S: undefined MEMORY region `%s'" -(_("%F%S: undefined MEMORY region `%s'" -(_("%F%S: unknown constant `%s' referenced in expression\n"), -("%X%P: %s\n", tree->assert_s.message); -(_("%F%S can not PROVIDE assignment to" -(_("%F%S invalid assignment to" -(_("%F%S assignment to location counter" -(_("%F%S cannot move location counter backwards" -(_("%P%F:%s: hash creation failed\n"), -(_("%F%S: nonconstant expression for %s\n"), -(_("%F%S: nonconstant expression for %s\n"), -(_("%F%S: nonconstant expression for %s\n"), -(_("%P%F: can not create hash table: %E\n")); -(_("%F%P: invalid BFD target `%s'\n"), entry->target); -(_("%P: skipping incompatible %s " -(_("%F%P: attempted static link of dynamic object `%s'\n"), -(_("%P: skipping incompatible %s " -(_("%P: cannot find %s (%s): %E\n"), -(_("%P: cannot find %s: %E\n"), entry->local_sym_name); -(_("%P: cannot find %s inside %s\n"), -(_("%P: cannot find %s\n"), entry->local_sym_name); -(_("%P%F: cannot open linker script file %s: %E\n"), name); -(_("%P%F: cannot represent machine `%s'\n"), string); -(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1); -(_("\%X%P:%S: unknown phdr type `%s' (try integer literal)\n"), -(_("%X%P:%S: PHDRS syntax error at `%s'\n"), -(_("%P:%s: file format not recognized; treating as linker script\n"), -("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]); -("%P%F:%S: %s\n", NULL, arg); -(_("%P%F: can not create hash table: %E\n")); -(_("%P:%S: warning: redeclaration of memory region `%s'\n"), -(_("%P:%S: warning: memory region `%s' not declared\n"), -(_("%F%P:%S: error: alias for default memory region\n"), NULL); -(_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME); -(_("%P%F: output format %s cannot represent section" -(_("%B: file not recognized: %E\n"), entry->the_bfd); -(_("%B: matching formats:"), entry->the_bfd); -(" %s", *p); -("%F\n"); -(_("%F%B: file not recognized: %E\n"), entry->the_bfd); -(_("%F%B: member %B in archive is not an object\n"), -(_("%F%B: error adding symbols: %E\n"), member); -(_("%F%B: error adding symbols: %E\n"), entry->the_bfd); -(_("%P: warning: could not find any targets" -(_("%P%F: target %s not found\n"), output_target); -(_("%P%F: cannot open output file %s: %E\n"), name); -(_("%P%F:%s: can not make object file: %E\n"), name); -(_("%P%F:%s: can not set architecture: %E\n"), name); -(_("%P%F: can not create hash table: %E\n")); -(_("%P: warning: %s contains output sections;" -("%F"); -(_("%P%F: bfd_link_hash_lookup failed: %E\n")); -(_("%P%X: required symbol `%s' not defined\n"), ptr->name); -(_("%F%P: %s not found for insert\n"), i->where); -(_("%X%P: section %s VMA wraps around address space\n"), -(_("%X%P: section %s LMA wraps around address space\n"), -(_("%X%P: section %s LMA [%V,%V]" -(_("%X%P: section %s VMA [%V,%V]" -(_("%X%P: region `%s' overflowed by %ld bytes\n"), -(_("%X%P: address 0x%v of %B section `%s'" -(_("%X%P: %B section `%s' will not fit in region `%s'\n"), -(_("%F%P: invalid data statement\n")); -(_("%F%P: invalid reloc statement\n")); -(_("%P%F: gc-sections requires either an entry or " -(_("%P%F:%s: can't set start address\n"), entry_symbol.name); -(_("%P%F: can't set start address\n")); -(_("%P: warning: cannot find entry symbol %s;" -(_("%P%F: can't set start address\n")); -(_("%P: warning: cannot find entry symbol %s;" -(_("%P%F: Relocatable linking with relocations from" -(_("%P%X: %s architecture of input file `%B'" -(_("%P%X: failed to merge target specific data" -(_("%P%F: Could not define common symbol `%T': %E\n"), -("%X%P: error: unplaced orphan section `%A' from `%B'.\n", -("%P: warning: orphan section `%A' from `%B' being " -(_("%P%F: invalid character %c (%d) in flags\n"), -(_("%F%P:%S: error: align with input and explicit align specified\n"), -(_("%P%F: Failed to create hash table\n")); -(_("%P%F: %s: plugin reported error after all symbols read\n"), -(_("%P%F: multiple STARTUP files\n")); -(_("%X%P:%S: section has both a load address and a load region\n"), -(_("%X%P:%S: PHDRS and FILEHDR are not supported" -(_("%F%P: no sections assigned to phdrs\n")); -(_("%F%P: bfd_record_phdr failed: %E\n")); -(_("%X%P: section `%s' assigned to non-existent phdr `%s'\n"), -(_("%X%P: unknown language `%s' in version information\n"), -(_("%X%P: anonymous version tag cannot be combined" -(_("%X%P: duplicate version tag `%s'\n"), name); -(_("%X%P: duplicate expression `%s'" -(_("%X%P: duplicate expression `%s'" -(_("%X%P: duplicate expression `%s'" -(_("%X%P: duplicate expression `%s'" -(_("%X%P: unable to find version dependency `%s'\n"), name); -(_("%X%P: unable to read .exports section contents\n"), sec); -(_("%F%P: invalid origin for memory region %s\n"), -(_("%F%P: invalid length for memory region %s\n"), -(_("%X%P: unknown feature `%s'\n"), p); -("%F:includes nested too deeply\n"); -("%F: macros nested too deeply\n"); -("%F%P: read in flex scanner failed\n"); -( "%F%P: EOF in comment\n"); -("%F%s: file not recognized: %E\n", ldlex_filename ()); -("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where); -(_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); -(_("%P%F: no input files\n")); -(_("%P%F: cannot open map file %s: %E\n"), -(_("%P: link errors found, deleting executable `%s'\n"), -(_("%F%B: final close failed: %E\n"), link_info.output_bfd); -(_("%P%F: unable to open for source of copy `%s'\n"), -(_("%P%F: unable to open for destination of copy `%s'\n"), -(_("%P: Error writing file `%s'\n"), dst_name); -(_("%P: Error closing file `%s'\n"), dst_name); -(_("%P%F: missing argument to -m\n")); -(_("%P%F: bfd_hash_table_init failed: %E\n")); -(_("%P%F: bfd_hash_lookup failed: %E\n")); -(_("%P%F: bfd_hash_table_init failed: %E\n")); -(_("%P%F: bfd_hash_lookup failed: %E\n")); -(_("%P%F: bfd_hash_table_init failed: %E\n")); -(_("%P%F: bfd_hash_lookup failed: %E\n")); -(_("%X%P: error: duplicate retain-symbols-file\n")); -("%X%P: %s: %E\n", filename); -(_("%P%F: bfd_hash_table_init failed: %E\n")); -(_("%P%F: bfd_hash_lookup for insertion failed: %E\n")); -(_("%P: `-retain-symbols-file' overrides `-s' and `-S'\n")); -(_("%X%C: multiple definition of `%T'\n"), -(_("%D: first defined here\n"), obfd, osec, oval); -(_("%P: Disabling relaxation: it will not work with multiple definitions\n")); -(_("%B: warning: definition of `%T' overriding common\n"), -(_("%B: warning: common is here\n"), obfd); -(_("%B: warning: common of `%T' overridden by definition\n"), -(_("%B: warning: defined here\n"), obfd); -(_("%B: warning: common of `%T' overridden by larger common\n"), -(_("%B: warning: larger common is here\n"), obfd); -(_("%B: warning: common of `%T' overriding smaller common\n"), -(_("%B: warning: smaller common is here\n"), obfd); -(_("%B: warning: multiple common of `%T'\n"), nbfd, name); -(_("%B: warning: previous common is here\n"), obfd); -(_("%P: warning: global constructor %s used\n"), -(_("%P: warning: global constructor %s used\n"), name); -(_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n")); -(_("%P%F: bfd_link_hash_lookup failed: %E\n")); -(_("%B%F: could not read symbols: %E\n"), abfd); -("%C: %s%s\n", abfd, section, address, _("warning: "), warning); -("%P: %s%s\n", _("warning: "), warning); -("%B: %s%s\n", abfd, _("warning: "), warning); -("%B: %s%s\n", abfd, _("warning: "), warning); -(_("%B%F: could not read relocs: %E\n"), abfd); -(_("%B%F: could not read relocs: %E\n"), abfd); -("%C: %s%s\n", abfd, sec, q->address, _("warning: "), -(_("%X%C: undefined reference to `%T'\n"), -(_("%C: warning: undefined reference to `%T'\n"), -(_("%X%D: more undefined references to `%T' follow\n"), -(_("%D: warning: more undefined references to `%T' follow\n"), -("%X"); -(_("%X%B: undefined reference to `%T'\n"), -(_("%B: warning: undefined reference to `%T'\n"), -(_("%X%B: more undefined references to `%T' follow\n"), -(_("%B: warning: more undefined references to `%T' follow\n"), -("%X"); -("%X%H:", abfd, section, address); -(_(" additional relocation overflows omitted from the output\n")); -(_(" relocation truncated to fit: " -(_(" relocation truncated to fit: " -(_(" relocation truncated to fit: %s against `%T'"), -("+%v", addend); -("\n"); -(_("%X%H: dangerous relocation: %s\n"), -(_("%X%H: reloc refers to symbol `%T' which is not being output\n"), -("%B: reference to %s\n", abfd, name); -("%B: definition of %s\n", abfd, name); -(_("%B%F: could not read symbols: %E\n"), abfd); -(_("%F%P: internal error %s %d\n"), file, line); -(_("%P: internal error: aborting at %s:%d in %s\n"), -(_("%P: internal error: aborting at %s:%d\n"), -(_("%P%F: please report this bug\n")); -(_("%P%F: bfd_new_link_order failed\n")); -(_("%P%F: bfd_new_link_order failed\n")); -(_("%P: %s: missing argument\n"), argv[last_optind]); -(_("%P: %s: missing argument\n"), argv[last_optind]); -(_("%P: unrecognized option '%s'\n"), argv[last_optind]); -(_("%P: unrecognized option '%s'\n"), argv[last_optind]); -(_("%P%F: use the --help option for usage information\n")); -(_("%P%F: use the --help option for usage information\n")); -(_("%P%F: unrecognized -a option `%s'\n"), optarg); -(_("%P%F: unrecognized -a option `%s'\n"), optarg); -(_("%P%F: unrecognized -assert option `%s'\n"), optarg); -(_("%P%F: unrecognized -assert option `%s'\n"), optarg); -(_("%F%P: unknown demangling style `%s'\n"), -(_("%F%P: unknown demangling style `%s'\n"), -(_("%P%F: invalid number `%s'\n"), optarg); -(_("%P%F: invalid number `%s'\n"), optarg); -(_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); -(_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); -(_("%P%F: bad -plugin-opt option\n")); -(_("%P%F: bad -plugin-opt option\n")); -(_("%P%F: unrecognised option: %s\n"), argv[optind]); -(_("%P%F: unrecognised option: %s\n"), argv[optind]); -(_("%P%F: -r and %s may not be used together\n"), -(_("%P%F: -r and %s may not be used together\n"), -(_("%P%F: -r and -shared may not be used together\n")); -(_("%P%F: -r and -shared may not be used together\n")); -(_("%P%F: -shared not supported\n")); -(_("%P%F: -shared not supported\n")); -(_("%P%F: -r and -pie may not be used together\n")); -(_("%P%F: -r and -pie may not be used together\n")); -(_("%P%F: -pie not supported\n")); -(_("%P%F: -pie not supported\n")); -(_("%P: SONAME must not be empty string; keeping previous one\n")); -(_("%P: SONAME must not be empty string; keeping previous one\n")); -(_("%P%F: invalid common section sorting option: %s\n"), -(_("%P%F: invalid common section sorting option: %s\n"), -(_("%P%F: invalid section sorting option: %s\n"), -(_("%P%F: invalid section sorting option: %s\n"), -(_("%P%F: invalid argument to option" -(_("%P%F: invalid argument to option" -(_("%P%F: missing argument(s) to option" -(_("%P%F: missing argument(s) to option" -(_("%P%F: -r and %s may not be used together\n"), -(_("%P%F: -r and %s may not be used together\n"), -(_("%P%F: invalid number `%s'\n"), optarg); -(_("%P%F: invalid number `%s'\n"), optarg); -(_("%P%F: group ended before it began (--help for usage)\n")); -(_("%P%F: group ended before it began (--help for usage)\n")); -(_("%P%X: --hash-size needs a numeric argument\n")); -(_("%P%X: --hash-size needs a numeric argument\n")); -(_("%P%F: no state pushed before popping\n")); -(_("%P%F: no state pushed before popping\n")); -(_("%P%F: invalid argument to option" -(_("%P%F: invalid argument to option" -(_("%P: SONAME must not be empty string; ignored\n")); -(_("%P: SONAME must not be empty string; ignored\n")); -(_("%P%F: -F may not be used without -shared\n")); -(_("%P%F: -F may not be used without -shared\n")); -(_("%P%F: -f may not be used without -shared\n")); -(_("%P%F: -f may not be used without -shared\n")); -(_("%P%F: invalid hex number `%s'\n"), valstr); -(_("%P%F: invalid hex number `%s'\n"), valstr); -(_("%P%F: unknown format type %s\n"), name); -(_("%P%X: Unsupported PEI architecture: %s\n"), target); -(_("%B%F: could not read symbols: %E\n"), b); -(_("%P%X: Cannot export %s: invalid export name\n"), -(_("%P%X: Error, duplicate EXPORT with ordinals: %s (%d vs %d)\n"), -(_("%P: Warning, duplicate EXPORT: %s\n"), -(_("%P%X: Cannot export %s: symbol not defined\n"), -(_("%P%X: Cannot export %s: symbol wrong type (%d vs %d)\n"), -(_("%P%X: Cannot export %s: symbol not found\n"), -("%X%P: can not create BFD: %E\n"); -("%X%P: can not create .edata section: %E\n"); -("%X%P: can not create .reloc section: %E\n"); -(_("%P%X: Error: ordinal used twice: %d (%s vs %s)\n"), -(_("%P%X: Error: export ordinal too large: %d\n"), -("DJ: zero vma section reloc detected: `%s' #%d f=%d\n", -(_("%B%F: could not read symbols: %E\n"), b); -(_("%P%X: Error: %d-bit reloc in dll\n"), -(_("%P: Can't open output def file %s\n"), -(_("%P: Error closing file `%s'\n"), pe_out_def_filename); -(_("%P%X%C: variable '%T' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.\n"), -(_("%P%X: Can't open .lib file: %s\n"), impfilename); -(_("%P%X: bfd_openr %s: %E\n"), ibfd->filename); -(_("%P%X: %s(%s): can't find member in non-archive file"), -(_("%P%X: %s(%s): can't find member in archive"), -("%P%X: bfd_set_archive_head: %E\n"); -("%P%X: bfd_close %s: %E\n", impfilename); -("%P%X: addsym %s: %E\n", name); -("%P%X: open %s: %E\n", filename); -("%P%X: %s: this doesn't appear to be a DLL\n", filename); -(_("%P%X: Error: can't use long section names on this arch\n")); -(_("%P%F: %s: error loading plugin: %s\n"), plugin, dlerror ()); -(_("%P: %s: duplicated plugin\n"), plugin); -(_("could not create dummy IR bfd: %F%E\n")); -(_("%P%F: %s: non-ELF symbol in ELF BFD!\n"), asym->name); -(_("%P%F: unknown ELF symbol visibility: %d!\n"), -(_("%P%F: unsupported input file size: %s (%ld bytes)\n"), -("%P%F: %s: plugin symbol table corrupt (sym type %d)\n", -(_("%P: %B: symbol `%s' " -(_("%P%F: %s: error loading plugin: %s\n"), -(_("%P%F: %s: plugin error: %d\n"), curplug->name, rv); -(_("%P%F: plugin_strdup failed to allocate memory: %s\n"), -(_("%P%F: plugin failed to allocate memory for input: %s\n"), -(_("%P%F: %s: plugin reported error claiming file\n"), diff --git a/document/BUGS.md b/document/BUGS.md new file mode 100644 index 0000000..75fcd02 --- /dev/null +++ b/document/BUGS.md @@ -0,0 +1,2 @@ +## Bugs + + "\<" and "\>" are not yet implemented; they actually signal complex regexes, there should be a regex preprocessor replacing them diff --git a/document/TODO b/document/TODO new file mode 100644 index 0000000..2bf3b11 --- /dev/null +++ b/document/TODO @@ -0,0 +1,5 @@ + > Complete C syntax hearer + > Add Ada syntax header + > Figure out what the fuck to do about offset when regex_search()-ing + > Binary search when looking up delta_table + > valgrind diff --git a/document/possible_messages.list b/document/possible_messages.list new file mode 100644 index 0000000..106c91e --- /dev/null +++ b/document/possible_messages.list @@ -0,0 +1,314 @@ +(_("Warning: .drectve `%s' unrecognized\n"), param); +(_("Warning: corrupt .drectve at end of def file\n")); +("%s:%d: Warning: path components stripped from %s, '%s'\n", +("%P: %s:%d: %s\n", +(_("%X%P: bfd_hash_table_init of cref table failed: %E\n")); +(_("%X%P: cref_hash_lookup failed: %E\n")); +(_("%X%P: cref alloc failed: %E\n")); +("%P: symbol `%T' missing from main hash table\n", +(_("%B%F: could not read symbols: %E\n"), abfd); +(_("%P: symbol `%T' missing from main hash table\n"), +(_("%B%F: could not read symbols: %E\n"), abfd); +(_("%B%F: could not read relocs: %E\n"), abfd); +(_("%B%F: could not read relocs: %E\n"), abfd); +(_("%X%C: prohibited cross reference from %s to `%T' in %s\n"), +(_("%P%X: Different relocs used in set %s\n"), +(_("%P%X: Different object file formats composing set %s\n"), +(_("%P%X: %s does not support reloc %s for set %s\n"), +(_("%P%X: Special section %s does not support reloc %s for set %s\n"), +(_("%P%X: %s does not support reloc %s for set %s\n"), +(_("%P%X: Unsupported size %d for set %s\n"), +(_("%P: unrecognised emulation mode: %s\n"), target); +(_("Supported emulations: ")); +("%F\n"); +(_("%P%F: bfd_hash_allocate failed creating symbol %s\n"), name); +(_("%P%F: bfd_hash_lookup failed creating symbol %s\n"), name); +(_("%P: warning: address of `%s' " +(_("%F%S %% by zero\n"), tree->binary.rhs); +(_("%F%S / by zero\n"), tree->binary.rhs); +(_("%P%F: bfd_link_hash_lookup failed: %E\n")); +(_("%X%S: unresolvable symbol `%s'" +(_("%F%S: undefined symbol `%s'" +(_("%F%S: undefined section `%s'" +(_("%F%S: undefined section `%s'" +(_("%F%S: undefined section `%s'" +(_("%F%S: undefined MEMORY region `%s'" +(_("%F%S: undefined MEMORY region `%s'" +(_("%F%S: unknown constant `%s' referenced in expression\n"), +("%X%P: %s\n", tree->assert_s.message); +(_("%F%S can not PROVIDE assignment to" +(_("%F%S invalid assignment to" +(_("%F%S assignment to location counter" +(_("%F%S cannot move location counter backwards" +(_("%P%F:%s: hash creation failed\n"), +(_("%F%S: nonconstant expression for %s\n"), +(_("%F%S: nonconstant expression for %s\n"), +(_("%F%S: nonconstant expression for %s\n"), +(_("%P%F: can not create hash table: %E\n")); +(_("%F%P: invalid BFD target `%s'\n"), entry->target); +(_("%P: skipping incompatible %s " +(_("%F%P: attempted static link of dynamic object `%s'\n"), +(_("%P: skipping incompatible %s " +(_("%P: cannot find %s (%s): %E\n"), +(_("%P: cannot find %s: %E\n"), entry->local_sym_name); +(_("%P: cannot find %s inside %s\n"), +(_("%P: cannot find %s\n"), entry->local_sym_name); +(_("%P%F: cannot open linker script file %s: %E\n"), name); +(_("%P%F: cannot represent machine `%s'\n"), string); +(_("%P%F: unrecognised keyword in MRI style script '%s'\n"),$1); +(_("\%X%P:%S: unknown phdr type `%s' (try integer literal)\n"), +(_("%X%P:%S: PHDRS syntax error at `%s'\n"), +(_("%P:%s: file format not recognized; treating as linker script\n"), +("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]); +("%P%F:%S: %s\n", NULL, arg); +(_("%P%F: can not create hash table: %E\n")); +(_("%P:%S: warning: redeclaration of memory region `%s'\n"), +(_("%P:%S: warning: memory region `%s' not declared\n"), +(_("%F%P:%S: error: alias for default memory region\n"), NULL); +(_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME); +(_("%P%F: output format %s cannot represent section" +(_("%B: file not recognized: %E\n"), entry->the_bfd); +(_("%B: matching formats:"), entry->the_bfd); +(" %s", *p); +("%F\n"); +(_("%F%B: file not recognized: %E\n"), entry->the_bfd); +(_("%F%B: member %B in archive is not an object\n"), +(_("%F%B: error adding symbols: %E\n"), member); +(_("%F%B: error adding symbols: %E\n"), entry->the_bfd); +(_("%P: warning: could not find any targets" +(_("%P%F: target %s not found\n"), output_target); +(_("%P%F: cannot open output file %s: %E\n"), name); +(_("%P%F:%s: can not make object file: %E\n"), name); +(_("%P%F:%s: can not set architecture: %E\n"), name); +(_("%P%F: can not create hash table: %E\n")); +(_("%P: warning: %s contains output sections;" +("%F"); +(_("%P%F: bfd_link_hash_lookup failed: %E\n")); +(_("%P%X: required symbol `%s' not defined\n"), ptr->name); +(_("%F%P: %s not found for insert\n"), i->where); +(_("%X%P: section %s VMA wraps around address space\n"), +(_("%X%P: section %s LMA wraps around address space\n"), +(_("%X%P: section %s LMA [%V,%V]" +(_("%X%P: section %s VMA [%V,%V]" +(_("%X%P: region `%s' overflowed by %ld bytes\n"), +(_("%X%P: address 0x%v of %B section `%s'" +(_("%X%P: %B section `%s' will not fit in region `%s'\n"), +(_("%F%P: invalid data statement\n")); +(_("%F%P: invalid reloc statement\n")); +(_("%P%F: gc-sections requires either an entry or " +(_("%P%F:%s: can't set start address\n"), entry_symbol.name); +(_("%P%F: can't set start address\n")); +(_("%P: warning: cannot find entry symbol %s;" +(_("%P%F: can't set start address\n")); +(_("%P: warning: cannot find entry symbol %s;" +(_("%P%F: Relocatable linking with relocations from" +(_("%P%X: %s architecture of input file `%B'" +(_("%P%X: failed to merge target specific data" +(_("%P%F: Could not define common symbol `%T': %E\n"), +("%X%P: error: unplaced orphan section `%A' from `%B'.\n", +("%P: warning: orphan section `%A' from `%B' being " +(_("%P%F: invalid character %c (%d) in flags\n"), +(_("%F%P:%S: error: align with input and explicit align specified\n"), +(_("%P%F: Failed to create hash table\n")); +(_("%P%F: %s: plugin reported error after all symbols read\n"), +(_("%P%F: multiple STARTUP files\n")); +(_("%X%P:%S: section has both a load address and a load region\n"), +(_("%X%P:%S: PHDRS and FILEHDR are not supported" +(_("%F%P: no sections assigned to phdrs\n")); +(_("%F%P: bfd_record_phdr failed: %E\n")); +(_("%X%P: section `%s' assigned to non-existent phdr `%s'\n"), +(_("%X%P: unknown language `%s' in version information\n"), +(_("%X%P: anonymous version tag cannot be combined" +(_("%X%P: duplicate version tag `%s'\n"), name); +(_("%X%P: duplicate expression `%s'" +(_("%X%P: duplicate expression `%s'" +(_("%X%P: duplicate expression `%s'" +(_("%X%P: duplicate expression `%s'" +(_("%X%P: unable to find version dependency `%s'\n"), name); +(_("%X%P: unable to read .exports section contents\n"), sec); +(_("%F%P: invalid origin for memory region %s\n"), +(_("%F%P: invalid length for memory region %s\n"), +(_("%X%P: unknown feature `%s'\n"), p); +("%F:includes nested too deeply\n"); +("%F: macros nested too deeply\n"); +("%F%P: read in flex scanner failed\n"); +( "%F%P: EOF in comment\n"); +("%F%s: file not recognized: %E\n", ldlex_filename ()); +("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where); +(_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); +(_("%P%F: no input files\n")); +(_("%P%F: cannot open map file %s: %E\n"), +(_("%P: link errors found, deleting executable `%s'\n"), +(_("%F%B: final close failed: %E\n"), link_info.output_bfd); +(_("%P%F: unable to open for source of copy `%s'\n"), +(_("%P%F: unable to open for destination of copy `%s'\n"), +(_("%P: Error writing file `%s'\n"), dst_name); +(_("%P: Error closing file `%s'\n"), dst_name); +(_("%P%F: missing argument to -m\n")); +(_("%P%F: bfd_hash_table_init failed: %E\n")); +(_("%P%F: bfd_hash_lookup failed: %E\n")); +(_("%P%F: bfd_hash_table_init failed: %E\n")); +(_("%P%F: bfd_hash_lookup failed: %E\n")); +(_("%P%F: bfd_hash_table_init failed: %E\n")); +(_("%P%F: bfd_hash_lookup failed: %E\n")); +(_("%X%P: error: duplicate retain-symbols-file\n")); +("%X%P: %s: %E\n", filename); +(_("%P%F: bfd_hash_table_init failed: %E\n")); +(_("%P%F: bfd_hash_lookup for insertion failed: %E\n")); +(_("%P: `-retain-symbols-file' overrides `-s' and `-S'\n")); +(_("%X%C: multiple definition of `%T'\n"), +(_("%D: first defined here\n"), obfd, osec, oval); +(_("%P: Disabling relaxation: it will not work with multiple definitions\n")); +(_("%B: warning: definition of `%T' overriding common\n"), +(_("%B: warning: common is here\n"), obfd); +(_("%B: warning: common of `%T' overridden by definition\n"), +(_("%B: warning: defined here\n"), obfd); +(_("%B: warning: common of `%T' overridden by larger common\n"), +(_("%B: warning: larger common is here\n"), obfd); +(_("%B: warning: common of `%T' overriding smaller common\n"), +(_("%B: warning: smaller common is here\n"), obfd); +(_("%B: warning: multiple common of `%T'\n"), nbfd, name); +(_("%B: warning: previous common is here\n"), obfd); +(_("%P: warning: global constructor %s used\n"), +(_("%P: warning: global constructor %s used\n"), name); +(_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n")); +(_("%P%F: bfd_link_hash_lookup failed: %E\n")); +(_("%B%F: could not read symbols: %E\n"), abfd); +("%C: %s%s\n", abfd, section, address, _("warning: "), warning); +("%P: %s%s\n", _("warning: "), warning); +("%B: %s%s\n", abfd, _("warning: "), warning); +("%B: %s%s\n", abfd, _("warning: "), warning); +(_("%B%F: could not read relocs: %E\n"), abfd); +(_("%B%F: could not read relocs: %E\n"), abfd); +("%C: %s%s\n", abfd, sec, q->address, _("warning: "), +(_("%X%C: undefined reference to `%T'\n"), +(_("%C: warning: undefined reference to `%T'\n"), +(_("%X%D: more undefined references to `%T' follow\n"), +(_("%D: warning: more undefined references to `%T' follow\n"), +("%X"); +(_("%X%B: undefined reference to `%T'\n"), +(_("%B: warning: undefined reference to `%T'\n"), +(_("%X%B: more undefined references to `%T' follow\n"), +(_("%B: warning: more undefined references to `%T' follow\n"), +("%X"); +("%X%H:", abfd, section, address); +(_(" additional relocation overflows omitted from the output\n")); +(_(" relocation truncated to fit: " +(_(" relocation truncated to fit: " +(_(" relocation truncated to fit: %s against `%T'"), +("+%v", addend); +("\n"); +(_("%X%H: dangerous relocation: %s\n"), +(_("%X%H: reloc refers to symbol `%T' which is not being output\n"), +("%B: reference to %s\n", abfd, name); +("%B: definition of %s\n", abfd, name); +(_("%B%F: could not read symbols: %E\n"), abfd); +(_("%F%P: internal error %s %d\n"), file, line); +(_("%P: internal error: aborting at %s:%d in %s\n"), +(_("%P: internal error: aborting at %s:%d\n"), +(_("%P%F: please report this bug\n")); +(_("%P%F: bfd_new_link_order failed\n")); +(_("%P%F: bfd_new_link_order failed\n")); +(_("%P: %s: missing argument\n"), argv[last_optind]); +(_("%P: %s: missing argument\n"), argv[last_optind]); +(_("%P: unrecognized option '%s'\n"), argv[last_optind]); +(_("%P: unrecognized option '%s'\n"), argv[last_optind]); +(_("%P%F: use the --help option for usage information\n")); +(_("%P%F: use the --help option for usage information\n")); +(_("%P%F: unrecognized -a option `%s'\n"), optarg); +(_("%P%F: unrecognized -a option `%s'\n"), optarg); +(_("%P%F: unrecognized -assert option `%s'\n"), optarg); +(_("%P%F: unrecognized -assert option `%s'\n"), optarg); +(_("%F%P: unknown demangling style `%s'\n"), +(_("%F%P: unknown demangling style `%s'\n"), +(_("%P%F: invalid number `%s'\n"), optarg); +(_("%P%F: invalid number `%s'\n"), optarg); +(_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); +(_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); +(_("%P%F: bad -plugin-opt option\n")); +(_("%P%F: bad -plugin-opt option\n")); +(_("%P%F: unrecognised option: %s\n"), argv[optind]); +(_("%P%F: unrecognised option: %s\n"), argv[optind]); +(_("%P%F: -r and %s may not be used together\n"), +(_("%P%F: -r and %s may not be used together\n"), +(_("%P%F: -r and -shared may not be used together\n")); +(_("%P%F: -r and -shared may not be used together\n")); +(_("%P%F: -shared not supported\n")); +(_("%P%F: -shared not supported\n")); +(_("%P%F: -r and -pie may not be used together\n")); +(_("%P%F: -r and -pie may not be used together\n")); +(_("%P%F: -pie not supported\n")); +(_("%P%F: -pie not supported\n")); +(_("%P: SONAME must not be empty string; keeping previous one\n")); +(_("%P: SONAME must not be empty string; keeping previous one\n")); +(_("%P%F: invalid common section sorting option: %s\n"), +(_("%P%F: invalid common section sorting option: %s\n"), +(_("%P%F: invalid section sorting option: %s\n"), +(_("%P%F: invalid section sorting option: %s\n"), +(_("%P%F: invalid argument to option" +(_("%P%F: invalid argument to option" +(_("%P%F: missing argument(s) to option" +(_("%P%F: missing argument(s) to option" +(_("%P%F: -r and %s may not be used together\n"), +(_("%P%F: -r and %s may not be used together\n"), +(_("%P%F: invalid number `%s'\n"), optarg); +(_("%P%F: invalid number `%s'\n"), optarg); +(_("%P%F: group ended before it began (--help for usage)\n")); +(_("%P%F: group ended before it began (--help for usage)\n")); +(_("%P%X: --hash-size needs a numeric argument\n")); +(_("%P%X: --hash-size needs a numeric argument\n")); +(_("%P%F: no state pushed before popping\n")); +(_("%P%F: no state pushed before popping\n")); +(_("%P%F: invalid argument to option" +(_("%P%F: invalid argument to option" +(_("%P: SONAME must not be empty string; ignored\n")); +(_("%P: SONAME must not be empty string; ignored\n")); +(_("%P%F: -F may not be used without -shared\n")); +(_("%P%F: -F may not be used without -shared\n")); +(_("%P%F: -f may not be used without -shared\n")); +(_("%P%F: -f may not be used without -shared\n")); +(_("%P%F: invalid hex number `%s'\n"), valstr); +(_("%P%F: invalid hex number `%s'\n"), valstr); +(_("%P%F: unknown format type %s\n"), name); +(_("%P%X: Unsupported PEI architecture: %s\n"), target); +(_("%B%F: could not read symbols: %E\n"), b); +(_("%P%X: Cannot export %s: invalid export name\n"), +(_("%P%X: Error, duplicate EXPORT with ordinals: %s (%d vs %d)\n"), +(_("%P: Warning, duplicate EXPORT: %s\n"), +(_("%P%X: Cannot export %s: symbol not defined\n"), +(_("%P%X: Cannot export %s: symbol wrong type (%d vs %d)\n"), +(_("%P%X: Cannot export %s: symbol not found\n"), +("%X%P: can not create BFD: %E\n"); +("%X%P: can not create .edata section: %E\n"); +("%X%P: can not create .reloc section: %E\n"); +(_("%P%X: Error: ordinal used twice: %d (%s vs %s)\n"), +(_("%P%X: Error: export ordinal too large: %d\n"), +("DJ: zero vma section reloc detected: `%s' #%d f=%d\n", +(_("%B%F: could not read symbols: %E\n"), b); +(_("%P%X: Error: %d-bit reloc in dll\n"), +(_("%P: Can't open output def file %s\n"), +(_("%P: Error closing file `%s'\n"), pe_out_def_filename); +(_("%P%X%C: variable '%T' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.\n"), +(_("%P%X: Can't open .lib file: %s\n"), impfilename); +(_("%P%X: bfd_openr %s: %E\n"), ibfd->filename); +(_("%P%X: %s(%s): can't find member in non-archive file"), +(_("%P%X: %s(%s): can't find member in archive"), +("%P%X: bfd_set_archive_head: %E\n"); +("%P%X: bfd_close %s: %E\n", impfilename); +("%P%X: addsym %s: %E\n", name); +("%P%X: open %s: %E\n", filename); +("%P%X: %s: this doesn't appear to be a DLL\n", filename); +(_("%P%X: Error: can't use long section names on this arch\n")); +(_("%P%F: %s: error loading plugin: %s\n"), plugin, dlerror ()); +(_("%P: %s: duplicated plugin\n"), plugin); +(_("could not create dummy IR bfd: %F%E\n")); +(_("%P%F: %s: non-ELF symbol in ELF BFD!\n"), asym->name); +(_("%P%F: unknown ELF symbol visibility: %d!\n"), +(_("%P%F: unsupported input file size: %s (%ld bytes)\n"), +("%P%F: %s: plugin symbol table corrupt (sym type %d)\n", +(_("%P: %B: symbol `%s' " +(_("%P%F: %s: error loading plugin: %s\n"), +(_("%P%F: %s: plugin error: %d\n"), curplug->name, rv); +(_("%P%F: plugin_strdup failed to allocate memory: %s\n"), +(_("%P%F: plugin failed to allocate memory for input: %s\n"), +(_("%P%F: %s: plugin reported error claiming file\n"), diff --git a/include/chad.h b/include/chad.h new file mode 100644 index 0000000..474186a --- /dev/null +++ b/include/chad.h @@ -0,0 +1,33 @@ +#ifndef CHAD_H + +#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 CHAD_H +#endif diff --git a/include/hl.h b/include/hl.h new file mode 100644 index 0000000..8735177 --- /dev/null +++ b/include/hl.h @@ -0,0 +1,323 @@ +/* hl.h + * Copyright 2023 Anon Anonson, Ognjen 'xolatile' Milan Robovic, Emil Williams + * SPDX Identifier: GPL-3.0-only / NO WARRANTY / NO GUARANTEE */ + +#include +#include +#include +#include +#include "chad.h" +#include "regex.h" + +// ------------------- +// ### Definitions ### +// ------------------- + +typedef enum { + KEYSYMBOL, + KEYWORD, + MATCH, + REGION +} token_type_t; + +typedef void (*attribute_callback_t) (const char * const string, + const int length, + void * const attributes); + +typedef struct { + char * key; + attribute_callback_t callback; + UT_hash_handle hh; +} display_t; + +typedef struct { + void * attributes; + struct hl_group_t * link; +} hl_group_t; + +typedef struct { + hl_group_t * hl; + regex_t * syntax; + token_type_t t; + char _pad[4]; +} token_t; + +extern vector_t token_table; +extern display_t * display_table; + +extern hl_group_t * keyword_hl; +extern hl_group_t * preprocessor_hl; +extern hl_group_t * symbol_hl; + +extern void new_display_mode(display_t * mode); +extern int free_token(token_t * token); +extern int append_token(token_t * token); + +// TODO: ALIGN PROPERLY... + +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); +extern token_t * new_keyword_token(const char * const word, + hl_group_t * const g); +extern int new_keyword_tokens(const char * const * words, + hl_group_t * const g); +extern token_t * new_token(const char * const word, + const token_type_t t, + hl_group_t * const g); + +// TODO: ALIGN PROPERLY... + +extern int token_fits(const token_t * const token, + const char * const to, + const int string_offset, + int * match_offset); + +extern void render_string(const char * const string, + const char * const mode); + +extern int hl_init(void); +extern int hl_deinit(void); + +// GLOBALS + +vector_t token_table = { + .data = NULL, + .element_size = sizeof(token_t *), + .element_count = 0UL +}; + +display_t * display_table = NULL; + +// -------------------------------- +// ### Constructors/Destructors ### +// -------------------------------- + +void new_display_mode(display_t * mode) { + HASH_ADD_STR(display_table, + key, + mode); +} + +int free_token(token_t * token) { + free(token->hl); + regex_free(token->syntax); + + return 0; +} + +int append_token(token_t * token) { + vector_push(&token_table, &token); + + return 0; +} + +token_t * new_symbol_token(const char * const c, + hl_group_t * const g) { + + token_t * mt = (token_t*)malloc(sizeof(token_t)); + + mt->hl = g; + mt->t = KEYSYMBOL; + mt->syntax = regex_compile(c); + + append_token(mt); + + return mt; +} + +int new_symbol_tokens(const char * const * symbols, + hl_group_t * const g) { + int i = 0; + + while (*symbols) { + if(new_symbol_token(*symbols, g)) { + ++i; + } else { + assert(!(bool)"Kinda failed to new symbol token thing."); + } + ++symbols; + } + + return i; +} + +int new_char_tokens(const char * characters, + hl_group_t * const g) { + int i = 0; + + char buffer[3]; + buffer[0] = '\\'; + buffer[2] = '\0'; + + for(const char * s = characters; *s != '\0'; s++) { + buffer[1] = *s; + if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) { + ++i; + } else { + assert(!(bool)"Kinda failed to new char token thing."); + } + } + + return i; +} + +token_t * new_keyword_token(const char * const word, + hl_group_t * const g) { + //char * new_word = strdup(word); + //size_t word_length = strlen(word); + //char * new_word = (char*)malloc(word_length + 4 + 1); + + //memcpy(new_word, "\\<", 2); + //memcpy(new_word + 2, word, word_length); + //strcpy(new_word + 2 + word_length, "\\>"); + + token_t * mt = (token_t*)malloc(sizeof(token_t)); + + mt->hl = g; + mt->t = KEYWORD; + //mt->syntax = regex_compile(new_word); + mt->syntax = regex_compile(word); + + append_token(mt); + + return mt; +} + +int new_keyword_tokens(const char * const * words, + hl_group_t * const g) { + int i = 0; + + while (*words) { + if(new_keyword_token(*words, g)) { + ++i; + } + ++words; + } + + return i; +} + +token_t * new_region_token(const char * const * start, + const char * const * end, + hl_group_t * const g) { + char buffer[100]; + buffer[0] = '\0'; + strcat(buffer, start); + strcat(buffer, "[\\d\\D]*"); + strcat(buffer, end); + + token_t * mt = (token_t*)malloc(sizeof(token_t)); + + mt->hl = g; + mt->t = KEYSYMBOL; + mt->syntax = regex_compile(buffer); + + append_token(mt); + + return mt; +} + +token_t * new_token(const char * const word, + const token_type_t t, + hl_group_t * const g) { + switch (t) { + case KEYSYMBOL: { + return new_symbol_token(word, g); + } + case KEYWORD: { + return new_keyword_token(word, g); + } + case MATCH: { + } break; + case REGION: { + } break; + } + + return NULL; +} + +// -------------------- +// ### Highlighting ### +// -------------------- + +int token_fits(const token_t * const token, + const char * const to, + const int string_offset, + int * match_offset) { + UNUSED(match_offset); + + //return regex_match(pattern, to, string_offset, match_offset); + return regex_match(token->syntax, to + string_offset); +} + +void render_string(const char * const string, + const char * const mode) { + for (const char * s = string; *s != '\00';) { + int f = 0; + size_t token_index = 0; + int offset = 0; + + for (; token_index < token_table.element_count; token_index++) { + token_t * t = *(token_t**)vector_get(&token_table, + token_index); + f = token_fits(t, string, (int) (s - string), &offset); + if (f) { + break; + } + } + // + display_t * display; + HASH_FIND_STR(display_table, + mode, + display); + // + if (f) { + for (int i = 0; i < offset; i++) { + token_t * t = *(token_t**)vector_get(&token_table, + token_index); + display->callback(s + i, + 0, + t->hl->attributes); + } + token_t * t = *(token_t**)vector_get(&token_table, + token_index); + display->callback(s + offset, + f, + t->hl->attributes); + s += f + offset; + } else { + display->callback(s, + 0, + NULL); + ++s; + } + } +} + +// ------------------------- +// ### Library Mangement ### +// ------------------------- +hl_group_t * special_hl = NULL; +hl_group_t * control_hl = NULL; +hl_group_t * keyword_hl = NULL; +hl_group_t * block_hl = NULL; +hl_group_t * separator_hl = NULL; +hl_group_t * operator_hl = NULL; +hl_group_t * comment_hl = NULL; +hl_group_t * string_literal_hl = NULL; + +int hl_init(void) { + return 0; +} + +int hl_deinit(void) { + for (size_t i = 0; i < token_table.element_count; i++) { + free_token(*(token_t**)vector_get(&token_table, i)); + } + + return 0; +} diff --git a/include/regex.h b/include/regex.h new file mode 100644 index 0000000..0049fcc --- /dev/null +++ b/include/regex.h @@ -0,0 +1,23 @@ +#ifndef REGEX_H +#define REGEX_H + +#include "chad.h" +#include "vector.h" + +extern bool is_case_on; + +typedef struct { + int accepting_state; + char * str; + vector_t delta_table; // + vector_t catch_table; // +} regex_t; + +extern regex_t * regex_compile(const char * const pattern); +extern int regex_free(regex_t * const regex); +extern bool regex_search(regex_t * regex, const char * const string); +extern int regex_match(regex_t * regex, const char * const string); + +extern bool is_magic(const char c); + +#endif diff --git a/include/terminal_hl.h b/include/terminal_hl.h new file mode 100644 index 0000000..5fe1947 --- /dev/null +++ b/include/terminal_hl.h @@ -0,0 +1,70 @@ +#include "hl.h" + +typedef struct { + char * attribute; + char * foreground_color; + char * background_color; +} terminal_hl_t; + +extern display_t * cterm; + +extern void cterm_render_callback(const char * const string, + const int length, + void * const attributes); + +extern int terminal_hl_init(void); + +display_t * cterm = &(display_t) { + .key = "cterm", + .callback = cterm_render_callback +}; + +void cterm_render_callback(const char * const string, + const int length, + void * const attributes) { + if(!length){ + fputs(TERMINAL_STYLE_BOLD, stdout); + putchar(*string); + fputs(TERMINAL_RESET, stdout); + return; + } + + terminal_hl_t * term_hl = (terminal_hl_t*)attributes; + if (term_hl->attribute) { + fputs(term_hl->attribute, stdout); + } + if (term_hl->foreground_color) { + fputs(term_hl->foreground_color, stdout); + } + for (int i = 0; i < length; i++) { + putchar(*(string+i)); + } + fputs(TERMINAL_RESET, stdout); +} + + +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; + (*group) = (hl_group_t *)malloc(sizeof(hl_group_t)); + (*group)->link = NULL; + (*group)->attributes = (void*)t; +} + +int terminal_hl_init(void) { + hl_init(); + new_display_mode(cterm); + // + fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_CYAN, &special_hl); + fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_YELLOW, &control_hl); + fun(NULL, TERMINAL_COLOR_FG_YELLOW, &operator_hl); + fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_GREEN, &keyword_hl); + fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_BLUE, &comment_hl); + fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_RED, &string_literal_hl); + + return 0; +} diff --git a/include/vector.h b/include/vector.h new file mode 100644 index 0000000..613c57c --- /dev/null +++ b/include/vector.h @@ -0,0 +1,36 @@ +#ifndef VECTOR_H +#define VECTOR_H + +#include +#include +#include +#include + +// TODO: Handle error warnings? +// TODO: Implement more useful functions? + +typedef struct { + char * data; + size_t element_size; + size_t element_count; +} vector_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(const vector_t * const vector, + const size_t element); + +extern void vector_set(vector_t * vector, + void * data, + size_t element); + +extern void vector_free(vector_t * vector); + +#endif diff --git a/source/chad.h b/source/chad.h deleted file mode 100644 index 474186a..0000000 --- a/source/chad.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CHAD_H - -#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 CHAD_H -#endif diff --git a/source/hl.h b/source/hl.h deleted file mode 100644 index 8735177..0000000 --- a/source/hl.h +++ /dev/null @@ -1,323 +0,0 @@ -/* hl.h - * Copyright 2023 Anon Anonson, Ognjen 'xolatile' Milan Robovic, Emil Williams - * SPDX Identifier: GPL-3.0-only / NO WARRANTY / NO GUARANTEE */ - -#include -#include -#include -#include -#include "chad.h" -#include "regex.h" - -// ------------------- -// ### Definitions ### -// ------------------- - -typedef enum { - KEYSYMBOL, - KEYWORD, - MATCH, - REGION -} token_type_t; - -typedef void (*attribute_callback_t) (const char * const string, - const int length, - void * const attributes); - -typedef struct { - char * key; - attribute_callback_t callback; - UT_hash_handle hh; -} display_t; - -typedef struct { - void * attributes; - struct hl_group_t * link; -} hl_group_t; - -typedef struct { - hl_group_t * hl; - regex_t * syntax; - token_type_t t; - char _pad[4]; -} token_t; - -extern vector_t token_table; -extern display_t * display_table; - -extern hl_group_t * keyword_hl; -extern hl_group_t * preprocessor_hl; -extern hl_group_t * symbol_hl; - -extern void new_display_mode(display_t * mode); -extern int free_token(token_t * token); -extern int append_token(token_t * token); - -// TODO: ALIGN PROPERLY... - -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); -extern token_t * new_keyword_token(const char * const word, - hl_group_t * const g); -extern int new_keyword_tokens(const char * const * words, - hl_group_t * const g); -extern token_t * new_token(const char * const word, - const token_type_t t, - hl_group_t * const g); - -// TODO: ALIGN PROPERLY... - -extern int token_fits(const token_t * const token, - const char * const to, - const int string_offset, - int * match_offset); - -extern void render_string(const char * const string, - const char * const mode); - -extern int hl_init(void); -extern int hl_deinit(void); - -// GLOBALS - -vector_t token_table = { - .data = NULL, - .element_size = sizeof(token_t *), - .element_count = 0UL -}; - -display_t * display_table = NULL; - -// -------------------------------- -// ### Constructors/Destructors ### -// -------------------------------- - -void new_display_mode(display_t * mode) { - HASH_ADD_STR(display_table, - key, - mode); -} - -int free_token(token_t * token) { - free(token->hl); - regex_free(token->syntax); - - return 0; -} - -int append_token(token_t * token) { - vector_push(&token_table, &token); - - return 0; -} - -token_t * new_symbol_token(const char * const c, - hl_group_t * const g) { - - token_t * mt = (token_t*)malloc(sizeof(token_t)); - - mt->hl = g; - mt->t = KEYSYMBOL; - mt->syntax = regex_compile(c); - - append_token(mt); - - return mt; -} - -int new_symbol_tokens(const char * const * symbols, - hl_group_t * const g) { - int i = 0; - - while (*symbols) { - if(new_symbol_token(*symbols, g)) { - ++i; - } else { - assert(!(bool)"Kinda failed to new symbol token thing."); - } - ++symbols; - } - - return i; -} - -int new_char_tokens(const char * characters, - hl_group_t * const g) { - int i = 0; - - char buffer[3]; - buffer[0] = '\\'; - buffer[2] = '\0'; - - for(const char * s = characters; *s != '\0'; s++) { - buffer[1] = *s; - if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) { - ++i; - } else { - assert(!(bool)"Kinda failed to new char token thing."); - } - } - - return i; -} - -token_t * new_keyword_token(const char * const word, - hl_group_t * const g) { - //char * new_word = strdup(word); - //size_t word_length = strlen(word); - //char * new_word = (char*)malloc(word_length + 4 + 1); - - //memcpy(new_word, "\\<", 2); - //memcpy(new_word + 2, word, word_length); - //strcpy(new_word + 2 + word_length, "\\>"); - - token_t * mt = (token_t*)malloc(sizeof(token_t)); - - mt->hl = g; - mt->t = KEYWORD; - //mt->syntax = regex_compile(new_word); - mt->syntax = regex_compile(word); - - append_token(mt); - - return mt; -} - -int new_keyword_tokens(const char * const * words, - hl_group_t * const g) { - int i = 0; - - while (*words) { - if(new_keyword_token(*words, g)) { - ++i; - } - ++words; - } - - return i; -} - -token_t * new_region_token(const char * const * start, - const char * const * end, - hl_group_t * const g) { - char buffer[100]; - buffer[0] = '\0'; - strcat(buffer, start); - strcat(buffer, "[\\d\\D]*"); - strcat(buffer, end); - - token_t * mt = (token_t*)malloc(sizeof(token_t)); - - mt->hl = g; - mt->t = KEYSYMBOL; - mt->syntax = regex_compile(buffer); - - append_token(mt); - - return mt; -} - -token_t * new_token(const char * const word, - const token_type_t t, - hl_group_t * const g) { - switch (t) { - case KEYSYMBOL: { - return new_symbol_token(word, g); - } - case KEYWORD: { - return new_keyword_token(word, g); - } - case MATCH: { - } break; - case REGION: { - } break; - } - - return NULL; -} - -// -------------------- -// ### Highlighting ### -// -------------------- - -int token_fits(const token_t * const token, - const char * const to, - const int string_offset, - int * match_offset) { - UNUSED(match_offset); - - //return regex_match(pattern, to, string_offset, match_offset); - return regex_match(token->syntax, to + string_offset); -} - -void render_string(const char * const string, - const char * const mode) { - for (const char * s = string; *s != '\00';) { - int f = 0; - size_t token_index = 0; - int offset = 0; - - for (; token_index < token_table.element_count; token_index++) { - token_t * t = *(token_t**)vector_get(&token_table, - token_index); - f = token_fits(t, string, (int) (s - string), &offset); - if (f) { - break; - } - } - // - display_t * display; - HASH_FIND_STR(display_table, - mode, - display); - // - if (f) { - for (int i = 0; i < offset; i++) { - token_t * t = *(token_t**)vector_get(&token_table, - token_index); - display->callback(s + i, - 0, - t->hl->attributes); - } - token_t * t = *(token_t**)vector_get(&token_table, - token_index); - display->callback(s + offset, - f, - t->hl->attributes); - s += f + offset; - } else { - display->callback(s, - 0, - NULL); - ++s; - } - } -} - -// ------------------------- -// ### Library Mangement ### -// ------------------------- -hl_group_t * special_hl = NULL; -hl_group_t * control_hl = NULL; -hl_group_t * keyword_hl = NULL; -hl_group_t * block_hl = NULL; -hl_group_t * separator_hl = NULL; -hl_group_t * operator_hl = NULL; -hl_group_t * comment_hl = NULL; -hl_group_t * string_literal_hl = NULL; - -int hl_init(void) { - return 0; -} - -int hl_deinit(void) { - for (size_t i = 0; i < token_table.element_count; i++) { - free_token(*(token_t**)vector_get(&token_table, i)); - } - - return 0; -} diff --git a/source/regex.h b/source/regex.h deleted file mode 100644 index 0049fcc..0000000 --- a/source/regex.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef REGEX_H -#define REGEX_H - -#include "chad.h" -#include "vector.h" - -extern bool is_case_on; - -typedef struct { - int accepting_state; - char * str; - vector_t delta_table; // - vector_t catch_table; // -} regex_t; - -extern regex_t * regex_compile(const char * const pattern); -extern int regex_free(regex_t * const regex); -extern bool regex_search(regex_t * regex, const char * const string); -extern int regex_match(regex_t * regex, const char * const string); - -extern bool is_magic(const char c); - -#endif diff --git a/source/terminal_hl.h b/source/terminal_hl.h deleted file mode 100644 index 5fe1947..0000000 --- a/source/terminal_hl.h +++ /dev/null @@ -1,70 +0,0 @@ -#include "hl.h" - -typedef struct { - char * attribute; - char * foreground_color; - char * background_color; -} terminal_hl_t; - -extern display_t * cterm; - -extern void cterm_render_callback(const char * const string, - const int length, - void * const attributes); - -extern int terminal_hl_init(void); - -display_t * cterm = &(display_t) { - .key = "cterm", - .callback = cterm_render_callback -}; - -void cterm_render_callback(const char * const string, - const int length, - void * const attributes) { - if(!length){ - fputs(TERMINAL_STYLE_BOLD, stdout); - putchar(*string); - fputs(TERMINAL_RESET, stdout); - return; - } - - terminal_hl_t * term_hl = (terminal_hl_t*)attributes; - if (term_hl->attribute) { - fputs(term_hl->attribute, stdout); - } - if (term_hl->foreground_color) { - fputs(term_hl->foreground_color, stdout); - } - for (int i = 0; i < length; i++) { - putchar(*(string+i)); - } - fputs(TERMINAL_RESET, stdout); -} - - -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; - (*group) = (hl_group_t *)malloc(sizeof(hl_group_t)); - (*group)->link = NULL; - (*group)->attributes = (void*)t; -} - -int terminal_hl_init(void) { - hl_init(); - new_display_mode(cterm); - // - fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_CYAN, &special_hl); - fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_YELLOW, &control_hl); - fun(NULL, TERMINAL_COLOR_FG_YELLOW, &operator_hl); - fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_GREEN, &keyword_hl); - fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_BLUE, &comment_hl); - fun(TERMINAL_STYLE_BOLD, TERMINAL_COLOR_FG_RED, &string_literal_hl); - - return 0; -} diff --git a/source/vector.h b/source/vector.h deleted file mode 100644 index 613c57c..0000000 --- a/source/vector.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef VECTOR_H -#define VECTOR_H - -#include -#include -#include -#include - -// TODO: Handle error warnings? -// TODO: Implement more useful functions? - -typedef struct { - char * data; - size_t element_size; - size_t element_count; -} vector_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(const vector_t * const vector, - const size_t element); - -extern void vector_set(vector_t * vector, - void * data, - size_t element); - -extern void vector_free(vector_t * vector); - -#endif 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); -}