ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libukcprog/src/strtol.c
Revision: 1.1
Committed: Sat Mar 29 16:30:33 2003 UTC (21 years, 9 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: LIBUKCPROG_1_0_2, LIBUKCPROG_1_0_1, LIBUKCPROG_1_0, HEAD
Log Message:
libukcprog is now a seperate package. I doubt this will be much use to
anyone other than us, but I see no reason why we can't package it up
and distribute it. Obviously we can't attach the GPL to this, as we
don't own it.

File Contents

# Content
1 /* strtol.c - strtol, for machines that don't have it */
2
3 /* Copyright 1991 Mark Russell, University of Kent at Canterbury. */
4
5 char ukcprog_strtol_sccsid[] = "$Id: strtol.c,v 1.4 1992/07/19 16:27:34 mtr Exp $ UKC";
6
7 #if defined(clipper) || (defined(vax) && !defined(ultrix))
8
9 #include <ctype.h>
10 #include <stdlib.h>
11
12 #define NO_STRTOL
13 #endif
14
15 #ifdef NO_STRTOL
16 long
17 strtol(nptr, eptr, base)
18 const char *nptr;
19 char **eptr;
20 int base;
21 {
22 const char *s, *save_s;
23 long val;
24
25 for (s = nptr; *s != '\0' && isspace(*s); ++s)
26 ;
27
28 if (base > 36) {
29 base = 10;
30 }
31 else if (base == 16) {
32 if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
33 s += 2;
34 }
35 else if (base == 0) {
36 if (*s == '0') {
37 ++s;
38 if (*s == 'x' || *s == 'X') {
39 ++s;
40 base = 16;
41 }
42 else if (isdigit(*s))
43 base = 8;
44 else {
45 --s;
46 base = 10;
47 }
48 }
49 else
50 base = 10;
51 }
52
53 val = 0;
54 for (save_s = s; *s != '\0'; ++s) {
55 int digit;
56
57 if (isdigit(*s))
58 digit = *s - '0';
59 else if (isupper(*s))
60 digit = *s - 'A' + 10;
61 else if (islower(*s))
62 digit = *s - 'a' + 10;
63 else
64 break;
65 if (digit >= base)
66 break;
67
68 val = val * base + digit;
69 }
70 if (s == save_s)
71 s = nptr;
72
73 if (eptr != NULL)
74 *eptr = (char *)((s > save_s) ? s : nptr);
75
76 return val;
77 }
78 #endif /* clipper || vax */