diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chkpar.c | 37 | ||||
-rw-r--r-- | src/cpy.c | 6 | ||||
-rw-r--r-- | src/exi.c | 2 | ||||
-rw-r--r-- | src/getsum.c | 2 | ||||
-rw-r--r-- | src/hlp.c | 5 | ||||
-rw-r--r-- | src/inidat.c | 2 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/pat.c | 2 |
8 files changed, 33 insertions, 30 deletions
diff --git a/src/chkpar.c b/src/chkpar.c index 02256d3..f6edfe7 100644 --- a/src/chkpar.c +++ b/src/chkpar.c @@ -22,9 +22,9 @@ agb_expparval (char const chrpar) } static bool -agb_chkchrpar (agb_dat * const restrict dat, char const* const restrict par) +agb_chkchrpar (struct agb_dat * const restrict dat, char const* const restrict par) { - char const chrpar = par[0x0u]; + char const chrpar = par[0x0]; if (chrpar == '\x0') {return true;} char const* const restrict paramval = &par[0x1]; @@ -38,7 +38,7 @@ agb_chkchrpar (agb_dat * const restrict dat, char const* const restrict par) agb_exi (agb_cnd_oky, NULL); case 'i': { - if (paramval[0x0u] == '\x0') {agb_expparval (chrpar);} + if (paramval[0x0] == '\x0') {agb_expparval (chrpar);} dat->pth = paramval; } return true; @@ -52,21 +52,24 @@ agb_chkchrpar (agb_dat * const restrict dat, char const* const restrict par) } void -agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* const argv) { +agb_chkpar (struct agb_dat * const restrict dat, int const argc, char const* const* const argv) { if (argc < 0x2) { agb_hlp (); agb_exi (agb_cnd_oky, NULL); } else { - size_t const numpar = argc; + size_t const numpar = argc; // Prettier. - for (size_t pos = 0x1u; pos < numpar; ++pos) { + for (ptrdiff_t pos = 0x1u; pos < (ptrdiff_t)numpar; ++pos) { + // Iterate over the parameters. One hyphen denotes character parameters (-h) whilst two denote long paramters (--help). char const* const par = argv[pos]; - if (par[0x0u] == '-') { - if (par[0x1u] == '-') { - char const* const lngparam = &par[0x2u]; + if (par[0x0] == '-') { + if (par[0x1] == '-') { + char const* const lngparam = &par[0x2]; - if (lngparam[0x0u] == '\x0') { + // Check long parameters. + + if (lngparam[0x0] == '\x0') { fputs ("Missing long parameter after '--' sequence\n", stderr); agb_exi (agb_cnd_err, NULL); } @@ -77,12 +80,6 @@ agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* con } if (!strcmp (lngparam,"version")) { - printf( - "agbsum #%" PRIX64 "\n" - "Copyright 2022-2023 Gabriel Jensen.\n" - "\n", - agb_rel - ); agb_cpy(); agb_exi (agb_cnd_oky, NULL); } @@ -91,17 +88,21 @@ agb_chkpar (agb_dat * const restrict dat, int const argc, char const* const* con agb_exi (agb_cnd_err, NULL); } - if (par[0x1u] == '\x0') { + if (par[0x1] == '\x0') { fputs ("Missing character parameter after '-'\n", stderr); agb_exi (agb_cnd_err, NULL); } - for (char const* chrpos = &par[0x1u];; ++chrpos) {if (agb_chkchrpar (dat, chrpos)) {break;}} + // Check character parameters. + + for (char const* chrpos = &par[0x1];; ++chrpos) {if (agb_chkchrpar (dat, chrpos)) {break;}} continue; } } + // We did not find the 'i' parameter, so we don't know where the ROM is. + if (dat->pth == NULL) { fputs ("ROM not set (missing character parameter 'i')\n", stderr); agb_exi (agb_cnd_err, NULL); @@ -15,7 +15,9 @@ void agb_cpy (void) { - fputs ( + printf ( + "agbsum #%" PRIX64 " - Copyright 2022-2023 Gabriel Jensen.\n" + "\n" "This program is free software: you can redistribute it and/or modify it under\n" " the terms of the GNU General Public License as published by the Free Software\n" " Foundation, either version 3 of the License, or (at your option) any later\n" @@ -25,6 +27,6 @@ agb_cpy (void) " A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n" "You should have received a copy of the GNU General Public License along with\n" " this program. If not, see <https://www.gnu.org/licenses/>.\n", - stdout + agb_rel ); } @@ -13,7 +13,7 @@ #include <stdlib.h> noreturn void -agb_exi (agb_cnd const cnd, FILE * restrict rom) +agb_exi (enum agb_cnd const cnd, FILE * restrict rom) { if (rom != NULL) {fclose (rom);} diff --git a/src/getsum.c b/src/getsum.c index 29bc093..31626fe 100644 --- a/src/getsum.c +++ b/src/getsum.c @@ -19,7 +19,7 @@ agb_getsum (void const* const restrict romptr) for (char unsigned const* restrict pos = rom; pos != rom + agb_sumoff; ++pos) {sum += *pos;} - sum = 0x0u-(0x19u + sum); + sum = 0x0u - (0x19u + sum); return sum; } @@ -15,9 +15,8 @@ void agb_hlp (void) { - printf ( + fputs ( "agbsum - Calculate GBA ROM header checksums.\n" - "Release #%" PRIX64 ". Copyright 2022-2023 Gabriel Jensen.\n" "\n" "Usage: agbsum [options] <ROM>\n" "Options:\n" @@ -26,7 +25,7 @@ agb_hlp (void) " -s Don't print the results\n" " --version Don't print the results\n" "\n", - agb_rel + stdout ); agb_cpy(); } diff --git a/src/inidat.c b/src/inidat.c index b215faf..b31860a 100644 --- a/src/inidat.c +++ b/src/inidat.c @@ -12,7 +12,7 @@ #include <stddef.h> void -agb_inidat (agb_dat * const restrict dat) +agb_inidat (struct agb_dat * const restrict dat) { dat->dopat = false; dat->pth = NULL; @@ -19,13 +19,13 @@ int main (int const argc, char const* const* const argv) { - agb_dat dat; + struct agb_dat dat; agb_inidat (&dat); agb_chkpar (&dat, argc, argv); dat.rom = agb_opn (dat.pth); - char unsigned buf[agb_sumoff + 0x1u]; + char unsigned buf[agb_sumoff + 0x1]; agb_red (buf, dat.rom); @@ -34,13 +34,14 @@ int main (int const argc, char const* const* const argv) char unsigned const romsum = buf[agb_sumoff]; if (romsum == sum || !dat.dopat) { + // Don't patch the ROM if it's already okay or we're not allowed to. if (!dat.sil) {printf ("\"%s\": %hhX (%hhX in file)\n", dat.pth, sum, romsum);} agb_exi (agb_cnd_oky, dat.rom); } agb_pat (dat.rom, sum); - if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_romsrt + agb_sumoff, romsum, sum);} + if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_romsrt + agb_sumoff, romsum, sum);} // If we aren't supposed to print anything then don't. } agb_exi (agb_cnd_oky, dat.rom); @@ -14,7 +14,7 @@ void agb_pat (FILE * const restrict rom, char unsigned sum) { - fseek (rom,(long)(agb_romsrt + agb_sumoff), SEEK_SET); + fseek (rom, (long)(agb_romsrt + agb_sumoff), SEEK_SET); if (fwrite (&sum,0x1u,0x1u, rom) != 0x1u) { fputs ("Unable to patch ROM\n", stderr); |