diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-07-06 15:42:04 +0000 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-07-06 15:42:04 +0000 |
commit | 232dbc756390d30a86ae6de0cc84600eddb1c0b2 (patch) | |
tree | e4aadbb4076392bcaf30cce6329dc715375a98d7 /src/recode.c | |
parent | 550bda3e54a0895e027fee14860f14171a357ac9 (diff) | |
download | librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.gz librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.bz2 librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.tar.xz librcc-232dbc756390d30a86ae6de0cc84600eddb1c0b2.zip |
Recode FS Fixes
Diffstat (limited to 'src/recode.c')
-rw-r--r-- | src/recode.c | 102 |
1 files changed, 69 insertions, 33 deletions
diff --git a/src/recode.c b/src/recode.c index f10221f..4c1c5bd 100644 --- a/src/recode.c +++ b/src/recode.c @@ -16,7 +16,7 @@ static rcc_charset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const rcc_class_type class_type; rcc_engine_ptr engine; - if ((!ctx)||(!buf)) return -1; + if (!buf) return (rcc_charset_id)-1; class_type = rccGetClassType(ctx, class_id); if ((class_type == RCC_CLASS_STANDARD)||((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_AUTODETECT_FS_TITLES)))) { @@ -25,24 +25,29 @@ static rcc_charset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const return engine->func(&ctx->engine_ctx, buf, len); } - return -1; + return (rcc_charset_id)-1; } -rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, int len, int *rlen) { +rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len, size_t *rlen) { int err; + size_t ret; rcc_language_id language_id; rcc_charset_id charset_id; iconv_t icnv = (iconv_t)-1; rcc_string result; - if ((!ctx)||(class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL; + if (!ctx) { + if (rcc_default_ctx) ctx = rcc_default_ctx; + else return NULL; + } + if ((class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL; err = rccConfigure(ctx); if (err) return NULL; // Checking if rcc_string passed - language_id = rccStringCheck((const rcc_string)buf); - if (language_id) return NULL; + ret = rccStringSizedCheck(buf, len); + if (ret) return NULL; language_id = rccGetCurrentLanguage(ctx); // DS: Learning. check database (language_id) @@ -58,9 +63,9 @@ rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, int if (icnv == (iconv_t)-2) { result = rccCreateString(language_id, buf, len, rlen); } else { - err = rccIConv(ctx, icnv, buf, len); - if (err<=0) return NULL; - result = rccCreateString(language_id, ctx->tmpbuffer, err, rlen); + ret = rccIConv(ctx, icnv, buf, len); + if (ret == (size_t)-1) return NULL; + result = rccCreateString(language_id, ctx->tmpbuffer, ret, rlen); } // DS: Learning. write database @@ -68,19 +73,28 @@ rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, int return result; } -char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, int len, int *rlen) { +char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t len, size_t *rlen) { int err; + size_t newlen; char *result; char *prefix, *name; + const char *utfstring; rcc_language_id language_id; rcc_charset_id charset_id; rcc_class_type class_type; iconv_t icnv; - - if ((!ctx)||(class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL; - language_id = rccStringCheck(buf); - if (!language_id) return NULL; + if (!ctx) { + if (rcc_default_ctx) ctx = rcc_default_ctx; + else return NULL; + } + if ((class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL; + + newlen = rccStringSizedCheck((const char*)buf, len); + if (!newlen) return NULL; + + language_id = rccStringGetLanguage(buf); + utfstring = rccStringGetString(buf); err = rccConfigure(ctx); if (err) return NULL; @@ -88,11 +102,17 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, int le icnv = ctx->iconv_to[class_id]; class_type = rccGetClassType(ctx, class_id); - if ((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_AUTODETECT_FS_NAMES))) { - prefix = NULL; name = buf + sizeof(rcc_string_header); - err = rccFS0(NULL, buf, &prefix, &name); - if (!err) { + if ((language_id)&&(class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_AUTODETECT_FS_NAMES))) { + name = (char*)utfstring; + prefix = NULL; + + err = rccFS0(ctx, NULL, buf, &prefix, &name); + if (err>=0) { result = rccFS3(ctx, language_id, class_id, prefix, name); + if (!err) { + if (prefix) free(prefix); + free(name); + } if ((rlen)&&(result)) *rlen = strlen(result); return result; } @@ -100,32 +120,37 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, int le if (icnv == (iconv_t)-1) return NULL; if (icnv == (iconv_t)-2) { - result = rccStringExtract(buf, len, rlen); + result = rccStringExtractString(buf); + if (rlen) *rlen = newlen; } else { - err = rccIConv(ctx, icnv, buf + sizeof(rcc_string_header), len?len-sizeof(rcc_string_header):0); - if (err<=0) return NULL; + newlen = rccIConv(ctx, icnv, rccStringGetString(buf), len?newlen:0); + if (newlen == (size_t)-1) return NULL; - result = rccCreateResult(ctx, err, rlen); + result = rccCreateResult(ctx, newlen, rlen); } return result; } -char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, int len, int *rlen) { - int nlen; +char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen) { + size_t nlen; rcc_string stmp; char *result; const char *from_charset, *to_charset; rcc_charset_id from_charset_id, to_charset_id; rcc_class_type class_type; - if ((!ctx)||(from<0)||(from>=ctx->n_classes)||(to<0)||(to>=ctx->n_classes)||(!buf)) return NULL; + if (!ctx) { + if (rcc_default_ctx) ctx = rcc_default_ctx; + else return NULL; + } + if ((from<0)||(from>=ctx->n_classes)||(to<0)||(to>=ctx->n_classes)||(!buf)) return NULL; class_type = rccGetClassType(ctx, to); if ((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_AUTODETECT_FS_NAMES))) goto recoding; from_charset_id = rccIConvAuto(ctx, from, buf, len); - if (from_charset_id>0) { + if (from_charset_id != (rcc_charset_id)-1) { from_charset = rccGetAutoCharsetName(ctx, from_charset_id); to_charset = rccGetCurrentCharsetName(ctx, to); if ((from_charset)&&(to_charset)&&(!strcasecmp(from_charset, to_charset))) return NULL; @@ -155,23 +180,34 @@ char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fsp char *stmp; char *result = NULL; - + + if (!ctx) { + if (rcc_default_ctx) ctx = rcc_default_ctx; + else return NULL; + } + if ((from<0)||(from>=ctx->n_classes)||(to<0)||(to>=ctx->n_classes)||(!filename)) return NULL; err = rccFS1(ctx, fspath, &prefix, &name); if (err) { - if (err<0) return NULL; - return name; + if (err < 0) return NULL; + + if (err&1) { + if (err&2) return NULL; + return name; + } } string = rccFrom(ctx, from, name, 0, NULL); if (string) { language_id = rccGetCurrentLanguage(ctx); - result = rccFS3(ctx, language_id, to, prefix, string + sizeof(rcc_string_header)); + result = rccFS3(ctx, language_id, to, prefix, rccStringGetString(string)); free(string); - } + } else result = NULL; - free(prefix); - free(name); + if (!(err&2)) { + if (prefix) free(prefix); + free(name); + } return result; } |