bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bison fix to not generate a temporary file


From: Hans Aberg
Subject: Re: Bison fix to not generate a temporary file
Date: Sun, 20 Oct 2002 11:47:03 +0200

At 00:39 -0700 2002/10/20, Paul Eggert wrote:
 static void
 output_skeleton (void)
 {
...
+  FILE *in;
+  FILE *out;
+  int filter_fd[2];
+  char const *argv[7];
+  pid_t pid;
+
+  /* Compute the names of the package data dir and skeleton file.
+     Test whether m4sugar.m4 is readable, to check for proper
+     installation.  A faulty installation can cause deadlock, so a
+     cheap sanity check is worthwhile.  */
+  char const m4sugar[] = "m4sugar/m4sugar.m4";
+  char *full_path;
+  char const *p;
+  char const *m4 = (p = getenv ("M4")) ? p : M4;
+  char const *pkgdatadir = (p = getenv ("BISON_PKGDATADIR")) ? p : PKGDATADIR;
+  size_t skeleton_size = strlen (skeleton) + 1;
+  size_t pkgdatadirlen = strlen (pkgdatadir);
+  while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/')
+    pkgdatadirlen--;
+  full_path = xmalloc (pkgdatadirlen + 1
+                      + (skeleton_size < sizeof m4sugar
+                         ? sizeof m4sugar : skeleton_size));
+  strcpy (full_path, pkgdatadir);
+  full_path[pkgdatadirlen] = '/';
+  strcpy (full_path + pkgdatadirlen + 1, m4sugar);
+  in = fopen (full_path, "r");
+  if (! in || fclose (in) != 0)
+    error (EXIT_FAILURE, errno, "%s", full_path);
+  strcpy (full_path + pkgdatadirlen + 1, skeleton);
...

One other thing: Code that relies on UNIX pathnames may experience problems
on platform not using that. MSOS (MS Windows) used to use "\" instead of
"/". I hope that the old MacOS convention, which is used ":" is dead in the
new MacOS X.

But one simple way to avoid this is to remove the directory m4sugar: After
all, it contains only two files. Rename version.m4 to say sugar_version.m4
or something and alter the path in m4sugar.m4.

If there is a risk that people compile Bison under MSOS and you want to
avoid a lot of complaints in the mail lists, add config variable
DIRECTORY_SEPARATOR or something, for the slash/backslash.

If MSOS compilers have some kind of translation feature back and forth to
the UNIX path name convention, then there is no point in doing this, though.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]