patch to fix NetServerEnum with multiple workgroup lists kindly supplied.
[Samba.git] / source / lib / charcnv.c
blobd9ee551d6a815aecd808fc61dfeeca5f07837559
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Character set conversion Extensions
5 Copyright (C) Andrew Tridgell 1992-1994
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 extern int DEBUGLEVEL;
25 static char cvtbuf[1024];
27 static mapsinited = 0;
29 static char unix2dos[256];
30 static char dos2unix[256];
32 static void initmaps() {
33 int k;
35 for (k = 0; k < 256; k++) unix2dos[k] = k;
36 for (k = 0; k < 256; k++) dos2unix[k] = k;
38 mapsinited = 1;
41 static void update_map(char * str) {
42 char *p;
44 for (p = str; *p; p++) {
45 if (p[1]) {
46 unix2dos[(unsigned char)*p] = p[1];
47 dos2unix[(unsigned char)p[1]] = *p;
48 p++;
53 static void initiso() {
55 if (!mapsinited) initmaps();
57 update_map("\241\255\242\233\243\234\244\236\245\235\246\272\247\025\250\251");
58 update_map("\251\273\252\246\253\256\254\252\255\274\256\310\257\257\260\370");
59 update_map("\261\361\262\375\263\264\264\265\265\266\266\024\267\371\270\267");
60 update_map("\271\270\272\247\273\275\274\254\275\253\276\276\277\250\200\277");
61 update_map("\301\300\302\301\303\302\304\216\305\217\306\222\307\200\310\303");
62 update_map("\311\220\312\305\313\306\314\307\315\315\316\317\317\320\320\311");
63 update_map("\321\245\322\321\323\322\324\323\325\324\326\231\327\312\330\325");
64 update_map("\331\326\332\327\333\330\334\232\335\313\336\314\337\341\340\205");
65 update_map("\341\240\342\203\343\331\344\204\345\206\346\221\347\207\350\212");
66 update_map("\351\202\352\210\353\211\354\215\355\241\356\214\357\213\360\316");
67 update_map("\361\244\362\225\363\242\364\223\365\332\366\224\367\366\370\362");
68 update_map("\371\227\372\243\373\226\374\201\375\304\376\263\377\230");
72 * Convert unix to dos
74 char *unix2dos_format(char *str,BOOL overwrite)
76 char *p;
77 char *dp;
79 if (!mapsinited) initmaps();
80 if (overwrite) {
81 for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p];
82 return str;
83 } else {
84 for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = unix2dos[(unsigned char)*p];
85 *dp = 0;
86 return cvtbuf;
91 * Convert dos to unix
93 char *dos2unix_format(char *str, BOOL overwrite)
95 char *p;
96 char *dp;
98 if (!mapsinited) initmaps();
99 if (overwrite) {
100 for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p];
101 return str;
102 } else {
103 for (p = str, dp = cvtbuf; *p; p++,dp++) *dp = dos2unix[(unsigned char)*p];
104 *dp = 0;
105 return cvtbuf;
111 * Interpret character set.
113 int interpret_character_set(char *str, int def)
116 if (strequal (str, "iso8859-1")) {
117 initiso();
118 return def;
119 } else {
120 DEBUG(0,("unrecognized character set\n"));
122 return def;