#include <stdio.h>
#include <stdlib.h>
extern int yyparse ();
extern FILE *yyin;
extern int line_nr;
/* main */
int
main (int argc, char *argv[])
{
FILE *fp_in, *fp_out, *fp_tmp;
fprintf (stderr, "\nsp2c:\nSimple ( or Stupid ) Perl to C translator\n\n");
if (argc != 3)
{
fprintf (stderr, "usage: sp2c <perl_file> <c_file>\n");
exit (1);
}
if ((fp_in = fopen (argv[1], "r")) == NULL)
perror (argv[1]);
if ((fp_out = fopen (argv[2], "w")) == NULL)
perror (argv[2]);
yyin = fp_in;
freopen ("./yytemp", "w", stdout);
line_nr = 1;
fprintf (fp_out,
"/*\n"
" * File generated with sp2c, a very simple\n"
" * Perl to C translator, written by\n"
" * Antonio Ospite (matr. 408/244).\n"
" * The structure of the project is inspired to\n"
" * Basic to C translator by Michele Sciabarra'.\n"
" *\n" " */\n");
fprintf (fp_out, "\n#include <stdio.h>\n");
fprintf (fp_out,
"\n/* definition of a wrapper function for input statement */");
fprintf (fp_out,
"\nint get_input(){ int tmp; fscanf(stdin, \"%%d\", &tmp); return tmp; }\n");
fprintf (fp_out, "\nint main(void)\n{\n\n");
yyparse ();
fclose (stdout);
print_variables (fp_out);
if ((fp_tmp = fopen ("./yytemp", "r")) == NULL)
perror ("./yytemp");
print_body (fp_out, fp_tmp);
fprintf (fp_out, "\nreturn 0;\n}\n");
fclose (fp_in);
fclose (fp_out);
fclose (fp_tmp);
remove ("./yytemp");
exit (0);
}
syntax highlighted by Code2HTML, v. 0.9.1