|
|
1.1 root 1: /*
2: *-IMPORTS:
3: * <sys/compat.h>
4: * CONST
5: * LOCAL
6: * USE_PROTO
7: * ARGS ()
8: * <stdlib.h>
9: * NULL
10: * malloc ()
11: * free ()
12: */
13:
14: #include <sys/compat.h>
15: #include <stdlib.h>
16:
17: #include "ehand.h"
18: #include "symbol.h"
19: #include "read.h"
20:
21: #include "mtune.h"
22:
23: LOCAL mtune_t * _mtunes;
24:
25:
26: /*
27: * Locate a parameter definition by symbol.
28: */
29:
30: #ifdef USE_PROTO
31: mtune_t * (find_mtune) (symbol_t * sym)
32: #else
33: mtune_t *
34: find_mtune ARGS ((sym))
35: symbol_t * sym;
36: #endif
37: {
38: mtune_t * scan;
39:
40: for (scan = _mtunes ; scan != NULL ; scan = scan->mt_next) {
41:
42: if (scan->mt_name == sym)
43: return scan;
44: }
45:
46: return NULL;
47: }
48:
49:
50: /*
51: * Read lines from an "mtune" file.
52: */
53:
54: #ifdef USE_PROTO
55: LOCAL int (read_mtune) (input_t * input, lex_t * lexp)
56: #else
57: LOCAL int
58: read_mtune ARGS ((input, lexp))
59: input_t * input;
60: lex_t * lexp;
61: #endif
62: {
63: int ch = '\n';
64: mtune_t * mtunep;
65: ehand_t err;
66:
67: if ((mtunep = (mtune_t *) malloc (sizeof (* mtunep))) == NULL)
68: throw_error ("out of memory in read_mtune ()");
69:
70: if (PUSH_HANDLER (err) == 0) {
71: /*
72: * If the first thing on the line works out to be an EOF,
73: * then bail out without an error.
74: */
75:
76: ch = read_symbol (input, lexp, & mtunep->mt_name);
77:
78: if (mtunep->mt_name == NULL) {
79: /*
80: * We allow an EOF at the beginning of a line and we
81: * also allow a blank line.
82: */
83:
84: goto at_eof;
85: }
86: check_not_eol (ch);
87:
88: if (mtunep->mt_name->s_size > MAX_PARAMNAME)
89: throw_error ("parameter name must be <= %d characters",
90: MAX_PARAMNAME);
91:
92: if (find_mtune (mtunep->mt_name) != NULL)
93: throw_error ("parameter name must be unique");
94:
95: /*
96: * Pull in the parameter values
97: */
98:
99: ch = read_longs (input, lexp, & mtunep->mt_min, NO_RANGE);
100: check_not_eol (ch);
101:
102: ch = read_longs (input, lexp, & mtunep->mt_default, NO_RANGE);
103: check_not_eol (ch);
104:
105: ch = read_longs (input, lexp, & mtunep->mt_max, NO_RANGE);
106: ch = expect_eol (input, lexp, ch);
107:
108:
109: /*
110: * Having passed all the reasonableness checks, we link the
111: * new entry into the chain.
112: */
113:
114: mtunep->mt_stune = NULL;
115:
116: mtunep->mt_next = _mtunes;
117: _mtunes = mtunep;
118: } else {
119:
120: free (mtunep);
121: CHAIN_ERROR (err);
122: }
123:
124: at_eof:
125: POP_HANDLER (err);
126: return ch;
127: }
128:
129:
130: #if 0
131: /*
132: * Regenerate an 'mtune' line from the stored record.
133: */
134:
135: #ifdef USE_PROTO
136: void (write_mtune) (mtune_t * mtunep, FILE * out)
137: #else
138: void
139: write_mtune ARGS ((mtunep, out))
140: mtune_t * mtunep;
141: FILE * out;
142: #endif
143: {
144: (void) fprintf (out, "%-8s %-7ld %-7ld %-7ld\n",
145: mtunep->mt_name->s_data,
146: mtunep->mt_min, mtunep->mt_default,
147: mtunep->mt_max);
148: }
149: #endif
150:
151:
152: /*
153: * Return the head of the list of all tuneable parameters.
154: */
155:
156: #ifdef USE_PROTO
157: mtune_t * (mtunes) (void)
158: #else
159: mtune_t *
160: mtunes ARGS (())
161: #endif
162: {
163: return _mtunes;
164: }
165:
166:
167: /*
168: * Suck in a complete 'mtune' file.
169: */
170:
171: #ifdef USE_PROTO
172: void (read_mtune_file) (CONST char * name)
173: #else
174: void
175: read_mtune_file ARGS ((name))
176: CONST char * name;
177: #endif
178: {
179: read_dev_file (name, read_mtune);
180: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.