2 static char *RCSid
= "$Id$";
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * More attention should be paid to overflow and underflow conditions.
26 * This *is* done in some of the routines for the GCC compiler, but should
27 * be done in an ANSI-compatible manner.
38 double strtod( const char *, char ** ) ;
41 double myatof( const tsd_t
*TSD
, const streng
*string
)
46 str
= str_ofTSD(string
) ;
47 answer
= strtod(str
,&ptr
) ;
49 /* remove leading spaces */
50 for (;(*ptr
)&&(isspace(*ptr
));ptr
++) ;
51 #ifdef SUNOS_STRTOD_BUG
52 for (;*ptr
=='0';ptr
++) ;
53 #endif /* SUNOS_STRTOD_BUG */
55 exiterror( ERR_BAD_ARITHMETIC
, 0 ) ;
62 int myisnumber( const streng
*string
)
64 const register char *ptr
=NULL
, *eptr
=NULL
;
71 eptr
= Str_end( string
) ;
73 for (; (ptr
<eptr
) && (isspace(*ptr
)); ptr
++) ;
74 if ((ptr
<eptr
) && ((*ptr
=='-') || (*ptr
=='+')))
75 for (ptr
++; (ptr
<eptr
) && (isspace(*ptr
)); ptr
++) ;
77 for (; (ptr
<eptr
) && isdigit(*ptr
); ptr
++, num
++) ;
78 if ((ptr
<eptr
) && *ptr
=='.')
79 for (ptr
++;(ptr
<eptr
) && isdigit(*ptr
); ptr
++, num
++) ;
84 if ((ptr
<eptr
) && ((*ptr
=='e') || (*ptr
=='E')))
88 if ((ptr
<eptr
) && ((*ptr
=='-') || (*ptr
=='+')))
91 for (; (ptr
<eptr
) && isdigit(*ptr
); ptr
++, num
++ ) ;
96 for (; (ptr
<eptr
) && (isspace(*ptr
)); ptr
++) ;
102 * Takes 'string' as parameter, analyze whether it is an integer, and
103 * return a boolean variable which is true iff 'string' is a legal
104 * integer. The format of a legal integer is (the regexpr):
105 * [ ]*([-+][ ]*)?[0-9]+[ ]*
107 int myisinteger( const streng
*string
)
109 const char *cptr
=NULL
, *eptr
=NULL
;
111 cptr
= string
->value
;
112 eptr
= cptr
+ string
->len
;
114 for (;cptr
<eptr
&& isspace(*cptr
); cptr
++) ;
115 if (cptr
<eptr
&& (*cptr
=='-' || *cptr
=='+'))
116 for (cptr
++; cptr
<eptr
&& isspace(*cptr
); cptr
++) ;
121 for (;cptr
<eptr
&& isdigit(*cptr
); cptr
++) ;
122 for (;cptr
<eptr
&& isspace(*cptr
); cptr
++) ;
123 return (cptr
==eptr
) ;