]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels-batch.c
Initial revision
[glabels] / glabels2 / src / glabels-batch.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  glabels.c: main program module
5  *
6  *  Copyright (C) 2001  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include <config.h>
24
25 #include <gnome.h>
26 #include <libgnomeprint/gnome-print-master.h>
27
28 #include "merge.h"
29 #include "xml-label.h"
30 #include "template.h"
31 #include "print.h"
32 #include "util.h"
33
34 /*============================================*/
35 /* Private globals                            */
36 /*============================================*/
37 static gboolean help_flag    = FALSE;
38 static gboolean version_flag = FALSE;
39 static gchar    *output      = "output.ps";
40 static gint     n_copies     = 1;
41 static gint     n_sheets     = 1;
42 static gboolean outline_flag = FALSE;
43 static gboolean reverse_flag = FALSE;
44
45 static struct poptOption options[] = {
46         {"help", 'h', POPT_ARG_NONE, &help_flag, 1,
47          N_("print this message"), NULL},
48         {"version", 'v', POPT_ARG_NONE, &version_flag, 0,
49          N_("print the version of glabels-batch being used"), NULL},
50         {"output", 'o', POPT_ARG_STRING, &output, 0,
51          N_("set output filename (default=\"output.ps\")"), N_("filename")},
52         {"sheets", 's', POPT_ARG_INT, &n_sheets, 0,
53          N_("number of sheets (default=1)"), N_("sheets")},
54         {"copies", 'c', POPT_ARG_INT, &n_copies, 0,
55          N_("number of copies (default=1)"), N_("copies")},
56         {"outline", 'l', POPT_ARG_NONE, &outline_flag, 0,
57          N_("print outlines (to test printer alignment)"), NULL},
58         {"reverse", 'r', POPT_ARG_NONE, &reverse_flag, 0,
59          N_("print in reverse (i.e. a mirror image)"), NULL},
60         {NULL, '\0', 0, NULL, 0, NULL, NULL}
61 };
62
63
64 \f
65 /*****************************************************************************/
66 /* Main                                                                      */
67 /*****************************************************************************/
68 int
69 main (int argc,
70       char *argv[])
71 {
72         poptContext pctx;
73         gchar **args;
74         gint rc;
75         GSList *p, *file_list = NULL;
76         gint n_files;
77         GnomePrintMaster *master = NULL;
78         gchar *abs_fn;
79         GnomePrintConfig *config = NULL;
80         glLabel *label = NULL;
81         glXMLLabelStatus status;
82
83         bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
84         textdomain (PACKAGE);
85
86         gtk_type_init ();
87
88         /* argument parsing */
89         pctx = poptGetContext (NULL, argc, argv, options, 0);
90         poptSetOtherOptionHelp (pctx, _("[OPTION...] GLABELS_FILE...") );
91         if ( (rc = poptGetNextOpt(pctx)) < -1 ) {
92                 fprintf (stderr, "%s: %s\n",
93                          poptBadOption (pctx,0), poptStrerror(rc));
94                 poptPrintUsage (pctx, stderr, 0);
95                 return -1;
96         }
97         if ( version_flag ) {
98                 fprintf ( stderr, "glabels-batch %s\n", VERSION );
99         }
100         if ( help_flag ) {
101                 poptPrintHelp (pctx, stderr, 0);
102                 return -1;
103         }
104         args = (char **) poptGetArgs (pctx);
105         for (n_files = 0; args && args[n_files]; n_files++) {
106                 file_list = g_slist_append (file_list, args[n_files]);
107         }
108         if ( !n_files ) {
109                 fprintf ( stderr, _("missing glabels file\n") );
110                 poptPrintHelp (pctx, stderr, 0);
111                 return -1;
112         }
113         poptFreeContext (pctx);
114
115         /* initialize components */
116         gl_merge_init ();
117         gl_template_init ();
118
119         /* now print the files */
120         for (p = file_list; p; p = p->next) {
121                 gl_xml_label_open (p->data, &status);
122                 if ( status == XML_LABEL_OK ) {
123
124                         if ( master == NULL ) {
125                                 master = gnome_print_master_new ();
126                                 config = gnome_print_master_get_config (master);
127                                 abs_fn = gl_util_make_absolute ( output );
128                                 gnome_print_config_set (config,
129                                                         GNOME_PRINT_KEY_OUTPUT_FILENAME,
130                                                         abs_fn);
131                                 g_free( abs_fn );
132                         }
133
134                         gl_print_batch( master, label, n_sheets, n_copies,
135                                         outline_flag, reverse_flag );
136
137                         g_object_unref( label );
138                 }
139                 else {
140                         fprintf ( stderr, _("cannot open glabels file %s\n"),
141                                   (char *)p->data );
142                 }
143         }
144         if ( master != NULL ) {
145                 gnome_print_master_print (master);
146         }
147
148         g_slist_free (file_list);
149
150         return 0;
151 }
152