config/make.tmpl: pass -nix flag also to LDFLAGS of configure
[AROS.git] / rom / filesys / fat / charset.c
bloba7b7060310fd0344a29156f7da2993a451e9d3b2
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dosextens.h>
7 #include <dos/dostags.h>
8 #include <proto/dos.h>
9 #include <proto/exec.h>
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include <string.h>
14 #include "fat_fs.h"
15 #include "charset.h"
17 #undef DOSBase
19 static ULONG readLine(struct Library *DOSBase, BPTR fh, char *buf,
20 ULONG size)
22 char *c;
24 if ((c = FGets(fh, buf, size)) == NULL)
25 return FALSE;
27 for (; *c; c++)
29 if (*c == '\n' || *c == '\r')
31 *c = '\0';
32 break;
36 return TRUE;
39 void InitCharsetTables(struct Globals *glob)
41 int i;
43 for (i = 0; i < 65536; i++)
44 if (i < 256)
46 glob->from_unicode[i] = i;
47 glob->to_unicode[i] = i;
49 else
50 glob->from_unicode[i] = '_';
53 // Reads a coding table
54 BOOL ReadUnicodeTable(struct Globals *glob, STRPTR name)
56 BPTR fh;
57 struct Library *DOSBase;
59 if (!(DOSBase = OpenLibrary("dos.library", 0)))
60 return FALSE;
62 fh = Open(name, MODE_OLDFILE);
63 if (fh)
65 int i, n;
66 char buf[512];
68 while (readLine(DOSBase, fh, buf, 512 * sizeof(char)))
70 if (!isdigit(*buf))
71 continue;
72 else
74 char *p = buf;
75 int fmt2 = 0;
77 if ((*p == '=') || (fmt2 = ((*p == '0')
78 || (*(p + 1) == 'x'))))
80 p++;
81 p += fmt2;
83 i = strtol((const char *)p, (char **)&p, 16);
84 if (i >= 0 && i < 256)
86 while (isspace(*p))
87 p++;
89 if (!strnicmp(p, "U+", 2))
91 p += 2;
92 n = strtol((const char *)p, (char **)&p, 16);
94 else
96 if (*p != '#')
97 n = strtol((const char *)p, (char **)&p, 0);
98 else
99 n = -1;
101 if (n >= 0 && n < 65536)
103 glob->from_unicode[n] = i;
104 glob->to_unicode[i] = n;
110 Close(fh);
113 CloseLibrary(DOSBase);
115 return fh ? TRUE : FALSE;