/* * chdrgen.c * * Generate csapph headers * * © 1995-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #if defined(__riscos) #include "kernel.h" #define lasterr (_kernel_last_oserror()->errmess) #else #define lasterr (strerror(errno)) #endif static char buf[256]; static int xtoi(const char *p) { int base=10; int flags=0; int a=0; unsigned t; char ch; int b10=0; for (;;) { ch=*p++; switch (ch) { case '&': case '%': if (flags & 0x3f) goto end; if (ch=='&') base=16; else base=2; flags|=(1<<5); break; case '_': if ((flags & 0x30) || !(flags & (1<<2))) goto end; base=b10; flags=(flags & ~0xA) | (1<<5); a=0; break; case '-': case '+': if (flags & 0x7f) goto end; flags|=(1<<6); if (ch=='-') flags|=(1<<7); break; default: t=ch-'A'; if (t>=26) t=ch-'a'; if (t<26) flags|=(1<<0); else { t=ch-'0'; if (t>=10) goto end; } if (t<10) { b10=(b10*10)+t; flags|=(1<<2); } else flags|=(1<<4); if (!(flags&(1<<3))) { if (t \n"); exit (1); } if (in=fopen(argv[1],"r"),!in) goto tidy_0; if (out=fopen(argv[2],"w"),!out) goto tidy_1; dogen(in,out,argv[1],argv[2]); fclose(out); fclose(in); return (0); tidy_1: fclose(in); tidy_0: fprintf(stderr,"%s\n",lasterr); exit(1); }