use a temporary file for the intermediate asm output

SVN revision: 13924
This commit is contained in:
tsauerbeck 2005-03-26 16:37:25 +00:00 committed by tsauerbeck
parent 0ba866f5cf
commit b02572979a
2 changed files with 17 additions and 10 deletions

View File

@ -411,7 +411,7 @@ typedef struct __s_stringpair
int sc_eofsrc(void *handle); int sc_eofsrc(void *handle);
/* output to intermediate (.ASM) file */ /* output to intermediate (.ASM) file */
void *sc_openasm(char *filename); /* read/write */ void *sc_openasm(int fd); /* read/write */
void sc_closeasm(void *handle, int deletefile); void sc_closeasm(void *handle, int deletefile);
void sc_resetasm(void *handle); void sc_resetasm(void *handle);
int sc_writeasm(void *handle, char *str); int sc_writeasm(void *handle, char *str);

View File

@ -214,9 +214,9 @@ sc_eofsrc(void *handle)
} }
void * void *
sc_openasm(char *filename) sc_openasm(int fd)
{ {
return fopen(filename, "w+"); return fdopen(fd, "w+");
} }
void void
@ -285,7 +285,7 @@ sc_lengthbin(void *handle)
int int
sc_compile(int argc, char *argv[]) sc_compile(int argc, char *argv[])
{ {
int entry, i, jmpcode; int entry, i, jmpcode, fd_out;
int retcode; int retcode;
char incfname[_MAX_PATH]; char incfname[_MAX_PATH];
char reportname[_MAX_PATH]; char reportname[_MAX_PATH];
@ -293,6 +293,7 @@ sc_compile(int argc, char *argv[])
void *inpfmark; void *inpfmark;
char lcl_ctrlchar; char lcl_ctrlchar;
int lcl_packstr, lcl_needsemicolon, lcl_tabsize; int lcl_packstr, lcl_needsemicolon, lcl_tabsize;
char *tmpdir;
/* set global variables to their initial value */ /* set global variables to their initial value */
binf = NULL; binf = NULL;
@ -314,11 +315,17 @@ sc_compile(int argc, char *argv[])
if (!phopt_init()) if (!phopt_init())
error(103); /* insufficient memory */ error(103); /* insufficient memory */
setopt(argc, argv, inpfname, outfname, incfname, reportname); setopt(argc, argv, inpfname, binfname, incfname, reportname);
/* set output names that depend on the input name */
set_extension(outfname, ".asm", TRUE); /* open the output file */
strcpy(binfname, outfname); tmpdir = getenv("TMPDIR");
set_extension(binfname, ".amx", TRUE); if (!tmpdir) tmpdir = "/tmp";
snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
fd_out = mkstemp(outfname);
if (fd_out < 0)
error(101, outfname);
setconfig(argv[0]); /* the path to the include files */ setconfig(argv[0]); /* the path to the include files */
lcl_ctrlchar = sc_ctrlchar; lcl_ctrlchar = sc_ctrlchar;
lcl_packstr = sc_packstr; lcl_packstr = sc_packstr;
@ -328,7 +335,7 @@ sc_compile(int argc, char *argv[])
if (inpf == NULL) if (inpf == NULL)
error(100, inpfname); error(100, inpfname);
freading = TRUE; freading = TRUE;
outf = (FILE *) sc_openasm(outfname); /* first write to assembler outf = (FILE *) sc_openasm(fd_out); /* first write to assembler
* file (may be temporary) */ * file (may be temporary) */
if (outf == NULL) if (outf == NULL)
error(101, outfname); error(101, outfname);