Adjust existing functions to new tables

This commit is contained in:
Michiel Broek 2007-02-19 18:50:11 +00:00
parent c569a92b8d
commit ca06511fe9
3 changed files with 112 additions and 131 deletions

View File

@ -66,6 +66,7 @@ struct _charalias charalias[] = {
* search from rfc -> ftn, best ftn kludge should be on top. * search from rfc -> ftn, best ftn kludge should be on top.
*/ */
struct _charmap charmap[] = { struct _charmap charmap[] = {
{FTNC_NONE, (char *)"Undef", (char *)"iso-8859-1", (char *)"Undef", (char *)"ISO-8859-1", (char *)"C", (char *)"Undefined"},
{FTNC_LATIN_1,(char *)"LATIN-1 2",(char *)"iso-8859-1", (char *)"LATIN1", (char *)"ISO-8859-1", (char *)"en_US", (char *)"ISO 8859-1 (Western European)"}, {FTNC_LATIN_1,(char *)"LATIN-1 2",(char *)"iso-8859-1", (char *)"LATIN1", (char *)"ISO-8859-1", (char *)"en_US", (char *)"ISO 8859-1 (Western European)"},
{FTNC_CP437, (char *)"CP437 2", (char *)"iso-8859-1", (char *)"CP437", (char *)"ISO-8859-1", (char *)"en_US", (char *)"IBM codepage 437 (Western European) (ANSI terminal)"}, {FTNC_CP437, (char *)"CP437 2", (char *)"iso-8859-1", (char *)"CP437", (char *)"ISO-8859-1", (char *)"en_US", (char *)"IBM codepage 437 (Western European) (ANSI terminal)"},
{FTNC_CP865, (char *)"CP865 2", (char *)"iso-8859-1", (char *)"CP865", (char *)"ISO-8859-1", (char *)"sv_SE", (char *)"IBM codepage 865 (Nordic)"}, {FTNC_CP865, (char *)"CP865 2", (char *)"iso-8859-1", (char *)"CP865", (char *)"ISO-8859-1", (char *)"sv_SE", (char *)"IBM codepage 865 (Nordic)"},
@ -79,7 +80,7 @@ struct _charmap charmap[] = {
{FTNC_LATIN_9,(char *)"LATIN-9 2",(char *)"iso-8859-15",(char *)"LATIN9", (char *)"ISO-8859-15",(char *)"en_US", (char *)"ISO 8859-1 (Western European EURO)"}, {FTNC_LATIN_9,(char *)"LATIN-9 2",(char *)"iso-8859-15",(char *)"LATIN9", (char *)"ISO-8859-15",(char *)"en_US", (char *)"ISO 8859-1 (Western European EURO)"},
{FTNC_KOI8_R, (char *)"KOI8-R 2", (char *)"koi8-r", (char *)"KOI8-R", (char *)"KOI8-R", (char *)"ru_RUi.koi8r",(char *)"Unix codepage KOI8-R (Russian)"}, {FTNC_KOI8_R, (char *)"KOI8-R 2", (char *)"koi8-r", (char *)"KOI8-R", (char *)"KOI8-R", (char *)"ru_RUi.koi8r",(char *)"Unix codepage KOI8-R (Russian)"},
{FTNC_CP936, (char *)"CP936 2", (char *)"hz-gb-2312", (char *)"GB2312", (char *)"GB2312", (char *)"zh_CN.gbk", (char *)"IBM codepage 936 (Chinese, GBK)"}, {FTNC_CP936, (char *)"CP936 2", (char *)"hz-gb-2312", (char *)"GB2312", (char *)"GB2312", (char *)"zh_CN.gbk", (char *)"IBM codepage 936 (Chinese, GBK)"},
{FTNC_NONE, NULL, NULL, NULL, NULL, NULL, (char *)"ERROR"} {FTNC_ERROR, NULL, NULL, NULL, NULL, NULL, (char *)"ERROR"}
}; };
@ -107,6 +108,73 @@ static CharsetTable *charset_table_last = NULL;
static CharsetTable *charset_table_used = NULL; static CharsetTable *charset_table_used = NULL;
#endif
/*
* Returns index of charset or -1 if not found.
*/
int find_ftn_charset(char *ftnkludge)
{
static int i;
int j;
char *ftn, *cmp;
Syslog('n', "find_ftn_charset(%s)", ftnkludge);
ftn = calloc(80, sizeof(char));
cmp = calloc(80, sizeof(char));
snprintf(ftn, 80, "%s", ftnkludge);
for (i = 0; i < strlen(ftn); i++) {
if (ftn[i] == ' ') {
ftn[i] = '\0';
break;
}
}
for (i = 0; charalias[i].alias; i++) {
if (strcasecmp(ftn, charalias[i].alias) == 0)
break;
}
if (charalias[i].alias == NULL) {
Syslog('n', "no alias found");
} else {
Syslog('n', "found alias %s", charalias[i].ftnkludge);
snprintf(ftn, 80, "%s", charalias[i].ftnkludge);
}
/*
* Now search real entry
*/
for (i = 0; charmap[i].ftnkludge; i++) {
snprintf(cmp, 80, "%s", charmap[i].ftnkludge);
for (j = 0; j < strlen(cmp); j++) {
if (cmp[j] == ' ') {
cmp[j] = '\0';
break;
}
}
if (strcasecmp(ftn, cmp) == 0)
break;
}
free(ftn);
free(cmp);
if (charmap[i].ftnkludge == NULL) {
WriteError("find_ftn_charset(%s) not found", ftnkludge);
return -1;
}
Syslog('n', "get_rfc_charset(%s) result %d", ftnkludge, i);
return i;
}
#ifndef USE_EXPERIMENT
/* /*
@ -161,48 +229,37 @@ char *str_copy(char *d, size_t n, char *s)
#endif #endif
char *getftnchrs(int val) char *getftnchrs(int val)
{ {
switch (val) { int i;
case FTNC_NONE: return (char *)"Undefined"; static char kludge[20];
case FTNC_CP437: return (char *)"CP437 2";
case FTNC_CP850: return (char *)"CP850 2"; for (i = 0; (charmap[i].ftncidx != FTNC_ERROR); i++) {
case FTNC_CP865: return (char *)"CP865 2"; if (val == charmap[i].ftncidx) {
case FTNC_CP866: return (char *)"CP866 2"; snprintf(kludge, 20, "%s", charmap[i].ftnkludge);
case FTNC_CP852: return (char *)"CP852 2"; return kludge;
case FTNC_CP895: return (char *)"CP895 2"; }
case FTNC_LATIN_1: return (char *)"LATIN-1 2";
case FTNC_LATIN_2: return (char *)"LATIN-2 2";
case FTNC_LATIN_5: return (char *)"LATIN-5 2";
case FTNC_LATIN_9: return (char *)"LATIN-9 2";
case FTNC_MAC: return (char *)"MAC 2";
case FTNC_KOI8_R: return (char *)"KOI8-R 2";
case FTNC_CP936: return (char *)"CP936 2";
default: return (char *)"LATIN-1 2";
} }
return (char *)"LATIN-1 2";
} }
char *getrfcchrs(int val) char *getrfcchrs(int val)
{ {
switch (val) { int i;
case FTNC_NONE: return (char *)"iso-8859-1"; static char rfcname[20];
case FTNC_CP437: return (char *)"cp437";
case FTNC_CP850: return (char *)"cp850"; for (i = 0; (charmap[i].ftncidx != FTNC_ERROR); i++) {
case FTNC_CP865: return (char *)"cp865"; if (val == charmap[i].ftncidx) {
case FTNC_CP866: return (char *)"cp866"; snprintf(rfcname, 20, "%s", charmap[i].rfcname);
case FTNC_CP852: return (char *)"cp852"; return rfcname;
case FTNC_CP895: return (char *)"cp895"; }
case FTNC_LATIN_1: return (char *)"iso-8859-1";
case FTNC_LATIN_2: return (char *)"iso-8859-2";
case FTNC_LATIN_5: return (char *)"iso-8859-5";
case FTNC_LATIN_9: return (char *)"iso-8859-15";
case FTNC_MAC: return (char *)"Macintosh";
case FTNC_KOI8_R: return (char *)"koi8-r";
case FTNC_CP936: return (char *)"hz-gb-2312";
default: return (char *)"iso-8859-1";
} }
return (char *)"iso-8859-1";
} }
@ -219,45 +276,34 @@ char *getrfcchrs(int val)
*/ */
char *getlocale(int val) char *getlocale(int val)
{ {
switch (val) { int i;
case FTNC_NONE: return (char *)"C"; static char langc[20];
case FTNC_CP437: return (char *)"en_US";
case FTNC_CP850: return (char *)"en_US"; for (i = 0; (charmap[i].ftncidx != FTNC_ERROR); i++) {
case FTNC_CP865: return (char *)"sv_SE"; if (val == charmap[i].ftncidx) {
case FTNC_CP866: return (char *)"ru_RU"; snprintf(langc, 20, "%s", charmap[i].lang);
case FTNC_CP852: return (char *)"cs_CZ"; return langc;
case FTNC_CP895: return (char *)"cs_CZ"; }
case FTNC_LATIN_1: return (char *)"en_US";
case FTNC_LATIN_9: return (char *)"en_US";
case FTNC_LATIN_2: return (char *)"cs_CZ";
case FTNC_MAC: return (char *)"en_US";
case FTNC_KOI8_R: return (char *)"ru_RU.koi8r";
case FTNC_CP936: return (char *)"zh_CN.gbk";
default: return (char *)"C";
} }
return (char *)"C";
} }
char *getchrsdesc(int val) char *getchrsdesc(int val)
{ {
switch (val) { int i;
case FTNC_NONE: return (char *)"Undefined"; static char desc[60];
case FTNC_CP437: return (char *)"IBM codepage 437 (Western European) (ANSI terminal)";
case FTNC_CP850: return (char *)"IBM codepage 850 (Latin-1)"; for (i = 0; (charmap[i].ftncidx != FTNC_ERROR); i++) {
case FTNC_CP865: return (char *)"IBM codepage 865 (Nordic)"; if (val == charmap[i].ftncidx) {
case FTNC_CP866: return (char *)"IBM codepage 866 (Russian)"; snprintf(desc, 60, "%s", charmap[i].desc);
case FTNC_CP852: return (char *)"IBM codepage 852 (Czech, Latin-1)"; return desc;
case FTNC_CP895: return (char *)"IBM codepage 895 (Czech, Kamenicky)"; }
case FTNC_LATIN_1: return (char *)"ISO 8859-1 (Western European)";
case FTNC_LATIN_9: return (char *)"ISO 8859-1 (Western European EURO)";
case FTNC_LATIN_2: return (char *)"ISO 8859-2 (Eastern European)";
case FTNC_LATIN_5: return (char *)"ISO 8859-5 (Turkish)";
case FTNC_MAC: return (char *)"MacIntosh character set";
case FTNC_KOI8_R: return (char *)"Unix codepage KOI8-R (Russian)";
case FTNC_CP936: return (char *)"IBM codepage 936 (Chinese, GBK)";
default: return (char *)"ERROR";
} }
return (char *)"ERROR";
} }

View File

@ -431,6 +431,7 @@ struct icmp_filter {
* *
* Supported character sets, only level 2 are defined. * Supported character sets, only level 2 are defined.
*/ */
#define FTNC_ERROR -1 /* Error entry */
#define FTNC_NONE 0 /* Undefined */ #define FTNC_NONE 0 /* Undefined */
#define FTNC_CP437 1 /* IBM CP 437 (Western Europe) */ #define FTNC_CP437 1 /* IBM CP 437 (Western Europe) */
#define FTNC_CP850 2 /* IBM CP 850 (Latin-1) */ #define FTNC_CP850 2 /* IBM CP 850 (Latin-1) */
@ -448,7 +449,6 @@ struct icmp_filter {
#define FTNC_MAXCHARS 13 /* Highest charset number */ #define FTNC_MAXCHARS 13 /* Highest charset number */
extern struct _charalias { extern struct _charalias {
char *alias; char *alias;
char *ftnkludge; char *ftnkludge;
@ -2624,7 +2624,7 @@ typedef struct st_charset_table {
#endif #endif
int find_ftn_charset(char *); /* Return FTN charset index */
char *getftnchrs(int); /* Return FTN characterset name */ char *getftnchrs(int); /* Return FTN characterset name */
char *getrfcchrs(int); /* Return RFC characterset name */ char *getrfcchrs(int); /* Return RFC characterset name */
char *getlocale(int); /* Return locale name */ char *getlocale(int); /* Return locale name */

View File

@ -59,71 +59,6 @@ static CharsetTable *charset_table_list;
#define POST_MAXSIZE 10000 #define POST_MAXSIZE 10000
/*
* Returns index of charset or -1 if not found.
*/
int find_ftn_charset(char *ftnkludge)
{
static int i;
int j;
char *ftn, *cmp;
Syslog('n', "find_ftn_charset(%s)", ftnkludge);
ftn = calloc(80, sizeof(char));
cmp = calloc(80, sizeof(char));
snprintf(ftn, 80, "%s", ftnkludge);
for (i = 0; i < strlen(ftn); i++) {
if (ftn[i] == ' ') {
ftn[i] = '\0';
break;
}
}
for (i = 0; charalias[i].alias; i++) {
if (strcasecmp(ftn, charalias[i].alias) == 0)
break;
}
if (charalias[i].alias == NULL) {
Syslog('n', "no alias found");
} else {
Syslog('n', "found alias %s", charalias[i].ftnkludge);
snprintf(ftn, 80, "%s", charalias[i].ftnkludge);
}
/*
* Now search real entry
*/
for (i = 0; charmap[i].ftnkludge; i++) {
snprintf(cmp, 80, "%s", charmap[i].ftnkludge);
for (j = 0; j < strlen(cmp); j++) {
if (cmp[j] == ' ') {
cmp[j] = '\0';
break;
}
}
if (strcasecmp(ftn, cmp) == 0)
break;
}
free(ftn);
free(cmp);
if (charmap[i].ftnkludge == NULL) {
WriteError("find_ftn_charset(%s) not found", ftnkludge);
return -1;
}
Syslog('n', "get_rfc_charset(%s) result %d", ftnkludge, i);
return i;
}
/* /*
* Safe sending to the client with charset translation. * Safe sending to the client with charset translation.
*/ */