|
|
1.1 root 1: /*
2: * File: rdefault.c
3: * Contents: defcset, deffile, defint, defshort, defstr
4: */
5:
6: #include "../h/rt.h"
7:
8: /*
9: * defcset(dp,cp,buf,def) - if dp is null, default to def;
10: * otherwise, convert to cset or die trying.
11: */
12:
13: defcset(dp, cp, buf, def)
14: struct descrip *dp;
15: int **cp;
16: int *buf, *def;
17: {
18: if (ChkNull(*dp)) {
19: *cp = def;
20: return 1;
21: }
22: if (cvcset(dp, cp, buf) == NULL)
23: runerr(104, dp);
24: return 0;
25: }
26:
27:
28: /*
29: * deffile - if dp is null, default to def; otherwise, make sure it's a file.
30: */
31:
32: deffile(dp, def)
33: struct descrip *dp, *def;
34: {
35: if (ChkNull(*dp)) {
36: *dp = *def;
37: return 1;
38: }
39: if (Qual(*dp) || (*dp).dword != D_File)
40: runerr(105, dp);
41: return 0;
42: }
43:
44:
45: /*
46: * defint - if dp is null, default to def; otherwise, convert to integer.
47: * Note that *lp gets the value.
48: */
49:
50: defint(dp, lp, def)
51: struct descrip *dp;
52: long *lp;
53: word def;
54: {
55: if (ChkNull(*dp)) {
56: *lp = (long)def;
57: return 1;
58: }
59: if (cvint(dp, lp) == NULL)
60: runerr(101, dp);
61: return 0;
62: }
63:
64:
65: /*
66: * defshort - if dp is null, default to def; otherwise, convert to short
67: * integer. The result is an integer value in *dp.
68: */
69:
70: defshort(dp, def)
71: struct descrip *dp;
72: int def;
73: {
74: long l;
75:
76: if (ChkNull(*dp)) {
77: dp->dword = D_Integer;
78: IntVal(*dp) = (int)def;
79: return 1;
80: }
81: switch (cvint(dp, &l)) {
82:
83: case T_Integer:
84: Mkint(l, dp);
85: break;
86:
87: case T_Longint:
88: runerr(205, dp);
89:
90: default:
91: runerr(101, dp);
92: }
93: return 0;
94: }
95:
96:
97: /*
98: * defstr - if dp is null, default to def; otherwise, convert to string.
99: * *dp gets a descriptor for the resulting string. buf is used as
100: * a scratch buffer for the conversion (if necessary).
101: */
102:
103: defstr(dp, buf, def)
104: struct descrip *dp;
105: char *buf;
106: struct descrip *def;
107: {
108: if (ChkNull(*dp)) {
109: *dp = *def;
110: return 1;
111: }
112: if (cvstr(dp, buf) == NULL)
113: runerr(103, dp);
114: return 0;
115: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.