revert between 56095 -> 55830 in arch
[AROS.git] / workbench / fs / ntfs / charset.c
blob982fd46e18e1f450b24b58fbccf7a37134b6304b
1 #include <dos/dosextens.h>
2 #include <dos/dostags.h>
3 #include <proto/dos.h>
4 #include <proto/exec.h>
5 #include <ctype.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include "ntfs_fs.h"
10 #include "charset.h"
12 static ULONG readLine(BPTR fh, char *buf, ULONG size)
14 char *c;
16 if((c = FGets(fh, buf, size)) == NULL)
17 return FALSE;
19 for(; *c; c++)
21 if(*c == '\n' || *c == '\r')
23 *c = '\0';
24 break;
28 return TRUE;
31 void InitCharsetTables(void)
33 int i;
35 for (i = 0; i < 65536; i++)
36 if (i < 256) {
37 glob->from_unicode[i] = i;
38 glob->to_unicode[i] = i;
39 } else
40 glob->from_unicode[i] = '_';
43 // Reads a coding table
44 BOOL ReadUnicodeTable(STRPTR name)
46 BPTR fh;
48 fh = Open(name, MODE_OLDFILE);
49 if (fh)
51 int i, n;
52 char buf[512];
54 while(readLine(fh, buf, 512*sizeof(char)))
56 if(!isdigit(*buf))
57 continue;
58 else
60 char *p = buf;
61 int fmt2 = 0;
63 if((*p=='=') || (fmt2 = ((*p=='0') || (*(p+1)=='x'))))
65 p++;
66 p += fmt2;
68 i = strtol((const char *)p,(char **)&p,16);
69 if(i>=0 && i<256)
71 while(isspace(*p)) p++;
73 if(!strnicmp(p, "U+", 2))
75 p += 2;
76 n = strtol((const char *)p,(char **)&p,16);
78 else
80 if(*p!='#')
81 n = strtol((const char *)p,(char **)&p,0);
82 else
83 n = -1;
85 if (n >= 0 && n < 65536) {
86 glob->from_unicode[n] = i;
87 glob->to_unicode[i] = n;
93 Close(fh);
95 return fh ? TRUE : FALSE;