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 >
Wrap
C/C++ Source or Header
|
1998-04-20
|
1KB
|
63 lines
/* $Id: num_unit_probe.c,v 1.1 1997/04/22 20:32:17 dps Exp $ */
#include "config.h"
#ifdef HAVE_STRING_H
#include <string.h>
#else /* HAVE_STRING_H */
#include <strings.h>
#endif
#include <ctype.h>
#define __EXCLUDE_READER_CLASSES
#include "lib.h"
struct unit_number n_unit_probe(const char *txt, struct unit_info *dp)
{
int i,j,n,c,l,unit;
struct unit_number u_num;
u_num.unit_num=-1;
unit=dp->unit_type-1;
l=strlen(txt);
i=0;
while(1)
{
n=0;
for (c=0; i<l && isdigit(txt[i]); i++, c++)
n=n*10+txt[i]-'0';
if (c==0)
break;
unit++;
if (unit>=NUNITS)
{
unit=NUNITS-1;
break;
}
if (dp->unit_number[unit]==-1)
{
if (n>MAX_START_NUM)
return u_num;
dp->unit_number[unit]=n;
for (j=unit+1; j<NUNITS; j++)
dp->unit_number[j]=0;
}
else if (dp->unit_number[unit]+1==n)
{
dp->unit_number[unit]++;
for (j=unit+1; j<NUNITS; j++)
dp->unit_number[j]=0;
}
else if (dp->unit_number[unit]!=n)
return u_num;
if (txt[i]!='.')
break;
i++;
}
if (unit==dp->unit_type-1)
return u_num;
u_num.unit_num=unit;
u_num.offset=i;
return u_num;
}