dont depend on TMP env var under WIN32

This commit is contained in:
Jeff Hill
1997-08-05 00:44:01 +00:00
parent 0ecc5418bd
commit 8944d5ac55
3 changed files with 17 additions and 68 deletions

View File

@@ -197,13 +197,10 @@ extern char *header[];
extern char *body[];
extern char *trailer[];
extern char *action_file_name;
extern char *code_file_name;
extern char *defines_file_name;
extern char *input_file_name;
extern char *output_file_name;
extern char *text_file_name;
extern char *union_file_name;
extern char *verbose_file_name;
extern FILE *action_file;

View File

@@ -15,13 +15,10 @@ char *temp_form = "yacc.XXXXXXX";
int lineno;
int outline;
char *action_file_name;
char *code_file_name;
char *defines_file_name;
char *input_file_name = "";
char *output_file_name;
char *text_file_name;
char *union_file_name;
char *verbose_file_name;
FILE *action_file; /* a temp file, used to save actions associated */
@@ -64,9 +61,9 @@ extern char *getenv();
done(k)
int k;
{
if (action_file) { fclose(action_file); unlink(action_file_name); }
if (text_file) { fclose(text_file); unlink(text_file_name); }
if (union_file) { fclose(union_file); unlink(union_file_name); }
if (action_file) { fclose(action_file); }
if (text_file) { fclose(text_file); }
if (union_file) { fclose(union_file); }
exit(k);
}
@@ -224,50 +221,13 @@ unsigned n;
}
/*
* joh - removed use TMPDIR variable by WIN32 here
*/
create_file_names()
{
int i, len;
char *tmpdir;
tmpdir = getenv("TMPDIR");
if (tmpdir == 0) tmpdir = "/tmp";
len = strlen(tmpdir);
i = len + 13;
if (len && tmpdir[len-1] != '/')
++i;
action_file_name = MALLOC(i);
if (action_file_name == 0) no_space();
text_file_name = MALLOC(i);
if (text_file_name == 0) no_space();
union_file_name = MALLOC(i);
if (union_file_name == 0) no_space();
strcpy(action_file_name, tmpdir);
strcpy(text_file_name, tmpdir);
strcpy(union_file_name, tmpdir);
if (len && tmpdir[len - 1] != '/')
{
action_file_name[len] = '/';
text_file_name[len] = '/';
union_file_name[len] = '/';
++len;
}
strcpy(action_file_name + len, temp_form);
strcpy(text_file_name + len, temp_form);
strcpy(union_file_name + len, temp_form);
action_file_name[len + 5] = 'a';
text_file_name[len + 5] = 't';
union_file_name[len + 5] = 'u';
mktemp(action_file_name);
mktemp(text_file_name);
mktemp(union_file_name);
int len;
len = strlen(file_prefix);
output_file_name = MALLOC(len + 7);
@@ -318,13 +278,13 @@ open_files()
open_error(input_file_name);
}
action_file = fopen(action_file_name, "w");
action_file = tmpfile();
if (action_file == 0)
open_error(action_file_name);
open_error("temp action file");
text_file = fopen(text_file_name, "w");
text_file = tmpfile();
if (text_file == 0)
open_error(text_file_name);
open_error("temp text file");
if (vflag)
{
@@ -338,9 +298,9 @@ open_files()
defines_file = fopen(defines_file_name, "w");
if (defines_file == 0)
open_error(defines_file_name);
union_file = fopen(union_file_name, "w");
union_file = tmpfile();
if (union_file == 0)
open_error(union_file_name);
open_error("temp union file");
}
output_file = fopen(output_file_name, "w");

View File

@@ -815,9 +815,7 @@ output_defines()
if (dflag && unionized)
{
fclose(union_file);
union_file = fopen(union_file_name, "r");
if (union_file == NULL) open_error(union_file_name);
rewind(union_file);
while ((c = getc(union_file)) != EOF)
putc(c, defines_file);
fprintf(defines_file, " YYSTYPE;\nstatic YYSTYPE %slval;\n",
@@ -831,10 +829,7 @@ output_stored_text()
register int c;
register FILE *in, *out;
fclose(text_file);
text_file = fopen(text_file_name, "r");
if (text_file == NULL)
open_error(text_file_name);
rewind(text_file);
in = text_file;
if ((c = getc(in)) == EOF)
return(0);
@@ -1143,10 +1138,7 @@ output_semantic_actions()
register int c, last;
register FILE *out;
fclose(action_file);
action_file = fopen(action_file_name, "r");
if (action_file == NULL)
open_error(action_file_name);
rewind(action_file);
if ((c = getc(action_file)) == EOF)
return(0);