* lib/tempname.c, lib/mkstemp.c, m4/mkstemp.m4: New, stolen from

Fileutils 4.1.5.
* configure.in: Invoke UTILS_FUNC_MKSTEMP.
* src/output.c (output_skeleton): Use mkstemp to create a real
temporary file.
Move the filling of `skeleton' and its muscle to...
(prepare): here.
(output): Move the definition of the prologue muscle to...
(prepare): here.
* src/system.h (DEFAULT_TMPDIR): New.
This commit is contained in:
Akim Demaille
2002-02-25 13:44:43 +00:00
parent 10b6b2be55
commit 381fb12e1e
8 changed files with 530 additions and 44 deletions

View File

@@ -956,60 +956,71 @@ output_actions (void)
static void
output_skeleton (void)
{
/* Find the right skeleton file. */
if (!skeleton)
{
if (semantic_parser)
skeleton = "bison.hairy";
else
skeleton = "bison.simple";
}
/* Parse the skeleton file and output the needed parsers. */
muscle_insert ("skeleton", skeleton);
/* Store the definition of all the muscles. */
{
FILE *muscles_m4 = xfopen ("/tmp/muscles.m4", "w");
/* There are no comments, especially not `#': we do want M4 expansion
after `#': think of CPP macros! */
fprintf (muscles_m4, "m4_changecom()\n");
fprintf (muscles_m4, "m4_init()\n");
char *tempdir = getenv ("TMPDIR");
char *tempfile = NULL;
FILE *out = NULL;
ssize_t bytes_read;
int fd;
fprintf (muscles_m4, "m4_define([b4_actions], \n[[");
actions_output (muscles_m4);
fprintf (muscles_m4, "]])\n\n");
if (tempdir == NULL)
tempdir = DEFAULT_TMPDIR;
tempfile = xmalloc (strlen (tempdir) + 11);
sprintf (tempfile, "%s/bsnXXXXXX", tempdir);
fd = mkstemp (tempfile);
if (fd == -1)
error (EXIT_FAILURE, errno, "%s", tempfile);
fprintf (muscles_m4, "m4_define([b4_guards], \n[[");
guards_output (muscles_m4);
fprintf (muscles_m4, "]])\n\n");
out = fdopen (fd, "w");
if (out == NULL)
error (EXIT_FAILURE, errno, "%s", tempfile);
fprintf (muscles_m4, "m4_define([b4_tokendef], \n[[");
token_definitions_output (muscles_m4);
fprintf (muscles_m4, "]])\n\n");
/* There are no comments, especially not `#': we do want M4 expansion
after `#': think of CPP macros! */
fputs ("m4_changecom()\n", out);
fputs ("m4_init()\n", out);
muscles_m4_output (muscles_m4);
fputs ("m4_define([b4_actions], \n[[", out);
actions_output (out);
fputs ("]])\n\n", out);
fprintf (muscles_m4, "m4_wrap([m4_divert_pop(0)])\n");
fprintf (muscles_m4, "m4_divert_push(0)dnl\n");
xfclose (muscles_m4);
}
fputs ("m4_define([b4_guards], \n[[", out);
guards_output (out);
fputs ("]])\n\n", out);
fputs ("m4_define([b4_tokendef], \n[[", out);
token_definitions_output (out);
fputs ("]])\n\n", out);
muscles_m4_output (out);
fputs ("m4_wrap([m4_divert_pop(0)])\n", out);
fputs ("m4_divert_push(0)dnl\n", out);
xfclose (out);
/* Invoke m4 on the definition of the muscles, and the skeleton. */
{
const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR");
if (!bison_pkgdatadir)
bison_pkgdatadir = PKGDATADIR;
if (trace_flag)
fprintf (stderr,
"running: m4 -I %s m4sugar/m4sugar.m4 %s %s\n",
bison_pkgdatadir, tempfile, skeleton);
skel_in = readpipe ("m4",
"-I",
bison_pkgdatadir,
"m4sugar/m4sugar.m4",
"/tmp/muscles.m4",
tempfile,
skeleton,
NULL);
if (!skel_in)
error (EXIT_FAILURE, errno, "cannot run m4");
skel_lex ();
/* If `debugging', keep this file alive. */
if (!trace_flag)
unlink (tempfile);
}
}
@@ -1040,6 +1051,22 @@ prepare (void)
MUSCLE_INSERT_INT ("locations_flag", locations_flag);
MUSCLE_INSERT_INT ("defines_flag", defines_flag);
/* Copy definitions in directive. */
obstack_1grow (&attrs_obstack, 0);
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
/* Find the right skeleton file. */
if (!skeleton)
{
if (semantic_parser)
skeleton = "bison.hairy";
else
skeleton = "bison.simple";
}
/* Parse the skeleton file and output the needed parsers. */
muscle_insert ("skeleton", skeleton);
}
/*-------------------------.
@@ -1122,9 +1149,6 @@ output (void)
output_actions ();
prepare ();
/* Copy definitions in directive. */
obstack_1grow (&attrs_obstack, 0);
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
/* Process the selected skeleton file. */
output_skeleton ();

View File

@@ -1,5 +1,5 @@
/* system-dependent definitions for Bison.
Copyright 2000, 2001 Free Software Foundation, Inc.
Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -249,7 +249,9 @@ do { \
#define BITISSET(x, i) (((x)[(i)/BITS_PER_WORD] & (1<<((i) % BITS_PER_WORD))) != 0)
/* Extensions to use for the output files. */
/*-----------------------------------------.
| Extensions to use for the output files. |
`-----------------------------------------*/
#ifdef VMS
/* VMS. */
@@ -273,11 +275,23 @@ do { \
# endif /* ! MSDOS */
#endif /* ! VMS */
/* As memcpy, but for shorts. */
#ifndef DEFAULT_TMPDIR
# define DEFAULT_TMPDIR "/tmp"
#endif
/*----------------------------.
| As memcpy, but for shorts. |
`----------------------------*/
#define shortcpy(Dest, Src, Num) \
memcpy (Dest, Src, Num * sizeof (short))
/* Free a linked list. */
/*---------------------.
| Free a linked list. |
`---------------------*/
#define LIST_FREE(Type, List) \
do { \
Type *_node, *_next; \
@@ -288,9 +302,10 @@ do { \
} \
} while (0)
/*---------------------------------.
| Debugging the memory allocator. |
`---------------------------------*/
/*---------------------------------------------.
| Debugging memory allocation (must be last). |
`---------------------------------------------*/
# if WITH_DMALLOC
# define DMALLOC_FUNC_CHECK