4 * Generate csapph headers
6 * © 1995-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, write to the Free Software Foundation,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #define lasterr (_kernel_last_oserror()->errmess)
38 #define lasterr (strerror(errno))
43 static int xtoi(const char *p)
59 if (flags & 0x3f) goto end;
60 if (ch=='&') base=16; else base=2;
65 if ((flags & 0x30) || !(flags & (1<<2))) goto end;
67 flags=(flags & ~0xA) | (1<<5);
73 if (flags & 0x7f) goto end;
75 if (ch=='-') flags|=(1<<7);
81 if (t<26) flags|=(1<<0);
109 if (flags & (1<<7)) a=-a;
113 static void dogen(FILE *in,FILE *out,char *inn,char *outn)
118 unsigned int var = 0;
126 strftime(buf,256,"%d %B %Y",localtime(&t));
146 " * [Generated from %s, %s]\n"
149 "#if !defined(__CC_NORCROFT) || !defined(__arm)\n"
150 "# error You must use the Norcroft ARM Compiler for Sapphire "
154 "#pragma include_only_once\n"
155 "#pragma force_top_level\n"
160 "#ifndef __sapphire_h\n"
161 "# include \"sapphire.h\"\n"
169 while (ch=getc(in),ch!=EOF && ch!='\n')
173 while (!isspace(*p) && *p)
176 while (isspace(*p) && *p)
179 while (!isspace(*q) && *q)
182 while (isspace(*r) && *r)
184 if (*buf!=';') *q=*s=0;
186 if (!strcmp(p,"MACRO"))
188 else if (!strcmp(p,"MEND"))
197 { fputs(footer,out); type=4; footer=" */\n\n"; flags=0; }
206 while (*p=='-') { putc(*p++,out); i++; }
207 while (*p!='-') { putc(*p++,out); i++; }
208 while (i<76) { putc('-',out); i++; }
210 fputs(ch==';' ? "*\n" : "*/\n",out);
212 if (ch!=';') footer="\n";
215 /* A BAS directive. Yawn. */
221 fputs(flags & 1 ? " *" : "/*",out);
224 fputs(ch==';' ? " *\n" : " */\n",out);
226 if (ch!=';') footer="\n";
230 fputs(flags & 1 ? " *" : "/*",out);
238 if (type!=0) { fputs(footer,out); type=0; footer=""; }
241 else if (!strcmp(p,"IMPORT"))
243 if (type!=1) { fputs(footer,out); type=1; footer="\n"; }
244 fprintf(out,"extern routine %s;\n",r);
246 else if (!strcmp(p,"EQU"))
248 if (type!=2) { fputs(footer,out); type=2; footer="\n"; }
249 fprintf(out,"#define %s (",buf);
255 case '&': while (i--) putc(' ',out); fputs("0x",out); i=0; break;
256 case ' ': case 9: i++; break;
258 default: while (i--) putc(' ',out); putc(*r,out); i=0; break;
265 else if (!strcmp(p,"^"))
270 else if (!strcmp(p,"#"))
272 if (type!=3) { fputs(footer,out); type=3; footer="\n"; }
273 if (*buf) fprintf(out,"#define %s %i\n",buf,var);
279 if (type!=0) putc('\n',out);
280 fputs("#endif\n",out);
283 int main(int argc,char *argv[])
288 fprintf(stderr,"Usage: chdrgen <asm-header> <c-header>\n");
291 if (in=fopen(argv[1],"r"),!in) goto tidy_0;
292 if (out=fopen(argv[2],"w"),!out) goto tidy_1;
293 dogen(in,out,argv[1],argv[2]);
301 fprintf(stderr,"%s\n",lasterr);