]> git.sur5r.net Git - glabels/blob - glabels1/src/glabels_batch.c
2009-09-22 Jim Evins <evins@snaught.com>
[glabels] / glabels1 / 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 <unistd.h>
26 #include <stdlib.h>
27 #include <gnome.h>
28 #include <libgnomeprint/gnome-printer.h>
29
30 #include "merge.h"
31 #include "label.h"
32 #include "template.h"
33 #include "print.h"
34 #include "util.h"
35
36 /*============================================*/
37 /* Private globals                            */
38 /*============================================*/
39 static gboolean help_flag    = FALSE;
40 static gboolean version_flag = FALSE;
41 static gchar    *output      = "output.ps";
42 static gint     n_copies     = 1;
43 static gint     n_sheets     = 1;
44 static gboolean outline_flag = FALSE;
45 static gboolean reverse_flag = FALSE;
46
47 static struct poptOption options[] = {
48         {"help", 'h', POPT_ARG_NONE, &help_flag, 1,
49          N_("print this message"), NULL},
50         {"version", 'v', POPT_ARG_NONE, &version_flag, 0,
51          N_("print the version of glabels-batch being used"), NULL},
52         {"output", 'o', POPT_ARG_STRING, &output, 0,
53          N_("set output filename (default=\"output.ps\")"), N_("filename")},
54         {"sheets", 's', POPT_ARG_INT, &n_sheets, 0,
55          N_("number of sheets (default=1)"), N_("sheets")},
56         {"copies", 'c', POPT_ARG_INT, &n_copies, 0,
57          N_("number of copies (default=1)"), N_("copies")},
58         {"outline", 'l', POPT_ARG_NONE, &outline_flag, 0,
59          N_("print outlines (to test printer alignment)"), NULL},
60         {"reverse", 'r', POPT_ARG_NONE, &reverse_flag, 0,
61          N_("print in reverse (i.e. a mirror image)"), NULL},
62         {NULL, '\0', 0, NULL, 0, NULL, NULL}
63 };
64
65
66 \f
67 /*****************************************************************************/
68 /* Main                                                                      */
69 /*****************************************************************************/
70 int
71 main (int argc,
72       char *argv[])
73 {
74         poptContext pctx;
75         gchar **args;
76         gint rc;
77         GSList *p, *file_list = NULL;
78         gint n_files;
79         GnomePrintMaster *master = NULL;
80         gchar *abs_fn;
81         GnomePrinter *prn = NULL;
82         glLabel *label = NULL;
83
84         bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
85         textdomain (PACKAGE);
86
87         setlocale (LC_ALL, "");
88         gtk_type_init ();
89
90         /* argument parsing */
91         pctx = poptGetContext (NULL, argc, argv, options, 0);
92         poptSetOtherOptionHelp (pctx, _("[OPTION...] GLABELS_FILE...") );
93         if ( (rc = poptGetNextOpt(pctx)) < -1 ) {
94                 fprintf (stderr, "%s: %s\n",
95                          poptBadOption (pctx,0), poptStrerror(rc));
96                 poptPrintUsage (pctx, stderr, 0);
97                 return -1;
98         }
99         if ( version_flag ) {
100                 fprintf ( stderr, "glabels-batch %s\n", VERSION );
101         }
102         if ( help_flag ) {
103                 poptPrintHelp (pctx, stderr, 0);
104                 return -1;
105         }
106         args = (char **) poptGetArgs (pctx);
107         for (n_files = 0; args && args[n_files]; n_files++) {
108                 file_list = g_slist_append (file_list, args[n_files]);
109         }
110         if ( !n_files ) {
111                 fprintf ( stderr, _("missing glabels file\n") );
112                 poptPrintHelp (pctx, stderr, 0);
113                 return -1;
114         }
115         poptFreeContext (pctx);
116
117         /* initialize components */
118         gl_merge_init ();
119         gl_template_init ();
120
121         /* now print the files */
122         for (p = file_list; p; p = p->next) {
123                 if ( gl_label_open_xml( &label, p->data ) == LABEL_OK ) {
124
125                         if ( master == NULL ) {
126                                 master = gnome_print_master_new ();
127                                 abs_fn = gl_util_make_absolute ( output );
128                                 prn = gnome_printer_new_generic_ps ( abs_fn );
129                                 g_free( abs_fn );
130                                 gnome_print_master_set_printer ( master, prn );
131                         }
132
133                         gl_print_batch( master, label, n_sheets, n_copies,
134                                         outline_flag, reverse_flag );
135
136                         gl_label_free( &label );
137                 }
138                 else {
139                         fprintf ( stderr, _("cannot open glabels file %s\n"),
140                                   (char *)p->data );
141                 }
142         }
143         if ( master != NULL ) {
144                 unlink (output);
145                 gnome_print_master_print (master);
146         }
147
148         g_slist_free (file_list);
149
150         return 0;
151 }
152