pre3 updates
[dia.git] / app / diaconv.c
blob01e0527c994d5d0ac17e92bcbd0a245724d4bd51
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.
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #include <errno.h>
26 #ifdef HAVE_DIRENT_H
27 #include <dirent.h>
28 #endif
29 #include <sys/stat.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <locale.h>
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #include <gmodule.h>
38 #include <libxml/parser.h>
40 #ifdef G_OS_WIN32
41 #include <direct.h>
42 #define mkdir(s,a) _mkdir(s)
43 #endif
45 #include "intl.h"
46 #include "app_procs.h"
47 #include "object.h"
48 #include "color.h"
49 #include "tool.h"
50 #include "modify_tool.h"
51 #include "interface.h"
52 #include "group.h"
53 #include "message.h"
54 #include "display.h"
55 #include "layer_dialog.h"
56 #include "load_save.h"
57 #include "preferences.h"
58 #include "dia_dirs.h"
59 #include "render_eps.h"
60 #include "sheet.h"
61 #include "plug-ins.h"
62 #include "utils.h"
63 #include "filter.h"
65 #if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
66 extern DiaExportFilter png_export_filter;
67 #endif
69 extern const char *argv0;
70 int quiet = 0;
72 #if (defined(HAVE_POPT_H))
73 #include <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);
80 int
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;
86 int rc = 0;
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;
104 argv0 = argv[0];
106 printf("hi !\n");
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");
114 #endif
115 textdomain(PACKAGE);
117 printf("hi !\n");
119 if (argv) {
120 poptCtx = poptGetContext(PACKAGE, argc, argv, options, 0);
121 poptSetOtherOptionHelp(poptCtx, _("[OPTION...] [FILE...]"));
122 printf("hi !\n");
124 while (rc >= 0) {
125 rc = poptGetNextOpt(poptCtx);
126 if (rc < -1) {
127 fprintf(stderr,
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),
131 poptStrerror(rc),
132 argv[0]);
133 exit(1);
135 switch (rc) {
136 case -1: break;
137 case 1:
138 poptPrintHelp(poptCtx, stdout, 0);
139 exit(0);
140 case 2:
141 quiet = 1;
142 break;
143 default:
144 break;
147 } else {
148 fprintf(stderr,
149 _("Error: No arguments found.\nRun '%s --help' to see a full "
150 "list of available command line options.\n"),
151 argv[0]);
152 exit(1);
154 printf("hop !\n");
156 /* we have leftover arguments now to process. */
157 if (export_file_format && export_file_name) {
158 fprintf(stderr,
159 _("%s error: can specify only one of -t or -o."),
160 argv[0]);
161 exit(1);
163 if (!(export_file_format || export_file_name)) {
164 fprintf(stderr,
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"),
168 argv[0],argv[0]);
169 exit(1);
171 in_file_name = poptGetArg(poptCtx);
172 if (!in_file_name) {
173 fprintf(stderr,
174 _("%s error: no input file."),
175 argv[0]);
176 exit(1);
179 printf("hip !\n");
180 /*dia_image_init();*/
181 printf("hop !\n");
182 /*color_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;
186 printf("hip !\n");
187 dia_font_init(pango_ft2_get_context(100,100));
188 printf("hop !\n");
189 object_registry_init();
190 printf("hap !\n");
192 dia_register_plugins();
193 printf("hup !\n");
194 dia_register_builtin_plugin(internal_plugin_init);
195 printf("hip !\n");
197 load_all_sheets();
198 printf("hzp !\n");
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"));
205 exit(1);
209 if (export_file_format) {
210 /* we know which target file format. We can now load diagrams and save
211 them in turn. */
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,
216 export_file_format);
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);
222 } else {
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) {
226 fprintf(stderr,
227 _("%s error: only one input file expected."),
228 argv[0]);
229 exit(1);
231 do_convert(in_file_name, export_file_name, NULL);
233 exit(0);
236 #else /* this is ugly. FIXME. */
237 int
238 main(int argc, char **argv) {
239 fprintf(stderr,
240 _("%s error: popt library not available on this system"),
241 argv[0]);
242 exit(1);
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"),
252 NULL, NULL))
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);
266 #endif
267 return DIA_PLUGIN_INIT_OK;
270 int app_is_embedded(void)
272 return 0;
275 static 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;
281 gint len;
283 len = format_string_length_upper_bound (fmt, args);
285 if (len >= alloc) {
286 if (buf)
287 g_free (buf);
289 alloc = nearest_pow (MAX(len + 1, 1024));
291 buf = g_new (char, alloc);
294 vsprintf (buf, fmt, *args2);
296 fprintf(stderr,
297 "%s %s: %s\n",
298 argv0,title,buf);