anon 8 mesi fa
parent
commit
2c44086b84
21 ha cambiato i file con 104 aggiunte e 642 eliminazioni
  1. +17
    -1
      Makefile
  2. +1
    -5
      chad.mk
  3. +0
    -18
      config.mk
  4. +0
    -0
      document/BUGS.md
  5. +0
    -0
      document/TODO
  6. +0
    -0
      document/possible_messages.list
  7. +8
    -0
      include/chad.h
  8. +20
    -15
      include/hl.h
  9. +2
    -1
      include/regex.h
  10. +0
    -0
      include/syntax/c.h
  11. +38
    -13
      include/terminal_hl.h
  12. +1
    -4
      include/vector.h
  13. +0
    -33
      source/chad.h
  14. +3
    -8
      source/main.c
  15. +9
    -10
      source/regex.c
  16. +5
    -0
      source/vector.c
  17. +0
    -1
      tests/comment.input
  18. +0
    -321
      tests/main.c
  19. +0
    -76
      tests/regex_tester.cpp
  20. +0
    -1
      tests/test.input
  21. +0
    -135
      tests/vector.c

+ 17
- 1
Makefile Vedi File

@@ -1,4 +1,20 @@
include config.mk
TARGET:=hl

CFLAGS:=-std=c99
CPPFLAGS:=-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


+ 1
- 5
chad.mk Vedi File

@@ -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}

+ 0
- 18
config.mk Vedi File

@@ -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)

BUGS.md → document/BUGS.md Vedi File


TODO → document/TODO Vedi File


docs/possible_messages.list → document/possible_messages.list Vedi File


+ 8
- 0
include/chad.h Vedi File

@@ -0,0 +1,8 @@
#ifndef CHAD_H

#include <stdbool.h>

#define UNUSED(x) ((void)x) /* much like this header */

#define CHAD_H
#endif

source/hl.h → include/hl.h Vedi File

@@ -6,6 +6,7 @@
#include <uthash.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include "chad.h"
#include "regex.h"

@@ -20,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;
@@ -57,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 +152,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 +160,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 +208,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);
@@ -255,8 +261,7 @@ int token_fits(const token_t * const token,
const int string_offset,
const bool is_start_of_line,
int * match_offset) {
UNUSED(match_offset);

UNUSED(match_offset);
//return regex_match(pattern, to, string_offset, match_offset);
return regex_match(token->syntax, to, is_start_of_line, string_offset);
}

source/regex.h → include/regex.h Vedi File

@@ -1,7 +1,8 @@
#ifndef REGEX_H
#define REGEX_H

#include "chad.h"
#include <stdbool.h>

#include "vector.h"

extern bool is_case_on;

syntax/c.h → include/syntax/c.h Vedi File


source/terminal_hl.h → include/terminal_hl.h Vedi File

@@ -1,9 +1,34 @@
#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;
char * background_color;
const char * attribute;
const char * foreground_color;
const char * background_color;
} terminal_hl_t;

extern display_t * cterm;
@@ -22,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);
@@ -43,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) {

source/vector.h → include/vector.h Vedi File

@@ -1,10 +1,7 @@
#ifndef VECTOR_H
#define VECTOR_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stddef.h>

// TODO: Handle error warnings?
// TODO: Implement more useful functions?

+ 0
- 33
source/chad.h Vedi File

@@ -1,33 +0,0 @@
#ifndef CHAD_H

#include <stdbool.h>

#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

+ 3
- 8
source/main.c Vedi File

@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#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);
}
@@ -40,7 +35,7 @@ int main(int argc,
// Highlight init
terminal_hl_init();
//
#include "c.h"
#include "syntax/c.h"
//

render_string(buffer, "cterm");


+ 9
- 10
source/regex.c Vedi File

@@ -7,6 +7,7 @@
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>

// ------------------
// ### Char tests ###
@@ -32,8 +33,6 @@ bool is_magic(const char c) {
return false;
}



// ----------------------
// ### Internal Types ###
// ----------------------
@@ -354,17 +353,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:;
}
}



+ 5
- 0
source/vector.c Vedi File

@@ -4,6 +4,11 @@

#include "vector.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

void vector_init(vector_t * vector,
size_t element_size,
size_t element_count) {


+ 0
- 1
tests/comment.input Vedi File

@@ -1 +0,0 @@
/* a */

+ 0
- 321
tests/main.c Vedi File

@@ -1,321 +0,0 @@
// @COMPILECMD gcc $@ -o test
#include <stdio.h>

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;
}

+ 0
- 76
tests/regex_tester.cpp Vedi File

@@ -1,76 +0,0 @@
// @COMPILECMD g++ $@ -o regtest -O0 -ggdb -pg -fno-inline
#include <stdio.h>
#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);
}

+ 0
- 1
tests/test.input Vedi File

@@ -1 +0,0 @@
while

+ 0
- 135
tests/vector.c Vedi File

@@ -1,135 +0,0 @@
// @COMPILECMD gcc $@ -o vector.out
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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);
}

Loading…
Annulla
Salva