summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2022-03-08 21:42:58 -0500
committerRangi <remy.oukaour+rangi42@gmail.com>2022-03-08 21:47:51 -0500
commit9a97c99f382477a8a17230519333222015dd2ae6 (patch)
tree537f8a1ba838919b5f78e7f51377f411d08a75a5
parent7d17d3ce8fc4b20901fec96417d91b9eb996df04 (diff)
Slightly refactor some C tools
-rw-r--r--Makefile2
-rw-r--r--tools/Makefile3
-rw-r--r--tools/gfx.c15
-rw-r--r--tools/scan_includes.c28
4 files changed, 20 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index e04ad8ca..7977d429 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ clean: tidy
find gfx \( -name "*.[12]bpp" -o -name "*.lz" -o -name "*.gbcpal" -o -name "*.dimensions" -o -name "*.sgb.tilemap" \) -delete
tidy:
- rm -f $(roms) $(pokegold_obj) $(pokesilver_obj) $(pokegold_debug_obj) $(pokesilver_debug_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) rgbdscheck.o
+ $(RM) $(roms) $(pokegold_obj) $(pokesilver_obj) $(pokegold_debug_obj) $(pokesilver_debug_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) rgbdscheck.o
$(MAKE) clean -C tools/
compare: $(roms)
diff --git a/tools/Makefile b/tools/Makefile
index 2b65921f..294b1173 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -9,11 +9,12 @@ tools := \
png_dimensions \
scan_includes \
stadium
+
all: $(tools)
@:
clean:
- rm -f $(tools)
+ $(RM) $(tools)
gfx: common.h
png_dimensions: common.h
diff --git a/tools/gfx.c b/tools/gfx.c
index 7fbbfaab..4264e669 100644
--- a/tools/gfx.c
+++ b/tools/gfx.c
@@ -134,15 +134,12 @@ void remove_whitespace(struct Graphic *graphic) {
graphic->size &= ~(tile_size - 1);
int i = 0;
for (int j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
- while (j < graphic->size && is_whitespace(&graphic->data[j], tile_size) && !is_preserved(j / tile_size - d)) {
+ for (; j < graphic->size && is_whitespace(&graphic->data[j], tile_size) && !is_preserved(j / tile_size - d); j += tile_size, d++) {
shift_preserved(j / tile_size - d);
- d++;
- j += tile_size;
}
if (j >= graphic->size) {
break;
- }
- if (j > i) {
+ } else if (j > i) {
memcpy(&graphic->data[i], &graphic->data[j], tile_size);
}
}
@@ -170,13 +167,11 @@ void remove_duplicates(struct Graphic *graphic) {
graphic->size &= ~(tile_size - 1);
int num_tiles = 0;
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
- while (j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) {
+ for (; j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles); j += tile_size, d++) {
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
break;
}
shift_preserved(j / tile_size - d);
- d++;
- j += tile_size;
}
if (j >= graphic->size) {
break;
@@ -227,13 +222,11 @@ void remove_flip(struct Graphic *graphic, bool xflip, bool yflip) {
graphic->size &= ~(tile_size - 1);
int num_tiles = 0;
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
- while (j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip)) {
+ for (; j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip); j += tile_size, d++) {
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
break;
}
shift_preserved(j / tile_size - d);
- d++;
- j += tile_size;
}
if (j >= graphic->size) {
break;
diff --git a/tools/scan_includes.c b/tools/scan_includes.c
index 3e93cbad..e57ddc35 100644
--- a/tools/scan_includes.c
+++ b/tools/scan_includes.c
@@ -47,17 +47,16 @@ void scan_file(const char *filename, bool strict) {
ptr = strchr(ptr, '\n');
if (!ptr) {
fprintf(stderr, "%s: no newline at end of file\n", filename);
- break;
}
break;
case '"':
ptr++;
ptr = strchr(ptr, '"');
- if (!ptr) {
+ if (ptr) {
+ ptr++;
+ } else {
fprintf(stderr, "%s: unterminated string\n", filename);
- break;
}
- ptr++;
break;
case 'I':
case 'i':
@@ -65,17 +64,16 @@ void scan_file(const char *filename, bool strict) {
is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
if (is_incbin || is_include) {
ptr = strchr(ptr, '"');
- if (!ptr) {
- break;
- }
- ptr++;
- char *include_path = ptr;
- size_t length = strcspn(ptr, "\"");
- ptr += length + 1;
- include_path[length] = '\0';
- printf("%s ", include_path);
- if (is_include) {
- scan_file(include_path, strict);
+ if (ptr) {
+ ptr++;
+ char *include_path = ptr;
+ size_t length = strcspn(ptr, "\"");
+ ptr += length + 1;
+ include_path[length] = '\0';
+ printf("%s ", include_path);
+ if (is_include) {
+ scan_file(include_path, strict);
+ }
}
}
break;