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
26 #include <libgnomeprint/gnome-print-master.h>
29 #include "xml-label.h"
34 /*============================================*/
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;
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}
65 /*****************************************************************************/
67 /*****************************************************************************/
69 main (int argc, char **argv)
71 GnomeProgram *program;
75 GSList *p, *file_list = NULL;
77 GnomePrintMaster *master = NULL;
79 GnomePrintConfig *config = NULL;
80 glLabel *label = NULL;
81 glXMLLabelStatus status;
83 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
84 textdomain (GETTEXT_PACKAGE);
86 /* Initialize minimal gnome program */
87 program = gnome_program_init ("glabels-batch", VERSION,
88 LIBGNOME_MODULE, 1, argv,
89 GNOME_PROGRAM_STANDARD_PROPERTIES,
92 /* argument parsing */
93 pctx = poptGetContext (NULL, argc, (const char **)argv, options, 0);
94 poptSetOtherOptionHelp (pctx, _("[OPTION...] GLABELS_FILE...") );
95 if ( (rc = poptGetNextOpt(pctx)) < -1 ) {
96 fprintf (stderr, "%s: %s\n",
97 poptBadOption (pctx,0), poptStrerror(rc));
98 poptPrintUsage (pctx, stderr, 0);
101 if ( version_flag ) {
102 fprintf ( stderr, "glabels-batch %s\n", VERSION );
105 poptPrintHelp (pctx, stderr, 0);
108 args = (char **) poptGetArgs (pctx);
109 for (n_files = 0; args && args[n_files]; n_files++) {
110 file_list = g_slist_append (file_list, args[n_files]);
113 fprintf ( stderr, _("missing glabels file\n") );
114 poptPrintHelp (pctx, stderr, 0);
117 poptFreeContext (pctx);
119 /* initialize components */
123 /* now print the files */
124 for (p = file_list; p; p = p->next) {
125 g_print ("LABEL FILE = %s\n", p->data);
126 label = gl_xml_label_open (p->data, &status);
127 if ( status == XML_LABEL_OK ) {
129 if ( master == NULL ) {
130 master = gnome_print_master_new ();
133 gl_print_batch (master, label, n_sheets, n_copies,
134 outline_flag, reverse_flag);
136 g_object_unref (label);
139 fprintf ( stderr, _("cannot open glabels file %s\n"),
143 if ( master != NULL ) {
145 abs_fn = gl_util_make_absolute ( output );
146 gnome_print_master_print_to_file (master, abs_fn);
149 gnome_print_master_close (master);
150 gnome_print_master_print (master);
152 g_object_unref (master);
155 g_slist_free (file_list);