[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.

Here is my original email:

Currently, dia can not convert diagrams to other file formats from the
command line when the target file name does not end in a normal extension.
For example, dia can convert foo.dia to bar.png using:                       
                                                        
dia -n -e bar.png foo.dia

or from foo.dia to foo.png using:

dia -n -t png foo.dia

However, I can not do the following:

TMPFILE=`mktemp /tmp/image.XXXXXX`
dia -n -t png -e $TMPFILE foo.dia (output does not end in .png)

Enclosed you should find a proposed patch.  It should make it so that
'-t' and '-e' are not mutually exclusive.  I would be very interested
to hear comments about my patch and alternatives.

Here is the patch:

diff -u --recursive dia-vanilla/app/app_procs.c dia/app/app_procs.c
--- dia-vanilla/app/app_procs.c 2003-07-19 11:35:27.000000000 -0500
+++ dia/app/app_procs.c 2003-09-11 20:01:01.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
@@ -454,14 +440,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)) {
@@ -499,13 +509,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/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-10 21:56:49.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-10 22:00:18.000000000 -0500
@@ -78,19 +78,13 @@
   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;
     g



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