mbfile now uses new charmap functions
This commit is contained in:
parent
7a7b810aec
commit
2f83de2991
@ -54,6 +54,11 @@ v0.51.1 21-Feb-2004
|
|||||||
mbfido:
|
mbfido:
|
||||||
Changed ^aTID to include OS and CPU.
|
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:
|
examples:
|
||||||
Added change character set in English menus and textfiles.
|
Added change character set in English menus and textfiles.
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
filelist ftscprod.c
|
filelist ftscprod.c charset.bin
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include "mbselib.h"
|
#include "mbselib.h"
|
||||||
|
|
||||||
|
|
||||||
#define strieq(a,b) (strcasecmp ((a),(b)) == 0)
|
|
||||||
#define BUF_APPEND(d,s) str_append(d,sizeof(d),s)
|
#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);
|
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);
|
n = vsprintf(buf, fmt, args);
|
||||||
if(n >= len) {
|
if (n >= len) {
|
||||||
WriteError("Internal error - str_printf() buf overflow");
|
WriteError("Internal error - str_printf() buf overflow");
|
||||||
/**NOT REACHED**/
|
/**NOT REACHED**/
|
||||||
return FALSE;
|
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
|
* should do this automatically as required by the ANSI C99
|
||||||
* proposal, but one never knows ... see also discussion on
|
* proposal, but one never knows ... see also discussion on
|
||||||
* BugTraq */
|
* BugTraq
|
||||||
|
*/
|
||||||
buf[len - 1] = 0;
|
buf[len - 1] = 0;
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
@ -201,27 +197,29 @@ int charset_write_bin(char *name)
|
|||||||
CharsetTable *pt;
|
CharsetTable *pt;
|
||||||
CharsetAlias *pa;
|
CharsetAlias *pa;
|
||||||
|
|
||||||
// debug(14, "Writing charset.bin file %s", name);
|
|
||||||
|
|
||||||
fp = fopen(name, "w+");
|
fp = fopen(name, "w+");
|
||||||
if(!fp)
|
if (!fp)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Write aliases */
|
/*
|
||||||
|
* Write aliases
|
||||||
|
*/
|
||||||
for (pa = charset_alias_list; pa; pa=pa->next) {
|
for (pa = charset_alias_list; pa; pa=pa->next) {
|
||||||
fputc(CHARSET_FILE_ALIAS, fp);
|
fputc(CHARSET_FILE_ALIAS, fp);
|
||||||
fwrite(pa, sizeof(CharsetAlias), 1, fp);
|
fwrite(pa, sizeof(CharsetAlias), 1, fp);
|
||||||
if(ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write tables */
|
/*
|
||||||
|
* Write tables
|
||||||
|
*/
|
||||||
for(pt = charset_table_list; pt; pt=pt->next) {
|
for(pt = charset_table_list; pt; pt=pt->next) {
|
||||||
fputc(CHARSET_FILE_TABLE, fp);
|
fputc(CHARSET_FILE_TABLE, fp);
|
||||||
fwrite(pt, sizeof(CharsetTable), 1, fp);
|
fwrite(pt, sizeof(CharsetTable), 1, fp);
|
||||||
if(ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -254,26 +252,23 @@ int charset_read_bin(void)
|
|||||||
}
|
}
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
while( (c = fgetc(fp)) != EOF ) {
|
while ((c = fgetc(fp)) != EOF) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case CHARSET_FILE_ALIAS:
|
case CHARSET_FILE_ALIAS: pa = charset_alias_new();
|
||||||
pa = charset_alias_new();
|
|
||||||
n = fread((void *)pa, sizeof(CharsetAlias), 1, fp);
|
n = fread((void *)pa, sizeof(CharsetAlias), 1, fp);
|
||||||
pa->next = NULL; /* overwritten by fread() */
|
pa->next = NULL; /* overwritten by fread() */
|
||||||
if(n != 1)
|
if (n != 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
Syslog('s', "read charset alias: %s -> %s", pa->alias, pa->name);
|
Syslog('s', "read charset alias: %s -> %s", pa->alias, pa->name);
|
||||||
break;
|
break;
|
||||||
case CHARSET_FILE_TABLE:
|
case CHARSET_FILE_TABLE: pt = charset_table_new();
|
||||||
pt = charset_table_new();
|
|
||||||
n = fread((void *)pt, sizeof(CharsetTable), 1, fp);
|
n = fread((void *)pt, sizeof(CharsetTable), 1, fp);
|
||||||
pt->next = NULL; /* overwritten by fread() */
|
pt->next = NULL; /* overwritten by fread() */
|
||||||
if(n != 1)
|
if (n != 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
Syslog('s', "read charset table: %s -> %s", pt->in, pt->out);
|
Syslog('s', "read charset table: %s -> %s", pt->in, pt->out);
|
||||||
break;
|
break;
|
||||||
default:
|
default: return FALSE;
|
||||||
return FALSE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,10 +290,9 @@ char *charset_qpen(int c, int qp)
|
|||||||
|
|
||||||
c &= 0xff;
|
c &= 0xff;
|
||||||
|
|
||||||
if( qp && (c == '=' || c >= 0x80) )
|
if (qp && (c == '=' || c >= 0x80))
|
||||||
str_printf(buf, sizeof(buf), "=%02.2X", c & 0xff);
|
str_printf(buf, sizeof(buf), "=%02.2X", c & 0xff);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
}
|
}
|
||||||
@ -319,14 +313,11 @@ char *charset_map_c(int c, int qp)
|
|||||||
c &= 0xff;
|
c &= 0xff;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
|
||||||
if(charset_table_used && c>=0x80)
|
if (charset_table_used && c>=0x80) {
|
||||||
{
|
|
||||||
s = charset_table_used->map[c - 0x80];
|
s = charset_table_used->map[c - 0x80];
|
||||||
while(*s)
|
while(*s)
|
||||||
BUF_APPEND(buf, charset_qpen(*s++, qp));
|
BUF_APPEND(buf, charset_qpen(*s++, qp));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BUF_COPY(buf, charset_qpen(c, qp));
|
BUF_COPY(buf, charset_qpen(c, qp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,10 +333,11 @@ char *charset_alias_fsc(char *name)
|
|||||||
{
|
{
|
||||||
CharsetAlias *pa;
|
CharsetAlias *pa;
|
||||||
|
|
||||||
/* Search for aliases */
|
/*
|
||||||
for(pa = charset_alias_list; pa; pa=pa->next)
|
* Search for aliases
|
||||||
{
|
*/
|
||||||
if(strieq(pa->name, name))
|
for (pa = charset_alias_list; pa; pa=pa->next) {
|
||||||
|
if (strcasecmp(pa->name, name) == 0)
|
||||||
return pa->alias;
|
return pa->alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,10 +350,11 @@ char *charset_alias_rfc(char *name)
|
|||||||
{
|
{
|
||||||
CharsetAlias *pa;
|
CharsetAlias *pa;
|
||||||
|
|
||||||
/* Search for aliases */
|
/*
|
||||||
for(pa = charset_alias_list; pa; pa=pa->next)
|
* Search for aliases
|
||||||
{
|
*/
|
||||||
if(strieq(pa->alias, name))
|
for (pa = charset_alias_list; pa; pa=pa->next) {
|
||||||
|
if (strcasecmp(pa->alias, name) == 0)
|
||||||
return pa->name;
|
return pa->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,16 +401,16 @@ int charset_set_in_out(char *in, char *out)
|
|||||||
|
|
||||||
/* Search for aliases */
|
/* Search for aliases */
|
||||||
for (pa = charset_alias_list; pa; pa=pa->next) {
|
for (pa = charset_alias_list; pa; pa=pa->next) {
|
||||||
if (strieq(pa->alias, in))
|
if (strcasecmp(pa->alias, in) == 0)
|
||||||
in = pa->name;
|
in = pa->name;
|
||||||
if (strieq(pa->alias, out))
|
if (strcasecmp(pa->alias, out) == 0)
|
||||||
out = pa->name;
|
out = pa->name;
|
||||||
}
|
}
|
||||||
Syslog('s', "charset3: in=%s out=%s", in, out);
|
Syslog('s', "charset3: in=%s out=%s", in, out);
|
||||||
|
|
||||||
/* Search for matching table */
|
/* Search for matching table */
|
||||||
for (pt = charset_table_list; pt; pt=pt->next) {
|
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);
|
Syslog('s', "charset: table found in=%s out=%s", pt->in, pt->out);
|
||||||
charset_table_used = pt;
|
charset_table_used = pt;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -61,29 +61,6 @@ static char *months[]= {(char *)"Jan",(char *)"Feb",(char *)"Mar",
|
|||||||
(char *)"Oct",(char *)"Nov",(char *)"Dec"};
|
(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
|
* Translate a string from ANSI to safe HTML characters
|
||||||
@ -93,19 +70,28 @@ char *To_Html(char *inp)
|
|||||||
{
|
{
|
||||||
static char temp[256];
|
static char temp[256];
|
||||||
int i;
|
int i;
|
||||||
|
char *xl;
|
||||||
|
|
||||||
memset(&temp, 0, sizeof(temp));
|
memset(&temp, 0, sizeof(temp));
|
||||||
strncpy(temp, inp, 80);
|
|
||||||
|
|
||||||
for (i = 0; i < strlen(temp); i++)
|
for (i = 0; i < strlen(inp); i++) {
|
||||||
temp[i] = htmltab[temp[i] & 0xff];
|
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;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void tidy_index(Findex **);
|
void tidy_index(Findex **);
|
||||||
void tidy_index(Findex **fap)
|
void tidy_index(Findex **fap)
|
||||||
{
|
{
|
||||||
@ -593,6 +579,11 @@ void HtmlIndex(char *Lang)
|
|||||||
fileptr = ftell(fi);
|
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++) {
|
for (i = 1; i <= iAreas; i++) {
|
||||||
|
|
||||||
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
|
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
|
||||||
|
Reference in New Issue
Block a user