home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / word2x0a.zip / source / num_unit_probe.c < prev    next >
C/C++ Source or Header  |  1998-04-20  |  1KB  |  63 lines

  1. /* $Id: num_unit_probe.c,v 1.1 1997/04/22 20:32:17 dps Exp $ */
  2. #include "config.h"
  3. #ifdef HAVE_STRING_H
  4. #include <string.h>
  5. #else /* HAVE_STRING_H */
  6. #include <strings.h>
  7. #endif
  8. #include <ctype.h>
  9. #define __EXCLUDE_READER_CLASSES
  10. #include "lib.h"
  11.  
  12. struct unit_number n_unit_probe(const char *txt, struct unit_info *dp)
  13. {    
  14.     int i,j,n,c,l,unit;
  15.     struct unit_number u_num;
  16.     
  17.     u_num.unit_num=-1;
  18.     unit=dp->unit_type-1;
  19.     l=strlen(txt);
  20.     i=0;
  21.     while(1)
  22.     {
  23.     n=0;
  24.     for (c=0; i<l && isdigit(txt[i]); i++, c++)
  25.         n=n*10+txt[i]-'0';
  26.     if (c==0)
  27.         break;
  28.     unit++;
  29.     if (unit>=NUNITS)
  30.     {
  31.         unit=NUNITS-1;
  32.         break;
  33.     }
  34.     if (dp->unit_number[unit]==-1)
  35.     {
  36.         if (n>MAX_START_NUM)
  37.         return u_num;
  38.         
  39.         dp->unit_number[unit]=n;
  40.         for (j=unit+1; j<NUNITS; j++)
  41.         dp->unit_number[j]=0;
  42.     }
  43.     else if (dp->unit_number[unit]+1==n)
  44.     {
  45.         dp->unit_number[unit]++;
  46.         for (j=unit+1; j<NUNITS; j++)
  47.         dp->unit_number[j]=0;
  48.     }
  49.     else if (dp->unit_number[unit]!=n)
  50.        return u_num;
  51.     
  52.     if (txt[i]!='.')
  53.         break;
  54.     i++;
  55.     }
  56.     
  57.     if (unit==dp->unit_type-1)
  58.     return u_num;
  59.     u_num.unit_num=unit;
  60.     u_num.offset=i;
  61.     return u_num;
  62. }
  63.