1: #include "../h/rt.h"
2:
3: /*
4: * cvint - convert the value represented by d into an integer and write
5: * the value into the location referenced by i. cvint returns one of
6: * T_INTEGER, T_LONGINT, and NULL depending on the outcome of the conversion.
7: */
8:
9: cvint(d, i)
10: register struct descrip *d;
11: long *i;
12: {
13: DclSave
14: union numeric result;
15:
16: /*
17: * Use cvnum to attempt the conversion into "result".
18: */
19: switch (cvnum(d, &result)) {
20: case T_LONGINT:
21: /*
22: * The value converted into an integer. Assign the value to *i.
23: * On systems with longs, distinguish between integer and long
24: * integer results via the return value.
25: */
26: *i = result.integer;
27: #ifdef LONGS
28: if (*i < (long)(int)MINSHORT || *i > (long)(int)MAXSHORT)
29: return (T_LONGINT);
30: #endif LONGS
31: return (T_INTEGER);
32:
33: case T_REAL:
34: /*
35: * The value converted into a real number. If it's not in the
36: * range of an integer, return a 0, otherwise convert the
37: * real value into an integer. As before, distinguish between
38: * integers and long integers if necessary.
39: */
40: if (result.real > MAXLONG || result.real < MINLONG)
41: return (NULL);
42: *i = (long)result.real;
43: #ifdef LONGS
44: if (*i < MINSHORT || *i > MAXSHORT)
45: return (T_LONGINT);
46: #endif LONGS
47: return (T_INTEGER);
48:
49: default:
50: return (NULL);
51: }
52: }
Defined functions
cvint
defined in line
9; used 5 times