Upstream qmail 1.01
[qmail] / scan_nbblong.c
CommitLineData
2117e02e
MW
1#include "scan.h"
2
3unsigned int scan_nbblong(s,n,base,bext,u)
4char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned long *u;
5/* Note that n == 0 means scan forever. Hopefully this is a good choice. */
6{
7 unsigned int pos; unsigned long result; unsigned long c;
8 pos = 0; result = 0;
9 while (((c = (unsigned long) (unsigned char) (s[pos] - '0')) < base)
10 ||(((c = (unsigned long) (unsigned char) (s[pos] - 'a')) < bext)
11 &&(c = c + base))
12 ||(((c = (unsigned long) (unsigned char) (s[pos] - 'A')) < bext)
13 &&(c = c + base))
14 ) /* this gets the job done */
15 { result = result * (base + bext) + c; ++pos; if (pos == n) break; }
16 *u = result; return pos;
17}
18
19unsigned int scan_nbbint(s,n,base,bext,u)
20char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned int *u;
21{
22 unsigned int pos; unsigned long result;
23 pos = scan_nbblong(s,n,base,bext,&result);
24 *u = result; return pos;
25}
26
27unsigned int scan_nbbshort(s,n,base,bext,u)
28char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned short *u;
29{
30 unsigned int pos; unsigned long result;
31 pos = scan_nbblong(s,n,base,bext,&result);
32 *u = result; return pos;
33}