diff options
| author | dannye <33dannye@gmail.com> | 2023-11-20 00:33:27 -0600 |
|---|---|---|
| committer | dannye <33dannye@gmail.com> | 2023-11-20 20:23:27 -0600 |
| commit | 298e99d3776580585c3f434e5d93137ae431bdd3 (patch) | |
| tree | a808c4ffd0fd0f9bd28972bae5236e0d3345c8e5 /tools | |
| parent | Add sound bits documentation for wOptions (#110) (diff) | |
| parent | Name 2 unnamed labels I missed in SeafoamIslandsB4F and PokemonMansion3F (#437) (diff) | |
| download | pokeyellow-298e99d3776580585c3f434e5d93137ae431bdd3.tar.gz pokeyellow-298e99d3776580585c3f434e5d93137ae431bdd3.tar.xz pokeyellow-298e99d3776580585c3f434e5d93137ae431bdd3.zip | |
Merge branch 'master' of https://github.com/pret/pokered
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/free_space.awk | 18 | ||||
| -rw-r--r-- | tools/scan_includes.c | 52 |
2 files changed, 51 insertions, 19 deletions
diff --git a/tools/free_space.awk b/tools/free_space.awk index e47f35c1..b0e46dc7 100755 --- a/tools/free_space.awk +++ b/tools/free_space.awk @@ -38,17 +38,25 @@ function register_bank(amount) { printf "Bank %3d: %5d/16384 (%.2f%%)\n", bank_num, amount, amount * 100 / 16384 } } +function register_bank_str(str) { + if (str ~ /\$[0-9A-F]+/) { + register_bank(strtonum("0x" substr(str, 2))) + } else { + printf "Malformed number? \"%s\" does not start with '$'\n", str + } +} rom_bank && toupper($0) ~ /^[ \t]*EMPTY$/ { # Empty bank register_bank(16384) } rom_bank && toupper($0) ~ /^[ \t]*SLACK:[ \t]/ { - if ($2 ~ /\$[0-9A-F]+/) { - register_bank(strtonum("0x" substr($2, 2))) - } else { - printf "Malformed slack line? \"%s\" does not start with '$'\n", $2 - } + # Old (rgbds <=0.6.0) end-of-bank free space + register_bank_str($2) +} +rom_bank && toupper($0) ~ /^[ \t]*TOTAL EMPTY:[ \t]/ { + # New (rgbds >=0.6.1) total free space + register_bank_str($3) } END { diff --git a/tools/scan_includes.c b/tools/scan_includes.c index e57ddc35..9ec5f3c5 100644 --- a/tools/scan_includes.c +++ b/tools/scan_includes.c @@ -3,6 +3,8 @@ #include "common.h" +#include <ctype.h> + void parse_args(int argc, char *argv[], bool *strict) { struct option long_options[] = { {"strict", no_argument, 0, 's'}, @@ -40,31 +42,47 @@ void scan_file(const char *filename, bool strict) { fclose(f); contents[size] = '\0'; - for (char *ptr = contents; ptr && ptr - contents < size; ptr++) { - bool is_incbin = false, is_include = false; + for (char *ptr = contents; ptr && ptr < contents + size; ptr++) { + ptr = strpbrk(ptr, ";\"Ii"); + if (!ptr) { + break; + } switch (*ptr) { case ';': - ptr = strchr(ptr, '\n'); - if (!ptr) { - fprintf(stderr, "%s: no newline at end of file\n", filename); + // Skip comments until the end of the line + ptr += strcspn(ptr + 1, "\r\n"); + if (*ptr) { + ptr++; } break; + case '"': - ptr++; - ptr = strchr(ptr, '"'); - if (ptr) { + // Skip string literal until the closing quote + ptr += strcspn(ptr + 1, "\""); + if (*ptr) { ptr++; - } else { - fprintf(stderr, "%s: unterminated string\n", filename); } break; + case 'I': case 'i': - is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6); - is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7); + /* empty statement between the label and the variable declaration */; + // Check that an INCLUDE/INCBIN starts as its own token + char before = ptr > contents ? *(ptr - 1) : '\n'; + if (!isspace((unsigned)before) && before != ':') { + break; + } + bool is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6); + bool is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7); if (is_incbin || is_include) { - ptr = strchr(ptr, '"'); - if (ptr) { + // Check that an INCLUDE/INCBIN ends as its own token + ptr += is_include ? 7 : 6; + if (!isspace((unsigned)*ptr) && *ptr != '"') { + break; + } + ptr += strspn(ptr, " \t"); + if (*ptr == '"') { + // Print the file path and recursively scan INCLUDEs ptr++; char *include_path = ptr; size_t length = strcspn(ptr, "\""); @@ -74,6 +92,12 @@ void scan_file(const char *filename, bool strict) { if (is_include) { scan_file(include_path, strict); } + } else { + fprintf(stderr, "%s: no file path after INC%s\n", filename, is_include ? "LUDE" : "BIN"); + // Continue to process a comment + if (*ptr == ';') { + ptr--; + } } } break; |
