summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt9
-rw-r--r--CMakeLists.txt2
-rw-r--r--agbsum/include/agbsum.h42
-rw-r--r--agbsum/src/chkpar.c22
-rw-r--r--agbsum/src/exi.c4
-rw-r--r--agbsum/src/getsum.c10
-rw-r--r--agbsum/src/hlp.c5
-rw-r--r--agbsum/src/inidat.c2
-rw-r--r--agbsum/src/main.c8
-rw-r--r--agbsum/src/opn.c2
-rw-r--r--agbsum/src/pat.c2
-rw-r--r--agbsum/src/red.c2
12 files changed, 59 insertions, 51 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index bfefe67..cb38070 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,12 @@
+| 9
+
+- Don't record compilation time;
+- Fix version macro;
+- Restrict pointers;
+- Use fixed-width types;
+- Update naming convention;
+- Update pointer style;
+
| 8
- Update naming convention;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3b29f1..eb2f24d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
project(
agbsum
- VERSION 8
+ VERSION 9
DESCRIPTION "GBA ROM header checksum patcher."
HOMEPAGE_URL "https://mandelbrot.dk/agbsum"
LANGUAGES C
diff --git a/agbsum/include/agbsum.h b/agbsum/include/agbsum.h
index 3d2fb80..13c3502 100644
--- a/agbsum/include/agbsum.h
+++ b/agbsum/include/agbsum.h
@@ -15,47 +15,47 @@
#include <stdio.h>
#if __STDC_VERSION__ > 199901
-#include <stdnoreturn.h>
+# include <stdnoreturn.h>
#else
-#ifdef __GNUC__
-#define _Noreturn __attribute__ ((noreturn))
-#elif defined(_MSC_VER)
-#define _Noreturn __declspec (noreturn)
-#else
-#define _Noreturn
-#endif
-#define noreturn _Noreturn
+# ifdef __GNUC__
+# define _Noreturn __attribute__ ((noreturn))
+# elif defined(_MSC_VER)
+# define _Noreturn __declspec (noreturn)
+# else
+# define _Noreturn
+# endif
+# define noreturn _Noreturn
#endif
-#define agb_rel ((uint_least64_t)+0x9u)
+#define agb_rel ((uint64_t)+0x9u)
#define agb_romsrt ((size_t)+0xA0u)
#define agb_chksumoff ((size_t)+0xBDu-agb_romsrt)
typedef enum {
agb_cnd_err,
- agb_cnd_ok,
+ agb_cnd_oky,
} agb_cnd;
typedef struct {
- bool dopat;
- char const * pth;
- bool sil;
- FILE * rom;
+ bool dopat;
+ char const* pth;
+ bool sil;
+ FILE * rom;
} agb_dat;
-uint8_t agb_getsum(void const * rom);
+uint8_t agb_getsum(void const* restrict rom);
-void agb_pat(FILE * rom,unsigned char chksum);
+void agb_pat(FILE * restrict rom,unsigned char chksum);
void agb_hlp(void);
-void agb_chkpar(agb_dat * dat,int argc,char const * const * argv);
+void agb_chkpar(agb_dat * restrict dat,int argc,char const* const* restrict argv);
-void agb_inidat(agb_dat * dat);
+void agb_inidat(agb_dat * restrict dat);
-FILE * agb_opn(char const * pth);
-void agb_red(void * buf,FILE * rom);
+FILE * agb_opn(char const* restrict pth);
+void agb_red(void * restrict buf,FILE * restrict rom);
noreturn void agb_exi(agb_cnd stat,FILE * rom);
diff --git a/agbsum/src/chkpar.c b/agbsum/src/chkpar.c
index dcf198a..e388305 100644
--- a/agbsum/src/chkpar.c
+++ b/agbsum/src/chkpar.c
@@ -13,16 +13,16 @@
#include <stdio.h>
#include <string.h>
-noreturn static void agb_xptparval(char const chrpar) {
+noreturn static void agb_expparval(char const chrpar) {
fprintf(stderr,"Expected value for character parameter '%c'\n",chrpar);
agb_exi(agb_cnd_err,NULL);
}
-static bool agb_chkchrpar(agb_dat * const dat,char const * const par) {
+static bool agb_chkchrpar(agb_dat * const restrict dat,char const* const restrict par) {
char const chrpar = par[0x0u];
if (chrpar == '\x0') {return true;}
- char const * const paramval = &par[0x1];
+ char const* const restrict paramval = &par[0x1];
switch (chrpar) {
default:
@@ -30,10 +30,10 @@ static bool agb_chkchrpar(agb_dat * const dat,char const * const par) {
agb_exi(agb_cnd_err,NULL);
case 'h':
agb_hlp();
- agb_exi(agb_cnd_ok,NULL);
+ agb_exi(agb_cnd_oky,NULL);
case 'i':
{
- if (paramval[0x0u] == '\x0') {agb_xptparval(chrpar);}
+ if (paramval[0x0u] == '\x0') {agb_expparval(chrpar);}
dat->pth = paramval;
}
return true;
@@ -46,20 +46,20 @@ static bool agb_chkchrpar(agb_dat * const dat,char const * const par) {
}
}
-void agb_chkpar(agb_dat * const dat,int const argc,char const * const * const argv) {
+void agb_chkpar(agb_dat * const restrict dat,int const argc,char const* const* const argv) {
if (argc < 0x2) {
agb_hlp();
- agb_exi(agb_cnd_ok,NULL);
+ agb_exi(agb_cnd_oky,NULL);
}
else {
size_t const numpar = argc;
for (size_t pos = 0x1u;pos < numpar;++pos) {
- char const * const par = argv[pos];
+ char const* const par = argv[pos];
if (par[0x0u] == '-') {
if (par[0x1u] == '-') {
- char const * const lngparam = &par[0x2u];
+ char const* const lngparam = &par[0x2u];
if (lngparam[0x0u] == '\x0') {
fputs("Missing long parameter after '--' sequence\n",stderr);
@@ -68,7 +68,7 @@ void agb_chkpar(agb_dat * const dat,int const argc,char const * const * const ar
if (!strcmp(lngparam,"help")) {
agb_hlp();
- agb_exi(agb_cnd_ok,NULL);
+ agb_exi(agb_cnd_oky,NULL);
}
fprintf(stderr,"Invalid long parameter \"%s\"\n",lngparam);
@@ -80,7 +80,7 @@ void agb_chkpar(agb_dat * const dat,int const argc,char const * const * const ar
agb_exi(agb_cnd_err,NULL);
}
- for (char const * chrpos = &par[0x1u];;++chrpos) {if (agb_chkchrpar(dat,chrpos)) {break;}}
+ for (char const* chrpos = &par[0x1u];;++chrpos) {if (agb_chkchrpar(dat,chrpos)) {break;}}
continue;
}
diff --git a/agbsum/src/exi.c b/agbsum/src/exi.c
index b24112a..4e0a80e 100644
--- a/agbsum/src/exi.c
+++ b/agbsum/src/exi.c
@@ -12,8 +12,8 @@
#include <stdio.h>
#include <stdlib.h>
-void agb_exi(agb_cnd const cnd,FILE * rom) {
+void agb_exi(agb_cnd const cnd,FILE * restrict rom) {
if (rom != NULL) {fclose(rom);}
- exit(cnd == agb_cnd_ok ? EXIT_SUCCESS : EXIT_FAILURE);
+ exit(cnd == agb_cnd_oky ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/agbsum/src/getsum.c b/agbsum/src/getsum.c
index 1ec9459..c6ce21b 100644
--- a/agbsum/src/getsum.c
+++ b/agbsum/src/getsum.c
@@ -11,13 +11,13 @@
#include <stdint.h>
-uint8_t agb_getsum(void const * const romptr) {
- uint8_t const * rom = romptr;
- uint8_t chksum = 0x0u;
+uint8_t agb_getsum(void const* const restrict romptr) {
+ uint8_t const* restrict rom = romptr;
+ uint8_t chksum = 0x0u;
- for (unsigned char const * pos = rom;pos != rom+agb_chksumoff;++pos) {chksum += *pos;}
+ for (unsigned char const* restrict pos = rom;pos != rom+agb_chksumoff;++pos) {chksum += *pos;}
- chksum = -(0x19u+chksum);
+ chksum = 0x0u-(0x19u+chksum);
return chksum;
}
diff --git a/agbsum/src/hlp.c b/agbsum/src/hlp.c
index 47f05b7..f6c87f6 100644
--- a/agbsum/src/hlp.c
+++ b/agbsum/src/hlp.c
@@ -15,15 +15,14 @@
void agb_hlp(void) {
fprintf(stderr,
"agbsum - Calculate GBA ROM header checksums.\n"
- "Release #%" PRIXLEAST64 ". Copyright 2022-2023 Gabriel Jensen.\n"
+ "Release #%" PRIX64 ". Copyright 2022-2023 Gabriel Jensen.\n"
"\n"
"Usage: agbsum [options] <ROM>\n"
"Options:\n"
" --help -h Print the help screen\n"
" -p Patch the ROM\n"
" -s Don't print the results\n"
- "\n"
- "Built at " __TIME__ ", " __DATE__ ".\n",
+ "\n",
agb_rel
);
}
diff --git a/agbsum/src/inidat.c b/agbsum/src/inidat.c
index 4ac5d6e..31f6790 100644
--- a/agbsum/src/inidat.c
+++ b/agbsum/src/inidat.c
@@ -11,7 +11,7 @@
#include <stddef.h>
-void agb_inidat(agb_dat * const dat) {
+void agb_inidat(agb_dat * const restrict dat) {
dat->dopat = false;
dat->pth = NULL;
dat->sil = false;
diff --git a/agbsum/src/main.c b/agbsum/src/main.c
index d573958..0b277ae 100644
--- a/agbsum/src/main.c
+++ b/agbsum/src/main.c
@@ -13,11 +13,11 @@
#include <stdint.h>
#include <stdio.h>
-#if CHAR_BIT != 0x8u
+#if CHAR_BIT != 0x8
#error "agbsum only support 8-bit byte systems"
#endif
-int main(int const argc,char const * const * const argv) {
+int main(int const argc,char const* const* const argv) {
agb_dat dat;
agb_inidat(&dat);
@@ -35,12 +35,12 @@ int main(int const argc,char const * const * const argv) {
if (romchksum == chksum || !dat.dopat) {
if (!dat.sil) {printf("\"%s\": %hhX (%hhX in file)\n",dat.pth,chksum,romchksum);}
- agb_exi(agb_cnd_ok,dat.rom);
+ agb_exi(agb_cnd_oky,dat.rom);
}
agb_pat(dat.rom,chksum);
if (!dat.sil) {printf("\"%s\" @ %zX: %hhX => %hhX\n",dat.pth,agb_romsrt+agb_chksumoff,romchksum,chksum);}
- agb_exi(agb_cnd_ok,dat.rom);
+ agb_exi(agb_cnd_oky,dat.rom);
}
diff --git a/agbsum/src/opn.c b/agbsum/src/opn.c
index 6279462..d876c51 100644
--- a/agbsum/src/opn.c
+++ b/agbsum/src/opn.c
@@ -11,7 +11,7 @@
#include <stdio.h>
-FILE * agb_opn(char const * const pth) {
+FILE * agb_opn(char const* const restrict pth) {
FILE * rom = fopen(pth,"r+");
if (rom == NULL) {
diff --git a/agbsum/src/pat.c b/agbsum/src/pat.c
index d849f5f..12a4627 100644
--- a/agbsum/src/pat.c
+++ b/agbsum/src/pat.c
@@ -11,7 +11,7 @@
#include <stdio.h>
-void agb_pat(FILE * const rom,unsigned char chksum) {
+void agb_pat(FILE * const restrict rom,unsigned char chksum) {
fseek(rom,(long)(agb_romsrt+agb_chksumoff),SEEK_SET);
if (fwrite(&chksum,0x1u,0x1u,rom) != 0x1u) {
diff --git a/agbsum/src/red.c b/agbsum/src/red.c
index eb310b7..7cb5140 100644
--- a/agbsum/src/red.c
+++ b/agbsum/src/red.c
@@ -11,7 +11,7 @@
#include <stdio.h>
-void agb_red(void * const buf,FILE * rom) {
+void agb_red(void * const restrict buf,FILE * restrict rom) {
fseek(rom,agb_romsrt,SEEK_SET); // We only need to read the part of the ROM that is used for the checksum.
size_t const num = agb_chksumoff+0x1u;