1 /* Diaconv -- a text-mode converter tool for dia (well, sort of).
2 * Copyright (C) 2001 Cyrille Chepelov, with lots of bits reused from code
3 * Copyright (C) 1998-2000 Alexander Larsson and others.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
38 #include <libxml/parser.h>
42 #define mkdir(s,a) _mkdir(s)
46 #include "app_procs.h"
50 #include "modify_tool.h"
51 #include "interface.h"
55 #include "layer_dialog.h"
56 #include "load_save.h"
57 #include "preferences.h"
59 #include "render_eps.h"
65 #if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
66 extern DiaExportFilter png_export_filter
;
69 extern const char *argv0
;
72 #if (defined(HAVE_POPT_H))
75 static PluginInitResult
internal_plugin_init(PluginInfo
*info
);
76 static void stderr_message_internal(char *title
, const char *fmt
,
77 va_list *args
, va_list *args2
);
81 main(int argc
, char **argv
)
83 char *export_file_format
= NULL
;
84 char *export_file_name
= NULL
;
85 const char *in_file_name
= NULL
;
88 poptContext poptCtx
= NULL
;
89 struct poptOption options
[] =
91 {"to", 't', POPT_ARG_STRING
, NULL
/* &export_file_format*/ , 0,
92 N_("Export format to use"), N_("eps,png,wmf,cgm,dxf,fig")},
93 {"output",'o', POPT_ARG_STRING
, NULL
/* &export_file_name*/, 0,
94 N_("Export file name to use"), N_("OUTPUT")},
95 {"help", 'h', POPT_ARG_NONE
, 0, 1, N_("Show this help message") },
96 {"quiet", 'q', POPT_ARG_NONE
, 0, 2, N_("Quiet operation") },
97 {(char *) NULL
, '\0', 0, NULL
, 0}
100 fprintf(stderr
,"THIS THING IS BROKEN. IT DOESN'T WORK. IT WILL CRASH.\n");
101 options
[0].arg
= &export_file_format
;
102 options
[1].arg
= &export_file_name
;
108 set_message_func(stderr_message_internal
);
109 setlocale(LC_NUMERIC
,"C");
111 bindtextdomain(PACKAGE
, LOCALEDIR
);
112 #if defined HAVE_BIND_TEXTDOMAIN_CODESET
113 bind_textdomain_codeset(PACKAGE
,"UTF-8");
120 poptCtx
= poptGetContext(PACKAGE
, argc
, argv
, options
, 0);
121 poptSetOtherOptionHelp(poptCtx
, _("[OPTION...] [FILE...]"));
125 rc
= poptGetNextOpt(poptCtx
);
128 _("Error on option %s: %s.\nRun '%s --help' to see a full "
129 "list of available command line options.\n"),
130 poptBadOption(poptCtx
, 0),
138 poptPrintHelp(poptCtx
, stdout
, 0);
149 _("Error: No arguments found.\nRun '%s --help' to see a full "
150 "list of available command line options.\n"),
156 /* we have leftover arguments now to process. */
157 if (export_file_format
&& export_file_name
) {
159 _("%s error: can specify only one of -t or -o."),
163 if (!(export_file_format
|| export_file_name
)) {
165 _("%s error: must specify only one of -t or -o.\n"
166 "Run '%s --help' to see a full list "
167 "of available command line options.\n"),
171 in_file_name
= poptGetArg(poptCtx
);
174 _("%s error: no input file."),
180 /*dia_image_init();*/
183 color_black
.red
= color_black
.green
= color_black
.blue
= 0.0;
184 color_white
.red
= color_white
.green
= color_white
.blue
= 1.0;
187 dia_font_init(pango_ft2_get_context(100,100));
189 object_registry_init();
192 dia_register_plugins();
194 dia_register_builtin_plugin(internal_plugin_init
);
200 if (object_get_type("Standard - Box") == NULL
) {
201 message_error(_("Couldn't find standard objects when looking for "
202 "object-libs; exiting...\n"));
203 fprintf(stderr
, _("Couldn't find standard objects when looking for "
204 "object-libs; exiting...\n"));
209 if (export_file_format
) {
210 /* we know which target file format. We can now load diagrams and save
213 while (in_file_name
) {
214 g_message("in_file_name = %s",in_file_name
);
215 export_file_name
= build_output_file_name(in_file_name
,
217 g_message("export_file_name = %s",export_file_name
);
218 do_convert(in_file_name
, export_file_name
, NULL
);
219 g_free(export_file_name
);
220 in_file_name
= poptGetArg(poptCtx
);
223 /* we know one output name, and normally only one input name. */
224 const char *next_in_file_name
= poptGetArg(poptCtx
);
225 if (next_in_file_name
) {
227 _("%s error: only one input file expected."),
231 do_convert(in_file_name
, export_file_name
, NULL
);
236 #else /* this is ugly. FIXME. */
238 main(int argc
, char **argv
) {
240 _("%s error: popt library not available on this system"),
245 #endif /* HAVE_POPT */
247 static PluginInitResult
248 internal_plugin_init(PluginInfo
*info
)
250 if (!dia_plugin_info_init(info
, "Internal",
251 _("Objects and filters internal to dia"),
253 return DIA_PLUGIN_INIT_ERROR
;
255 /* register the group object type */
256 object_register_type(&group_type
);
258 /* register import filters */
259 filter_register_import(&dia_import_filter
);
261 /* register export filters */
262 filter_register_export(&dia_export_filter
);
263 filter_register_export(&eps_export_filter
);
264 #if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
265 filter_register_export(&png_export_filter
);
267 return DIA_PLUGIN_INIT_OK
;
270 int app_is_embedded(void)
276 stderr_message_internal(char *title
, const char *fmt
,
277 va_list *args
, va_list *args2
)
279 static gchar
*buf
= NULL
;
280 static gint alloc
= 0;
283 len
= format_string_length_upper_bound (fmt
, args
);
289 alloc
= nearest_pow (MAX(len
+ 1, 1024));
291 buf
= g_new (char, alloc
);
294 vsprintf (buf
, fmt
, *args2
);