-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSTOI.C
66 lines (61 loc) · 1.45 KB
/
STOI.C
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*---------------------------------------------------------*
* STOI.C -- a string to hex conversion for inclusion *
* into QALIB.L86. *
*---------------------------------------------------------*
* 1.0 05/06/85 cpg first try. *
*---------------------------------------------------------*/
#include "portab.h"
#include "ctyp40.h"
LONG stoi( str )
char *str;
{
LONG lval = 0;
char *istr;
int sign = 1;
istr = str;
while( *istr == ' ' || *istr == '\t' || *istr == '\n' )
istr++;
if( *istr == '-' )
{
sign = -1;
istr++;
}
if( *istr == '0' )
{
istr++;
if( *istr == 'x' || *istr == 'X' )
{
istr++;
while( ('0' <= *istr && *istr <= '9') ||
('a' <= *istr && *istr <= 'f') ||
('A' <= *istr && *istr <= 'F') )
{
lval *= 16;
lval += ('0' <= *istr && *istr <= '9') ?
*istr - '0' : (*istr & 0x47) - 'A' + 10;
istr++;
}
}
else
{
while( '0' <= *istr && *istr <= '7' )
{
lval *= 8;
lval += *istr++ - '0';
}
}
}
else
{
while( '0' <= *istr && *istr <= '9' )
{
lval *= 10;
lval += *istr++ - '0';
}
}
*str = istr;
return( lval * sign );
}
/*---------------------------------------------------------*
* End of STOI.C routine *
*---------------------------------------------------------*/