Revision: | 1.1 |
Committed: | Fri Mar 8 14:37:29 2002 UTC (22 years, 8 months ago) by tdb |
Content type: | text/plain |
Branch: | MAIN |
CVS Tags: | IHOST_1_5_3, IHOST_1_5_2, IHOST_1_5_1, IHOST_1_5, IHOST_1_0_RC1 |
Log Message: | I'm not usually up for putting third party sources in here, but in this case I'll make an exception. This is ukcprog, a set of useful C functions which the ihost plugins Pete's writing uses. It's got a pretty free license too. I've munged the Makefile around, as all it needs to do now is make the library, not install anything. The idea is to statically compile the other programs against this library, making the final binary independent of this code etc. |
# | User | Rev | Content |
---|---|---|---|
1 | tdb | 1.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 */ |