1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
/*
* langinfo.c - parameter interface to langinfo via curses
*
* This file is part of zsh, the Z shell.
*
* Copyright (c) 2002 Peter Stephenson, Clint Adams
* All rights reserved.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and to distribute modified versions of this software for any
* purpose, provided that the above copyright notice and the following
* two paragraphs appear in all copies of this software.
*
* In no event shall Peter Stephenson, Clint Adams or the Zsh Development Group
* be liable to any party for direct, indirect, special, incidental, or
* consequential damages arising out of the use of this software and its
* documentation, even if Sven Wishnowsky, Clint Adams and the Zsh
* Development Group have been advised of the possibility of such damage.
*
* Peter Stephenson, Clint Adams and the Zsh Development Group specifically
* disclaim any warranties, including, but not limited to, the implied
* warranties of merchantability and fitness for a particular purpose.
* The software provided hereunder is on an "as is" basis, and Peter
* Stephenson, Clint Adams and the Zsh Development Group have no obligation
* to provide maintenance, support, updates, enhancements, or modifications.
*
*/
#include "langinfo.mdh"
#include "langinfo.pro"
static char langinfo_nam[] = "langinfo";
#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif
static Param langinfo_pm;
/**/
#ifdef HAVE_NL_LANGINFO
static char *nl_names[] = {
#ifdef CODESET
"CODESET",
#endif /* CODESET */
#ifdef D_T_FMT
"D_T_FMT",
#endif /* D_T_FMT */
#ifdef D_FMT
"D_FMT",
#endif /* D_FMT */
#ifdef T_FMT
"T_FMT",
#endif /* T_FMT */
#ifdef RADIXCHAR
"RADIXCHAR",
#endif /* RADIXCHAR */
#ifdef THOUSEP
"THOUSEP",
#endif /* THOUSEP */
#ifdef YESEXPR
"YESEXPR",
#endif /* YESEXPR */
#ifdef NOEXPR
"NOEXPR",
#endif /* NOEXPR */
#ifdef CRNCYSTR
"CRNCYSTR",
#endif /* CRNCYSTR */
#ifdef ABDAY_1
"ABDAY_1",
#endif /* ABDAY_1 */
#ifdef ABDAY_2
"ABDAY_2",
#endif /* ABDAY_2 */
#ifdef ABDAY_3
"ABDAY_3",
#endif /* ABDAY_3 */
#ifdef ABDAY_4
"ABDAY_4",
#endif /* ABDAY_4 */
#ifdef ABDAY_5
"ABDAY_5",
#endif /* ABDAY_5 */
#ifdef ABDAY_6
"ABDAY_6",
#endif /* ABDAY_6 */
#ifdef ABDAY_7
"ABDAY_7",
#endif /* ABDAY_7 */
#ifdef DAY_1
"DAY_1",
#endif /* DAY_1 */
#ifdef DAY_2
"DAY_2",
#endif /* DAY_2 */
#ifdef DAY_3
"DAY_3",
#endif /* DAY_3 */
#ifdef DAY_4
"DAY_4",
#endif /* DAY_4 */
#ifdef DAY_5
"DAY_5",
#endif /* DAY_5 */
#ifdef DAY_6
"DAY_6",
#endif /* DAY_6 */
#ifdef DAY_7
"DAY_7",
#endif /* DAY_7 */
#ifdef ABMON_1
"ABMON_1",
#endif /* ABMON_1 */
#ifdef ABMON_2
"ABMON_2",
#endif /* ABMON_2 */
#ifdef ABMON_3
"ABMON_3",
#endif /* ABMON_3 */
#ifdef ABMON_4
"ABMON_4",
#endif /* ABMON_4 */
#ifdef ABMON_5
"ABMON_5",
#endif /* ABMON_5 */
#ifdef ABMON_6
"ABMON_6",
#endif /* ABMON_6 */
#ifdef ABMON_7
"ABMON_7",
#endif /* ABMON_7 */
#ifdef ABMON_8
"ABMON_8",
#endif /* ABMON_8 */
#ifdef ABMON_9
"ABMON_9",
#endif /* ABMON_9 */
#ifdef ABMON_10
"ABMON_10",
#endif /* ABMON_10 */
#ifdef ABMON_11
"ABMON_11",
#endif /* ABMON_11 */
#ifdef ABMON_12
"ABMON_12",
#endif /* ABMON_12 */
#ifdef MON_1
"MON_1",
#endif /* MON_1 */
#ifdef MON_2
"MON_2",
#endif /* MON_2 */
#ifdef MON_3
"MON_3",
#endif /* MON_3 */
#ifdef MON_4
"MON_4",
#endif /* MON_4 */
#ifdef MON_5
"MON_5",
#endif /* MON_5 */
#ifdef MON_6
"MON_6",
#endif /* MON_6 */
#ifdef MON_7
"MON_7",
#endif /* MON_7 */
#ifdef MON_8
"MON_8",
#endif /* MON_8 */
#ifdef MON_9
"MON_9",
#endif /* MON_9 */
#ifdef MON_10
"MON_10",
#endif /* MON_10 */
#ifdef MON_11
"MON_11",
#endif /* MON_11 */
#ifdef MON_12
"MON_12",
#endif /* MON_12 */
#ifdef T_FMT_AMPM
"T_FMT_AMPM",
#endif /* T_FMT_AMPM */
#ifdef AM_STR
"AM_STR",
#endif /* AM_STR */
#ifdef PM_STR
"PM_STR",
#endif /* PM_STR */
#ifdef ERA
"ERA",
#endif /* ERA */
#ifdef ERA_D_FMT
"ERA_D_FMT",
#endif /* ERA_D_FMT */
#ifdef ERA_D_T_FMT
"ERA_D_T_FMT",
#endif /* ERA_D_T_FMT */
#ifdef ERA_T_FMT
"ERA_T_FMT",
#endif /* ERA_T_FMT */
#ifdef ALT_DIGITS
"ALT_DIGITS",
#endif /* ALT_DIGITS */
NULL
};
static nl_item nl_vals[] = {
#ifdef CODESET
CODESET,
#endif /* CODESET */
#ifdef D_T_FMT
D_T_FMT,
#endif /* D_T_FMT */
#ifdef D_FMT
D_FMT,
#endif /* D_FMT */
#ifdef T_FMT
T_FMT,
#endif /* T_FMT */
#ifdef RADIXCHAR
RADIXCHAR,
#endif /* RADIXCHAR */
#ifdef THOUSEP
THOUSEP,
#endif /* THOUSEP */
#ifdef YESEXPR
YESEXPR,
#endif /* YESEXPR */
#ifdef NOEXPR
NOEXPR,
#endif /* NOEXPR */
#ifdef CRNCYSTR
CRNCYSTR,
#endif /* CRNCYSTR */
#ifdef ABDAY_1
ABDAY_1,
#endif /* ABDAY_1 */
#ifdef ABDAY_2
ABDAY_2,
#endif /* ABDAY_2 */
#ifdef ABDAY_3
ABDAY_3,
#endif /* ABDAY_3 */
#ifdef ABDAY_4
ABDAY_4,
#endif /* ABDAY_4 */
#ifdef ABDAY_5
ABDAY_5,
#endif /* ABDAY_5 */
#ifdef ABDAY_6
ABDAY_6,
#endif /* ABDAY_6 */
#ifdef ABDAY_7
ABDAY_7,
#endif /* ABDAY_7 */
#ifdef DAY_1
DAY_1,
#endif /* DAY_1 */
#ifdef DAY_2
DAY_2,
#endif /* DAY_2 */
#ifdef DAY_3
DAY_3,
#endif /* DAY_3 */
#ifdef DAY_4
DAY_4,
#endif /* DAY_4 */
#ifdef DAY_5
DAY_5,
#endif /* DAY_5 */
#ifdef DAY_6
DAY_6,
#endif /* DAY_6 */
#ifdef DAY_7
DAY_7,
#endif /* DAY_7 */
#ifdef ABMON_1
ABMON_1,
#endif /* ABMON_1 */
#ifdef ABMON_2
ABMON_2,
#endif /* ABMON_2 */
#ifdef ABMON_3
ABMON_3,
#endif /* ABMON_3 */
#ifdef ABMON_4
ABMON_4,
#endif /* ABMON_4 */
#ifdef ABMON_5
ABMON_5,
#endif /* ABMON_5 */
#ifdef ABMON_6
ABMON_6,
#endif /* ABMON_6 */
#ifdef ABMON_7
ABMON_7,
#endif /* ABMON_7 */
#ifdef ABMON_8
ABMON_8,
#endif /* ABMON_8 */
#ifdef ABMON_9
ABMON_9,
#endif /* ABMON_9 */
#ifdef ABMON_10
ABMON_10,
#endif /* ABMON_10 */
#ifdef ABMON_11
ABMON_11,
#endif /* ABMON_11 */
#ifdef ABMON_12
ABMON_12,
#endif /* ABMON_12 */
#ifdef MON_1
MON_1,
#endif /* MON_1 */
#ifdef MON_2
MON_2,
#endif /* MON_2 */
#ifdef MON_3
MON_3,
#endif /* MON_3 */
#ifdef MON_4
MON_4,
#endif /* MON_4 */
#ifdef MON_5
MON_5,
#endif /* MON_5 */
#ifdef MON_6
MON_6,
#endif /* MON_6 */
#ifdef MON_7
MON_7,
#endif /* MON_7 */
#ifdef MON_8
MON_8,
#endif /* MON_8 */
#ifdef MON_9
MON_9,
#endif /* MON_9 */
#ifdef MON_10
MON_10,
#endif /* MON_10 */
#ifdef MON_11
MON_11,
#endif /* MON_11 */
#ifdef MON_12
MON_12,
#endif /* MON_12 */
#ifdef T_FMT_AMPM
T_FMT_AMPM,
#endif /* T_FMT_AMPM */
#ifdef AM_STR
AM_STR,
#endif /* AM_STR */
#ifdef PM_STR
PM_STR,
#endif /* PM_STR */
#ifdef ERA
ERA,
#endif /* ERA */
#ifdef ERA_D_FMT
ERA_D_FMT,
#endif /* ERA_D_FMT */
#ifdef ERA_D_T_FMT
ERA_D_T_FMT,
#endif /* ERA_D_T_FMT */
#ifdef ERA_T_FMT
ERA_T_FMT,
#endif /* ERA_T_FMT */
#ifdef ALT_DIGITS
ALT_DIGITS,
#endif /* ALT_DIGITS */
0
};
static nl_item *
liitem(char *name)
{
char **element;
nl_item *nlcode;
nlcode = &nl_vals[0];
for (element = (char **)nl_names; *element; element++, nlcode++) {
if ((!strcmp(*element, name)))
return nlcode;
}
return NULL;
}
/**/
static void
shempty(void)
{
}
/* Create a simple special hash parameter. */
/**/
static Param
createlihash()
{
Param pm;
HashTable ht;
unsetparam(langinfo_nam);
if (!(pm = createparam(langinfo_nam, PM_SPECIAL|PM_HIDE|PM_HIDEVAL|
PM_REMOVABLE|PM_HASHED)))
return NULL;
pm->level = pm->old ? locallevel : 0;
pm->gsu.h = &stdhash_gsu;
pm->u.hash = ht = newhashtable(7, langinfo_nam, NULL);
ht->hash = hasher;
ht->emptytable = (TableFunc) shempty;
ht->filltable = NULL;
ht->addnode = (AddNodeFunc) shempty;
ht->getnode = ht->getnode2 = getlanginfo;
ht->removenode = (RemoveNodeFunc) shempty;
ht->disablenode = NULL;
ht->enablenode = NULL;
ht->freenode = (FreeNodeFunc) shempty;
ht->printnode = printparamnode;
ht->scantab = scanlanginfo;
return (langinfo_pm = pm);
}
/**/
static HashNode
getlanginfo(UNUSED(HashTable ht), char *name)
{
int len, *elem;
char *listr;
Param pm = NULL;
unmetafy(name, &len);
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name);
pm->node.flags = PM_READONLY | PM_SCALAR;
pm->gsu.s = &nullsetscalar_gsu;
if(name)
elem = liitem(name);
else
elem = NULL;
if (elem && (listr = nl_langinfo(*elem))) {
pm->u.str = dupstring(listr);
}
else
{
/* zwarn("no such lang info: %s", name); */
pm->u.str = dupstring("");
pm->node.flags |= PM_UNSET;
}
return &pm->node;
}
/**/
static void
scanlanginfo(UNUSED(HashTable ht), ScanFunc func, int flags)
{
Param pm = NULL;
char **element, *langstr;
nl_item *nlcode;
pm = (Param) hcalloc(sizeof(struct param));
pm->gsu.s = &nullsetscalar_gsu;
pm->node.flags = PM_READONLY | PM_SCALAR;
nlcode = &nl_vals[0];
for (element = (char **)nl_names; *element; element++, nlcode++) {
if ((langstr = nl_langinfo(*nlcode)) != NULL) {
pm->u.str = dupstring(langstr);
pm->node.nam = dupstring(*element);
func(&pm->node, flags);
}
}
}
/**/
#endif /* HAVE_NL_LANGINFO */
/**/
int
setup_(UNUSED(Module m))
{
return 0;
}
/**/
int
boot_(UNUSED(Module m))
{
#ifdef HAVE_NL_LANGINFO
if (!createlihash())
return 1;
#else
unsetparam(langinfo_nam);
#endif
return 0;
}
/**/
int
cleanup_(UNUSED(Module m))
{
#ifdef HAVE_NL_LANGINFO
Param pm;
if ((pm = (Param) paramtab->getnode(paramtab, langinfo_nam)) &&
pm == langinfo_pm) {
pm->node.flags &= ~PM_READONLY;
unsetparam_pm(pm, 0, 1);
}
#endif
return 0;
}
/**/
int
finish_(UNUSED(Module m))
{
return 0;
}
|