2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * glabels.c: main program module
6 * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
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.
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.
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
28 #include <libgnomeprint/gnome-printer.h>
36 /*============================================*/
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;
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}
67 /*****************************************************************************/
69 /*****************************************************************************/
77 GSList *p, *file_list = NULL;
79 GnomePrintMaster *master = NULL;
81 GnomePrinter *prn = NULL;
82 glLabel *label = NULL;
84 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
87 setlocale (LC_ALL, "");
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);
100 fprintf ( stderr, "glabels-batch %s\n", VERSION );
103 poptPrintHelp (pctx, stderr, 0);
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]);
111 fprintf ( stderr, _("missing glabels file\n") );
112 poptPrintHelp (pctx, stderr, 0);
115 poptFreeContext (pctx);
117 /* initialize components */
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 ) {
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 );
130 gnome_print_master_set_printer ( master, prn );
133 gl_print_batch( master, label, n_sheets, n_copies,
134 outline_flag, reverse_flag );
136 gl_label_free( &label );
139 fprintf ( stderr, _("cannot open glabels file %s\n"),
143 if ( master != NULL ) {
145 gnome_print_master_print (master);
148 g_slist_free (file_list);