18 char *loop [] = {"","n","m","/*BAD*/"};
19 char *names[] = {" ","[n]","[n][m]"};
20 char *pnames[]= {"","*","**"};
33 %token <i> NUMBER UNIT
35 %type <s> attr_desc attr_id attr_type
42 printf("#ifdef SYSROFF_SWAP_IN\n");
45 printf("#ifdef SYSROFF_p\n");
50 printf("#ifdef SYSROFF_SWAP_OUT\n");
53 printf("#ifdef SYSROFF_PRINT\n");
54 printf("#include <stdio.h>\n");
55 printf("#include <stdlib.h>\n");
86 printf("\n\n\n#define IT_%s_CODE 0x%x\n", it,code);
87 printf("struct IT_%s { \n", it);
90 printf("void sysroff_swap_%s_in(ptr)\n",$2);
91 printf("struct IT_%s *ptr;\n", it);
93 printf("char raw[255];\n");
94 printf("\tint idx = 0 ;\n");
95 printf("\tint size;\n");
96 printf("memset(raw,0,255);\n");
97 printf("memset(ptr,0,sizeof(*ptr));\n");
98 printf("size = fillup(raw);\n");
101 printf("void sysroff_swap_%s_out(file,ptr)\n",$2);
102 printf("FILE * file;\n");
103 printf("struct IT_%s *ptr;\n", it);
105 printf("\tchar raw[255];\n");
106 printf("\tint idx = 16 ;\n");
107 printf("\tmemset (raw, 0, 255);\n");
108 printf("\tcode = IT_%s_CODE;\n", it);
111 printf("void sysroff_swap_%s_out(abfd,ptr)\n",$2);
112 printf("bfd * abfd;\n");
113 printf("struct IT_%s *ptr;\n",it);
115 printf("int idx = 0 ;\n");
118 printf("void sysroff_print_%s_out(ptr)\n",$2);
119 printf("struct IT_%s *ptr;\n", it);
121 printf("itheader(\"%s\", IT_%s_CODE);\n",$2,$2);
137 printf("\tchecksum(file,raw, idx, IT_%s_CODE);\n", it);
151 it_field it_field_list
152 | cond_it_field it_field_list
153 | repeat_it_field it_field_list
157 repeat_it_field: '(' REPEAT NAME
164 printf("\tprintf(\"repeat %%d\\n\", %s);\n",$3);
166 printf("\tprintf(\"repeat %%d\\n\", %s[n]);\n",$3);
173 printf("\t{ int n; for (n = 0; n < %s; n++) {\n", $3);
176 printf("\t{ int m; for (m = 0; m < %s[n]; m++) {\n", $3);
204 cond_it_field: '(' COND NAME
212 printf("\tif (%s) {\n", $3);
231 '(' attr_desc '(' attr_type attr_size ')' attr_id
239 char *p = names[rdepth];
240 char *ptr = pnames[rdepth];
247 printf("\twriteBITS(ptr->%s%s,raw,&idx,%d);\n",
249 names[rdepth], size);
253 printf("\twrite%s(ptr->%s%s,raw,&idx,%d,file);\n",
256 names[rdepth],size/8);
265 printf("if (!ptr->%s) ptr->%s = (%s*)xcalloc(%s, sizeof(ptr->%s[0]));\n",
275 printf("if (!ptr->%s[n]) ptr->%s[n] = (%s**)xcalloc(%s[n], sizeof(ptr->%s[n][0]));\n",
287 printf("\tptr->%s%s = getBITS(raw,&idx, %d,size);\n",
293 printf("\tptr->%s%s = get%s(raw,&idx, %d,size);\n",
301 printf("\tput%s(raw,%d,%d,&idx,ptr->%s%s);\n", type,size/8,size%8,id,names[rdepth]);
305 printf("\t/* repeat %s */\n", repeat);
307 if (type[0] == 'I') {
308 printf("\tint %s%s; \t/* %s */\n",ptr,id, desc);
310 else if (type[0] =='C') {
311 printf("\tchar %s*%s;\t /* %s */\n",ptr,id, desc);
314 printf("\tbarray %s%s;\t /* %s */\n",ptr,id, desc);
318 printf("tabout();\n");
319 printf("\tprintf(\"/*%-30s*/ ptr->%s = \");\n", desc, id);
322 printf("\tprintf(\"%%d\\n\",ptr->%s%s);\n", id,p);
323 else if (type[0] == 'C')
324 printf("\tprintf(\"%%s\\n\",ptr->%s%s);\n", id,p);
326 else if (type[0] == 'B')
328 printf("\tpbarray(&ptr->%s%s);\n", id,p);
355 '(' NAME ')' { $$ = $2; }
360 | '(' enum_list ')' ;
364 enum_list '(' NAME NAME ')' {
368 printf("#define %s %s\n", $3,$4);
371 printf("if (ptr->%s%s == %s) { tabout(); printf(\"%s\\n\");}\n", name, names[rdepth],$4,$3);
382 -d write structure defintions for sysroff in host format
383 -i write functions to swap into sysroff format in
384 -o write functions to swap into sysroff format out
385 -c write code to print info in human form */
397 writecode = av[1][1];
398 if (writecode == 'd')
400 printf("typedef struct { unsigned char *data; int len; } barray; \n");
401 printf("typedef int INT;\n");
402 printf("typedef char * CHARS;\n");
413 fprintf(stderr, "%s\n" , s);