ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libukcprog/strtol.c
Revision: 1.2
Committed: Sat Mar 29 18:05:09 2003 UTC (21 years, 8 months ago) by tdb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
State: FILE REMOVED
Log Message:
ihost now makes use of an external copy of libukcprog. This is
available as a seperate download. All files updated accordingly to make
this version 1.5.4.

File Contents

# 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 tdb 1.2 char ukcprog_strtol_sccsid[] = "$Id: strtol.c,v 1.1 2002/03/08 14:37:29 tdb Exp $ UKC";
6 tdb 1.1
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 */