|
|
1.1.1.3 ! root 1: /* putdriver.c,v 1.2 1993/05/20 05:28:31 cgd Exp */
1.1 root 2:
3: /*
4: * This code is such a kludge that I don't want to put my name on it.
5: * It was a ridiculously fast hack and needs rewriting.
6: * However it does work...
7: */
8:
9: /* The original idea was to put all the driver code
10: * in one place so it would be easy to modify
11: * but as hacks got thrown in it got worse and worse...
12: * It's to the point where a user would be better off
13: * writing his own driver and xebec should JUST produce
14: * the tables.
15: */
16:
17: #include <stdio.h>
18: #include "main.h"
19: #include "debug.h"
20:
21: extern char protocol[];
22: char Eventshiftstring[10];
23: static char statename[] = {'_', 's', 't', 'a', 't', 'e', 0 };
24:
25: static char *strings[] = {
26:
27: #define PART1 { 0,3 }
28:
29: "\n#include \"",
30: kerneldirname,
31: protocol,
32: "_states.h\"",
33: (char *)0,
34: (char *)0,
35: (char *)0,
36: (char *)0,
37: (char *)0,
38: (char *)0,
39:
40: #define PART12 { 10,12 }
41: "\n\nstatic struct act_ent {\n",
42: "\tint a_newstate;\n\tint a_action;\n",
43: "} statetable[] = { {0,0},\n",
44: (char *)0,
45: (char *)0,
46: (char *)0,
47: (char *)0,
48: (char *)0,
49: (char *)0,
50: (char *)0,
51:
52: #define PART2 { 20,20 }
53: "};\n",
54: (char *)0,
55: (char *)0,
56: (char *)0,
57: (char *)0,
58: (char *)0,
59: (char *)0,
60: (char *)0,
61: (char *)0,
62: (char *)0,
63:
64: #define PART3 { 30,41 }
65: "\n",
66: protocol,
67: "_driver(p, e)\nregister ",
68: protocol,
69: PCBNAME,
70: " *p;\nregister struct ",
71: protocol,
72: "_event *e;\n",
73: "{\n",
74: "\tregister int index, error=0;\n",
75: "\tstruct act_ent *a;\n",
76: "\tstatic struct act_ent erroraction = {0,-1};\n",
77: (char *)0,
78: (char *)0,
79: (char *)0,
80: (char *)0,
81: (char *)0,
82: (char *)0,
83: (char *)0,
84: (char *)0,
85:
86: #define PART4 { 50,54 }
87:
88: "\textern int ",
89: protocol,
90: "_debug;\n\textern FILE *",
91: protocol,
92: "_astringfile;\n",
93: (char *)0,
94: (char *)0,
95: (char *)0,
96: (char *)0,
97: (char *)0,
98:
99: #define PART6 { 60, 65 }
100: "\n\tindex = inx[1 + e->ev_number][p->",
101: protocol,
102: statename,
103: "];\n\tif(index<0) index=_Xebec_index(e, p);\n",
104: "\tif (index==0) {\n\t\ta = &erroraction;\n",
105: "\t} else\n\t\ta = &statetable[index];\n\n",
106: (char *)0,
107: (char *)0,
108: (char *)0,
109: (char *)0,
110:
111: #define PART7 {70, 77 }
112: "\tif(",
113: protocol,
114: "_debug) fprintf(",
115: protocol,
116: "_astringfile, \"%15s <-- %15s [%15s] \\n\\t%s\\n\",\n",
117: "\t\tsstring[a->a_newstate], sstring[p->",
118: protocol,
119: "_state], estring[e->ev_number], astring[a->a_action]);\n\n",
120: (char *)0,
121: (char *)0,
122:
123: #define PART8 { 80, 84 }
124: "\tif(a->a_action)\n",
125: "\t\terror = _Xebec_action( a->a_action, e, p );\n",
126: "\tif(error==0)\n\tp->",
127: protocol,
128: "_state = a->a_newstate;\n\treturn error;\n}\n",
129: (char *)0,
130: (char *)0,
131: (char *)0,
132: (char *)0,
133: (char *)0,
134:
135: #define PART9 { 90, 99 }
136: "\n_XEBEC_PG int _Xebec_action(a,e,p)\nint a;\nstruct ",
137: protocol,
138: "_event *e;\n",
139: protocol,
140: PCBNAME,
141: " *p;\n{\n",
142: "switch(a) {\n",
143: "case -1: return ",
144: protocol,
145: "_protocol_error(e,p);\n",
146: (char *)0,
147:
148: #define PART10 { 101, 105 }
149: "\tif(",
150: protocol,
151: "_debug) fprintf(",
152: protocol,
153: "_astringfile, \"index 0x%5x\\n\", index);\n",
154: (char *)0,
155: (char *)0,
156: (char *)0,
157: (char *)0,
158:
159: #define PART5 { 110, 121 }
160: "\n_XEBEC_PG int\n_Xebec_index( e,p )\n",
161: "\tstruct ",
162: protocol,
163: "_event *e;\n\t",
164: protocol,
165: PCBNAME,
166: " *p;\n{\nswitch( (e->ev_number<<",
167: Eventshiftstring,
168: ")+(p->",
169: protocol,
170: statename,
171: ") ) {\n",
172: (char *)0,
173: (char *)0,
174: (char *)0,
175: (char *)0,
176: (char *)0,
177: (char *)0,
178: (char *)0,
179: (char *)0,
180:
181: #define PART11 {130, 137 }
182: "\tIFTRACE(D_DRIVER)\n",
183: "\t",
184: protocol,
185: "trace(DRIVERTRACE,",
186: "\t\ta->a_newstate, p->",
187: protocol,
188: "_state, e->ev_number, a->a_action, 0);\n\n",
189: "\tENDTRACE\n",
190: (char *)0,
191: (char *)0,
192:
193: #define PART13 {140, 147 }
194: "\tif(",
195: protocol,
196: "_debug) fprintf(",
197: protocol,
198: "_astringfile, \"%15s <-- %15s [%15s] \\n\",\n",
199: "\t\tsstring[a->a_newstate], sstring[p->",
200: protocol,
201: "_state], estring[e->ev_number]);\n\n",
202: (char *)0,
203: (char *)0,
204:
205: #define PART14 { 150,150 }
206: "#define _XEBEC_PG static\n",
207:
208: #define PART15 { 151,151 }
209: "#define _XEBEC_PG \n",
210:
211: };
212:
213: static struct { int start; int finish; } parts[] = {
214: { 0,0 },
215: PART1,
216: PART2,
217: PART3,
218: PART4,
219: PART5,
220: PART6,
221: PART7,
222: PART8,
223: PART9,
224: PART10,
225: PART11,
226: PART12,
227: PART13,
228: PART14,
229: PART15,
230: };
231:
232: putdriver(f, x)
233: FILE *f;
234: int x;
235: {
236: register int i;
237:
238: for( i = parts[x].start; i<= parts[x].finish; i++)
239: fprintf(f, "%s", strings[i]);
240: IFDEBUG(d)
241: fflush(f);
242: ENDDEBUG
243: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.