| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992-1994 Anders Christensen <[email protected]> |
| 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 |
* More attention should be paid to overflow and underflow conditions. |
| 22 |
* This *is* done in some of the routines for the GCC compiler, but should |
| 23 |
* be done in an ANSI-compatible manner. |
| 24 |
*/ |
| 25 |
|
| 26 |
|
| 27 |
#include "rexx.h" |
| 28 |
#include <math.h> |
| 29 |
#include <stdio.h> |
| 30 |
#include <string.h> |
| 31 |
|
| 32 |
#ifdef SunKludges |
| 33 |
double strtod( const char *, char ** ) ; |
| 34 |
#endif |
| 35 |
|
| 36 |
double myatof( const tsd_t *TSD, const streng *string ) |
| 37 |
{ |
| 38 |
char *str,*ptr ; |
| 39 |
double answer ; |
| 40 |
|
| 41 |
str = str_ofTSD(string) ; |
| 42 |
answer = strtod(str,&ptr) ; |
| 43 |
|
| 44 |
/* remove leading spaces */ |
| 45 |
for (;(*ptr)&&(rx_isspace(*ptr));ptr++) ; |
| 46 |
#ifdef SUNOS_STRTOD_BUG |
| 47 |
for (;*ptr=='0';ptr++) ; |
| 48 |
#endif /* SUNOS_STRTOD_BUG */ |
| 49 |
if (*ptr) |
| 50 |
exiterror( ERR_BAD_ARITHMETIC, 0 ) ; |
| 51 |
FreeTSD( str ) ; |
| 52 |
|
| 53 |
return answer ; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
/* |
| 58 |
* Takes 'string' as parameter, analyze whether it is an integer, and |
| 59 |
* return a boolean variable which is true iff 'string' is a legal |
| 60 |
* integer. The format of a legal integer is (the regexpr): |
| 61 |
* [ ]*([-+][ ]*)?[0-9]+[ ]* |
| 62 |
*/ |
| 63 |
int myisinteger( const streng *string ) |
| 64 |
{ |
| 65 |
const char *cptr=NULL, *eptr=NULL ; |
| 66 |
|
| 67 |
cptr = string->value ; |
| 68 |
eptr = cptr + string->len ; |
| 69 |
|
| 70 |
for (;cptr<eptr && rx_isspace(*cptr); cptr++) ; |
| 71 |
if (cptr<eptr && (*cptr=='-' || *cptr=='+')) |
| 72 |
for (cptr++; cptr<eptr && rx_isspace(*cptr); cptr++) ; |
| 73 |
|
| 74 |
if (cptr>=eptr) |
| 75 |
return 0 ; |
| 76 |
|
| 77 |
for (;cptr<eptr && rx_isdigit(*cptr); cptr++) ; |
| 78 |
for (;cptr<eptr && rx_isspace(*cptr); cptr++) ; |
| 79 |
return (cptr==eptr) ; |
| 80 |
} |