# HG changeset patch # User Matti Hamalainen # Date 1580085193 -7200 # Node ID 199284ba94ea4fe617d738927e3b7b090432b66e # Parent 811eb6c6695e44062fefe35a7d6e2b01b7b7f4e8 Cleanup and few comments added. diff -r 811eb6c6695e -r 199284ba94ea sidutil.c --- a/sidutil.c Mon Jan 27 02:32:59 2020 +0200 +++ b/sidutil.c Mon Jan 27 02:33:13 2020 +0200 @@ -162,9 +162,14 @@ }; +#define SI_PUTCH(xch) th_strbuf_putch(&outBuf, &outSize, &outLen, (xch)) + + +// +// Convert _ONLY_ FROM ISO-8859-1 encoding to few other encodings +// static char *sidutil_chconv_internal(SIDUtilChConvCtx *ctx, const char *src) { - // Fallback conversion of ISO-8859-1 to X const uint8_t *srcPtr = (const uint8_t *) src; const uint8_t *convTable; size_t outSize, outLen; @@ -185,26 +190,26 @@ // Not 100% correct really, but close enough if (*srcPtr < 0x80) { - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, *srcPtr)) + if (!SI_PUTCH(*srcPtr)) goto err; } else if (*srcPtr < 0xBF) { - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, 0xC2) || - !th_strbuf_putch(&outBuf, &outSize, &outLen, *srcPtr)) + if (!SI_PUTCH(0xC2) || + !SI_PUTCH(*srcPtr)) goto err; } else { - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, 0xC3) || - !th_strbuf_putch(&outBuf, &outSize, &outLen, *srcPtr - 0x40)) + if (!SI_PUTCH(0xC3) || + !SI_PUTCH(*srcPtr - 0x40)) goto err; } break; case TH_LANG_ISO88591: - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, *srcPtr)) + if (!SI_PUTCH(*srcPtr)) goto err; break; @@ -224,13 +229,13 @@ else outByte = '?'; - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, outByte)) + if (!SI_PUTCH(outByte)) goto err; break; } } - if (!th_strbuf_putch(&outBuf, &outSize, &outLen, *srcPtr)) + if (!SI_PUTCH(*srcPtr)) goto err; return outBuf;