/* UT - ut.yc ** (C) 2006 by Remo Dentato (rdentato@users.sourceforge.net) ** ** Permission to use, copy, modify and distribute this code and ** its documentation for any purpose is hereby granted without ** fee, provided that the above copyright notice, or equivalent ** attribution acknowledgement, appears in all copies and ** supporting documentation. ** ** Copyright holder makes no representations about the suitability ** of this software for any purpose. It is provided "as is" without ** express or implied warranty. ** */ #include #include #include #include #include #include "yrx.h" #define TMPFNAME "__utproto.tmp" int main(int argc, char **argv) { int tests=0; YYSTREAM *y; int argn,c; FILE *ftmp=fopen(TMPFNAME,"w"); if (ftmp == NULL) { fprintf(stderr,"Error: Unable to write on a temporary file\n"); return 1; } fprintf(ftmp,"ut_test ut_tests[] = {\n"); for (argn = 1;argn < argc; argn++) { y=YYFILE(argv[argn],0); if (y == NULL) { fprintf(stderr,"Warning: Unable to open file %s\n",argv[argn]); } while (y) { YYSWITCH(y) { YYEOF: YYCLOSE(y); y=NULL; break; "^\YTESTCASE\Y\((\w+),(\Q)\)" : fprintf(ftmp," {ut_"); YYFWRITE(y,1,ftmp); fprintf(ftmp,","); YYFWRITE(y,2,ftmp); fprintf(ftmp,"},\n"); printf("extern char *ut_"); YYFWRITE(y,1,stdout); printf("(int);\n"); tests++; break; ".+" : break; } } } fprintf(ftmp," {NULL, \"\"}\n};\n\n#define UT_NUMTESTS %d\n\n",tests); fclose(ftmp); ftmp = fopen(TMPFNAME,"r"); if (ftmp != NULL) { while ((c = fgetc(ftmp)) != EOF) { fputc(c,stdout); } } else fprintf(stderr,"Error: Unable to read from the temporary file\n"); if (ftmp) fclose(ftmp); remove(TMPFNAME); return 0; }