From 70823ccf09b654f6cefd9f0eb8df9a04257808db Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 27 Jul 2013 01:48:57 +0000 Subject: [PATCH] fusedrv: '--nokoi' option (not tested, shitty, etc) FossilOrigin-Name: 4616f5fe42ab8717da4641742c3777b7054592a4918f88e13c844189995028be --- src/fusedrv/fusedrv.c | 3 ++ src/tagload.c | 86 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/fusedrv/fusedrv.c b/src/fusedrv/fusedrv.c index ef79cfd..d5b0e20 100644 --- a/src/fusedrv/fusedrv.c +++ b/src/fusedrv/fusedrv.c @@ -883,6 +883,9 @@ int main (int argc, char *argv[]) { dbglog_set_screenout(0); dbglog_set_fileout(1); killoption = 1; + } else if (strcmp(argv[f], "--nokoi") == 0) { + opt_tagload_koi8 = 0; + killoption = 1; } if (killoption) { for (int c = f+killoption; c < argc; ++c) argv[c-killoption] = argv[c]; diff --git a/src/tagload.c b/src/tagload.c index c7c4895..a486a13 100644 --- a/src/tagload.c +++ b/src/tagload.c @@ -1,4 +1,7 @@ //////////////////////////////////////////////////////////////////////////////// +static int opt_tagload_koi8 = 1; + + static char *str_transliterate (const char *str) { iconv_t cd; size_t il, ol, ool; @@ -55,36 +58,40 @@ done: //////////////////////////////////////////////////////////////////////////////// static char *str_tokoi (const char *str) { - iconv_t cd; - size_t il, ol, ool; - char *outs, *ibuf, *obuf, *res; - int asis = 1; - if (str == NULL) return strdup(""); - if (str == NULL || !str[0]) { res = strdup(str); goto done; } - for (const unsigned char *u = (const unsigned char *)str; *u; ++u) if (*u >= 128) { asis = 0; break; } - if (asis) { res = strdup(str); goto done; } - cd = iconv_open("koi8-u//translit//ignore", "utf-8"); - if (cd == (iconv_t)-1) return NULL; - outs = calloc(1, strlen(str)*6+4); - if (outs == NULL) { + if (opt_tagload_koi8) { + iconv_t cd; + size_t il, ol, ool; + char *outs, *ibuf, *obuf, *res; + int asis = 1; + if (str == NULL) return strdup(""); + if (str == NULL || !str[0]) { res = strdup(str); goto done; } + for (const unsigned char *u = (const unsigned char *)str; *u; ++u) if (*u >= 128) { asis = 0; break; } + if (asis) { res = strdup(str); goto done; } + cd = iconv_open("koi8-u//translit//ignore", "utf-8"); + if (cd == (iconv_t)-1) return NULL; + outs = calloc(1, strlen(str)*6+4); + if (outs == NULL) { + iconv_close(cd); + return NULL; + } + ibuf = (char *)str; + obuf = outs; + il = strlen(str); + ool = ol = il*4; + il = iconv(cd, &ibuf, &il, &obuf, &ol); iconv_close(cd); - return NULL; - } - ibuf = (char *)str; - obuf = outs; - il = strlen(str); - ool = ol = il*4; - il = iconv(cd, &ibuf, &il, &obuf, &ol); - iconv_close(cd); - if (il == (size_t)-1) { + if (il == (size_t)-1) { + free(outs); + return NULL; + } + res = calloc(ool-ol+1, 1); + if (ool-ol > 0) memcpy(res, outs, ool-ol); free(outs); - return NULL; + done: + return res; } - res = calloc(ool-ol+1, 1); - if (ool-ol > 0) memcpy(res, outs, ool-ol); - free(outs); -done: - return res; + if (str == NULL) return strdup(""); + return strdup(str); } @@ -314,14 +321,23 @@ static inline void normalize_tag_str (char *d, const char *s) { unsigned char ch = (unsigned char)(*s); if (isspace(*s)) continue; if (ch == 127) continue; - *d = le2lower(*s); - if (ch >= 128) { - if (*d == '£') *d = 'Å'; - if (*d == 'Ý') *d = 'Û'; - if (*d == 'Ó') *d = 'c'; // russian to latin - ++d; - } else if (isdigit(*d) || (*d >= 'a' && *d <= 'z')) { - ++d; + if (opt_tagload_koi8) { + *d = le2lower(*s); + if (ch >= 128) { + if (*d == '£') *d = 'Å'; + if (*d == 'Ý') *d = 'Û'; + if (*d == 'Ó') *d = 'c'; // russian to latin + ++d; + } else if (isdigit(*d) || (*d >= 'a' && *d <= 'z')) { + ++d; + } + } else { + *d = *s; + if (ch >= 128) { + ++d; + } else if (isdigit(*d) || (*d >= 'a' && *d <= 'z')) { + ++d; + } } } *d = 0; -- 2.11.4.GIT