From a1837e5cba51dad2199502f9fc5e88c1184ca8c7 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 1 Feb 2024 15:36:55 +1300 Subject: [PATCH] Fix C code, it compiles now! --- cbits/transcode.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/cbits/transcode.c b/cbits/transcode.c index 5b3d864..4efb28c 100644 --- a/cbits/transcode.c +++ b/cbits/transcode.c @@ -92,7 +92,7 @@ fail: return NULL; } -bool encodeCharSet(cmp_ctx_t *bytes, FcCharSet *data) { +bool encodeCharSet(cmp_ctx_t *bytes, const FcCharSet *data) { if (bytes == NULL || data == NULL) return false; FcChar32 size = FcCharSetCount(data); @@ -135,7 +135,7 @@ fail: return NULL; } -bool encodeLangSet(cmp_ctx_t *bytes, FcLangSet *data) { +bool encodeLangSet(cmp_ctx_t *bytes, const FcLangSet *data) { if (bytes == NULL || data == NULL) return false; FcStrSet *langs = FcLangSetGetLangs(data); if (langs == NULL) return false; @@ -154,7 +154,7 @@ FcObjectSet *decodeObjectSet(cmp_ctx_t *bytes) { for (uint32_t i = 0; i < size; i++) { char object[20]; uint32_t o_size = 20; - if (!cmp_read_str(bytes, lang, &str_size)) goto fail; + if (!cmp_read_str(bytes, object, &o_size)) goto fail; if (!FcObjectSetAdd(ret, object)) goto fail; } return ret; @@ -177,10 +177,10 @@ FcRange *decodeRange(cmp_ctx_t *bytes) { if (!cmp_read_uint(bytes, &j)) return NULL; if (!cmp_read_double(bytes, &range[j])) return NULL; } - return FcCreateDouble(range[0], range[1]); + return FcRangeCreateDouble(range[0], range[1]); } -bool encodeRange(cmp_ctx_t *bytes, FcRange *data) { +bool encodeRange(cmp_ctx_t *bytes, const FcRange *data) { if (bytes == NULL || data == NULL) return false; double begin, end; @@ -211,7 +211,7 @@ fail: return NULL; } -bool encodeMatrix(cmp_ctx_t *bytes, FcMatrix *data) { +bool encodeMatrix(cmp_ctx_t *bytes, const FcMatrix *data) { if (bytes == NULL || data == NULL) return NULL; if (!cmp_write_array(bytes, 4)) return false; @@ -225,12 +225,20 @@ bool encodeMatrix(cmp_ctx_t *bytes, FcMatrix *data) { bool decodeValue(cmp_ctx_t *bytes, FcValue *out) { if (bytes == NULL || out == NULL) return false; + bool b; + uint32_t str_size; if (cmp_read_nil(bytes)) out->type = FcTypeVoid; else if (cmp_read_int(bytes, &out->u.i)) out->type = FcTypeInteger; else if (cmp_read_double(bytes, &out->u.d)) out->type = FcTypeDouble; - else if (cmp_read_string(bytes, &out->u.s, NULL)) out->type = FcTypeString; - else if (cmp_read_bool(bytes, &out->u.b)) out->type = FcTypeBool; - else if ((out->u.m = decodeMatrix(bytes)) != NULL) out->type = FcTypeMatrix; + else if (cmp_read_str_size(bytes, &str_size)) { + out->type = FcTypeString; + char *str = malloc(str_size); + out->u.s = str; + return cmp_read_str(bytes, str, &str_size); + } else if (cmp_read_bool(bytes, &b)) { + out->type = FcTypeBool; + out->u.b = b ? FcTrue : FcFalse; // Didn't auto-convert. + } else if ((out->u.m = decodeMatrix(bytes)) != NULL) out->type = FcTypeMatrix; else if ((out->u.c = decodeCharSet(bytes)) != NULL) out->type = FcTypeCharSet; // Not supporting FcTypeFcFace else if ((out->u.l = decodeLangSet(bytes)) != NULL) out->type = FcTypeLangSet; @@ -250,14 +258,14 @@ bool encodeValue(cmp_ctx_t *bytes, FcValue *data) { case FcTypeDouble: return cmp_write_double(bytes, data->u.d); case FcTypeString: - return cmp_write_string(bytes, data->u.s, strlen(data->u.s)); + return cmp_write_str(bytes, data->u.s, strlen(data->u.s)); case FcTypeBool: return cmp_write_bool(bytes, data->u.b); case FcTypeMatrix: return encodeMatrix(bytes, data->u.m); case FcTypeCharSet: return encodeCharSet(bytes, data->u.c); - case FcTypeFcFace: + case FcTypeFTFace: return true; // Not supporting this yet... case FcTypeLangSet: return encodeLangSet(bytes, data->u.l); @@ -278,22 +286,22 @@ FcPattern *decodePattern(cmp_ctx_t *bytes) { for (uint32_t i = 0; i < size; i++) { char object[20]; uint32_t osize = 20; - if (!cmp_read_string(bytes, object, &osize)) goto fail; + if (!cmp_read_str(bytes, object, &osize)) goto fail; uint32_t vsize; if (!cmp_read_array(bytes, &vsize)) goto fail; - for (uint32 j = 0; j < vsize; j++) { + for (uint32_t j = 0; j < vsize; j++) { uint32_t tsize; if (!cmp_read_array(bytes, &tsize) || tsize != 2) goto fail; bool is_strong = false; - if (cmp_read_bool(bytes, &is_weak)) {} + if (cmp_read_bool(bytes, &is_strong)) {} else if (cmp_read_nil(bytes)) {} else goto fail; FcValue val; if (!decodeValue(bytes, &val)) goto fail; if (is_strong) { - if (!FcPatternAdd(bytes, object, value, true)) goto fail; + if (!FcPatternAdd(ret, object, val, true)) goto fail; } else { - if (!FcPatternAddWeak(bytes, object, value, true)) goto fail; + if (!FcPatternAddWeak(ret, object, val, true)) goto fail; } } } @@ -307,15 +315,15 @@ bool encodePattern(cmp_ctx_t *bytes, FcPattern *data) { if (bytes == NULL || data == NULL) return false; int size = FcPatternObjectCount(data); - if (!cmp_write_map(bytes, &size)) return false; + if (!cmp_write_map(bytes, size)) return false; FcPatternIter iter; FcPatternIterStart(data, &iter); int count = 0; while (FcPatternIterNext(data, &iter)) { count++; - char *obj = FcPatternIterGetObject(data, &iter); - if (!cmp_write_string(bytes, obj, strlen(obj))) return false; + const char *obj = FcPatternIterGetObject(data, &iter); + if (!cmp_write_str(bytes, obj, strlen(obj))) return false; int nvalues = FcPatternIterValueCount(data, &iter); if (!cmp_write_array(bytes, nvalues)) return false; for (int j = 0; j < nvalues; j++) { -- 2.30.2