summaryrefslogtreecommitdiff
path: root/src/runtime/def.r
blob: 012aab43de778ee33fe865db9f8b3051a79555b0 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * def.r -- defaulting conversion routines.
 */

/*
 * DefConvert - macro for general form of defaulting conversion.
 */
#begdef DefConvert(default, dftype, destype, converter, body)
int default(s,df,d)
dptr s;
dftype df;
destype d;
   {
   if (is:null(*s)) {
      body
      return 1;
      }
   else
      return converter(s,d); /* I really mean cnv:type */
   }
#enddef

/*
 * def_c_dbl - def:C_double(*s, df, *d), convert to C double with a
 *  default value. Default is of type C double; if used, just copy to
 *  destination.
 */

#begdef C_DblAsgn
   *d = df;
#enddef

DefConvert(def_c_dbl, double, double *, cnv_c_dbl, C_DblAsgn)

/*
 * def_c_int - def:C_integer(*s, df, *d), convert to C_integer with a
 *  default value. Default type C_integer; if used, just copy to
 *  destination.
 */
#begdef C_IntAsgn
   *d = df;
#enddef

DefConvert(def_c_int, C_integer, C_integer *, cnv_c_int, C_IntAsgn)

/*
 * def_c_str - def:C_string(*s, df, *d), convert to (tended) C string with
 *  a default value. Default is of type "char *"; if used, point destination
 *  descriptor to it.
 */

#begdef C_StrAsgn
   StrLen(*d) = strlen(df);
   StrLoc(*d) = (char *)df;
#enddef

DefConvert(def_c_str, char *, dptr, cnv_c_str, C_StrAsgn)

/*
 * def_cset - def:cset(*s, *df, *d), convert to cset with a default value.
 *  Default is of type "struct b_cset *"; if used, point destination descriptor
 *  to it.
 */

#begdef CsetAsgn
   d->dword = D_Cset;
   BlkLoc(*d) = (union block *)df;
#enddef

DefConvert(def_cset, struct b_cset *, dptr, cnv_cset, CsetAsgn)

/*
 * def_ec_int - def:(exact)C_integer(*s, df, *d), convert to C Integer
 *  with a default value, but disallow conversions from reals. Default
 *  is of type C_Integer; if used, just copy to destination.
 */

#begdef EC_IntAsgn
   *d = df;
#enddef

DefConvert(def_ec_int, C_integer, C_integer *, cnv_ec_int, EC_IntAsgn)

/*
 * def_eint - def:(exact)integer(*s, df, *d), convert to C_integer
 *  with a default value, but disallow conversions from reals. Default
 *  is of type C_Integer; if used, assign it to the destination descriptor.
 */

#begdef EintAsgn
   d->dword = D_Integer;
   IntVal(*d) = df;
#enddef

DefConvert(def_eint, C_integer, dptr, cnv_eint, EintAsgn)

/*
 * def_int - def:integer(*s, df, *d), convert to integer with a default
 *  value. Default is of type C_integer; if used, assign it to the
 *  destination descriptor.
 */

#begdef IntAsgn
   d->dword = D_Integer;
   IntVal(*d) = df;
#enddef

DefConvert(def_int, C_integer, dptr, cnv_int, IntAsgn)

/*
 * def_real - def:real(*s, df, *d), convert to real with a default value.
 *  Default is of type double; if used, allocate real block and point
 *  destination descriptor to it.
 */

#begdef RealAsgn
   Protect(BlkLoc(*d) = (union block *)alcreal(df), fatalerr(0,NULL));
   d->dword = D_Real;
#enddef

DefConvert(def_real, double, dptr, cnv_real, RealAsgn)

/*
 * def_str - def:string(*s, *df, *d), convert to string with a default
 *  value. Default is of type "struct descrip *"; if used, copy the
 *  decriptor value to the destination.
 */

#begdef StrAsgn
   *d = *df;
#enddef

DefConvert(def_str, dptr, dptr, cnv_str, StrAsgn)

/*
 * def_tcset - def:tmp_cset(*s, *df, *d), conversion to temporary cset with
 *  a default value. Default is of type "struct b_cset *"; if used,
 *  point destination descriptor to it. Note that this routine needs
 *  a cset buffer (cset block) to perform an actual conversion.
 */
int def_tcset(cbuf, s, df, d)
struct b_cset *cbuf, *df;
dptr s, d;
{
   if (is:null(*s)) {
      d->dword = D_Cset;
      BlkLoc(*d) = (union block *)df;
      return 1;
      }
   return cnv_tcset(cbuf, s, d);
   }

/*
 * def_tstr - def:tmp_string(*s, *df, *d), conversion to temporary string
 *  with a default value. Default is of type "struct descrip *"; if used,
 *  copy it to destination descriptor. Note that this routine needs
 *  a string buffer to perform an actual conversion.
 */
int def_tstr(sbuf, s, df, d)
char *sbuf;
dptr s, df, d;
   {
   if (is:null(*s)) {
      *d = *df;
      return 1;
      }
   return cnv_tstr(sbuf, s, d);
   }