gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 3895fe9a799e06d78fe359a4b3961e33deaf7a69 parent 8f2a9288b14f57eec398456a62c03577808d0834 Author: bbbbbr <reg+github@roughhousing.com> Date: Sun, 20 Jun 2021 09:15:49 -0700 Merge pull request #201 from bbbbbr/macos_building Building on MacOS: Fix misc warnings Diffstat:
| M | gbdk-support/bankpack/files.c | 7 | +++---- |
| M | gbdk-support/bankpack/files.h | 7 | +++---- |
| M | gbdk-support/bankpack/obj_data.c | 4 | ++-- |
| M | gbdk-support/bankpack/obj_data.h | 7 | +++---- |
| M | gbdk-support/gbcompress/files.c | 58 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
| M | gbdk-support/gbcompress/files.h | 3 | +++ |
| M | gbdk-support/gbcompress/files_c_source.c | 20 | ++++++++++++-------- |
| M | gbdk-support/gbcompress/files_c_source.h | 2 | +- |
| M | gbdk-support/gbcompress/main.c | 12 | +++++++----- |
| M | gbdk-support/lcc/Makefile | 5 | +++-- |
| M | gbdk-support/lcc/lcc.c | 31 | +++++++++++++++++++------------ |
11 files changed, 113 insertions(+), 43 deletions(-)
diff --git a/gbdk-support/bankpack/files.c b/gbdk-support/bankpack/files.c @@ -132,7 +132,7 @@ static char * file_read_to_buffer(char * filename) { // Extract areas from files, then collected assign them to banks -int files_extract(void) { +void files_extract(void) { uint32_t c; char strline_in[OBJ_NAME_MAX_STR_LEN] = ""; file_item * files = (file_item *)filelist.p_array; @@ -166,7 +166,7 @@ int files_extract(void) { } -int files_rewrite(void) { +void files_rewrite(void) { uint32_t c; char * in_file_buf = NULL; @@ -213,4 +213,4 @@ int files_rewrite(void) { fclose(out_file); } -} - +} diff --git a/gbdk-support/bankpack/files.h b/gbdk-support/bankpack/files.h @@ -25,7 +25,7 @@ char * file_get_name_out_by_id(uint32_t); void files_set_out_ext(char *); void files_set_out_path(char *); -int files_extract(void); -int files_rewrite(void); +void files_extract(void); +void files_rewrite(void); -#endif // _FILES_H - +#endif // _FILES_H diff --git a/gbdk-support/bankpack/obj_data.c b/gbdk-support/bankpack/obj_data.c @@ -418,7 +418,7 @@ static void areas_sort(void) { // Assigns all areas -> banks, and bank numbers -> files // Fixed bank areas are placed first, then auto-banks fill the rest in // Only call after all areas have been collected from object files -int obj_data_process(list_type * p_filelist) { +void obj_data_process(list_type * p_filelist) { uint32_t c, s; area_item * areas = (area_item *)arealist.p_array; symbol_item * symbols = (symbol_item *)symbollist.p_array; @@ -467,7 +467,7 @@ int obj_data_process(list_type * p_filelist) { // Display file/area/bank assignment // Should be called after obj_data_process() -int banks_show(void) { +void banks_show(void) { uint32_t c; uint32_t a; diff --git a/gbdk-support/bankpack/obj_data.h b/gbdk-support/bankpack/obj_data.h @@ -55,12 +55,12 @@ int areas_add(char * area_str, uint32_t file_id); int symbols_add(char * area_str, uint32_t file_id); void symbol_match_add(char *); -int obj_data_process(list_type *); +void obj_data_process(list_type *); bool area_modify_and_write_to_file(char * strline_in, FILE * out_file, uint16_t bank_num); bool symbol_modify_and_write_to_file(char * strline_in, FILE * out_file, uint16_t bank_num, uint32_t file_id); -int banks_show(void); +void banks_show(void); -#endif // _AREAS_H - +#endif // _AREAS_H diff --git a/gbdk-support/gbcompress/files.c b/gbdk-support/gbcompress/files.c @@ -1,10 +1,10 @@ - #include <stdio.h> #include <stdbool.h> #include <stdint.h> #include <stdlib.h> + // Read from a file into a buffer (will allocate needed memory) // Returns NULL if reading file didn't succeed uint8_t * file_read_into_buffer(char * filename, uint32_t *ret_size) { @@ -57,3 +57,59 @@ bool file_write_from_buffer(char * filename, uint8_t * p_buf, uint32_t data_len) } return status; } + + + + +// Read from a file into a buffer (will allocate needed memory) +// Returns NULL if reading file didn't succeed +char * file_read_into_buffer_char(char * filename, uint32_t *ret_size) { + + long fsize; + FILE * file_in = fopen(filename, "r"); + char * filedata = NULL; + + if (file_in) { + // Get file size + fseek(file_in, 0, SEEK_END); + fsize = ftell(file_in); + if (fsize != -1L) { + fseek(file_in, 0, SEEK_SET); + + filedata = malloc(fsize); + if (filedata) { + if (fsize != fread(filedata, 1, fsize, file_in)) { + printf("gbcompress: Warning: File read size didn't match expected for %s\n", filename); + filedata = NULL; + } + // Read was successful, set return size + *ret_size = fsize; + } else printf("gbcompress: ERROR: Failed to allocate memory to read file %s\n", filename); + + } else printf("gbcompress: ERROR: Failed to read size of file %s\n", filename); + + fclose(file_in); + } else printf("gbcompress: ERROR: Failed to open input file %s\n", filename); + + return filedata; +} + + + +// Writes a buffer to a file +bool file_write_from_buffer_char(char * filename, char * p_buf, uint32_t data_len) { + + bool status = false; + size_t wrote_bytes; + FILE * file_out = fopen(filename, "w"); + + if (file_out) { + if (data_len == fwrite(p_buf, 1, data_len, file_out)) + status = true; + else + printf("gbcompress: Warning: File write size didn't match expected for %s\n", filename); + + fclose(file_out); + } + return status; +} diff --git a/gbdk-support/gbcompress/files.h b/gbdk-support/gbcompress/files.h @@ -4,4 +4,7 @@ uint8_t * file_read_into_buffer(char * filename, uint32_t *ret_size); bool file_write_from_buffer(char * filename, uint8_t * p_buf, uint32_t data_len); +char * file_read_into_buffer_char(char * filename, uint32_t *ret_size); +bool file_write_from_buffer_char(char * filename, char * p_buf, uint32_t data_len); + #endif // _FILES_H diff --git a/gbdk-support/gbcompress/files_c_source.c b/gbdk-support/gbcompress/files_c_source.c @@ -116,29 +116,33 @@ static uint8_t * str_array_to_buf(char * str_in, uint32_t * p_ret_len) { // uint8_t * file_read_c_input_into_buffer(char * filename, uint32_t *ret_size) { - uint8_t * filedata = NULL; + char * filedata = NULL; uint32_t file_size; - uint8_t * str_c_array = NULL; - uint8_t * str_c_array_start = NULL; + char * str_c_array = NULL; + char * str_c_array_start = NULL; uint8_t * p_array_data = NULL; - filedata = file_read_into_buffer(filename, &file_size); + filedata = file_read_into_buffer_char(filename, &file_size); if (filedata) { str_c_array = filedata; // Find array opening bracket `[` - if ( str_c_array = str_ffwd_to(str_c_array, &file_size, '[', STR_FFWD_MATCH_ANY) ) { + str_c_array = str_ffwd_to(str_c_array, &file_size, '[', STR_FFWD_MATCH_ANY); + if (str_c_array) { // Find Array closing bracket `]` - if ( str_c_array = str_ffwd_to(str_c_array, &file_size, ']', "[xX0123456789ABCDEFabcdef\t\n\r ") ) { + str_c_array = str_ffwd_to(str_c_array, &file_size, ']', "[xX0123456789ABCDEFabcdef\t\n\r "); + if (str_c_array) { // Find Start or array - if ( str_c_array = str_ffwd_to(str_c_array, &file_size, '{', "]\t\n\r =") ) { + str_c_array = str_ffwd_to(str_c_array, &file_size, '{', "]\t\n\r ="); + if (str_c_array) { // Save start of array str_c_array_start = str_c_array + 1; // Find end of array - if ( str_c_array = str_ffwd_to(str_c_array, &file_size, '}', "{xX0123456789ABCDEFabcdef,\t\n\r ") ) { + str_c_array = str_ffwd_to(str_c_array, &file_size, '}', "{xX0123456789ABCDEFabcdef,\t\n\r "); + if (str_c_array) { // Terminate string at end of array *str_c_array = '\0'; diff --git a/gbdk-support/gbcompress/files_c_source.h b/gbdk-support/gbcompress/files_c_source.h @@ -4,6 +4,6 @@ void c_source_set_sizes(uint32_t, uint32_t); bool file_write_c_output_from_buffer(char *, uint8_t *, uint32_t, char *, bool); -char * file_read_c_input_into_buffer(char * filename, uint32_t *ret_size); +uint8_t * file_read_c_input_into_buffer(char * filename, uint32_t *ret_size); #endif // _FILES_C_SOURCE_H diff --git a/gbdk-support/gbcompress/main.c b/gbdk-support/gbcompress/main.c @@ -131,12 +131,12 @@ static int compress() { if ((p_buf_in) && (p_buf_out) && (buf_size_in > 0)) { out_len = gbcompress_buf(p_buf_in, buf_size_in, &p_buf_out, buf_size_out); - if (out_len > 0) + if (out_len > 0) { if (opt_c_source_output) { c_source_set_sizes(out_len, buf_size_in); // compressed, decompressed result = file_write_c_output_from_buffer(filename_out, p_buf_out, out_len, opt_c_source_output_varname, true); - } + } else result = file_write_from_buffer(filename_out, p_buf_out, out_len); @@ -145,7 +145,7 @@ static int compress() { printf("Compressed: %d bytes -> %d bytes (%%%.2f)\n", buf_size_in, out_len, ((double)out_len / (double)buf_size_in) * 100); return EXIT_SUCCESS; } - + } } return EXIT_FAILURE; @@ -172,20 +172,22 @@ static int decompress() { if ((p_buf_in) && (p_buf_out) && (buf_size_in > 0)) { out_len = gbdecompress_buf(p_buf_in, buf_size_in, &p_buf_out, buf_size_out); - if (out_len > 0) + if (out_len > 0) { if (opt_c_source_output) { c_source_set_sizes(buf_size_in, out_len); // compressed, decompressed result = file_write_c_output_from_buffer(filename_out, p_buf_out, out_len, opt_c_source_output_varname, true); } - else + else { result = file_write_from_buffer(filename_out, p_buf_out, out_len); + } if (result) { if (opt_verbose) printf("Decompressed: %d bytes -> %d bytes (compression was %%%.2f)\n", buf_size_in, out_len, ((double)buf_size_in / (double)out_len) * 100); return EXIT_SUCCESS; } + } } return EXIT_FAILURE; diff --git a/gbdk-support/lcc/Makefile b/gbdk-support/lcc/Makefile @@ -4,8 +4,9 @@ ifndef TARGETDIR TARGETDIR = /opt/gbdk endif -BUILDDATE=$(shell date --utc +%Y/%m/%d) -BUILDTIME=$(shell date --utc +%H:%M:%S) +# MacOS date doesn't support '--utc', use '-u' +BUILDDATE=$(shell date -u +%Y/%m/%d) +BUILDTIME=$(shell date -u +%H:%M:%S) CC = $(TOOLSPREFIX)gcc CFLAGS = -ggdb -O -Wno-incompatible-pointer-types -DGBDKLIBDIR=\"$(TARGETDIR)\" diff --git a/gbdk-support/lcc/lcc.c b/gbdk-support/lcc/lcc.c @@ -92,7 +92,7 @@ char *progname; static List lccinputs; /* list of input directories */ char bankpack_newext[1024] = {'\0'}; static int ihx_inputs = 0; // Number of ihx files present in input list -static char ihxFile[256] = ""; +static char ihxFile[256] = {'\0'}; int main(int argc, char *argv[]) { @@ -116,8 +116,10 @@ int main(int argc, char *argv[]) { else if (getenv("TMPDIR")) tempdir = getenv("TMPDIR"); assert(tempdir); + + // Remove trailing slashes i = strlen(tempdir); - for (; i > 0 && tempdir[i - 1] == '/' || tempdir[i - 1] == '\\'; i--) + for (; (i > 0) && ((tempdir[i - 1] == '/') || (tempdir[i - 1] == '\\')); i--) tempdir[i - 1] = '\0'; if (argc <= 1) { help(); @@ -199,11 +201,12 @@ int main(int argc, char *argv[]) { if (*argv[i] == '-') opt(argv[i]); else { - // Process filenames + // Process filenames char *name = exists(argv[i]); if (name) { if (strcmp(name, argv[i]) != 0 - || nf > 1 && suffix(name, suffixes, 3) != SUFX_NOMATCH) // Does it match: .c, .i, .asm, .s + || ((nf > 1) && (suffix(name, suffixes, 3) != SUFX_NOMATCH)) ) // Does it match: .c, .i, .asm, .s + fprintf(stderr, "%s:\n", name); // Send input filename argument to "filename processor" // which will add them to llist[n] in some form most of the time @@ -216,7 +219,7 @@ int main(int argc, char *argv[]) { // Perform Link / ihxcheck / makebin stages (unless some conditions prevent it) if (errcnt == 0 && !Eflag && !cflag && !Sflag && - (llist[1] || (ihxFile && ihx_inputs))) { + (llist[1] || ((ihxFile[0] != '\0') && ihx_inputs))) { int target_is_ihx = 0; @@ -598,7 +601,8 @@ static void compose(char *cmd[], List a, List b, List c) { if (s && isdigit(s[1])) { int k = s[1] - '0'; assert(k >= 1 && k <= 3); - if (b = lists[k - 1]) { + b = lists[k - 1]; + if (b) { b = b->link; av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1); strncpy(av[j], cmd[i], s - cmd[i]); @@ -729,7 +733,7 @@ static int filename(char *name, char *base) { llist[1] = append(name, llist[1]); break; case 4: // .ihx files - // Append .ihx files (there can be only one as input) + // Apply "name" as .ihx file (there can be only one as input) strncpy(ihxFile, name, sizeof(ihxFile) - 1); break; default: @@ -749,7 +753,8 @@ static int filename(char *name, char *base) { static List find(char *str, List list) { List b; - if (b = list) + b = list; + if (b) do { if (strcmp(str, b->str) == 0) return b; @@ -810,7 +815,7 @@ static void help(void) { if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir) fprintf(stderr, "; default=%s", tempdir); } -#define xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s) +#define xx(v) if ((s = getenv(#v))) fprintf(stderr, #v "=%s\n", s) xx(LCCINPUTS); xx(LCCDIR); #ifdef WIN32 @@ -829,7 +834,8 @@ static void initinputs(void) { s = "."; if (s) { lccinputs = path2list(s); - if (b = lccinputs) + b = lccinputs; + if (b) do { b = b->link; if (strcmp(b->str, ".") != 0) { @@ -1092,7 +1098,8 @@ static List path2list(const char *path) { sep = ';'; while (*path) { char *p, buf[512]; - if (p = strchr(path, sep)) { + p = strchr(path, sep); + if (p) { size_t len = p - path; if(len >= sizeof(buf)) len = sizeof(buf)-1; strncpy(buf, path, len); @@ -1160,7 +1167,7 @@ int suffix(char *name, char *tails[], int n) { for (i = 0; i < n; i++) { char *s = tails[i], *t; - for (; t = strchr(s, ';'); s = t + 1) { + for (; (t = strchr(s, ';')); s = t + 1) { int m = t - s; if (len > m && strncmp(&name[len - m], s, m) == 0) return i;
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.