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

Re: [PATCH] change -e and -t behavior



>> A little over a week ago I sent a patch to dia-list that modified dia's
>> -e and -t behavior.  I think the new behavior is sane and useful (in my
>> case for creating thumbnails of diagram files).  I'd really like to hear
>> what people think of my solution.  I would like to see dia have the
>> ability to convert(from the command line) diagrams and save the output
>> using any filename, not just ones ending in .png, etc.
 
> While the idea is sound, I wish you'd at least try to compile the patch
> before submitting it.

Okay, it compiles now.  The patch was done against the CVS version of dia
(as of 20 Sept. 2003).  However, since this version is a bit unstable
on my machine, most testing was done using 0.91.  The important parts
of the patch apply against 0.91 but of course the patch is intended
for CVS.

==============================================================================

diff -u --recursive dia-vanilla/app/app_procs.c dia/app/app_procs.c
--- dia-vanilla/app/app_procs.c	2003-09-20 15:59:33.000000000 -0500
+++ dia/app/app_procs.c	2003-09-20 18:45:20.000000000 -0500
@@ -149,9 +149,9 @@
 
 gboolean 
 do_convert(const char *infname,
-           const char *outfname)
+           const char *outfname,
+	   DiaExportFilter *ef)
 {
-  DiaExportFilter *ef = NULL;
   DiaImportFilter *inf = NULL;
   DiagramData *diagdata = NULL;
 
@@ -174,13 +174,6 @@
             argv0,infname);
             exit(1);
   }
-  ef = filter_guess_export_filter(outfname);
-  if (!ef) {
-    fprintf(stderr,
-            _("%s error: don't know how to export into %s\n"),
-            argv0,outfname);
-            exit(1);
-  }
   ef->export(diagdata, outfname, infname, ef->user_data);
   /* if (!quiet) */ fprintf(stdout,
                       _("%s --> %s\n"),
@@ -313,13 +306,6 @@
             exit(0);
         }
 
-        if (export_file_format && export_file_name) {
-            fprintf(stderr,
-                    _("%s error: can specify only one of -f or -o."),
-                    argv[0]);
-            exit(1);
-        }
-
     }
 #endif
 #endif
@@ -458,14 +444,38 @@
       while (poptPeekArg(poptCtx)) {
           Diagram *diagram = NULL;
           DDisplay *ddisp = NULL;
+	  DiaExportFilter *ef = NULL;
           char *in_file_name = (char *)poptGetArg(poptCtx);
 
-          if (export_file_name) {
-              made_conversions |= do_convert(in_file_name,export_file_name);
+          if (export_file_name && export_file_format) {
+              ef = filter_get_export_filter(export_file_format);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s (%s)\n"),
+                  argv0,export_file_name,export_file_format);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
+          } else if (export_file_name) {
+              ef = filter_guess_export_filter(export_file_name);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s\n"),
+                  argv0,export_file_name);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
           } else if (export_file_format) {
               export_file_name = build_output_file_name(in_file_name,
                                                         export_file_format);
-              made_conversions |= do_convert(in_file_name,export_file_name);
+              ef = filter_guess_export_filter(export_file_name);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s\n"),
+                  argv0,export_file_name);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
               g_free(export_file_name);
           } else {
 	      if (g_file_test(in_file_name, G_FILE_TEST_EXISTS)) {
@@ -503,13 +513,36 @@
                   continue;
               }
           }
-          
-          if (export_file_name) {
-              made_conversions |= do_convert(in_file_name,export_file_name);
+
+          if (export_file_name && export_file_format) {
+              ef = filter_get_export_filter(export_file_format);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s (%s)\n"),
+                  argv0,export_file_name,export_file_format);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
+          } else if (export_file_name) {
+              ef = filter_guess_export_filter(export_file_name);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s\n"),
+                  argv0,export_file_name);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
           } else if (export_file_format) {
               export_file_name = build_output_file_name(in_file_name,
                                                         export_file_format);
-              made_conversions |= do_convert(in_file_name,export_file_name);
+              ef = filter_guess_export_filter(export_file_name);
+              if (!ef) {
+                  fprintf(stderr,
+                  _("%s error: don't know how to export into %s\n"),
+                  argv0,export_file_name);
+                  exit(1);
+              }
+              made_conversions |= do_convert(in_file_name,export_file_name,ef);
               g_free(export_file_name);
           } else {
               diagram = diagram_load(in_file_name, NULL);
diff -u --recursive dia-vanilla/app/app_procs.h dia/app/app_procs.h
--- dia-vanilla/app/app_procs.h	2002-02-10 18:37:06.000000000 -0600
+++ dia/app/app_procs.h	2003-09-20 20:44:19.000000000 -0500
@@ -18,11 +18,13 @@
 #ifndef APP_PROCS_H
 #define APP_PROCS_H
 
+#include <diatypes.h>
+
 void app_init(int argc, char **argv);
 void app_exit(void);
 int app_is_embedded(void);
 
-gboolean do_convert(const char *infname, const char *outfname);
+gboolean do_convert(const char *infname, const char *outfname, DiaExportFilter *ef);
 char *build_output_file_name(const char *infname, const char *format);
 
 void app_splash_init(const gchar* name);
diff -u --recursive dia-vanilla/app/diaconv.c dia/app/diaconv.c
--- dia-vanilla/app/diaconv.c	2002-06-22 12:19:13.000000000 -0500
+++ dia/app/diaconv.c	2003-09-20 18:45:20.000000000 -0500
@@ -213,7 +213,13 @@
       export_file_name = build_output_file_name(in_file_name,
                                                 export_file_format);
       g_message("export_file_name = %s",export_file_name);
-      do_convert(in_file_name,export_file_name);
+      ef = filter_guess_export_filter(export_file_name);
+      if (!ef) {
+          fprintf(stderr, _("%s error: don't know how to export into %s\n"),
+                  argv0,export_file_name);
+          exit(1);
+      }
+      do_convert(in_file_name,export_file_name,ef);
       g_free(export_file_name);
       in_file_name = poptGetArg(poptCtx);
     }
@@ -226,7 +232,13 @@
               argv[0]);
       exit(1);
     }
-    do_convert(in_file_name,export_file_name);
+    ef = filter_guess_export_filter(export_file_name);
+    if (!ef) {
+        fprintf(stderr, _("%s error: don't know how to export into %s\n"),
+                argv0,export_file_name);
+        exit(1);
+    }
+    do_convert(in_file_name,export_file_name,ef);
   }
   exit(0);
 }
diff -u --recursive dia-vanilla/lib/filter.c dia/lib/filter.c
--- dia-vanilla/lib/filter.c	2003-02-16 01:04:31.000000000 -0600
+++ dia/lib/filter.c	2003-09-20 18:53:12.000000000 -0500
@@ -78,18 +78,11 @@
   return ret;
 }
 
-/* guess the filter for a given filename. */
+/* return the filter for a given file extension. */
 DiaExportFilter *
-filter_guess_export_filter(const gchar *filename)
+filter_get_export_filter(const gchar *ext)
 {
   GList *tmp;
-  gchar *ext;
-
-  ext = strrchr(filename, '.');
-  if (ext)
-    ext++;
-  else
-    ext = "";
 
   for (tmp = export_filters; tmp != NULL; tmp = tmp->next) {
     DiaExportFilter *ef = tmp->data;
@@ -102,6 +95,21 @@
   return NULL;
 }
 
+/* guess the filter for a given filename. */
+DiaExportFilter *
+filter_guess_export_filter(const gchar *filename)
+{
+  gchar *ext;
+
+  ext = strrchr(filename, '.');
+  if (ext)
+    ext++;
+  else
+    ext = "";
+
+  return filter_get_export_filter(ext);
+}
+
 static gint
 import_filter_compare(gconstpointer a, gconstpointer b)
 {

==============================================================================

-- 
Mike

:wq



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK