ReactOS 0.4.15-dev-8348-gc1b9bb5
sic_nls.c File Reference
#include <schily/mconfig.h>
#include <schily/stdio.h>
#include <schily/stdlib.h>
#include <schily/string.h>
#include <schily/libport.h>
#include <schily/unistd.h>
#include <schily/schily.h>
#include <schily/dirent.h>
#include <schily/siconv.h>
Include dependency graph for sic_nls.c:

Go to the source code of this file.

Macros

#define TAB_SIZE   (UINT8_MAX+1)
 
#define __CAN_TAB_SIZE__
 

Functions

LOCAL siconvt_t *insert_sic __PR ((siconvt_t *sip))
 
EXPORT siconvt_t *sic_open __PR ((char *name))
 
EXPORT const char *sic_base __PR ((void))
 
EXPORT int sic_list __PR ((FILE *f))
 
LOCAL void freetbl __PR ((UInt8_t **uni2cs))
 
LOCAL siconvt_tinsert_sic (siconvt_t *sip)
 
LOCAL int remove_sic (siconvt_t *sip)
 
EXPORT siconvt_tsic_open (char *charset)
 
EXPORT const charsic_base ()
 
EXPORT int sic_close (siconvt_t *sip)
 
EXPORT int sic_list (FILE *f)
 
LOCAL void freetbl (UInt8_t **uni2cs)
 
LOCAL FILEpfopen (char *name)
 
LOCAL siconvt_tcreate_sic (char *name)
 

Variables

static UConst char sccsid []
 
LOCAL UInt8_t nullpage [TAB_SIZE] = { 0 }
 
LOCAL charins_base
 
LOCAL siconvt_tglist = (siconvt_t *) NULL
 

Macro Definition Documentation

◆ __CAN_TAB_SIZE__

#define __CAN_TAB_SIZE__

Definition at line 41 of file sic_nls.c.

◆ TAB_SIZE

#define TAB_SIZE   (UINT8_MAX+1)

Definition at line 40 of file sic_nls.c.

Function Documentation

◆ __PR() [1/5]

EXPORT siconvt_t *sic_open __PR ( (char *name )

◆ __PR() [2/5]

EXPORT int sic_list __PR ( (FILE *f )

◆ __PR() [3/5]

LOCAL siconvt_t *insert_sic __PR ( (siconvt_t *sip)  )

◆ __PR() [4/5]

LOCAL void freetbl __PR ( (UInt8_t **uni2cs)  )

◆ __PR() [5/5]

EXPORT const char *sic_base __PR ( (void )

◆ create_sic()

LOCAL siconvt_t * create_sic ( char name)

Definition at line 312 of file sic_nls.c.

314{
315 UInt16_t *cs2uni = NULL;
316 UInt8_t **uni2cs = NULL;
317 siconvt_t *sip;
318 char line[1024];
319 FILE *f;
320 unsigned ch;
321 unsigned uni;
322 int i;
323 int numtrans = 0;
324
325 if (name == NULL || *name == '\0')
326 return ((siconvt_t *)NULL);
327
328#ifdef USE_ICONV
329 /*
330 * Explicitly search for an iconv based translation
331 */
332 if (strncmp("iconv:", name, 6) == 0) {
333 return (create_iconv_sic(name));
334 }
335#else
336 if (strncmp("iconv:", name, 6) == 0) {
337 return ((siconvt_t *)NULL);
338 }
339#endif
340
341 if ((f = pfopen(name)) == (FILE *)NULL) {
342 if (strcmp(name, "default") == 0) {
343 if ((cs2uni = (UInt16_t *)
344 malloc(sizeof (UInt16_t) * TAB_SIZE)) == NULL) {
345 return ((siconvt_t *)NULL);
346 }
347 /*
348 * Set up a 1:1 translation table like ISO-8859-1
349 */
350 for (i = 0; i < TAB_SIZE; i++)
351 cs2uni[i] = i;
352 goto do_reverse;
353 }
354#ifdef USE_ICONV
355 return (create_iconv_sic(name));
356#else
357 return ((siconvt_t *)NULL);
358#endif
359 }
360
361 if ((cs2uni = (UInt16_t *)
362 malloc(sizeof (UInt16_t) * TAB_SIZE)) == NULL) {
363 fclose(f);
364 return ((siconvt_t *)NULL);
365 }
366
367 /*
368 * Set up mapping base.
369 * Always map the control characters 0x00 .. 0x1F
370 */
371 for (i = 0; i < 32; i++)
372 cs2uni[i] = i;
373
374 for (i = 32; i < TAB_SIZE; i++)
375 cs2uni[i] = '\0'; /* nul marks an illegal character */
376
377 cs2uni[0x7f] = 0x7F; /* Always map DELETE character 0x7F */
378
379 while (fgets(line, sizeof (line), f) != NULL) {
380 char *p;
381
382 if ((p = strchr(line, '#')) != NULL)
383 *p = '\0';
384
385 if (sscanf(line, "%x%x", &ch, &uni) == 2) {
386 /*
387 * Only accept exactly two values in the right range.
388 */
389 if (ch > 0xFF || uni > 0xFFFF)
390 continue;
391
392 cs2uni[ch] = uni; /* Set up unicode translation */
393 numtrans++;
394 }
395 }
396 fclose(f);
397
398 if (numtrans == 0) { /* No valid translations found */
399 free(cs2uni);
400 return ((siconvt_t *)NULL);
401 }
402
403do_reverse:
404 if ((uni2cs = (UInt8_t **)
405 malloc(sizeof (unsigned char *) * TAB_SIZE)) == NULL) {
406 free(cs2uni);
407 return ((siconvt_t *)NULL);
408 }
409 for (i = 0; i < TAB_SIZE; i++) /* Map all pages to the nullpage */
410 uni2cs[i] = nullpage;
411
412 /*
413 * Create a reversed table from the forward table read from the file.
414 */
415 for (i = 0; i < TAB_SIZE; i++) {
416 UInt8_t high;
417 UInt8_t low;
418 UInt8_t *page;
419
420 uni = cs2uni[i];
421 high = (uni >> 8) & 0xFF;
422 low = uni & 0xFF;
423 page = uni2cs[high];
424
425 if (page == nullpage) {
426 int j;
427
428 /*
429 * Do not write to the nullpage but replace it by
430 * new and specific memory.
431 */
432 if ((page = (UInt8_t *) malloc(TAB_SIZE)) == NULL) {
433 free(cs2uni);
434 freetbl(uni2cs);
435 return ((siconvt_t *)NULL);
436 }
437 for (j = 0; j < TAB_SIZE; j++)
438 page[j] = '\0';
439 uni2cs[high] = page;
440 }
441 page[low] = i; /* Set up the reverse translation */
442 }
443
444 if ((sip = (siconvt_t *)malloc(sizeof (siconvt_t))) == NULL) {
445 free(cs2uni);
446 freetbl(uni2cs);
447 return ((siconvt_t *)NULL);
448 }
449
450 sip->sic_name = strdup(name);
451 sip->sic_uni2cs = uni2cs;
452 sip->sic_cs2uni = cs2uni;
453 sip->sic_cd2uni = NULL;
454 sip->sic_uni2cd = NULL;
455 sip->sic_alt = NULL;
456 sip->sic_next = NULL;
457 sip->sic_refcnt = 1;
458
459 return (insert_sic(sip));
460}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
GLfloat f
Definition: glext.h:7540
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define f
Definition: ke_i.h:83
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
LOCAL siconvt_t * insert_sic(siconvt_t *sip)
Definition: sic_nls.c:98
LOCAL FILE * pfopen(char *name)
Definition: sic_nls.c:286
LOCAL UInt8_t nullpage[TAB_SIZE]
Definition: sic_nls.c:72
LOCAL void freetbl(UInt8_t **uni2cs)
Definition: sic_nls.c:268
#define TAB_SIZE
Definition: sic_nls.c:40
Definition: parser.c:49
Definition: name.c:39
Definition: module.h:576
iconv_t sic_cd2uni
Definition: siconv.h:42
char * sic_name
Definition: siconv.h:39
UInt8_t ** sic_uni2cs
Definition: siconv.h:41
siconvt_t * sic_alt
Definition: siconv.h:44
siconvt_t * sic_next
Definition: siconv.h:45
UInt16_t * sic_cs2uni
Definition: siconv.h:40
int sic_refcnt
Definition: siconv.h:46
iconv_t sic_uni2cd
Definition: siconv.h:43
unsigned char UInt8_t
Definition: stdint.h:322

Referenced by sic_open().

◆ freetbl()

LOCAL void freetbl ( UInt8_t **  uni2cs)

Definition at line 268 of file sic_nls.c.

270{
271 int i;
272
273 for (i = 0; i < TAB_SIZE; i++) {
274 if (uni2cs[i] != nullpage) {
275 free(uni2cs[i]);
276 }
277 }
278 free(uni2cs);
279}

Referenced by create_sic(), and sic_close().

◆ insert_sic()

LOCAL siconvt_t * insert_sic ( siconvt_t sip)

Definition at line 98 of file sic_nls.c.

100{
101 siconvt_t **sp = &glist;
102
103 if (sip == (siconvt_t *)NULL) /* No table arg */
104 return ((siconvt_t *)NULL);
105 if (sip->sic_next) /* Already in list */
106 return (sip);
107
108 while (*sp) {
109 if (sip == *sp) { /* Already in list */
110 return (sip);
111 }
112 sp = &(*sp)->sic_next;
113 }
114 sip->sic_next = glist;
115 glist = sip;
116 return (sip);
117}
static const WCHAR sp[]
Definition: suminfo.c:287
LOCAL siconvt_t * glist
Definition: sic_nls.c:92

Referenced by create_sic().

◆ pfopen()

LOCAL FILE * pfopen ( char name)

Definition at line 286 of file sic_nls.c.

288{
289 char path[1024];
290 char *p;
291
292 if (strchr(name, '/'))
293 return (fopen(name, "r"));
294
295 if (ins_base == NULL)
296 (void) sic_base();
297
298 p = ins_base;
299 if (p != NULL) {
300 snprintf(path, sizeof (path), "%s%s", p, name);
301 return (fopen(path, "r"));
302 }
303 snprintf(path, sizeof (path), "%s/lib/siconv/%s", INS_BASE, name);
304 return (fopen(path, "r"));
305}
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
LOCAL char * ins_base
Definition: sic_nls.c:73
EXPORT const char * sic_base()
Definition: sic_nls.c:186
#define snprintf
Definition: wintirpc.h:48

Referenced by create_sic().

◆ remove_sic()

LOCAL int remove_sic ( siconvt_t sip)

Definition at line 123 of file sic_nls.c.

125{
126 siconvt_t **sp = &glist;
127
128 while (*sp) {
129#ifdef USE_ICONV
130 if (strcmp(sip->sic_name, (*sp)->sic_name) == 0) {
131 siconvt_t *sap = *sp;
132
133 if (sip == *sp) {
134 *sp = sip->sic_next;
135 return (0);
136 }
137 while (sap->sic_alt != NULL) {
138 if (sap->sic_alt == sip) {
139 sap->sic_alt = sip->sic_alt;
140 sip->sic_name = NULL; /* No free() */
141 return (0);
142 }
143 sap = sap->sic_alt;
144 }
145 }
146#endif
147 if (sip == *sp) {
148 *sp = sip->sic_next;
149 return (0);
150 }
151 sp = &(*sp)->sic_next;
152 }
153 return (-1);
154}

Referenced by sic_close().

◆ sic_base()

EXPORT const char * sic_base ( )

Definition at line 186 of file sic_nls.c.

187{
188 if (ins_base == NULL) {
189 ins_base = searchfileinpath("lib/siconv/iso8859-1", R_OK,
191 if (ins_base != NULL) {
192 int len = strlen(ins_base);
193
194 ins_base[len - 9] = '\0';
195 }
196 }
197 return (ins_base);
198}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLsizei len
Definition: glext.h:6722
#define SIP_PLAIN_FILE
Definition: schily.h:429
#define R_OK
Definition: io.h:171
EXPORT char * searchfileinpath(char *name, int mode, int file_mode, char *path)
Definition: searchinpath.c:68

Referenced by list_locales(), pfopen(), and sic_list().

◆ sic_close()

EXPORT int sic_close ( siconvt_t sip)

Definition at line 204 of file sic_nls.c.

206{
207 if (remove_sic(sip) < 0)
208 return (-1);
209
210 if (--sip->sic_refcnt > 0)
211 return (0);
212
213 if (sip->sic_name)
214 free(sip->sic_name);
215 if (sip->sic_uni2cs)
216 freetbl(sip->sic_uni2cs);
217 if (sip->sic_cs2uni)
218 free(sip->sic_cs2uni);
219#ifdef USE_ICONV
220 if (sip->sic_cd2uni)
222 if (sip->sic_uni2cd)
224#endif
225
226 return (0);
227}
int iconv_close(iconv_t cd)
Definition: win_iconv.c:756
LOCAL int remove_sic(siconvt_t *sip)
Definition: sic_nls.c:123

◆ sic_list()

EXPORT int sic_list ( FILE f)

Definition at line 233 of file sic_nls.c.

235{
236 char path[1024];
237 DIR *d;
238 struct dirent *dp;
239 int i = 0;
240
241 if (ins_base == NULL)
242 (void) sic_base();
243
244 if (ins_base != NULL)
245 snprintf(path, sizeof (path), "%s", ins_base);
246 else
247 snprintf(path, sizeof (path), "%s/lib/siconv/", INS_BASE);
248 if ((d = opendir(path)) == NULL)
249 return (-1);
250
251 while ((dp = readdir(d)) != NULL) {
252 if (dp->d_name[0] == '.') {
253 if (dp->d_name[1] == '\0')
254 continue;
255 if (dp->d_name[1] == '.' && dp->d_name[2] == '\0')
256 continue;
257 }
258 fprintf(f, "%s\n", dp->d_name);
259 i++;
260 }
261 return (i);
262}
DIR *__cdecl opendir(const char *)
struct dirent *__cdecl readdir(DIR *)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define d
Definition: ke_i.h:81
Definition: dirent.h:40
Definition: fatfs.h:198
char * d_name
Definition: dirent.h:29

Referenced by list_locales().

◆ sic_open()

EXPORT siconvt_t * sic_open ( char charset)

Definition at line 160 of file sic_nls.c.

162{
163 siconvt_t *sip = glist;
164
165 if (charset == NULL || *charset == '\0')
166 return ((siconvt_t *)NULL);
167
168 while (sip) {
169 if (strcmp(sip->sic_name, charset) == 0) {
170#ifdef USE_ICONV
171 if (sip->sic_cd2uni != 0)
172 return (dup_iconv_sic(sip));
173#endif
174 sip->sic_refcnt++;
175 return (sip);
176 }
177 sip = sip->sic_next;
178 }
179 return (create_sic(charset));
180}
CFF_Charset charset
Definition: cffcmap.c:138
LOCAL siconvt_t * create_sic(char *name)
Definition: sic_nls.c:312

Referenced by main().

Variable Documentation

◆ glist

◆ ins_base

LOCAL char* ins_base

Definition at line 73 of file sic_nls.c.

Referenced by list_locales(), pfopen(), sic_base(), and sic_list().

◆ nullpage

LOCAL UInt8_t nullpage[TAB_SIZE] = { 0 }

Definition at line 72 of file sic_nls.c.

Referenced by create_sic(), and freetbl().

◆ sccsid

UConst char sccsid[]
static
Initial value:
=
"@(#)sic_nls.c 1.18 14/01/15 Copyright 2007-2014 J. Schilling"

Definition at line 4 of file sic_nls.c.