File: scan_nbblong.c

package info (click to toggle)
qmail 1.01-5
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,188 kB
  • ctags: 1,711
  • sloc: ansic: 13,993; makefile: 1,914; perl: 448; sh: 377
file content (33 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download
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
#include "scan.h"

unsigned int scan_nbblong(s,n,base,bext,u)
char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned long *u;
/* Note that n == 0 means scan forever. Hopefully this is a good choice. */
{
  unsigned int pos; unsigned long result; unsigned long c;
  pos = 0; result = 0;
  while (((c = (unsigned long) (unsigned char) (s[pos] - '0')) < base)
       ||(((c = (unsigned long) (unsigned char) (s[pos] - 'a')) < bext)
        &&(c = c + base))
       ||(((c = (unsigned long) (unsigned char) (s[pos] - 'A')) < bext)
        &&(c = c + base))
        ) /* this gets the job done */
    { result = result * (base + bext) + c; ++pos; if (pos == n) break; }
  *u = result; return pos;
}

unsigned int scan_nbbint(s,n,base,bext,u)
char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned int *u;
{
  unsigned int pos; unsigned long result;
  pos = scan_nbblong(s,n,base,bext,&result);
  *u = result; return pos;
}

unsigned int scan_nbbshort(s,n,base,bext,u)
char *s; unsigned int n; unsigned int base; unsigned int bext; unsigned short *u;
{
  unsigned int pos; unsigned long result;
  pos = scan_nbblong(s,n,base,bext,&result);
  *u = result; return pos;
}