1/*
2 *  Generic Call Interface for Rexx
3 *  Copyright � 2003-2004, Florian Gro�e-Coosmann
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Library General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Library General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Library General Public
16 *  License along with this library; if not, write to the Free
17 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * ----------------------------------------------------------------------------
20 *
21 * This file configures the number converting system. Have a look at
22 * gci_convert.c for the requirements. This file must include gci.h.
23 */
24
25#include <limits.h>
26#include <float.h>
27#include <assert.h>
28#include <ctype.h>
29#include <errno.h>
30#include "gci.h"
31
32#ifdef __MINGW32__
33# define _I64_MIN    (-9223372036854775807LL - 1)
34# define _I64_MAX      9223372036854775807LL
35# define _UI64_MAX     0xffffffffffffffffULL
36#endif
37
38/*
39 * Note: You can use strtobigl and strtobigl as strtol and strtoul functions
40 * if you define NEED_STRTOBIGL and NEED_STRTOBIGUL. This will let create
41 * gci_convert.c the needed functions. They are slow but will work.
42 */
43
44#define NEED_STRTOBIGL
45#define NEED_STRTOBIGUL
46#define GCI_Ir(s,p,b) strtobigl( hidden, s, p, b )
47#define GCI_Iw(s,v)   sprintf( s, "%I64d", v )
48#define GCI_I_1       signed char
49#define GCI_I_1m      SCHAR_MIN
50#define GCI_I_1M      SCHAR_MAX
51#define GCI_I_2       signed short
52#define GCI_I_2m      SHRT_MIN
53#define GCI_I_2M      SHRT_MAX
54#define GCI_I_4       signed int
55#define GCI_I_4m      INT_MIN
56#define GCI_I_4M      INT_MAX
57#define GCI_I_8       __int64
58#define GCI_I_8m      _I64_MIN
59#define GCI_I_8M      _I64_MAX
60
61#define GCI_Ur(s,p,b) strtobigul( hidden, s, p, b )
62#define GCI_Uw(s,v)   sprintf( s, "%I64u", v )
63#define GCI_U_1       unsigned char
64#define GCI_U_1M      UCHAR_MAX
65#define GCI_U_2       unsigned short
66#define GCI_U_2M      USHRT_MAX
67#define GCI_U_4       unsigned
68#define GCI_U_4M      UINT_MAX
69#define GCI_U_8       unsigned __int64
70#define GCI_U_8M      _UI64_MAX
71
72#define GCI_Fr        strtod
73#define GCI_Fw(s,v)   sprintf( s, "%.*E", DBL_MANT_DIG/3, v )
74#define GCI_F_4       float
75#define GCI_F_4m      (-FLT_MAX)
76#define GCI_F_4M      FLT_MAX
77#define GCI_F_8       double
78#define GCI_F_8m      (-DBL_MAX)
79#define GCI_F_8M      DBL_MAX
80
81/*
82 ******************************************************************************
83 */
84
85/*
86 * GCI_STACK_ELEMENT sets integral type of a stack element. This is typically
87 * an unsigned or int.
88 */
89#define GCI_STACK_ELEMENT unsigned
90
91/*
92 * GCI_LITTLE_ENDIAN must be set to 1 or 0 depending on whether little endian
93 * or big endian is the machine's representation.
94 * In doubt, select 1 for Intel compatibles and 0 for others.
95 */
96#if defined(_BIG_ENDIAN) || defined(BIG_ENDIAN)
97# define GCI_LITTLE_ENDIAN 0   /* definitiv! Nicht �ndern */
98#elif defined(_LITTLE_ENDIAN) || defined(LITTLE_ENDIAN)
99# define GCI_LITTLE_ENDIAN 1   /* definitiv! Nicht �ndern */
100#else
101# define GCI_LITTLE_ENDIAN 1
102#endif
103
104/*
105 * GCI_ARGS shall be the maximum number of GCI_STACK_ELEMENTs which shall
106 * be passed on the stack. This is usually the base type of maximum width
107 * (e.g. long long or long double) / sizeof(unsigned) * GCI_REXX_ARGS.
108 * But you can't use sizeof(), therefore you have to compute it by hand.
109 * 4 * GCI_REXX_ARGS is an upper maximum for all useful systems I can imagine.
110 */
111#define GCI_ARGS 50   /* 25 full sized arguments */
112
113/*
114 * GCI_PASSARGS is a macro which enumerates GCI_ARGS args of an array which
115 * is passed to the macro. I don't know a good ANSI macro for this purpose.
116 * Feel free to provide it!
117 */
118#define GCI_PASSARGS(a) a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],\
119                        a[10],a[11],a[12],a[13],a[14],a[15],a[16],a[17],a[18],\
120                        a[19],a[20],a[21],a[22],a[23],a[24],a[25],a[26],a[27],\
121                        a[28],a[29],a[30],a[31],a[32],a[33],a[34],a[35],a[36],\
122                        a[37],a[38],a[39],a[40],a[41],a[42],a[43],a[44],a[45],\
123                        a[46],a[47],a[48],a[49]
124