add remtask before addtask
[AROS.git] / rom / filesys / fat / charset.c
blob6293426f5176910acd576fa2abff92350c197f08
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 "fat_fs.h"
10 #include "charset.h"
12 #undef DOSBase
14 static ULONG readLine(struct Library *DOSBase, BPTR fh, char *buf, ULONG size)
16 char *c;
18 if((c = FGets(fh, buf, size)) == NULL)
19 return FALSE;
21 for(; *c; c++)
23 if(*c == '\n' || *c == '\r')
25 *c = '\0';
26 break;
30 return TRUE;
33 void InitCharsetTables(struct Globals *glob)
35 int i;
37 for (i = 0; i < 65536; i++)
38 if (i < 256) {
39 glob->from_unicode[i] = i;
40 glob->to_unicode[i] = i;
41 } else
42 glob->from_unicode[i] = '_';
45 // Reads a coding table
46 BOOL ReadUnicodeTable(struct Globals *glob, STRPTR name)
48 BPTR fh;
49 struct Library *DOSBase;
51 if (!(DOSBase = OpenLibrary("dos.library", 0)))
52 return FALSE;
54 fh = Open(name, MODE_OLDFILE);
55 if (fh)
57 int i, n;
58 char buf[512];
60 while(readLine(DOSBase, fh, buf, 512*sizeof(char)))
62 if(!isdigit(*buf))
63 continue;
64 else
66 char *p = buf;
67 int fmt2 = 0;
69 if((*p=='=') || (fmt2 = ((*p=='0') || (*(p+1)=='x'))))
71 p++;
72 p += fmt2;
74 i = strtol((const char *)p,(char **)&p,16);
75 if(i>=0 && i<256)
77 while(isspace(*p)) p++;
79 if(!strnicmp(p, "U+", 2))
81 p += 2;
82 n = strtol((const char *)p,(char **)&p,16);
84 else
86 if(*p!='#')
87 n = strtol((const char *)p,(char **)&p,0);
88 else
89 n = -1;
91 if (n >= 0 && n < 65536) {
92 glob->from_unicode[n] = i;
93 glob->to_unicode[i] = n;
99 Close(fh);
102 CloseLibrary(DOSBase);
104 return fh ? TRUE : FALSE;