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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
include <lexnum.h>
include <ctype.h>
include <mach.h>
# FM_CHECK -- Check a string against a data type
#
# B.Simon 28-Mar-91 Modified to check INDEF correctly
bool procedure fm_check (datatype, str)
int datatype # i: Datatype to check
char str[ARB] # i: String to be checked
#--
bool match
double strval
int ic, nc, lextype, strtype
pointer sp, temp
string yorn "|yes|no|"
bool streq()
int strlen(), lexnum(), ctod(), strdic()
begin
# Don't check null strings
if (str[1] == EOS)
return (true)
call smark (sp)
call salloc (temp, SZ_LINE, TY_CHAR)
if (datatype < 0)
# The only check on string types is that they not exceed their
# maximum length
match = strlen (str) <= -(datatype)
else {
# Get the data type of the string
# Reduce this to character, integer or real
# Get the value of the string if it is not character
if (streq (str, "INDEF")) {
strtype = datatype
strval = 0.0
} else {
ic = 1
lextype = lexnum (str, ic, nc)
for (ic = ic + nc; IS_WHITE(str[ic]); ic = ic + 1)
;
if (str[ic] != EOS)
lextype = LEX_NONNUM
if (lextype == LEX_HEX || lextype == LEX_NONNUM) {
strtype = TY_CHAR
strval = 0.0
} else {
if (lextype == LEX_REAL)
strtype = TY_REAL
else
strtype = TY_INT
ic = 1
nc = ctod (str, ic, strval)
strval = abs (strval)
}
}
# See if the string matches the expected datatype
switch (datatype) {
case TY_BOOL:
match = strdic (str, Memc[temp], SZ_LINE, yorn) > 0
case TY_CHAR:
match = strlen (str) <= 1
case TY_SHORT:
match = strtype == TY_INT && strval <= MAX_SHORT
case TY_INT:
match = strtype == TY_INT && strval <= MAX_INT
case TY_LONG:
match = strtype == TY_INT && strval <= MAX_LONG
case TY_REAL:
match = strtype != TY_CHAR && strval <= MAX_REAL
case TY_DOUBLE:
match = strtype != TY_CHAR && strval <= MAX_DOUBLE
default:
match = true
}
}
call sfree (sp)
return (match)
end
|