Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / features / limits.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: limits.c /main/2 1996/05/08 19:42:11 drk $ */
24 /***************************************************************
25 *                                                              *
26 *                      AT&T - PROPRIETARY                      *
27 *                                                              *
28 *         THIS IS PROPRIETARY SOURCE CODE LICENSED BY          *
29 *                          AT&T CORP.                          *
30 *                                                              *
31 *                Copyright (c) 1995 AT&T Corp.                 *
32 *                     All Rights Reserved                      *
33 *                                                              *
34 *           This software is licensed by AT&T Corp.            *
35 *       under the terms and conditions of the license in       *
36 *       http://www.research.att.com/orgs/ssr/book/reuse        *
37 *                                                              *
38 *               This software was created by the               *
39 *           Software Engineering Research Department           *
40 *                    AT&T Bell Laboratories                    *
41 *                                                              *
42 *               For further information contact                *
43 *                     gsf@research.att.com                     *
44 *                                                              *
45 ***************************************************************/
46
47 /* : : generated by proto : : */
48
49 #if !defined(__PROTO__)
50 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
51 #if defined(__cplusplus)
52 #define __MANGLE__      "C"
53 #else
54 #define __MANGLE__
55 #endif
56 #define __STDARG__
57 #define __PROTO__(x)    x
58 #define __OTORP__(x)
59 #define __PARAM__(n,o)  n
60 #if !defined(__STDC__) && !defined(__cplusplus)
61 #if !defined(c_plusplus)
62 #define const
63 #endif
64 #define signed
65 #define void            int
66 #define volatile
67 #define __V_            char
68 #else
69 #define __V_            void
70 #endif
71 #else
72 #define __PROTO__(x)    ()
73 #define __OTORP__(x)    x
74 #define __PARAM__(n,o)  o
75 #define __MANGLE__
76 #define __V_            char
77 #define const
78 #define signed
79 #define void            int
80 #define volatile
81 #endif
82 #if defined(__cplusplus) || defined(c_plusplus)
83 #define __VARARG__      ...
84 #else
85 #define __VARARG__
86 #endif
87 #if defined(__STDARG__)
88 #define __VA_START__(p,a)       va_start(p,a)
89 #else
90 #define __VA_START__(p,a)       va_start(p)
91 #endif
92 #endif
93 #if defined(__STDPP__directive) && defined(__STDPP__hide)
94 __STDPP__directive pragma pp:hide printf
95 #else
96 #define printf          ______printf
97 #endif
98
99 #ifndef _POSIX_SOURCE
100 #define _POSIX_SOURCE   1
101 #endif
102
103 #include <sys/types.h>
104
105 #include "FEATURE/lib"
106 #include "FEATURE/limits.lcl"
107 #include "FEATURE/unistd.lcl"
108 #include "FEATURE/param"
109 #include "FEATURE/types"
110
111 #if defined(__STDPP__directive) && defined(__STDPP__hide)
112 __STDPP__directive pragma pp:nohide printf
113 #endif
114
115 #if defined(__STDPP__hide) || defined(printf)
116 #undef  printf
117 extern __MANGLE__ int           printf __PROTO__((const char*, ...));
118 #endif
119
120 #include "conflib.h"
121
122 main()
123 {
124         register int    i;
125         register int    n;
126
127         char            c;
128         unsigned char   uc;
129         unsigned short  us;
130         unsigned int    ui;
131         unsigned long   ul;
132         unsigned long   val;
133
134         /*
135          * <limits.h> with *constant* valued macros
136          */
137
138         printf("\n");
139 #ifdef CHAR_BIT
140         val = CHAR_BIT;
141         printf("#undef  CHAR_BIT\n");
142 #else
143         uc = 0;
144         uc = ~uc;
145         val = 1;
146         while (uc >>= 1) val++;
147 #endif
148         printf("#define CHAR_BIT        %lu\n", val);
149 #ifdef MB_LEN_MAX
150         val = MB_LEN_MAX;
151         printf("#undef  MB_LEN_MAX\n");
152 #else
153         val = 1;
154 #endif
155         printf("#define MB_LEN_MAX      %lu\n", val);
156
157         c = 0;
158         c = ~c;
159         uc = 0;
160         uc = ~uc;
161         us = 0;
162         us = ~us;
163         ui = 0;
164         ui = ~ui;
165         ul = 0;
166         ul = ~ul;
167
168 #ifdef UCHAR_MAX
169         val = UCHAR_MAX;
170         printf("#undef  UCHAR_MAX\n");
171 #else
172         val = uc;
173 #endif
174         printf("#if defined(__STDC__)\n");
175         printf("#define UCHAR_MAX       %luU\n", val);
176         printf("#else\n");
177         printf("#define UCHAR_MAX       %lu\n", val);
178         printf("#endif\n");
179
180 #ifdef SCHAR_MIN
181         val = -(SCHAR_MIN);
182         printf("#undef  SCHAR_MIN\n");
183 #else
184         val = (unsigned char)(uc >> 1) + 1;
185 #endif
186         printf("#define SCHAR_MIN       -%lu\n", val);
187
188 #ifdef SCHAR_MAX
189         val = SCHAR_MAX;
190         printf("#undef  SCHAR_MAX\n");
191 #else
192         val = (unsigned char)(uc >> 1);
193 #endif
194         printf("#define SCHAR_MAX       %lu\n", val);
195
196         if (c < 0)
197         {
198 #ifdef CHAR_MIN
199                 printf("#undef  CHAR_MIN\n");
200 #endif
201                 printf("#define CHAR_MIN        SCHAR_MIN\n");
202
203 #ifdef CHAR_MAX
204                 printf("#undef  CHAR_MAX\n");
205 #endif
206                 printf("#define CHAR_MAX        SCHAR_MAX\n");
207         }
208         else
209         {
210 #ifdef CHAR_MIN
211                 printf("#undef  CHAR_MIN\n");
212 #endif
213                 printf("#define CHAR_MIN        0\n");
214
215 #ifdef CHAR_MAX
216                 printf("#undef  CHAR_MAX\n");
217 #endif
218                 printf("#define CHAR_MAX        UCHAR_MAX\n");
219         }
220
221 #ifdef USHRT_MAX
222         val = USHRT_MAX;
223         printf("#undef  USHRT_MAX\n");
224 #else
225         val = us;
226 #endif
227         printf("#if defined(__STDC__)\n");
228         printf("#define USHRT_MAX       %luU\n", val);
229         printf("#else\n");
230         printf("#define USHRT_MAX       %lu\n", val);
231         printf("#endif\n");
232
233 #ifdef SHRT_MIN
234         val = -(SHRT_MIN);
235         printf("#undef  SHRT_MIN\n");
236 #else
237         val = (unsigned short)(us >> 1) + 1;
238 #endif
239         printf("#define SHRT_MIN        -%lu\n", val);
240
241 #ifdef SHRT_MAX
242         val = SHRT_MAX;
243         printf("#undef  SHRT_MAX\n");
244 #else
245         val = (unsigned short)(us >> 1);
246 #endif
247         printf("#define SHRT_MAX        %lu\n", val);
248
249         if (ui == us)
250         {
251 #ifdef UINT_MAX
252                 printf("#undef  UINT_MAX\n");
253 #endif
254                 printf("#define UINT_MAX        USHRT_MAX\n");
255
256 #ifdef INT_MIN
257                 printf("#undef  INT_MIN\n");
258 #endif
259                 printf("#define INT_MIN         SHRT_MIN\n");
260
261 #ifdef INT_MAX
262                 printf("#undef  INT_MAX\n");
263 #endif
264                 printf("#define INT_MAX         SHRT_MAX\n");
265         }
266         else
267         {
268 #ifdef UINT_MAX
269                 val = UINT_MAX;
270                 printf("#undef  UINT_MAX\n");
271 #else
272                 val = ui;
273 #endif
274                 printf("#if defined(__STDC__)\n");
275                 printf("#define UINT_MAX        %luU\n", val);
276                 printf("#else\n");
277                 printf("#define UINT_MAX        %lu\n", val);
278                 printf("#endif\n");
279
280 #ifdef INT_MIN
281                 val = -(INT_MIN);
282                 printf("#undef  INT_MIN\n");
283 #else
284                 val = (unsigned int)(ui >> 1) + 1;
285 #endif
286                 if (ui == ul) printf("#define INT_MIN           (-%lu-1)\n", val - 1);
287                 else printf("#define INT_MIN            -%lu\n", val);
288
289 #ifdef INT_MAX
290                 val = INT_MAX;
291                 printf("#undef  INT_MAX\n");
292 #else
293                 val = (unsigned int)(ui >> 1);
294 #endif
295                 printf("#define INT_MAX         %lu\n", val);
296         }
297
298         if (ul == ui)
299         {
300 #ifdef ULONG_MAX
301                 printf("#undef  ULONG_MAX\n");
302 #endif
303                 printf("#define ULONG_MAX       UINT_MAX\n");
304
305 #ifdef LONG_MIN
306                 printf("#undef  LONG_MIN\n");
307 #endif
308                 printf("#define LONG_MIN        INT_MIN\n");
309
310 #ifdef LONG_MAX
311                 printf("#undef  LONG_MAX\n");
312 #endif
313                 printf("#define LONG_MAX        INT_MAX\n");
314         }
315         else
316         {
317 #ifdef ULONG_MAX
318                 val = ULONG_MAX;
319                 printf("#undef  ULONG_MAX\n");
320 #else
321                 val = ui;
322 #endif
323                 printf("#if defined(__STDC__)\n");
324                 printf("#define ULONG_MAX       %luU\n", val);
325                 printf("#else\n");
326                 printf("#define ULONG_MAX       %lu\n", val);
327                 printf("#endif\n");
328
329 #ifdef LONG_MIN
330                 val = -(LONG_MIN);
331                 printf("#undef  LONG_MIN\n");
332 #else
333                 val = (unsigned long)(ul >> 1) + 1;
334 #endif
335                 printf("#define LONG_MIN        (-%lu-1)\n", val - 1);
336
337 #ifdef LONG_MAX
338                 val = LONG_MAX;
339                 printf("#undef  LONG_MAX\n");
340 #else
341                 val = (unsigned long)(ul >> 1);
342 #endif
343                 printf("#define LONG_MAX        %lu\n", val);
344         }
345
346 #ifdef ULONGLONG_MAX
347         printf("#undef  ULONGLONG_MAX\n");
348         printf("#if defined(__STDC__)\n");
349         printf("#define ULONGLONG_MAX   %lluLLU\n", ULONGLONG_MAX);
350         printf("#else\n");
351         printf("#define ULONGLONG_MAX   %llu\n", ULONGLONG_MAX);
352         printf("#endif\n");
353 #endif
354
355 #ifdef LONGLONG_MIN
356         printf("#undef  LONGLONG_MIN\n");
357         printf("#if defined(__STDC__)\n");
358         printf("#define LONGLONG_MIN    %lldLL\n", LONGLONG_MIN);
359         printf("#else\n");
360         printf("#define LONGLONG_MIN    %lld\n", LONGLONG_MIN);
361         printf("#endif\n");
362 #endif
363
364 #ifdef LONGLONG_MAX
365         printf("#undef  LONGLONG_MAX\n");
366         printf("#if defined(__STDC__)\n");
367         printf("#define LONGLONG_MAX    %lldLL\n", LONGLONG_MAX);
368         printf("#else\n");
369         printf("#define LONGLONG_MAX    %lld\n", LONGLONG_MAX);
370         printf("#endif\n");
371 #endif
372
373         printf("\n");
374 #include "conflim.h"
375         printf("\n");
376
377         /*
378          * pollution control
379          */
380
381         printf("/*\n");
382         printf(" * pollution control\n");
383         printf(" */\n");
384         printf("\n");
385         printf("#if defined(__STDPP__directive) && defined(__STDPP__ignore)\n");
386         printf("__STDPP__directive pragma pp:ignore \"limits.h\"\n");
387         printf("#else\n");
388 #ifdef  _limits_h
389         printf("#define _limits_h\n");
390 #endif
391 #ifdef  __limits_h
392         printf("#define __limits_h\n");
393 #endif
394 #ifdef  _sys_limits_h
395         printf("#define _sys_limits_h\n");
396 #endif
397 #ifdef  __sys_limits_h
398         printf("#define __sys_limits_h\n");
399 #endif
400 #ifdef  _LIMITS_H_
401         printf("#define _LIMITS_H_\n");
402 #endif
403 #ifdef  __LIMITS_H
404         printf("#define __LIMITS_H\n");
405 #endif
406 #ifdef  __LIMITS_INCLUDED
407         printf("#define __LIMITS_INCLUDED\n");
408 #endif
409 #ifdef  _MACH_MACHLIMITS_H_
410         printf("#define _MACH_MACHLIMITS_H_\n");
411 #endif
412 #ifdef  _SYS_LIMITS_H_
413         printf("#define _SYS_LIMITS_H_\n");
414 #endif
415 #ifdef  __SYS_LIMITS_H
416         printf("#define __SYS_LIMITS_H\n");
417 #endif
418 #ifdef  __SYS_LIMITS_INCLUDED
419         printf("#define __SYS_LIMITS_INCLUDED\n");
420 #endif
421 #ifdef  _SYS_SYSLIMITS_H_
422         printf("#define _SYS_SYSLIMITS_H_\n");
423 #endif
424 #ifdef  _H_LIMITS
425         printf("#define _H_LIMITS\n");
426 #endif
427 #ifdef  __H_LIMITS
428         printf("#define __H_LIMITS\n");
429 #endif
430 #ifdef  _H_SYS_LIMITS
431         printf("#define _H_SYS_LIMITS\n");
432 #endif
433 #ifdef  __H_SYS_LIMITS
434         printf("#define __H_SYS_LIMITS\n");
435 #endif
436         printf("#endif\n");
437         printf("\n");
438
439         return(0);
440 }