patch for ydr to play nicely with make -j

Derrick J Brashear shadow at dementia.org
Sat Feb 27 10:26:04 CET 1999


It's attached. It also makes "make clean" make cleaner (kill a few test
programs).

The idea is that make -j will work if there aren't files by the names
things are looking for which are only partially written, so this causes
them to be written as temporary files, and moved into place when they're
ready.

-D



diff -urN arla-0.22/TODO arla-0.22.ydr/TODO
--- arla-0.22/TODO	Wed Dec 23 21:08:49 1998
+++ arla-0.22.ydr/TODO	Sat Feb 27 04:23:23 1999
@@ -9,8 +9,6 @@
 
 */Makefile.in: allow creation of shared libraries
 
-*/Makefile.in: make sure make -j works properly
-
 tests: make sure all tests work everywhere
 
 tests: figure out what output should be sent where and with what options
diff -urN arla-0.22/lwp/Makefile.in arla-0.22.ydr/lwp/Makefile.in
--- arla-0.22/lwp/Makefile.in	Mon Feb  1 19:46:20 1999
+++ arla-0.22.ydr/lwp/Makefile.in	Sat Feb 27 04:19:11 1999
@@ -78,7 +78,7 @@
 testlwp.o: testlwp.c
 
 clean:
-	rm -f *.o *.a core process.ss $(LIB) make-process.o.sh
+	rm -f *.o *.a core process.ss $(LIB) make-process.o.sh rw testlwp
 
 distclean: clean
 
diff -urN arla-0.22/util/Makefile.in arla-0.22.ydr/util/Makefile.in
--- arla-0.22/util/Makefile.in	Sat Feb 13 00:04:57 1999
+++ arla-0.22.ydr/util/Makefile.in	Sat Feb 27 04:20:07 1999
@@ -36,10 +36,10 @@
 
 libutil_SRCS	= hash.c list.c freelist.c timeval.c log.c efile.c \
 		  strutil.c fnameutil.c date_rfc822.c strmatch.c strsplit.c \
-		  atom.c ip.c mmaptime.c heap.c
+		  atom.c ip.c mmaptime.c heap.c eefile.c
 libutil_OBJS	= hash.o list.o freelist.o timeval.o log.o efile.o \
 		  strutil.o fnameutil.o date_rfc822.o strmatch.o strsplit.o \
-		  atom.o ip.o mmaptime.o heap.o
+		  atom.o ip.o mmaptime.o heap.o eefile.o
 
 util_tester_PROG = util-tester
 
@@ -95,7 +95,7 @@
 		$(ETAGS) -t $(SRCS)
 
 clean:		
-		rm -f $(OBJS) libutil.a *~ *.o core
+		rm -f $(OBJS) libutil.a *~ *.o core heaptest mmaptime_test util-tester
 
 mostlyclean:	clean
 
diff -urN arla-0.22/util/eefile.c arla-0.22.ydr/util/eefile.c
--- arla-0.22/util/eefile.c	Wed Dec 31 19:00:00 1969
+++ arla-0.22.ydr/util/eefile.c	Sat Feb 27 04:09:30 1999
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the Kungliga Tekniska
+ *      Högskolan and its contributors.
+ * 
+ * 4. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+RCSID("$Id: eefile.c,v 1.4 1998/02/22 11:22:14 assar Exp $");
+#endif
+
+#include <stdio.h>
+#include <roken.h>
+#include "eefile.h"
+
+void
+eefopen (char *name, char *mode, fileblob *f)
+{
+     int streamfd;
+
+     f->curname = (char *)emalloc(strlen(name)+7);
+     snprintf(f->curname, strlen(name)+7, "%sXXXXXX", name);
+     streamfd = mkstemp(f->curname);
+     f->stream = fdopen (streamfd, mode);
+     if (f->stream == NULL) {
+	  fprintf (stderr, "Could not open file %s in mode %s\n",
+		   f->curname, mode);
+	  perror ("open");
+	  exit (1);
+     }
+     f->newname = strdup(name);
+     return;
+}
+
+void
+eefclose (fileblob *f)
+{
+     if (fclose (f->stream)) {
+	  fprintf (stderr, "Problems closing a file\n");
+	  perror ("close");
+     }
+     if (rename(f->curname, f->newname)) {
+	  fprintf (stderr, "Problems renaming a file\n");
+	  perror ("rename");
+     }
+     free(f->curname);
+     free(f->newname);
+}
+
+size_t
+eefread (void *ptr, size_t size, size_t nitems, fileblob *f)
+{
+     size_t res;
+
+     res = fread (ptr, size, nitems, f->stream);
+     if (res == 0) {
+	  fprintf (stderr, "Error reading\n");
+	  perror ("read");
+	  exit (1);
+     }
+     return res;
+}
+
+size_t
+eefwrite (const void *ptr, size_t size, size_t nitems, fileblob *f)
+{
+     size_t res;
+
+     res = fwrite (ptr, size, nitems, f->stream);
+     if (res == 0) {
+	  fprintf (stderr, "Error writing\n");
+	  perror ("read");
+	  exit (1);
+     }
+     return res;
+}
diff -urN arla-0.22/util/eefile.h arla-0.22.ydr/util/eefile.h
--- arla-0.22/util/eefile.h	Wed Dec 31 19:00:00 1969
+++ arla-0.22.ydr/util/eefile.h	Sat Feb 27 03:36:48 1999
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the Kungliga Tekniska
+ *      Högskolan and its contributors.
+ * 
+ * 4. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id: eefile.h,v 1.2 1997/11/09 23:48:47 assar Exp $ */
+
+#ifndef _EEFILE_
+#define _EEFILE_
+
+#include <stdio.h>
+#include <stdlib.h>
+
+struct _fileblob {
+  FILE *stream;
+  char *curname;
+  char *newname;
+};
+
+typedef struct _fileblob fileblob;
+void eefopen(char *name, char *mode, fileblob *f);
+void eefclose(fileblob *);
+size_t eefread (void *ptr, size_t size, size_t nitems, fileblob *stream);
+size_t eefwrite (const void *ptr, size_t size, size_t nitems, fileblob *stream);
+
+#endif /* _EEFILE_ */
diff -urN arla-0.22/ydr/main.c arla-0.22.ydr/ydr/main.c
--- arla-0.22/ydr/main.c	Thu Feb 18 00:48:55 1999
+++ arla-0.22.ydr/ydr/main.c	Sat Feb 27 03:51:54 1999
@@ -109,8 +109,8 @@
     yyin = popen (arg, "r");
     free (arg);
     ret = yyparse ();
-    generate_server_switch (serverfile, serverhdrfile);
-    generate_tcpdump_patches (td_file);
+    generate_server_switch (serverfile->stream, serverhdrfile->stream);
+    generate_tcpdump_patches (td_file->stream);
     pclose (yyin);
     close_generator (filename);
     unlink (tmp_filename);
diff -urN arla-0.22/ydr/output.c arla-0.22.ydr/ydr/output.c
--- arla-0.22/ydr/output.c	Fri Feb 12 23:43:37 1999
+++ arla-0.22.ydr/ydr/output.c	Sat Feb 27 04:07:23 1999
@@ -43,7 +43,7 @@
 
 #include <stdio.h>
 #include <list.h>
-#include <efile.h>
+#include <eefile.h>
 #include <string.h>
 #include <strutil.h>
 #include <roken.h>
@@ -63,7 +63,7 @@
  * File handles for the generated files themselves.
  */
 
-FILE *headerfile,
+fileblob *headerfile,
     *clientfile,
     *serverfile,
     *clienthdrfile,
@@ -71,6 +71,14 @@
     *td_file,
     *ydrfile;
 
+fileblob _headerfile,
+    _clientfile,
+    _serverfile,
+    _clienthdrfile,
+    _serverhdrfile,
+    _td_file,
+    _ydrfile;
+
 long tmpcnt = 0;
 
 /*
@@ -1663,78 +1671,86 @@
 
      func_list = listnew ();
 
+     headerfile = &_headerfile;
+     clientfile = &_clientfile;
+     serverfile = &_serverfile;
+     clienthdrfile = &_clienthdrfile;
+     serverhdrfile = &_serverhdrfile;
+     td_file = &_td_file;
+     ydrfile = &_ydrfile;
+
      tmp = (char *)emalloc (strlen (filename) + 17);
      sprintf (tmp, "%s.h", filename);
-     headerfile = efopen (tmp, "w");
+     eefopen (tmp, "w", headerfile);
      fileuppr = strdup (filename);
      strupr (fileuppr);
-     fprintf (headerfile, "/* Generated from %s.xg */\n", filename);
-     fprintf (headerfile, "#ifndef _%s_\n"
+     fprintf (headerfile->stream, "/* Generated from %s.xg */\n", filename);
+     fprintf (headerfile->stream, "#ifndef _%s_\n"
 	      "#define _%s_\n\n", fileuppr, fileuppr);
      free (fileuppr);
      
      sprintf (tmp, "%s.ydr.c", filename);
-     ydrfile = efopen (tmp, "w");
-     fprintf (ydrfile, "/* Generated from %s.xg */\n", filename);
-     fprintf (ydrfile, "#include <%s.h>\n\n", filename);
-     fprintf (ydrfile, "#include <stdio.h>\n");
-     fprintf (ydrfile, "#include <stdlib.h>\n");
-     fprintf (ydrfile, "#include <sys/types.h>\n");
-     fprintf (ydrfile, "#include <netinet/in.h>\n");
-     fprintf (ydrfile, "#include <roken.h>\n");
-     fprintf (ydrfile, "#ifndef HAVE_BCOPY\n"
+     eefopen (tmp, "w", ydrfile);
+     fprintf (ydrfile->stream, "/* Generated from %s.xg */\n", filename);
+     fprintf (ydrfile->stream, "#include <%s.h>\n\n", filename);
+     fprintf (ydrfile->stream, "#include <stdio.h>\n");
+     fprintf (ydrfile->stream, "#include <stdlib.h>\n");
+     fprintf (ydrfile->stream, "#include <sys/types.h>\n");
+     fprintf (ydrfile->stream, "#include <netinet/in.h>\n");
+     fprintf (ydrfile->stream, "#include <roken.h>\n");
+     fprintf (ydrfile->stream, "#ifndef HAVE_BCOPY\n"
 	      "#define bcopy(a,b,c) memcpy((b),(a),(c))\n"
 	      "#endif /* !HAVE_BCOPY */\n\n");
-     fprintf (ydrfile, "#ifdef RCSID\n"
+     fprintf (ydrfile->stream, "#ifdef RCSID\n"
 	      "RCSID(\"%s generated from %s.xg with $Id: output.c,v 1.44 1999/02/13 04:43:37 assar Exp $\");\n"
 	      "#endif\n\n", tmp, filename);
 
      sprintf (tmp, "%s.cs.c", filename);
-     clientfile = efopen (tmp, "w");
-     fprintf (clientfile, "/* Generated from %s.xg */\n", filename);
-     fprintf (clientfile, "#include \"%s.h\"\n\n", filename);
-     fprintf (clientfile, "#include \"%s.cs.h\"\n\n", filename);
-     fprintf (clientfile, "#include <stdio.h>\n");
-     fprintf (clientfile, "#include <stdlib.h>\n");
-     fprintf (clientfile, "#include <sys/types.h>\n");
-     fprintf (clientfile, "#include <netinet/in.h>\n");
-     fprintf (clientfile, "#include <roken.h>\n");
-     fprintf (clientfile, "#include <arlad/fs_errors.h>\n");
-     fprintf (clientfile, "#ifndef HAVE_BCOPY\n"
+     eefopen (tmp, "w", clientfile);
+     fprintf (clientfile->stream, "/* Generated from %s.xg */\n", filename);
+     fprintf (clientfile->stream, "#include \"%s.h\"\n\n", filename);
+     fprintf (clientfile->stream, "#include \"%s.cs.h\"\n\n", filename);
+     fprintf (clientfile->stream, "#include <stdio.h>\n");
+     fprintf (clientfile->stream, "#include <stdlib.h>\n");
+     fprintf (clientfile->stream, "#include <sys/types.h>\n");
+     fprintf (clientfile->stream, "#include <netinet/in.h>\n");
+     fprintf (clientfile->stream, "#include <roken.h>\n");
+     fprintf (clientfile->stream, "#include <arlad/fs_errors.h>\n");
+     fprintf (clientfile->stream, "#ifndef HAVE_BCOPY\n"
 	      "#define bcopy(a,b,c) memcpy((b),(a),(c))\n"
 	      "#endif /* !HAVE_BCOPY */\n\n");
-     fprintf (clientfile, "#ifdef RCSID\n"
+     fprintf (clientfile->stream, "#ifdef RCSID\n"
 	      "RCSID(\"%s generated from %s.xg with $Id: output.c,v 1.44 1999/02/13 04:43:37 assar Exp $\");\n"
 	      "#endif\n\n", tmp, filename);
 
      sprintf (tmp, "%s.ss.c", filename);
-     serverfile = efopen (tmp, "w");
-     fprintf (serverfile, "/* Generated from %s.xg */\n", filename);
-     fprintf (serverfile, "#include \"%s.h\"\n\n", filename);
-     fprintf (serverfile, "#include \"%s.ss.h\"\n\n", filename);
-     fprintf (serverfile, "#include <stdio.h>\n");
-     fprintf (serverfile, "#include <stdlib.h>\n");
-     fprintf (serverfile, "#include <sys/types.h>\n");
-     fprintf (serverfile, "#include <netinet/in.h>\n");
-     fprintf (serverfile, "#include <roken.h>\n");
-     fprintf (serverfile, "#ifndef HAVE_BCOPY\n"
+     eefopen (tmp, "w", serverfile);
+     fprintf (serverfile->stream, "/* Generated from %s.xg */\n", filename);
+     fprintf (serverfile->stream, "#include \"%s.h\"\n\n", filename);
+     fprintf (serverfile->stream, "#include \"%s.ss.h\"\n\n", filename);
+     fprintf (serverfile->stream, "#include <stdio.h>\n");
+     fprintf (serverfile->stream, "#include <stdlib.h>\n");
+     fprintf (serverfile->stream, "#include <sys/types.h>\n");
+     fprintf (serverfile->stream, "#include <netinet/in.h>\n");
+     fprintf (serverfile->stream, "#include <roken.h>\n");
+     fprintf (serverfile->stream, "#ifndef HAVE_BCOPY\n"
 	      "#define bcopy(a,b,c) memcpy((b),(a),(c))\n"
 	      "#endif /* !HAVE_BCOPY */\n\n");
-     fprintf (serverfile, "#ifdef RCSID\n"
+     fprintf (serverfile->stream, "#ifdef RCSID\n"
 	      "RCSID(\"%s generated from %s.xg with $Id: output.c,v 1.44 1999/02/13 04:43:37 assar Exp $\");\n"
 	      "#endif\n\n", tmp, filename);
 
      sprintf (tmp, "%s.cs.h", filename);
-     clienthdrfile = efopen (tmp, "w");
-     fprintf (clienthdrfile, "/* Generated from %s.xg */\n", filename);
+     eefopen (tmp, "w", clienthdrfile);
+     fprintf (clienthdrfile->stream, "/* Generated from %s.xg */\n", filename);
 
      sprintf (tmp, "%s.ss.h", filename);
-     serverhdrfile = efopen (tmp, "w");
-     fprintf (serverhdrfile, "/* Generated from %s.xg */\n", filename);
-     fprintf (serverhdrfile, "#include <rx/rx.h>\n");
+     eefopen (tmp, "w", serverhdrfile);
+     fprintf (serverhdrfile->stream, "/* Generated from %s.xg */\n", filename);
+     fprintf (serverhdrfile->stream, "#include <rx/rx.h>\n");
 
      sprintf (tmp, "%s.td.c", filename);
-     td_file = efopen (tmp, "w");
+     eefopen (tmp, "w", td_file);
 
      free (tmp);
 }
@@ -1745,13 +1761,14 @@
      char *fileupr = strdup (filename);
 	  
      strupr (fileupr);
-     fprintf (headerfile, "\n#endif /* %s */\n", fileupr);
-     efclose (headerfile);
-     efclose (clientfile);
-     efclose (serverfile);
-     efclose (clienthdrfile);
-     efclose (serverhdrfile);
-     efclose (ydrfile);
+     fprintf (headerfile->stream, "\n#endif /* %s */\n", fileupr);
+     eefclose (headerfile);
+     eefclose (clientfile);
+     eefclose (serverfile);
+     eefclose (clienthdrfile);
+     eefclose (serverhdrfile);
+     eefclose (ydrfile);
+     eefclose (td_file);
 }
 
 /*
diff -urN arla-0.22/ydr/output.h arla-0.22.ydr/ydr/output.h
--- arla-0.22/ydr/output.h	Sun Dec 13 11:52:12 1998
+++ arla-0.22.ydr/ydr/output.h	Sat Feb 27 03:58:14 1999
@@ -43,6 +43,8 @@
 
 #include <stdio.h>
 #include <bool.h>
+/* For fileblob */
+#include "eefile.h"
 
 void generate_header (Symbol *s, FILE *f);
 void generate_sizeof (Symbol *s, FILE *f);
@@ -60,7 +62,7 @@
 
 extern char *package;
 
-extern FILE *headerfile, *clientfile, *serverfile, *clienthdrfile,
+extern fileblob *headerfile, *clientfile, *serverfile, *clienthdrfile,
     *serverhdrfile, *ydrfile, *td_file;
 
 extern char *error_function;
diff -urN arla-0.22/ydr/parse.y arla-0.22.ydr/ydr/parse.y
--- arla-0.22/ydr/parse.y	Fri Feb 12 23:42:05 1999
+++ arla-0.22.ydr/ydr/parse.y	Sat Feb 27 03:51:04 1999
@@ -94,19 +94,19 @@
 		;
 
 declaration:	type_decl { 
-     		     generate_header ($1, headerfile);
-		     generate_sizeof ($1, headerfile);
-		     generate_function ($1, ydrfile, TRUE);
-		     generate_function_prototype ($1, headerfile, TRUE);
-		     generate_function ($1, ydrfile, FALSE);
-		     generate_function_prototype ($1, headerfile, FALSE);
-		     generate_printfunction ($1, ydrfile);
-		     generate_printfunction_prototype ($1, headerfile);
+     		     generate_header ($1, headerfile->stream);
+		     generate_sizeof ($1, headerfile->stream);
+		     generate_function ($1, ydrfile->stream, TRUE);
+		     generate_function_prototype ($1, headerfile->stream, TRUE);
+		     generate_function ($1, ydrfile->stream, FALSE);
+		     generate_function_prototype ($1, headerfile->stream, FALSE);
+		     generate_printfunction ($1, ydrfile->stream);
+		     generate_printfunction_prototype ($1, headerfile->stream);
 		}
 		| proc_decl { 
-		     generate_client_stub ($1, clientfile, clienthdrfile);
-		     generate_server_stub ($1, serverfile, serverhdrfile);
-		     generate_tcpdump_stub ($1, td_file);
+		     generate_client_stub ($1, clientfile->stream, clienthdrfile->stream);
+		     generate_server_stub ($1, serverfile->stream, serverhdrfile->stream);
+		     generate_tcpdump_stub ($1, td_file->stream);
 		}
 		;
 
@@ -157,7 +157,7 @@
 directive:	T_PACKAGE T_IDENTIFIER
 		{ package = $2; }
 		| T_VERBATIM
-		{ fprintf (headerfile, "%s\n", $1); }
+		{ fprintf (headerfile->stream, "%s\n", $1); }
 		| T_ERROR_FUNCTION T_IDENTIFIER
 		{ error_function = $2; }
 		;





More information about the Arla-drinkers mailing list