From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/lib/charcnv.c | 204 +++++++++++++++++++++++++++++++------------------- 1 file changed, 129 insertions(+), 75 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 29ef72d7ac..8f91e4573a 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -23,7 +23,7 @@ #define CTRLZ 26 extern int DEBUGLEVEL; -static char cvtbuf[1024]; +static char cvtbuf[sizeof(pstring)]; static BOOL mapsinited = 0; @@ -39,7 +39,7 @@ static void initmaps(void) { mapsinited = True; } -static void update_map(char * str) { +static void update_map(char *str) { char *p; for (p = str; *p; p++) { @@ -51,47 +51,55 @@ static void update_map(char * str) { } } -static void init_iso8859_1(void) { - +static void setupmaps(void) +{ int i; if (!mapsinited) initmaps(); /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) + for (i = 128; i < 256; i++) { unix2dos[i] = CTRLZ; dos2unix[i] = CTRLZ; } +} -/* MSDOS Code Page 850 -> ISO-8859 */ -update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); -update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); -update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); -update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); -update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); -update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); -update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); -update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); -update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); -update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); -update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); -update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); +static void init_iso8859_1(int codepage) { + setupmaps(); + + if (codepage == 437) { + /* MSDOS Code Page 437 -> ISO-8859-1 */ + update_map("\xA1\xAD\xA2\x98\xA3\x9C\xA4\xED\xA5\x9D\xA6\xB3\xA7\xEE"); + update_map("\xAA\xA6\xAB\xAE\xAC\xAA\xAE\xE9\xAF\xC4"); + update_map("\xB0\xF8\xB1\xF1\xB2\xFD\xB5\xE6\xB7\xFA\xBA\xA7\xBC\xAC\xBD\xAB\xBF\xA8"); + update_map("\xC0\x85\xC1\xA0\xC2\x83\xC4\x8E\xC5\x8F\xC6\x92\xC7\x80\xC8\x8A"); + update_map("\xC9\x90\xCA\x88\xCB\x89\xCC\x8D\xCD\xA1\xCE\x8C\xCF\x8B"); + update_map("\xD1\xA5\xD2\x96\xD3\xA2\xD4\x93\xD6\x99\xD9\x97\xDA\xA3\xDB\x96\xDC\x9A\xDF\xE1"); + update_map("\xE0\x85\xE1\xA0\xE2\x83\xE4\x84\xE5\x86\xE6\x91\xE7\x87\xE8\x8A\xE9\x82\xEA\x88\xEB\x89\xEC\x8D\xED\xA1\xEE\x8C\xEF\x8B"); + update_map("\xF0\xEB\xF1\xA4\xF2\x95\xF3\xA2\xF4\x93\xF6\x94\xF7\xF6\xF8\xED\xF9\x97\xFA\xA3\xFB\x96\xFC\x81\xFF\x98"); + } else { + /* MSDOS Code Page 850 -> ISO-8859-1 */ + update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365"); + update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356"); + update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372"); + update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250"); + update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200"); + update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330"); + update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236"); + update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341"); + update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207"); + update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213"); + update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366"); + update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230"); + } } /* Init for eastern european languages. */ static void init_iso8859_2(void) { - int i; - if (!mapsinited) initmaps(); - - /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) - { - unix2dos[i] = CTRLZ; - dos2unix[i] = CTRLZ; - } + setupmaps(); /* * Tranlation table created by Petr Hubeny @@ -120,36 +128,48 @@ update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372"); static void init_iso8859_5(void) { - int i; - if (!mapsinited) initmaps(); - - /* Do not map undefined characters to some accidental code */ - for (i = 128; i < 256; i++) - { - unix2dos[i] = CTRLZ; - dos2unix[i] = CTRLZ; - } + setupmaps(); /* MSDOS Code Page 866 -> ISO8859-5 */ -update_map("\200\260\201\261\202\262\203\263\204\264\205\265\206\266\207\267"); -update_map("\210\270\211\271\212\272\213\273\214\274\215\275\216\276\217\277"); -update_map("\220\300\221\301\222\302\223\303\224\304\225\305\226\306\227\307"); -update_map("\230\310\231\311\232\312\233\313\234\314\235\315\236\316\237\317"); -update_map("\240\320\241\321\242\322\243\323\244\324\245\325\246\326\247\327"); -update_map("\250\330\251\331\252\332\253\333\254\334\255\335\256\336\257\337"); +update_map("\260\200\261\201\262\202\263\203\264\204\265\205\266\206\267\207"); +update_map("\270\210\271\211\272\212\273\213\274\214\275\215\276\216\277\217"); +update_map("\300\220\301\221\302\222\303\223\304\224\305\225\306\226\307\227"); +update_map("\310\230\311\231\312\232\313\233\314\234\315\235\316\236\317\237"); +update_map("\320\240\321\241\322\242\323\243\324\244\325\245\326\246\327\247"); +update_map("\330\250\331\251\332\252\333\253\334\254\335\255\336\256\337\257"); update_map("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347"); update_map("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357"); -update_map("\360\241\361\361\362\244\363\364\364\247\365\367\366\256\367\376"); -update_map("\374\360\377\240"); +update_map("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367"); +update_map("\360\374\240\377"); +} + +/* Added by Antonios Kavarnos (Antonios.Kavarnos@softlab.ece.ntua.gr */ + +static void init_iso8859_7(void) +{ + setupmaps(); + +/* MSDOS Code Page 737 -> ISO-8859-7 (Greek-Hellenic) */ + +update_map("\301\200\302\201\303\202\304\203\305\204\306\205\307\206"); +update_map("\310\207\311\210\312\211\313\212\314\213\315\214\316\215\317\216"); +update_map("\320\217\321\220\323\221\324\222\325\223\326\224\327\225"); +update_map("\330\226\331\227"); +update_map("\341\230\342\231\343\232\344\233\345\234\346\235\347\236"); +update_map("\350\237\351\240\352\241\353\242\354\243\355\244\356\245\357\246"); +update_map("\360\247\361\250\362\252\363\251\364\253\365\254\366\255\367\256"); +update_map("\370\257\371\340"); +update_map("\332\364\333\365\334\341\335\342\336\343\337\345"); +update_map("\372\344\373\350\374\346\375\347\376\351"); +update_map("\266\352"); +update_map("\270\353\271\354\272\355\274\356\276\357\277\360"); } /* Init for russian language (koi8) */ static void init_koi8_r(void) { - if (!mapsinited) initmaps(); - - /* There aren't undefined characters between 128 and 255 */ + setupmaps(); /* MSDOS Code Page 866 -> KOI8-R */ update_map("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264"); @@ -170,24 +190,49 @@ update_map("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202"); update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232"); } + +/* Init for ROMAN-8 (HP-UX) */ + +static void init_roman8(void) { + + setupmaps(); + +/* MSDOS Code Page 850 -> ROMAN8 */ +update_map("\240\377\241\267\242\266\243\324\244\322\245\323\246\327\247\330"); +update_map("\250\357\253\371\255\353\256\352\257\234"); +update_map("\260\356\261\355\262\354\263\370\264\200\265\207\266\245\267\244"); +update_map("\270\255\271\250\272\317\273\234\274\276\275\365\276\237\277\275"); +update_map("\300\203\301\210\302\223\303\226\304\240\305\202\306\242\307\243"); +update_map("\310\205\311\212\312\225\313\227\314\204\315\211\316\224\317\201"); +update_map("\320\217\321\214\322\235\323\222\324\206\325\241\326\233\327\221"); +update_map("\330\216\331\215\332\231\333\232\334\220\335\213\336\341\337\342"); +update_map("\340\265\341\307\342\306\343\321\344\320\345\326\346\336\347\340"); +update_map("\350\343\351\345\352\344\355\351\357\230"); +update_map("\360\350\361\347\362\372\363\346\364\364\365\363\366\360\367\254"); +update_map("\370\253\371\246\372\247\373\256\374\376\375\257\376\361"); +} + /* * Convert unix to dos */ char *unix2dos_format(char *str,BOOL overwrite) { - char *p; - char *dp; - - if (!mapsinited) initmaps(); - - if (overwrite) { - for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + char *p; + char *dp; + + if (!mapsinited) + initmaps(); + + if (overwrite) { + for (p = str; *p; p++) + *p = unix2dos[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) + *dp = unix2dos[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } /* @@ -195,36 +240,45 @@ char *unix2dos_format(char *str,BOOL overwrite) */ char *dos2unix_format(char *str, BOOL overwrite) { - char *p; - char *dp; - - if (!mapsinited) initmaps(); - - if (overwrite) { - for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; - return str; - } else { - for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p]; - *dp = 0; - return cvtbuf; - } + char *p; + char *dp; + + if (!mapsinited) + initmaps(); + + if (overwrite) { + for (p = str; *p; p++) + *p = dos2unix[(unsigned char)*p]; + return str; + } else { + for (p = str, dp = cvtbuf;*p && (dp - cvtbuf < sizeof(cvtbuf) - 1); p++,dp++) + *dp = dos2unix[(unsigned char)*p]; + *dp = 0; + return cvtbuf; + } } /* * Interpret character set. */ -void interpret_character_set(char *str) +void interpret_character_set(char *str, int codepage) { if (strequal (str, "iso8859-1")) { - init_iso8859_1(); + init_iso8859_1(codepage); } else if (strequal (str, "iso8859-2")) { init_iso8859_2(); } else if (strequal (str, "iso8859-5")) { init_iso8859_5(); + } else if (strequal (str, "iso8859-7")) { + init_iso8859_7(); } else if (strequal (str, "koi8-r")) { init_koi8_r(); + } else if (strequal (str, "roman8")) { + init_roman8(); } else { DEBUG(0,("unrecognized character set %s\n", str)); } + + load_unix_unicode_map(str); } -- cgit