home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff254.lzh / Etale / tnump.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  1KB  |  53 lines

  1. /*  tnump.c  -- (part of efr)  Copyright © 1989 by William F. Hammond   */
  2. /*           --  parse string for first number ignoring leading white-  */
  3. /*           --  space, i.e., " ", 0x09, "/", "*", ";", and "'"         */
  4. #ifndef TDM_H
  5. #include "tdm.h"
  6. #endif
  7. #define MAXNPSTR 10
  8. LONG tnump(numstr)
  9. UBYTE *numstr;
  10. {
  11. LONG lnum;                  /* that which is returned                */
  12. SHORT jnp, knp;
  13. int npsln;
  14. UBYTE sgnflg, numflg, *nps;
  15. lnum = -1L;
  16. nps = numstr;
  17. npsln = strlen(nps);
  18. if (npsln <= 0) return 0L;
  19. numflg = NULB;
  20. sgnflg = 0;
  21. jnp = 0;
  22. while(jnp < npsln)
  23.    {
  24.    if( (nps[jnp]==' ') || (nps[jnp]==0x09) || (nps[jnp]=='/')
  25.     || (nps[jnp]=='*') || (nps[jnp]==';') || (nps[jnp]=='\'') )
  26.       {
  27.       if(numflg) break;
  28.       nps++;
  29.       }
  30.    else if( (nps[jnp] < '0') || (nps[jnp] > '9') )
  31.       {
  32.       break;
  33.       }
  34.    else
  35.       {
  36.       numflg = ONEB;
  37.       jnp ++;
  38.       }
  39.    }
  40. if(numflg == NULB) return 0L;
  41. if(jnp == 0) return 0L;
  42. /*  The passed string is OK  */
  43. lnum = 0L;
  44. knp = 0;
  45. if(jnp > MAXNPSTR) return 0L;
  46. while(knp < jnp)
  47.    {
  48.    lnum = 10L * lnum + (LONG)(nps[knp] - '0');
  49.    knp ++;
  50.    }
  51. return lnum;
  52. }
  53.