Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
unicode.h
Go to the documentation of this file.
1 //
2 // Project: Lhogho
3 // File: unicode.h
4 //
5 // Copyright (C) 2007 P.Boytchev
6 //
7 // Revision history:
8 // 2006-10-08 - file created
9 // 2006-10-11 - UNICODE macro
10 // STRLEN,STRNCPY,SPRINTF,PUTCHAR,FILENAME macros
11 // STR,NULL_CHAR macros
12 // extern to ASCII_to_ASCII()
13 // SPACE, TAB macros
14 // 2006-10-17 - CHR macro
15 // 2006-10-26 - FORMAT_ERR
16 // 2007-02-25 - split FORMAT_ERR to FORMAT_ERR_CODE
17 // and FORMAT_ERR_POS
18 // 2007-02-27 - module renamed to UNICODE
19 // - TEXT()
20 // 2007-05-17 - license info
21 // 2007-05-22 - doxygen-friendly documentation
22 // 2007-05-26 - FORMAT_ERR_TEXT macro
23 // - CLONE macro
24 // 2007-06-02 - UNFILENAME macro
25 // 2007-06-06 - definitions spread to where they belong
26 // 2007-06-25 - STRTOD macro
27 // 2007-06-30 - fixed bug #1745627 Option -Zm does not show memory (all Linuxes)
28 // - fixed bug #1745786 -Zm option does not work in Cygwin
29 // 2007-09-14 - added TOUPPER and TOLOWER
30 // 2007-10-28 - added ISDIGIT and STRCHR
31 // 2009-06-02 - added GETCHAR
32 // 2012-01-23 - added STRFTIME
33 //
34 //
35 // This program is free software; you can redistribute it and/or modify
36 // it under the terms of the GNU General Public License as published by
37 // the Free Software Foundation; either version 2 of the License, or
38 // (at your option) any later version.
39 //
40 // This program is distributed in the hope that it will be useful,
41 // but WITHOUT ANY WARRANTY; without even the implied warranty of
42 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 // GNU General Public License for more details.
44 //
45 // You should have received a copy of the GNU General Public License
46 // along with this program; if not, write to the Free Software
47 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
48 //
49 
50 
51 #ifndef LHOGHO_UNICODE_H
52 #define LHOGHO_UNICODE_H
53 
54 
55 #include "globals.h"
56 #include "atoms.h"
57 #include <string.h>
58 #include <ctype.h>
59 #include <stdio.h>
60 #ifdef UNICODE_CHARS
61  #include <wchar.h>
62 #endif
63 
64 
65 
66 
67 //===================================================
72 //===================================================
73 #ifdef UNICODE_CHARS
74  #define TEXT(a) L##a
75  #define FILENAME(x) UTF16_to_ASCII(x)
76  #define UNFILENAME(x) ASCII_to_UTF16(x)
77 #else
78  #define TEXT(a) a
79  #define FILENAME(x) (x)
80  #define UNFILENAME(x) ASCII_to_ASCII(x)
81 #endif
82 
83 
84 
85 
86 //===================================================
88 //===================================================
89 #define NULL_CHAR TEXT('\0')
90 #ifdef UNICODE_CHARS
91  #define STR "%S"
92  #define CHR "%C"
93 #else
94  #define STR "%s"
95  #define CHR "%c"
96 #endif //UNICODE_CHARS
97 
98 
99 
100 
101 //===================================================
107 //===================================================
108 #ifdef UNICODE_CHARS
109  #define NO_MORE WEOF
110  #define PUTCHAR(x,y) putwc(x,y)
111  #define GETCHAR(x) getwc(x)
112  #define STRLEN(x) wcslen(x)
113  #define STRNCPY(x,y,z) wcsncpy(x,y,z)
114 //#define STRNCMP(x,y,z) wcsncmp(x,y,z)
115  #define STRCMP(x,y) wcscmp(x,y)
116  #define STRTOD(x,y) wcstod(x,y)
117  #define STRTOL(x,y) wcstoll(x,y,0)
118  #define TOUPPER(x) towupper(x)
119  #define TOLOWER(x) towlower(x)
120  #define ISDIGIT(x) iswdigit(x)
121  #define STRCHR(x,y) wcschr(x,y)
122  #define PRINT(x,...) printf(x,__VA_ARGS__)
123  #define STRFTIME(x,y,z,t) wcsftime(x,y,z,t)
124  #ifdef WINDOWS
125  #define SPRINTF(x,n,y,z) swprintf(x,y,z)
126  #define SPRINT(x,n,y,...) swprintf(x,y,__VA_ARGS__)
127  #else
128  #define SPRINTF(x,n,y,z) swprintf(x,n,y,z)
129  #define SPRINT(x,n,y,...) swprintf(x,n,y,__VA_ARGS__)
130  #endif
131 #else
132  #define NO_MORE EOF
133  #define STRFTIME(x,y,z,t) strftime(x,y,z,t)
134  #define PRINT(x,...) printf(x,__VA_ARGS__)
135  #define PUTCHAR(x,y) putc(x,y)
136  #define GETCHAR(x) getc(x)
137  #define STRLEN(x) strlen(x)
138  #define TOUPPER(x) toupper(x)
139  #define TOLOWER(x) tolower(x)
140  #define STRCHR(x,y) strchr(x,y)
141  #define ISDIGIT(x) isdigit(x)
142  #define STRNCPY(x,y,z) strncpy(x,y,z)
143 // #define STRNCMP(x,y,z) strncmp(x,y,z)
144  #define STRCMP(x,y) strcmp(x,y)
145  #define STRTOD(x,y) strtod(x,y)
146  #define STRTOL(x,y) strtoll(x,y,0)
147 // #define USTRNCMP(x,y,z) strncasecmp(x,y,z)
148 #ifdef WINDOWS
149  #define SPRINTF(x,n,y,z) _snprintf(x,n,y,z)
150 #else
151  #define SPRINTF(x,n,y,z) snprintf(x,n,y,z)
152 #endif
153  #define SPRINT(x,n,y,...) snprintf(x,n,y,__VA_ARGS__)
154 #endif //UNICODE_CHARS
155 
156 
157 //===================================================
159 //===================================================
160 #ifdef UNICODE_CHARS
161 extern chars_t UTF8_to_UTF16 ( byte_t* source );
162 extern byte_t* UTF16_to_UTF8 (chars_t source );
163 extern char* UTF16_to_ASCII ( chars_t ws );
164 extern chars_t ASCII_to_UTF16 (const char* s);
165 #ifdef LINUX
166 extern long long int wcstoll (__const wchar_t *__restrict __nptr,
167  wchar_t **__restrict __endptr, int __base);
168 extern int swprintf (wchar_t *__restrict __s, size_t __n,
169  __const wchar_t *__restrict __format, ...);
170 extern size_t wcslen (__const wchar_t *__s) __THROW __attribute_pure__;
171 extern int fwide (__FILE *__fp, int __mode) __THROW;
172 extern int wprintf (__const wchar_t *__restrict __format, ...);
173 extern int wcsncmp (__const wchar_t *__s1, __const wchar_t *__s2, size_t __n)
174  __THROW __attribute_pure__;
175 extern int wcsncasecmp (__const wchar_t *__s1, __const wchar_t *__s2,
176  size_t __n) __THROW;
177 extern wchar_t *wcsncpy (wchar_t *__restrict __dest,
178  __const wchar_t *__restrict __src, size_t __n)
179  __THROW;
180 #endif //LINUX
181 #endif //UNICODE_CHARS
182 
183 extern chars_t ASCII_to_ASCII ( const char* s );
184 extern void* load_file( chars_t wfilename, int* filesize );
185 
186 
187 #endif //LHOGHO_UNICODE_H

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013