/* new.c */ /* The driver for to compile and execute etpro */ /* (c) Kenrou Adachi, 2006 */ #include #include #include #define COMPILE_ETPRO "tpc etpro.pas" int main(void) { int defun(void); int status; status = defun(); if (status == EXIT_SUCCESS) status = system(COMPILE_ETPRO); else { fprintf(stderr, "fail to generate fun.pas\n"); fprintf(stderr, "Please retry\n"); exit(EXIT_FAILURE); } if (status == EXIT_SUCCESS) system("etpro"); else { fprintf(stderr, "fail to compile etpro\n"); exit(EXIT_FAILURE); } return EXIT_SUCCESS; } int defun(void) { FILE *file; char *fs, *gs; fs = (char *)malloc(60 * sizeof(char)); gs = (char *)malloc(60 * sizeof(char)); fprintf(stderr, "Input dx/dt = f(x, y, r)\n ? "); scanf("%s", fs); fprintf(stderr, "Input dy/dt = g(x, y, r)\n ? "); scanf("%s", gs); fprintf(stderr, "\n"); if ((file = fopen("fun.pas", "w")) == NULL) return EXIT_FAILURE; fprintf(file, "function fx(x, y, r : real) : real;\n"); fprintf(file, "begin\n"); fprintf(file, " fx := %s\n", fs); fprintf(file, "end;\n\n"); fprintf(file, "function gy(x, y, r : real) : real;\n"); fprintf(file, "begin\n"); fprintf(file, " gy := %s\n", gs); fprintf(file, "end;\n"); fclose(file); free(gs); free(fs); return(EXIT_SUCCESS); }