From 2f83de29911eaa23ea86900127597765f6805c2e Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 29 Feb 2004 12:47:03 +0000 Subject: [PATCH] mbfile now uses new charmap functions --- ChangeLog | 5 +++ lib/.cvsignore | 2 +- lib/charset.c | 105 ++++++++++++++++++++++------------------------ mbfido/mbfindex.c | 45 ++++++++------------ 4 files changed, 73 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3b90a2f..0a0e621f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,11 @@ v0.51.1 21-Feb-2004 mbfido: Changed ^aTID to include OS and CPU. + mbfile: + For creating www pages of the download areas, the new mapping + tables are used to translate from ibmpc characters to + iso-8859-1. + examples: Added change character set in English menus and textfiles. diff --git a/lib/.cvsignore b/lib/.cvsignore index 3866a77d..e85f1f89 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -1 +1 @@ -filelist ftscprod.c +filelist ftscprod.c charset.bin diff --git a/lib/charset.c b/lib/charset.c index d6b4a147..3b06e1da 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -32,7 +32,6 @@ #include "mbselib.h" -#define strieq(a,b) (strcasecmp ((a),(b)) == 0) #define BUF_APPEND(d,s) str_append(d,sizeof(d),s) @@ -66,23 +65,20 @@ int str_printf(char *buf, size_t len, const char *fmt, ...) va_start(args, fmt); -#ifdef HAS_SNPRINTF - n = vsnprintf(buf, len, fmt, args); - /**FIXME: check for n==-1 and errno**/ -#else n = vsprintf(buf, fmt, args); - if(n >= len) { + if (n >= len) { WriteError("Internal error - str_printf() buf overflow"); /**NOT REACHED**/ return FALSE; } -#endif - /* Make sure that buf[] is terminated with a \0. vsnprintf() + + /* + * Make sure that buf[] is terminated with a \0. vsnprintf() * should do this automatically as required by the ANSI C99 * proposal, but one never knows ... see also discussion on - * BugTraq */ + * BugTraq + */ buf[len - 1] = 0; - va_end(args); return n; @@ -201,27 +197,29 @@ int charset_write_bin(char *name) CharsetTable *pt; CharsetAlias *pa; -// debug(14, "Writing charset.bin file %s", name); - fp = fopen(name, "w+"); - if(!fp) + if (!fp) return FALSE; - /* Write aliases */ + /* + * Write aliases + */ for (pa = charset_alias_list; pa; pa=pa->next) { fputc(CHARSET_FILE_ALIAS, fp); fwrite(pa, sizeof(CharsetAlias), 1, fp); - if(ferror(fp)) { + if (ferror(fp)) { fclose(fp); return FALSE; } } - /* Write tables */ + /* + * Write tables + */ for(pt = charset_table_list; pt; pt=pt->next) { fputc(CHARSET_FILE_TABLE, fp); fwrite(pt, sizeof(CharsetTable), 1, fp); - if(ferror(fp)) { + if (ferror(fp)) { fclose(fp); return FALSE; } @@ -254,27 +252,24 @@ int charset_read_bin(void) } free(name); - while( (c = fgetc(fp)) != EOF ) { + while ((c = fgetc(fp)) != EOF) { switch(c) { - case CHARSET_FILE_ALIAS: - pa = charset_alias_new(); - n = fread((void *)pa, sizeof(CharsetAlias), 1, fp); - pa->next = NULL; /* overwritten by fread() */ - if(n != 1) - return FALSE; - Syslog('s', "read charset alias: %s -> %s", pa->alias, pa->name); - break; - case CHARSET_FILE_TABLE: - pt = charset_table_new(); - n = fread((void *)pt, sizeof(CharsetTable), 1, fp); - pt->next = NULL; /* overwritten by fread() */ - if(n != 1) - return FALSE; - Syslog('s', "read charset table: %s -> %s", pt->in, pt->out); - break; - default: - return FALSE; - break; + case CHARSET_FILE_ALIAS: pa = charset_alias_new(); + n = fread((void *)pa, sizeof(CharsetAlias), 1, fp); + pa->next = NULL; /* overwritten by fread() */ + if (n != 1) + return FALSE; + Syslog('s', "read charset alias: %s -> %s", pa->alias, pa->name); + break; + case CHARSET_FILE_TABLE: pt = charset_table_new(); + n = fread((void *)pt, sizeof(CharsetTable), 1, fp); + pt->next = NULL; /* overwritten by fread() */ + if (n != 1) + return FALSE; + Syslog('s', "read charset table: %s -> %s", pt->in, pt->out); + break; + default: return FALSE; + break; } } @@ -295,10 +290,9 @@ char *charset_qpen(int c, int qp) c &= 0xff; - if( qp && (c == '=' || c >= 0x80) ) + if (qp && (c == '=' || c >= 0x80)) str_printf(buf, sizeof(buf), "=%02.2X", c & 0xff); - else - { + else { buf[0] = c; buf[1] = 0; } @@ -319,14 +313,11 @@ char *charset_map_c(int c, int qp) c &= 0xff; buf[0] = 0; - if(charset_table_used && c>=0x80) - { + if (charset_table_used && c>=0x80) { s = charset_table_used->map[c - 0x80]; while(*s) BUF_APPEND(buf, charset_qpen(*s++, qp)); - } - else - { + } else { BUF_COPY(buf, charset_qpen(c, qp)); } @@ -342,10 +333,11 @@ char *charset_alias_fsc(char *name) { CharsetAlias *pa; - /* Search for aliases */ - for(pa = charset_alias_list; pa; pa=pa->next) - { - if(strieq(pa->name, name)) + /* + * Search for aliases + */ + for (pa = charset_alias_list; pa; pa=pa->next) { + if (strcasecmp(pa->name, name) == 0) return pa->alias; } @@ -358,10 +350,11 @@ char *charset_alias_rfc(char *name) { CharsetAlias *pa; - /* Search for aliases */ - for(pa = charset_alias_list; pa; pa=pa->next) - { - if(strieq(pa->alias, name)) + /* + * Search for aliases + */ + for (pa = charset_alias_list; pa; pa=pa->next) { + if (strcasecmp(pa->alias, name) == 0) return pa->name; } @@ -408,16 +401,16 @@ int charset_set_in_out(char *in, char *out) /* Search for aliases */ for (pa = charset_alias_list; pa; pa=pa->next) { - if (strieq(pa->alias, in)) + if (strcasecmp(pa->alias, in) == 0) in = pa->name; - if (strieq(pa->alias, out)) + if (strcasecmp(pa->alias, out) == 0) out = pa->name; } Syslog('s', "charset3: in=%s out=%s", in, out); /* Search for matching table */ for (pt = charset_table_list; pt; pt=pt->next) { - if(strieq(pt->in, in) && strieq(pt->out, out)) { + if ((strcasecmp(pt->in, in) == 0) && (strcasecmp(pt->out, out) == 0)) { Syslog('s', "charset: table found in=%s out=%s", pt->in, pt->out); charset_table_used = pt; return TRUE; diff --git a/mbfido/mbfindex.c b/mbfido/mbfindex.c index 73df3713..9c19a13a 100644 --- a/mbfido/mbfindex.c +++ b/mbfido/mbfindex.c @@ -61,29 +61,6 @@ static char *months[]= {(char *)"Jan",(char *)"Feb",(char *)"Mar", (char *)"Oct",(char *)"Nov",(char *)"Dec"}; -/* - * Translation table from Hi-USA-ANSI to low ASCII and HTML codes, - */ -char htmltab[] = { - "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017" - "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" - "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057" - "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077" - "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117" - "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137" - "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157" - "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177" - "\103\374\351\342\344\340\345\143\352\353\350\357\357\354\304\305" /* done */ - "\311\346\306\364\366\362\374\371\171\326\334\244\243\245\120\146" /* done */ - "\341\355\363\372\361\321\141\157\277\055\055\275\274\241\074\076" /* done */ - "\043\043\043\174\053\053\053\053\053\043\174\043\043\053\053\053" /* done */ - "\053\053\053\053\053\053\053\053\043\043\043\043\043\075\043\053" /* done */ - "\053\053\053\053\053\053\053\053\053\053\053\043\043\043\043\043" /* done */ - "\141\102\114\156\105\157\265\370\060\060\060\157\070\330\145\156" /* doesn't look good */ - "\075\261\076\074\146\146\367\075\260\267\267\126\262\262\267\040" /* almost */ -}; - - /* * Translate a string from ANSI to safe HTML characters @@ -93,19 +70,28 @@ char *To_Html(char *inp) { static char temp[256]; int i; + char *xl; memset(&temp, 0, sizeof(temp)); - strncpy(temp, inp, 80); - for (i = 0; i < strlen(temp); i++) - temp[i] = htmltab[temp[i] & 0xff]; + for (i = 0; i < strlen(inp); i++) { + if (inp[i] & 0x80) { + if ((xl = charset_map_c(inp[i], FALSE))) { + while (*xl) { + temp[i] = *xl++; + if (*xl) + i++; + } + } + } else + temp[i] = inp[i]; + } return temp; } - void tidy_index(Findex **); void tidy_index(Findex **fap) { @@ -593,6 +579,11 @@ void HtmlIndex(char *Lang) fileptr = ftell(fi); } + /* + * Setup the correct tabel to produce file listings for the www. + */ + charset_set_in_out((char *)"x-ibmpc", (char *)"iso-8859-1"); + for (i = 1; i <= iAreas; i++) { fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);