# HG changeset patch # User Matti Hamalainen # Date 1670408352 -7200 # Node ID db64a58314a96318835220fe2d7155445c4a7956 # Parent ad0fe49a211a8dec019fdb37ff177583f818df41 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available. diff -r ad0fe49a211a -r db64a58314a9 Makefile --- a/Makefile Thu Jul 14 01:56:07 2022 +0300 +++ b/Makefile Wed Dec 07 12:19:12 2022 +0200 @@ -14,6 +14,7 @@ CFLAGS += -DHAVE_ICONV CFLAGS += -DHAVE_STRING_H +CFLAGS += -DHAVE_STDBOOL_H CFLAGS += -DHAVE_INTTYPES_H #CFLAGS += -DHAVE_STDINT_H #CFLAGS += -DHAVE_SYS_TYPES_H diff -r ad0fe49a211a -r db64a58314a9 Makefile.cross-mingw --- a/Makefile.cross-mingw Thu Jul 14 01:56:07 2022 +0300 +++ b/Makefile.cross-mingw Wed Dec 07 12:19:12 2022 +0200 @@ -38,6 +38,7 @@ -DTH_BYTEORDER=TH_LITTLE_ENDIAN \ -D_NO_BOOL_TYPEDEF \ -DHAVE_STRING_H \ + -DHAVE_STDBOOL_H \ -DHAVE_INTTYPES_H LDFLAGS += -s diff -r ad0fe49a211a -r db64a58314a9 sidinfo.c --- a/sidinfo.c Thu Jul 14 01:56:07 2022 +0300 +++ b/sidinfo.c Wed Dec 07 12:19:12 2022 +0200 @@ -101,12 +101,12 @@ char *setHVSCPath = NULL, *setSLDBPath = NULL, *setSTILDBPath = NULL; -BOOL optParsable = FALSE, - optFieldNamePrefix = TRUE, - optHexadecimal = FALSE, - optFieldOutput = TRUE, - optRecurseDirs = FALSE, - optShowHelp = FALSE; +bool optParsable = false, + optFieldNamePrefix = true, + optHexadecimal = false, + optFieldOutput = true, + optRecurseDirs = false, + optShowHelp = false; char *optOneLineFieldSep = NULL, *optEscapeChars = NULL; int optNFiles = 0, @@ -235,7 +235,7 @@ } -BOOL siStackAddItem(PSFStack *stack, const PSFStackItem *item) +bool siStackAddItem(PSFStack *stack, const PSFStackItem *item) { if (stack->items == NULL || stack->nitems + 1 >= stack->nallocated) { @@ -243,13 +243,13 @@ if ((stack->items = th_realloc(stack->items, stack->nallocated * sizeof(PSFStackItem))) == NULL) { THERR("Could not allocate memory for format item stack.\n"); - return FALSE; + return false; } } memcpy(stack->items + stack->nitems, item, sizeof(PSFStackItem)); stack->nitems++; - return TRUE; + return true; } @@ -274,7 +274,7 @@ } -BOOL argParsePSFields(PSFStack *stack, const char *fmt) +bool argParsePSFields(PSFStack *stack, const char *fmt) { const char *start = fmt; siClearStack(stack); @@ -293,14 +293,14 @@ th_free(field); if (found < 0) - return FALSE; + return false; memset(&item, 0, sizeof(item)); item.cmd = found; item.fmt = th_strdup(optPSOptions[found].dfmt); if (!siStackAddItem(stack, &item)) - return FALSE; + return false; } if (!end) @@ -309,17 +309,17 @@ start = end + 1; } - return TRUE; + return true; } static int siItemFormatStrPutInt(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const int value, const int f_radix, int f_flags, int f_width, int f_prec, - const BOOL f_unsig, th_vprintf_altfmt_func f_alt) + const bool f_unsig, th_vprintf_altfmt_func f_alt) { char buf[64]; int f_len = 0, vret; - BOOL f_neg = FALSE; + bool f_neg = false; vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, value, f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); @@ -347,7 +347,7 @@ else { int f_width = -1, f_prec = -1, f_flags = 0; - BOOL end = FALSE; + bool end = false; fmt++; @@ -381,7 +381,7 @@ break; default: - end = TRUE; + end = true; break; } if (!end) fmt++; @@ -425,7 +425,7 @@ case 'o': if (otype != OTYPE_INT) return -120; - if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF) + if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct)) == EOF) goto out; break; @@ -442,7 +442,7 @@ if (otype != OTYPE_INT) return -120; if (*fmt == 'X') f_flags |= TH_PF_UPCASE; - if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) + if ((ret = siItemFormatStrPutInt(ctx, vputch, d_int, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) goto out; break; @@ -517,7 +517,7 @@ } -static BOOL siItemFormatStrCheck(const char *fmt, const PSFOption *opt) +static bool siItemFormatStrCheck(const char *fmt, const PSFOption *opt) { th_vprintf_ctx ctx; @@ -530,11 +530,11 @@ // // Parse a format string into a PSFStack structure // -static BOOL argParsePSFormatStr(PSFStack *stack, const char *fmt) +static bool argParsePSFormatStr(PSFStack *stack, const char *fmt) { const char *start = NULL; int mode = 0; - BOOL rval = TRUE; + bool rval = true; siClearStack(stack); @@ -573,7 +573,7 @@ item.chr = '@'; if (!siStackAddItem(stack, &item)) - return FALSE; + return false; } else { @@ -601,15 +601,15 @@ else { THERR("Invalid field format specifier '%s' in '%s'.\n", fopt, field); - rval = FALSE; + rval = false; } } if (!siStackAddItem(stack, &item)) - rval = FALSE; + rval = false; } else - rval = FALSE; + rval = false; th_free(fopt); th_free(field); @@ -628,7 +628,7 @@ item.str = th_strndup(start, fmt - start); if (!siStackAddItem(stack, &item)) - return FALSE; + return false; mode = (*fmt == 0) ? -1 : 0; } @@ -641,12 +641,12 @@ } -static BOOL argHandleOpt(const int optN, char *optArg, char *currArg) +static bool argHandleOpt(const int optN, char *optArg, char *currArg) { switch (optN) { case 0: - optShowHelp = TRUE; + optShowHelp = true; break; case 1: @@ -659,15 +659,15 @@ break; case 10: - optParsable = TRUE; + optParsable = true; break; case 12: - optHexadecimal = TRUE; + optHexadecimal = true; break; case 14: - optFieldNamePrefix = FALSE; + optFieldNamePrefix = false; break; case 16: @@ -680,17 +680,17 @@ case 20: if (!argParsePSFields(&optFormat, optArg)) - return FALSE; + return false; break; case 22: - optFieldOutput = FALSE; + optFieldOutput = false; if (!argParsePSFormatStr(&optFormat, optArg)) - return FALSE; + return false; break; case 24: - optRecurseDirs = TRUE; + optRecurseDirs = true; break; case 30: @@ -707,14 +707,14 @@ default: THERR("Unknown option '%s'.\n", currArg); - return FALSE; + return false; } - return TRUE; + return true; } -static void siPrintFieldPrefixName(FILE *outfh, const char *name, const BOOL multifield) +static void siPrintFieldPrefixName(FILE *outfh, const char *name, const bool multifield) { if (optFieldNamePrefix) { @@ -731,11 +731,11 @@ { siPrintFieldPrefixName(outfh, (optParsable || opt->lname == NULL) ? opt->name : opt->lname, - FALSE); + false); } -static void siPrintFieldSeparator(FILE *outfh, const BOOL multifield, const BOOL last) +static void siPrintFieldSeparator(FILE *outfh, const bool multifield, const bool last) { if (optFieldOutput) fputs(optOneLineFieldSep != NULL ? optOneLineFieldSep : "\n", outfh); @@ -767,10 +767,10 @@ } -static void siPrintPSIDInfoLine(FILE *outfh, BOOL *shown, +static void siPrintPSIDInfoLine(FILE *outfh, bool *shown, const char *fmt, const int otype, const char *d_str, const int d_int, - const BOOL convert) + const bool convert) { char *formatted, *escaped; @@ -792,56 +792,56 @@ th_free(formatted); th_free(escaped); - *shown = TRUE; + *shown = true; } #define PRS(d_str, d_conv) do { \ siPrintFieldPrefix(outfh, opt); \ siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, d_str, -1, d_conv); \ - siPrintFieldSeparator(outfh, FALSE, TRUE); \ + siPrintFieldSeparator(outfh, false, true); \ } while (0) #define PRI(d_int) do { \ siPrintFieldPrefix(outfh, opt); \ - siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, FALSE); \ - siPrintFieldSeparator(outfh, FALSE, TRUE); \ + siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, opt->type), opt->type, NULL, d_int, false); \ + siPrintFieldSeparator(outfh, false, true); \ } while (0) static void siPrintPSIDInformationField(FILE *outfh, const char *filename, - const SIDLibPSIDHeader *psid, BOOL *shown, const PSFStackItem *item) + const SIDLibPSIDHeader *psid, bool *shown, const PSFStackItem *item) { const PSFOption *opt = &optPSOptions[item->cmd]; char tmp[128]; switch (item->cmd) { - case 0: PRS(filename, FALSE); break; + case 0: PRS(filename, false); break; case 1: snprintf(tmp, sizeof(tmp), "%s%s", psid->magic, psid->isInvalidRSID ? " (INVALID RSID!)" : ""); - PRS(tmp, FALSE); + PRS(tmp, false); break; case 2: snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8)); - PRS(tmp, FALSE); + PRS(tmp, false); break; case 3: - PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", FALSE); + PRS((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", false); break; case 4: if (psid->version >= 2) - PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", FALSE); + PRS((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", false); break; case 5: if (psid->version >= 2) - PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), FALSE); + PRS(sidlib_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), false); break; case 6: if (psid->version >= 2) - PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), FALSE); + PRS(sidlib_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), false); break; case 7: PRI(psid->dataOffset); break; @@ -867,7 +867,7 @@ if (flags == PSF_MODEL_UNKNOWN) flags = (psid->flags >> 4) & PSF_MODEL_MASK; - PRS(sidlib_get_sid_model_str(flags), FALSE); + PRS(sidlib_get_sid_model_str(flags), false); } break; case 17: @@ -877,7 +877,7 @@ if (flags == PSF_MODEL_UNKNOWN) flags = (psid->flags >> 4) & PSF_MODEL_MASK; - PRS(sidlib_get_sid_model_str(flags), FALSE); + PRS(sidlib_get_sid_model_str(flags), false); } break; case 18: @@ -889,9 +889,9 @@ PRI(0xD000 | (psid->sid3Addr << 4)); break; - case 20: PRS(psid->sidName, TRUE); break; - case 21: PRS(psid->sidAuthor, TRUE); break; - case 22: PRS(psid->sidReleased, TRUE); break; + case 20: PRS(psid->sidName, true); break; + case 21: PRS(psid->sidAuthor, true); break; + case 22: PRS(psid->sidReleased, true); break; case 23: { @@ -899,7 +899,7 @@ for (i = k = 0; i < TH_MD5HASH_LENGTH && k < sizeof(tmp) - 1; i++, k += 2) sprintf(&tmp[k], "%02x", psid->hash[i]); - PRS(tmp, FALSE); + PRS(tmp, false); } break; @@ -919,9 +919,9 @@ siGetInfoFormat(item, OTYPE_STR), OTYPE_STR, tmp, - -1, FALSE); + -1, false); } - siPrintFieldSeparator(outfh, FALSE, TRUE); + siPrintFieldSeparator(outfh, false, true); } break; @@ -970,14 +970,14 @@ sidlib_stil_fields_uc[nfield]); } - siPrintFieldPrefixName(outfh, tmp, TRUE); + siPrintFieldPrefixName(outfh, tmp, true); siPrintPSIDInfoLine(outfh, shown, siGetInfoFormat(item, OTYPE_STR), OTYPE_STR, fld->data[nitem], - -1, TRUE); + -1, true); - siPrintFieldSeparator(outfh, TRUE, + siPrintFieldSeparator(outfh, true, ++nfieldn >= nfieldcount); } } @@ -995,12 +995,12 @@ } -BOOL siHandleSIDFile(const char *filename) +bool siHandleSIDFile(const char *filename) { SIDLibPSIDHeader *psid = NULL; th_ioctx *infh = NULL; FILE *outfh; - BOOL shown = FALSE; + bool shown = false; int res; outfh = stdout; @@ -1062,15 +1062,15 @@ sidlib_free_sid_file(psid); th_io_close(infh); - return TRUE; + return true; } -BOOL argHandleFileDir(const char *path, const char *filename, const char *pattern) +bool argHandleFileDir(const char *path, const char *filename, const char *pattern) { th_stat_data sdata; char *npath; - BOOL ret = TRUE; + bool ret = true; if (filename != NULL) npath = th_strdup_printf("%s%c%s", path, TH_DIR_SEPARATOR_CHR, filename); @@ -1080,7 +1080,7 @@ if (!th_stat_path(npath, &sdata)) { THERR("File or path '%s' does not exist.\n", npath); - ret = FALSE; + ret = false; goto out; } @@ -1100,7 +1100,7 @@ int err = th_get_error(); THERR("Could not open directory '%s': %s\n", path, th_error_str(err)); - ret = FALSE; + ret = false; goto out; } @@ -1109,7 +1109,7 @@ { if (!argHandleFileDir(npath, entry->d_name, pattern)) { - ret = FALSE; + ret = false; goto out; } } @@ -1128,13 +1128,13 @@ } -BOOL argHandleFile(char *path) +bool argHandleFile(char *path) { char *pattern, *filename, *pt, *npath; - BOOL ret; + bool ret; if ((npath = th_strdup(path)) == NULL) - return FALSE; + return false; // Check if we have path separators if ((pt = strrchr(npath, '/')) != NULL || @@ -1177,7 +1177,7 @@ th_pstr_cpy(&setHVSCPath, getenv("HVSC_BASE")); // Initialize - th_init("SIDInfo", "PSID/RSID information displayer", "0.9.5", + th_init("SIDInfo", "PSID/RSID information displayer", "1.0.0", "By Matti 'ccr' Hamalainen (C) Copyright 2014-2022 TNSP", "This program is distributed under a 3-clause BSD -style license."); @@ -1231,7 +1231,7 @@ (!optFieldOutput && optFormat.nitems > 0)) { // For one-line format and formatted output (-F), disable parsable - optParsable = FALSE; + optParsable = false; // If no escape chars have been set, use the field separator(s) if (optEscapeChars == NULL) diff -r ad0fe49a211a -r db64a58314a9 sidlib.c --- a/sidlib.c Thu Jul 14 01:56:07 2022 +0300 +++ b/sidlib.c Wed Dec 07 12:19:12 2022 +0200 @@ -43,7 +43,7 @@ } -static BOOL sidlib_fread_str(th_ioctx *ctx, SIDLibChConvCtx *chconv, char **str, const size_t len) +static bool sidlib_fread_str(th_ioctx *ctx, SIDLibChConvCtx *chconv, char **str, const size_t len) { char *tmp; @@ -70,11 +70,11 @@ *str = chconv->convert(chconv, tmp); th_free(tmp); } - return TRUE; + return true; err: th_free(tmp); - return FALSE; + return false; } @@ -152,7 +152,7 @@ psid->playAddress != 0 || psid->speed != 0) { - psid->isInvalidRSID = TRUE; + psid->isInvalidRSID = true; } } @@ -271,7 +271,7 @@ if ((*ppsid = th_malloc0(sizeof(SIDLibPSIDHeader))) == NULL) return THERR_MALLOC; - (*ppsid)->allocated = TRUE; + (*ppsid)->allocated = true; return sidlib_read_sid_file(ctx, *ppsid, flags, chconv); } @@ -380,7 +380,7 @@ int ret = THERR_OK; SIDLibSLDBNode *node; size_t pos, tmpLen, savePos; - BOOL isOK; + bool isOK; int i; // Allocate new node @@ -414,7 +414,7 @@ tmpLen = strlen(line); // Get number of sub-tune lengths - isOK = TRUE; + isOK = true; while (pos < tmpLen && isOK) { th_findnext(line, &pos); @@ -422,7 +422,7 @@ if (sidlib_sldb_gettime(line, &pos) >= 0) node->nlengths++; else - isOK = FALSE; + isOK = false; } // Allocate memory for lengths @@ -440,7 +440,7 @@ } // Read lengths in - for (i = 0, pos = savePos, isOK = TRUE; + for (i = 0, pos = savePos, isOK = true; pos < tmpLen && i < node->nlengths && isOK; i++) { int l; @@ -451,7 +451,7 @@ if (l >= 0) node->lengths[i] = l; else - isOK = FALSE; + isOK = false; } return ret; @@ -658,7 +658,7 @@ static int sidlib_stildb_entry_realloc( SIDLibSTILNode *node, - const int nsubtune, const BOOL alloc, + const int nsubtune, const bool alloc, const int nfield, const char *fdata, SIDLibChConvCtx *chconv) { @@ -737,7 +737,7 @@ if ((node->filename = th_strdup(filename)) == NULL) return THERR_MALLOC; - if ((res = sidlib_stildb_entry_realloc(node, 1, FALSE, -1, NULL, chconv)) != THERR_OK) + if ((res = sidlib_stildb_entry_realloc(node, 1, false, -1, NULL, chconv)) != THERR_OK) { sidlib_stildb_node_free(node); return res; @@ -788,7 +788,7 @@ size_t lineNum; ssize_t linePos; int ch, prevMode, nextMode, parseMode; - BOOL lineStart; + bool lineStart; } SIDLibSTILParserCtx; @@ -840,7 +840,7 @@ memset(&ctx, 0, sizeof(ctx)); ctx.nextMode = ctx.prevMode = ctx.parseMode = PM_IDLE; ctx.ch = -1; - ctx.lineStart = TRUE; + ctx.lineStart = true; strPos = 0; // Parse the STIL database @@ -859,7 +859,7 @@ default: if (ctx.linePos < 0) { - ctx.lineStart = TRUE; + ctx.lineStart = true; ctx.linePos = 0; } else @@ -919,7 +919,7 @@ sidlib_stildb_set_parsemode(&ctx, PM_SUBTUNE); ctx.ch = -1; - ctx.lineStart = TRUE; + ctx.lineStart = true; } else if (th_isalpha(ctx.ch)) @@ -981,7 +981,7 @@ case PM_SUBTUNE: if (ctx.ch == EOF || ctx.ch == ')') { - BOOL neg = FALSE; + bool neg = false; // Subtune indicator end tmpStr[strPos] = 0; @@ -1030,7 +1030,7 @@ } ctx.ch = -1; - ctx.lineStart = FALSE; + ctx.lineStart = false; break; case PM_FIELD_NAME: @@ -1050,7 +1050,7 @@ } sidlib_stildb_set_next_parsemode(&ctx, PM_FIELD_DATA); - ctx.lineStart = FALSE; + ctx.lineStart = false; strPos = 0; } else @@ -1075,7 +1075,7 @@ else if (th_iscrlf(ctx.ch)) { - ctx.lineStart = TRUE; + ctx.lineStart = true; ctx.ch = -1; } else @@ -1088,7 +1088,7 @@ { // Supported field, add it if ((ret = sidlib_stildb_entry_realloc( - entry, subtune, TRUE, field, tmpStr, chconv)) != THERR_OK) + entry, subtune, true, field, tmpStr, chconv)) != THERR_OK) { ret = th_io_error(fh, THERR_MALLOC, "Could not allocate memory for field '%s'.", @@ -1101,7 +1101,7 @@ } else { - ctx.lineStart = FALSE; + ctx.lineStart = false; VADDCH(ctx.ch) else { diff -r ad0fe49a211a -r db64a58314a9 sidlib.h --- a/sidlib.h Thu Jul 14 01:56:07 2022 +0300 +++ b/sidlib.h Wed Dec 07 12:19:12 2022 +0200 @@ -146,12 +146,12 @@ uint8_t sid2Addr, sid3Addr; // Extra data - BOOL isRSID, isInvalidRSID; + bool isRSID, isInvalidRSID; size_t dataSize; // Total size of data - header th_md5hash_t hash; // Songlength database hash // Internal use only - BOOL allocated; // TRUE if structure has been allocated + bool allocated; // true if structure has been allocated SIDLibSLDBNode *lengths; // Songlength information node pointer SIDLibSTILNode *stil; // STIL database node pointer } SIDLibPSIDHeader; diff -r ad0fe49a211a -r db64a58314a9 sidutil.c --- a/sidutil.c Thu Jul 14 01:56:07 2022 +0300 +++ b/sidutil.c Wed Dec 07 12:19:12 2022 +0200 @@ -248,7 +248,7 @@ #endif -// NOTICE! Only call this function IF ctx->enabled == TRUE +// NOTICE! Only call this function IF ctx->enabled == true char * sidutil_chconv_convert(SIDUtilChConvCtx *ctx, const char *src) { #ifdef HAVE_ICONV diff -r ad0fe49a211a -r db64a58314a9 sidutil.h --- a/sidutil.h Thu Jul 14 01:56:07 2022 +0300 +++ b/sidutil.h Wed Dec 07 12:19:12 2022 +0200 @@ -47,7 +47,7 @@ // typedef struct { - BOOL enabled; + bool enabled; char *outLang; #ifdef HAVE_ICONV iconv_t iconvCtx;