Fix bugs related to merging of input files
This patch fixes a couple of bugs related to passing multiple input files to pawncc, e.g. pawncc a.pwn b.pwn Summary of changes: * One of the specified input files could be deleted by the compiler because inpfname was overwritten while parsing the code (#file directives for example), but in the end of compilation it thought that inpfname was holding the name of the temporary file, so it deleted that file. To fix this we now store the temporary file's name separately (in tname). * During the copying of input source code into a temporary file the last line of each input file was duplicated. For some reason feof() returnd zero, indicating the there was more data to read, but subsequent call to fgets() could not read anything, and the output buffer remained unchanged. * Added a newline at the end of each input file. This fixes #206.
This commit is contained in:
parent
9a16724b6a
commit
736904b13f
@ -473,6 +473,7 @@ int pc_compile(int argc, char *argv[])
|
||||
int hdrsize=0;
|
||||
#endif
|
||||
char *ptr;
|
||||
char *tname=NULL;
|
||||
|
||||
/* set global variables to their initial value */
|
||||
binf=NULL;
|
||||
@ -528,7 +529,7 @@ int pc_compile(int argc, char *argv[])
|
||||
assert(get_sourcefile(0)!=NULL); /* there must be at least one source file */
|
||||
if (get_sourcefile(1)!=NULL) {
|
||||
/* there are at least two or more source files */
|
||||
char *tname,*sname;
|
||||
char *sname;
|
||||
FILE *ftmp,*fsrc;
|
||||
int fidx;
|
||||
ftmp=pc_createtmpsrc(&tname);
|
||||
@ -542,15 +543,14 @@ int pc_compile(int argc, char *argv[])
|
||||
pc_writesrc(ftmp,(unsigned char*)"#file \"");
|
||||
pc_writesrc(ftmp,(unsigned char*)sname);
|
||||
pc_writesrc(ftmp,(unsigned char*)"\"\n");
|
||||
while (!pc_eofsrc(fsrc)) {
|
||||
pc_readsrc(fsrc,tstring,sizeof tstring);
|
||||
while (pc_readsrc(fsrc,tstring,sizeof tstring)!=NULL) {
|
||||
pc_writesrc(ftmp,tstring);
|
||||
} /* while */
|
||||
pc_writesrc(ftmp,"\n");
|
||||
pc_closesrc(fsrc);
|
||||
} /* for */
|
||||
pc_closesrc(ftmp);
|
||||
strcpy(inpfname,tname);
|
||||
free(tname);
|
||||
} else {
|
||||
strcpy(inpfname,get_sourcefile(0));
|
||||
} /* if */
|
||||
@ -764,11 +764,12 @@ cleanup:
|
||||
} /* if */
|
||||
#endif
|
||||
|
||||
if (inpfname!=NULL) {
|
||||
if (get_sourcefile(1)!=NULL)
|
||||
remove(inpfname); /* the "input file" was in fact a temporary file */
|
||||
free(inpfname);
|
||||
if (get_sourcefile(1)!=NULL && tname!=NULL) {
|
||||
remove(tname); /* the "input file" was in fact a temporary file */
|
||||
free(tname);
|
||||
} /* if */
|
||||
if (inpfname!=NULL)
|
||||
free(inpfname);
|
||||
if (litq!=NULL)
|
||||
free(litq);
|
||||
stgbuffer_cleanup();
|
||||
|
4
source/compiler/tests/gh_206_multiple_inputs.meta
Normal file
4
source/compiler/tests/gh_206_multiple_inputs.meta
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
'test_type': 'output_check',
|
||||
'extra_args': ['gh_206_multiple_inputs_2.pwn']
|
||||
}
|
5
source/compiler/tests/gh_206_multiple_inputs.pwn
Normal file
5
source/compiler/tests/gh_206_multiple_inputs.pwn
Normal file
@ -0,0 +1,5 @@
|
||||
#include <console>
|
||||
|
||||
main() {
|
||||
b_main();
|
||||
}
|
5
source/compiler/tests/gh_206_multiple_inputs_2.pwn
Normal file
5
source/compiler/tests/gh_206_multiple_inputs_2.pwn
Normal file
@ -0,0 +1,5 @@
|
||||
#include <console>
|
||||
|
||||
b_main() {
|
||||
print("hello");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user