home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / libtex / strtol.c < prev    next >
C/C++ Source or Header  |  1991-03-21  |  796b  |  57 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. /*
  5.  * This is for people who don't have strtol defined on their systems.
  6.  * -- Compliments of Daniel.Stodolsky@cs.cmu.edu
  7.  */
  8.  
  9. long strtol(nptr,base,eptr)
  10. char *nptr;
  11. int base;
  12. char **eptr;
  13. {
  14.   long l;
  15.   
  16.   if (base==10)
  17.     {
  18.       if (sscanf(nptr,"%ld",&l)!=1)
  19.     {
  20.       *eptr = nptr;
  21.       return 0;
  22.     }
  23.       else
  24.     {
  25.       while(!isdigit(*nptr))
  26.         nptr++;
  27.       while (isdigit(*nptr))
  28.         nptr++;
  29.       *eptr = nptr;
  30.       return l;
  31.     }
  32.     }
  33.   else
  34.     if (base==16)
  35.       {
  36.     if (sscanf(nptr,"%lx",&l)!=1)
  37.     {
  38.       *eptr = nptr;
  39.       return 0;
  40.     }
  41.       else
  42.     {
  43.       while(!isxdigit(*nptr))
  44.         nptr++;
  45.       while (isxdigit(*nptr))
  46.         nptr++;
  47.       *eptr = nptr;
  48.       return l;
  49.     }
  50.       }
  51.     else
  52.       { /* a base we don't understand. Puke */
  53.     *eptr = nptr;
  54.     return 0;
  55.       }
  56. }
  57.