From 8431a195e080bc1bb90316389c4b09225e80e705 Mon Sep 17 00:00:00 2001
From: Bert Timmerman <bert.timmerman@xs4all.nl>
Date: Thu, 3 Mar 2011 22:13:34 +0100
Subject: [PATCH 1/1] Add pcb specific code to file.c and file.h.

---
 file.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 file.h |    2 ++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/file.c b/file.c
index c8a0e69..7ba6e6e 100644
--- a/file.c
+++ b/file.c
@@ -19,6 +19,7 @@
 
 #include "dump.h"
 #include "kicad.h"
+#include "pcb.h"
 #include "postscript.h"
 #include "util.h"
 #include "file.h"
@@ -78,6 +79,31 @@ int save_to(const char *name, int (*fn)(FILE *file))
 }
 
 
+int
+pcb_save_to (const char *name, int (*fn)(FILE *file))
+{
+        FILE *file;
+
+        file = fopen (name, "w");
+        if (!file)
+        {
+                perror (name);
+                return 0;
+        }
+        if (!fn (file))
+        {
+                perror (name);
+                return 0;
+        }
+        if (fclose (file) == EOF)
+        {
+                perror (name);
+                return 0;
+        }
+        return 1;
+}
+
+
 void save_with_backup(const char *name, int (*fn)(FILE *file))
 {
 	char *s = stralloc(name);
@@ -169,6 +195,26 @@ void write_kicad(void)
 }
 
 
+void write_pcb (void)
+{
+        char *name;
+
+        if (save_file_name)
+        {
+                name = set_extension (save_file_name, "fp");
+                pcb_save_to (name, pcb);
+                free (name);
+        }
+        else
+        {
+                if (!pcb (stdout))
+                {
+                        perror ("stdout");
+                }
+        }
+}
+
+
 static void do_write_ps(int (*fn)(FILE *file))
 {
 	char *name;
diff --git a/file.h b/file.h
index 582d712..f7bb5c1 100644
--- a/file.h
+++ b/file.h
@@ -24,10 +24,12 @@ int file_exists(const char *name);
 
 char *set_extension(const char *name, const char *ext);
 int save_to(const char *name, int (*fn)(FILE *file));
+int pcb_save_to(const char *name, int (*fn)(FILE *file));
 void save_with_backup(const char *name, int (*fn)(FILE *file));
 
 void save_fpd(void);
 void write_kicad(void);
+void write_pcb(void);
 void write_ps(void);
 void write_ps_fullpage(void);
 
-- 
1.7.3.4

