diff options
author | pfero <ohpee@loves.dicksinhisan.us> | 2018-05-31 01:18:27 +0200 |
---|---|---|
committer | pfero <ohpee@loves.dicksinhisan.us> | 2018-05-31 02:59:50 +0200 |
commit | 96049270e07c304e290bf711beb28b52c5d013b0 (patch) | |
tree | 3ca2ed26d16bcc0f02335d602700eafb1e9c438e | |
parent | 88b51cfe5f883a6226752efffcba41da5331b5b9 (diff) |
Remove scan_includes.c
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | tools/Makefile | 1 | ||||
-rw-r--r-- | tools/scan_includes.c | 123 |
4 files changed, 2 insertions, 125 deletions
@@ -23,4 +23,4 @@ shim.asm tools/scan_includes tools/pkmncompress tools/gfx -pret/ +build/ @@ -42,6 +42,7 @@ tools tools/pkmncompress tools/gfx: .PHONY: clean clean: rm -rf $(ROMS) $(BUILD) $(ROMS:.gb=.sym) $(ROMS:.gb=.map) + make -C tools clean # Remove files except for graphics. .PHONY: mostlyclean diff --git a/tools/Makefile b/tools/Makefile index 8a9a284..6c49ccb 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,7 +3,6 @@ CFLAGS := -O3 -std=c99 -Wall -Wextra tools := \ - scan_includes \ pkmncompress \ gfx diff --git a/tools/scan_includes.c b/tools/scan_includes.c deleted file mode 100644 index 2babdcf..0000000 --- a/tools/scan_includes.c +++ /dev/null @@ -1,123 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <getopt.h> - -void usage(void) { - printf("Usage: scan_includes [-h] [-s] filename\n" - "-h, --help\n" - " Print usage and exit\n" - "-s, --strict\n" - " Fail if a file cannot be read\n"); -} - -struct Options { - bool help; - bool strict; -}; - -struct Options Options = {0}; - -void scan_file(char* filename) { - FILE *f = fopen(filename, "rb"); - if (!f) { - if (Options.strict) { - fprintf(stderr, "Could not open file: '%s'\n", filename); - exit(1); - } else { - return; - } - } - - fseek(f, 0, SEEK_END); - long size = ftell(f); - rewind(f); - - char *buffer = malloc(size + 1); - char *orig = buffer; - size = fread(buffer, 1, size, f); - buffer[size] = '\0'; - fclose(f); - - for (; buffer && (buffer - orig < size); buffer++) { - bool is_include = false; - bool is_incbin = false; - switch (*buffer) { - case ';': - buffer = strchr(buffer, '\n'); - if (!buffer) { - fprintf(stderr, "%s: no newline at end of file\n", filename); - } - break; - - case 'i': - case 'I': - if ((strncmp(buffer, "INCBIN", 6) == 0) || (strncmp(buffer, "incbin", 6) == 0)) { - is_incbin = true; - } else if ((strncmp(buffer, "INCLUDE", 7) == 0) || (strncmp(buffer, "include", 7) == 0)) { - is_include = true; - } - if (is_incbin || is_include) { - buffer = strchr(buffer, '"'); - if (!buffer++) { - break; - } - int length = strcspn(buffer, "\""); - char *include = malloc(length + 1); - strncpy(include, buffer, length); - include[length] = '\0'; - printf("%s ", include); - if (is_include) { - scan_file(include); - } - free(include); - buffer = strchr(buffer, '"'); - } - break; - - } - if (!buffer) { - break; - } - - } - - free(orig); -} - -int main(int argc, char* argv[]) { - int i = 0; - struct option long_options[] = { - {"strict", no_argument, 0, 's'}, - {"help", no_argument, 0, 'h'}, - {0} - }; - int opt = -1; - while ((opt = getopt_long(argc, argv, "sh", long_options, &i)) != -1) { - switch (opt) { - case 's': - Options.strict = true; - break; - case 'h': - Options.help = true; - break; - default: - usage(); - exit(1); - break; - } - } - argc -= optind; - argv += optind; - if (Options.help) { - usage(); - return 0; - } - if (argc < 1) { - usage(); - exit(1); - } - scan_file(argv[0]); - return 0; -} |