Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
LCONV.cpp
Go to the documentation of this file.
1// checking for struct lconv in <locale.h>
2
3
25#include <locale.h> // for lconv
26#include <stddef.h> // for offsetof, size_t
27#include <stdio.h> // for printf
28#include <string.h> // for strlen
29
30#include "config.h"
31
32#ifndef _RWSTD_NO_OFFSETOF
33# define OFF(T, m) offsetof (T, m)
34#else
35 // provide own equivalent when offsetof() macro doesn't work
36 // (e.g., when using the EDG eccp front end with an incompatible
37 // version of gcc)
38# define OFF(T, m) (((const char*)&((T*)0)->m) - ((const char*)(T*)0))
39#endif // _RWSTD_NO_OFFSETOF
40
41// prevent IBM xlC 5.0 errors caused by using /usr/include/string.h
42// which #defines this (and other) names to undeclared symbols
43#undef strlen
44
45int main ()
46{
47 struct {
48 size_t offset;
49 size_t size;
50 const char *type;
51 const char *name;
52 const char *comment;
53 } lconv_info[] = {
54
55#define ENTRY(type, member, comment) { \
56 OFF (lconv, member), \
57 sizeof ((lconv*)0)->member, \
58 type, \
59 # member, \
60 "/* " comment " */" \
61 }
62
63 // C90 and POSIX.1 members
64 ENTRY ("char*", decimal_point, ""),
65 ENTRY ("char*", thousands_sep, ""),
66 ENTRY ("char*", grouping, ""),
67 ENTRY ("char*", int_curr_symbol, ""),
68 ENTRY ("char*", currency_symbol, ""),
69 ENTRY ("char*", mon_decimal_point, ""),
70 ENTRY ("char*", mon_thousands_sep, ""),
71 ENTRY ("char*", mon_grouping, ""),
72 ENTRY ("char*", positive_sign, ""),
73 ENTRY ("char*", negative_sign, ""),
74 ENTRY ("char", int_frac_digits, ""),
75 ENTRY ("char", frac_digits, ""),
76 ENTRY ("char", p_cs_precedes, ""),
77 ENTRY ("char", p_sep_by_space, ""),
78 ENTRY ("char", n_cs_precedes, ""),
79 ENTRY ("char", n_sep_by_space, ""),
80 ENTRY ("char", p_sign_posn, ""),
81 ENTRY ("char", n_sign_posn, "")
82
83#ifndef _RWSTD_NO_LCONV_INT_FMAT
84
85 // C99 and POSIX.2 members
86 , ENTRY ("char", int_p_cs_precedes, ""),
87 ENTRY ("char", int_n_cs_precedes, ""),
88 ENTRY ("char", int_p_sep_by_space, ""),
89 ENTRY ("char", int_n_sep_by_space, ""),
90 ENTRY ("char", int_p_sign_posn, ""),
91 ENTRY ("char", int_n_sign_posn, "")
92
93#endif // _RWSTD_NO_LCONV_INT_FMAT
94
95 };
96
97 const size_t N = sizeof lconv_info / sizeof *lconv_info;
98
99 char def [4096] = "";
100
101 size_t curoff = 0; // current offset
102 size_t size = 0; // cumulative size
103
104 for (size_t i = 0; i != N; ++i) {
105
106 for (size_t j = 0; j != N; ++j) {
107
108 if (curoff == lconv_info [j].offset) {
109
110 sprintf (def + strlen (def),
111 " %s %s; \\\n",
112 lconv_info [j].type,
113 lconv_info [j].name);
114
115 // invalidate offset
116 lconv_info [j].offset = size_t (-1);
117 curoff += lconv_info [j].size;
118 size += lconv_info [j].size;
119
120 break;
121 }
122 }
123 }
124
125 printf ("#define _RWSTD_LCONV { "
126 "/* sizeof (lconv) == %u */ \\\n%s",
127 sizeof (lconv), def);
128
129
130 if (size != sizeof (lconv)) {
131 printf (" char _C_fill [%u]; /* fill to size */ \\\n",
132 sizeof (lconv) - size);
133 }
134
135 printf (" }\n");
136
137 return 0;
138}
139
#define N
Definition 17.names.cpp:157
#define i
Definition 17.names.cpp:126
#define j
Definition 17.names.cpp:127
#define offset
Definition 17.names.cpp:508
IMPORT_C SInt32 printf(const Char *,...)
#define ENTRY(type, member, comment)
int main()
Definition LCONV.cpp:45
const char * name
Definition codecvt1.cpp:72