/* tnump.c -- (part of efr) Copyright © 1989 by William F. Hammond */ /* -- parse string for first number ignoring leading white- */ /* -- space, i.e., " ", 0x09, "/", "*", ";", and "'" */ #ifndef TDM_H #include "tdm.h" #endif #define MAXNPSTR 10 LONG tnump(numstr) UBYTE *numstr; { LONG lnum; /* that which is returned */ SHORT jnp, knp; int npsln; UBYTE sgnflg, numflg, *nps; lnum = -1L; nps = numstr; npsln = strlen(nps); if (npsln <= 0) return 0L; numflg = NULB; sgnflg = 0; jnp = 0; while(jnp < npsln) { if( (nps[jnp]==' ') || (nps[jnp]==0x09) || (nps[jnp]=='/') || (nps[jnp]=='*') || (nps[jnp]==';') || (nps[jnp]=='\'') ) { if(numflg) break; nps++; } else if( (nps[jnp] < '0') || (nps[jnp] > '9') ) { break; } else { numflg = ONEB; jnp ++; } } if(numflg == NULB) return 0L; if(jnp == 0) return 0L; /* The passed string is OK */ lnum = 0L; knp = 0; if(jnp > MAXNPSTR) return 0L; while(knp < jnp) { lnum = 10L * lnum + (LONG)(nps[knp] - '0'); knp ++; } return lnum; }