summaryrefslogtreecommitdiff
path: root/support/word2x/part_num_probe.c
blob: 61f38e254fa3c8eaf918d727e0bdd886ac0a5904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* $Id: part_num_probe.c,v 1.1 1997/04/25 17:53:00 dps Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif /* HAVE_CTYPE_H */

/* Find part number and return it or -1 if no number */
int get_part_num(const char *st, const char *fence)
{
    int n;

    while (st<fence)
    {
	if (isspace(*st))
	{
	    st++;
	    continue;
	}
	if (isdigit(*st))
	{
	    n=0;
	    while (st<fence && isdigit(*st))
	    {
		n=n*10+(*st)-'0';
		st++;
	    }
	    if (!isspace(*st))
		return -1;
	    else
		return n;

	}
	if (isupper(*st) && isspace(*(st+1)))
	    return (*st)-'A'+1;

	if (islower(*st) && isspace(*(st+1)))
	    return (*st)-'a'+1;

	/* Nothing else understood at this time */
	return -1;
    }
    return -1;
}