/* after the options there must not be anything but filenames */
if(optind>=argc)/* no files specified */
for(fnr=optind;fnr<argc;fnr++)
usage(argv[0]);
else
{
{
char*filename,
/* after the options there must not be anything but filenames */
*ptr2ext;
for(fnr=optind;fnr<argc;fnr++)
filename=malloc(strlen(argv[fnr])+2);
if(filename==NULL)
{
{
perror("malloc");
char*filename,*ptr2ext;
continue;
}
strcpy(filename,argv[fnr]);
filename=malloc(strlen(argv[fnr])+2);
if(filename==NULL)
{
perror("malloc");
continue;
}
ptr2ext=strrchr(filename,'.');
strcpy(filename,argv[fnr]);
/* no extension or extension not equal .pgc */
if(ptr2ext==NULL||strcmp(ptr2ext,".pgc")!=0)
{
ptr2ext=filename+strlen(filename);
ptr2ext[0]='.';
}
/* make extension = .c */
ptr2ext=strrchr(filename,'.');
ptr2ext[1]='c';
/* no extension or extension not equal .pgc */
ptr2ext[2]='\0';
if(ptr2ext==NULL||strcmp(ptr2ext,".pgc")!=0)
{
ptr2ext=filename+strlen(filename);
ptr2ext[0]='.';
}
if(out_option==0)/* calculate the output name */
/* make extension = .c */
{
ptr2ext[1]='c';
yyout=fopen(filename,"w");
ptr2ext[2]='\0';
if(yyout==NULL)
if(out_option==0)/* calculate the output name */
{
{
perror(filename);
yyout=fopen(filename,"w");
free(filename);
if(yyout==NULL)
continue;
{
perror(filename);
free(filename);
continue;
}
}
}
}
yyin=fopen(input_filename=argv[fnr],"r");
yyin=fopen(input_filename=argv[fnr],"r");
if(yyin==NULL)
if(yyin==NULL)
{
perror(argv[fnr]);
perror(argv[fnr]);
else
}
{
else
/* initialize lex */
{
lex_init();
/* initialize lex */
lex_init();
/* we need two includes everytime */
/* we need two includes */
fprintf(yyout,"/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n");
fprintf(yyout,"/* Processed by ecpg (%d.%d.%d) */\n/*These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL);