[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Another m4 problem....



> <pissed> Can you just Turn off m4.... </pissed>

Try this patch.

Index: file.c
===================================================================
RCS file: /cvsroot/pcb/pcb/src/file.c,v
retrieving revision 1.48
diff -p -U2 -r1.48 file.c
--- file.c	10 Nov 2006 21:56:53 -0000	1.48
+++ file.c	14 Jan 2007 04:25:10 -0000
@@ -806,27 +806,40 @@ WritePipe (char *Filename, Boolean thePc
   char *p;
   static DynamicStringType command;
+  int used_popen = 0;
 
-  /* setup commandline */
-  DSClearString (&command);
-  for (p = Settings.SaveCommand; *p; p++)
-    {
-      /* copy character if not special or add string to command */
-      if (!(*p == '%' && *(p + 1) == 'f'))
-	DSAddCharacter (&command, *p);
-      else
+  if (EMPTY_STRING_P (Settings.SaveCommand))
+    {
+      fp = fopen (Filename, "w");
+      if (fp == 0)
 	{
-	  DSAddString (&command, Filename);
-
-	  /* skip the character */
-	  p++;
+	  Message ("Unable to write to file %s\n", Filename);
+	  return STATUS_ERROR;
 	}
     }
-  DSAddCharacter (&command, '\0');
-
-  printf ("write to pipe \"%s\"\n", command.Data);
-  if ((fp = popen (command.Data, "w")) == NULL)
+  else
     {
-      PopenErrorMessage (command.Data);
-      return (STATUS_ERROR);
+      used_popen = 1;
+      /* setup commandline */
+      DSClearString (&command);
+      for (p = Settings.SaveCommand; *p; p++)
+	{
+	  /* copy character if not special or add string to command */
+	  if (!(*p == '%' && *(p + 1) == 'f'))
+	    DSAddCharacter (&command, *p);
+	  else
+	    {
+	      DSAddString (&command, Filename);
+
+	      /* skip the character */
+	      p++;
+	    }
+	}
+      DSAddCharacter (&command, '\0');
+      printf ("write to pipe \"%s\"\n", command.Data);
+      if ((fp = popen (command.Data, "w")) == NULL)
+	{
+	  PopenErrorMessage (command.Data);
+	  return (STATUS_ERROR);
+	}
     }
   if (thePcb)
@@ -834,5 +847,8 @@ WritePipe (char *Filename, Boolean thePc
   else
     result = WriteBuffer (fp);
-  return (pclose (fp) ? STATUS_ERROR : result);
+
+  if (used_popen)
+    return (pclose (fp) ? STATUS_ERROR : result);
+  return (fclose (fp) ? STATUS_ERROR : result);
 }
 
@@ -1145,16 +1161,31 @@ ReadNetlist (char *filename)
   int i, j, lines, kind;
   Boolean continued;
+  int used_popen = 0;
 
   if (!filename)
     return (1);			/* nothing to do */
-  MYFREE (command);
-  command = EvaluateFilename (Settings.RatCommand,
-			      Settings.RatPath, filename, NULL);
 
-  /* open pipe to stdout of command */
-  if (*command == '\0' || (fp = popen (command, "r")) == NULL)
+  if (EMPTY_STRING_P (Settings.RatCommand))
     {
-      PopenErrorMessage (command);
-      return (1);
+      fp = fopen (filename, "r");
+      if (!fp)
+	{
+	  Message("Cannot open %s for reading", filename);
+	  return 1;
+	}
+    }
+  else
+    {
+      used_popen = 1;
+      MYFREE (command);
+      command = EvaluateFilename (Settings.RatCommand,
+				  Settings.RatPath, filename, NULL);
+
+      /* open pipe to stdout of command */
+      if (*command == '\0' || (fp = popen (command, "r")) == NULL)
+	{
+	  PopenErrorMessage (command);
+	  return (1);
+	}
     }
   lines = 0;
@@ -1229,5 +1260,8 @@ ReadNetlist (char *filename)
       return (1);
     }
-  pclose (fp);
+  if (used_popen)
+    pclose (fp);
+  else
+    fclose (fp);
   sort_netlist ();
   return (0);
Index: macro.h
===================================================================
RCS file: /cvsroot/pcb/pcb/src/macro.h,v
retrieving revision 1.24
diff -p -U2 -r1.24 macro.h
--- macro.h	12 Oct 2006 02:46:31 -0000	1.24
+++ macro.h	14 Jan 2007 04:25:10 -0000
@@ -102,4 +102,5 @@
 #define NSTRCMP(a, b)		((a) ? ((b) ? strcmp((a),(b)) : 1) : -1)
 #define	EMPTY(a)		((a) ? (a) : "")
+#define	EMPTY_STRING_P(a)	((a) ? (a)[0]==0 : 1)
 #define XOR(a,b)		(((a) && !(b)) || (!(a) && (b)))
 #define SQUARE(x)		((float) (x) * (float) (x))
Index: main.c
===================================================================
RCS file: /cvsroot/pcb/pcb/src/main.c,v
retrieving revision 1.61
diff -p -U2 -r1.61 main.c
--- main.c	7 Dec 2006 13:10:35 -0000	1.61
+++ main.c	14 Jan 2007 04:25:10 -0000
@@ -491,5 +491,5 @@ HID_Attribute main_attribute_list[] = {
   SSET (FontCommand, "M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4,
 	"font-command", 0),
-  SSET (FileCommand, "cat '%f'", "file-command", "Command to read a file."),
+  SSET (FileCommand, "", "file-command", "Command to read a file."),
   SSET (ElementCommand,
 	"M4PATH='%p';export M4PATH;echo 'include(%f)' | " GNUM4,
@@ -503,5 +503,5 @@ HID_Attribute main_attribute_list[] = {
   SSET (LibraryTree, PCBTREEDIR, "lib-newlib",
 	"Top level directory for the newlib style library"),
-  SSET (SaveCommand, "cat - > '%f'", "save-command", 0),
+  SSET (SaveCommand, "", "save-command", 0),
   SSET (LibraryFilename, LIBRARYFILENAME, "lib-name", 0),
   SSET (FontFile, "default_font", "default-font",
@@ -512,5 +512,5 @@ HID_Attribute main_attribute_list[] = {
 	0),
   SSET (FilePath, "", "file-path", 0),
-  SSET (RatCommand, "cat %f", "rat-command", 0),
+  SSET (RatCommand, "", "rat-command", 0),
   SSET (FontPath, ".:" PCBLIBDIR, "font-path", 0),
   SSET (ElementPath, ".:" PCBLIBDIR, "element-path", 0),
Index: parse_l.l
===================================================================
RCS file: /cvsroot/pcb/pcb/src/parse_l.l,v
retrieving revision 1.15
diff -p -U2 -r1.15 parse_l.l
--- parse_l.l	10 Nov 2006 21:56:53 -0000	1.15
+++ parse_l.l	14 Jan 2007 04:25:10 -0000
@@ -195,5 +195,6 @@ static int Parse(char *Executable, char 
 {
 	static	char	*command = NULL;
-			int		returncode;
+	int		returncode;
+	int		used_popen = 0;
 
 #ifdef FLEX_SCANNER
@@ -201,15 +202,28 @@ static int Parse(char *Executable, char 
 #endif
 
-		/* release old command and create new from template */
-	if (command)
-	  MYFREE (command);
-	command = EvaluateFilename(Executable, Path, Filename, Parameter);
-
-		/* open pipe to stdout of command */
-	if (*command == '\0' || (yyin = popen(command, "r")) == NULL)
-	{
+	if (EMPTY_STRING_P (Executable))
+	  {
+	    yyin = fopen (Filename, "r");
+	    if (!yyin)
+	      {
+		Message("Can't open %s for reading\n", Filename);
+		return(1);
+	      }
+	  }
+	else
+	  {
+	    used_popen = 1;
+	    /* release old command and create new from template */
+	    if (command)
+	      MYFREE (command);
+	    command = EvaluateFilename(Executable, Path, Filename, Parameter);
+
+	    /* open pipe to stdout of command */
+	    if (*command == '\0' || (yyin = popen(command, "r")) == NULL)
+	      {
 		PopenErrorMessage(command);
 		return(1);
-	}
+	      }
+	  }
 
 #ifdef FLEX_SCANNER
@@ -241,5 +255,7 @@ static int Parse(char *Executable, char 
 	yy_delete_buffer(YY_CURRENT_BUFFER);
 
-	return(pclose(yyin) ? 1 : returncode);
+	if (used_popen)
+	  return(pclose(yyin) ? 1 : returncode);
+	return(fclose(yyin) ? 1 : returncode);
 }
 
@@ -253,5 +269,5 @@ int ParseElementFile(DataTypePtr Ptr, ch
 	yyFont = &PCB->Font;
 	yyElement = NULL;
-	return(Parse(Settings.ElementCommand,Settings.ElementPath,Filename,NULL));
+	return(Parse(NULL,NULL,Filename,NULL));
 }
 


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user