home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / netiso / xebec / putdriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  4.3 KB  |  245 lines

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