home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / iconc / ivalues.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  1KB  |  53 lines

  1. /*
  2.  * ivalues.c - routines for manipulating Icon values.
  3.  */
  4. #include <ctype.h>
  5. #include "::h:gsupport.h"
  6. #include "ctrans.h"
  7. #include "csym.h"
  8. #include "ctree.h"
  9. #include "ccode.h"
  10. #include "cproto.h"
  11. #include "cglobals.h"
  12.  
  13.  
  14. /*
  15.  * iconint - convert the string representation of an Icon integer to a C long. 
  16.  *   Return -1 if the number is too big and large integers are supported.
  17.  */
  18. long iconint(image)
  19. char *image;
  20.    {
  21.    register int c;
  22.    register int r;
  23.    register char *s;
  24.    long n, n1;
  25.    int overflow;
  26.  
  27.    s = image;
  28.    overflow = 0;
  29.    n = 0L;
  30.    while ((c = *s++) >= '0' && c <= '9') {
  31.       n1 = n * 10 + (c - '0');
  32.       if (n != n1 / 10)
  33.          overflow = 1;
  34.       n = n1;
  35.       }
  36.    if (c == 'r' || c == 'R') {
  37.       r = n;
  38.       n = 0L;
  39.       while ((c = *s++) != '\0') {
  40.          n1 = n * r + tonum(c);
  41.          if (n != n1 / r)
  42.             overflow = 1;
  43.          n = n1;
  44.          }
  45.       }
  46.    if (overflow)
  47.       if (largeints)
  48.          n = -1;
  49.       else
  50.          tfatal("large integer option required", image);
  51.    return n;
  52.    }
  53.