diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /sys/fmtio/gctox.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/fmtio/gctox.x')
-rw-r--r-- | sys/fmtio/gctox.x | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/sys/fmtio/gctox.x b/sys/fmtio/gctox.x new file mode 100644 index 00000000..2a23a917 --- /dev/null +++ b/sys/fmtio/gctox.x @@ -0,0 +1,81 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <ctype.h> +include <chars.h> +include <lexnum.h> + +define OCTAL 8 +define DECIMAL 10 +define HEX 16 + + +# GCTOX -- General character string to complex. Any legal number, e.g., +# integer, floating point, complex, or character constant, is decoded and +# returned as a complex. + +int procedure gctox (str, ip, oxval) + +char str[ARB] # input string +int ip # pointer into input string +complex oxval # output complex + +char ch +double dval +complex xval +long lval +int ip_save, radix, nchars, vtype +int ctox(), cctoc(), ctod(), gctol(), lexnum() + +begin + vtype = TY_DOUBLE # val to be returned + while (IS_WHITE (str[ip])) + ip = ip + 1 + + ip_save = ip + ch = str[ip] # first nonwhite + + if (ch == '(') { # complex number? + if (ctox (str, ip, xval) <= 0) + return (0) # not a number + else + vtype = TY_COMPLEX + + } else if (ch == SQUOTE || ch == ESCAPE) { + if (cctoc (str, ip, ch) <= 0) # character constant? + return (0) + else + dval = ch + + } else { # determine type of number + switch (lexnum (str, ip, nchars)) { + case LEX_OCTAL: + radix = OCTAL + case LEX_DECIMAL: + radix = DECIMAL + case LEX_HEX: + radix = HEX + case LEX_REAL: + radix = TY_REAL + default: + return (0) + } + + if (radix == TY_REAL) # perform the conversion + nchars = ctod (str, ip, dval) + else { + nchars = gctol (str, ip, lval, radix) + dval = lval + if (IS_INDEFL (lval)) + dval = INDEFD + } + } + + if (vtype == TY_DOUBLE) { + oxval = dval + if (IS_INDEFD (dval)) + oxval = INDEFX + } else + oxval = xval + + return (ip - ip_save) +end |