1 /* main.c
2 *
3 * Copyright (c) 1998-2004 Mike Oliphant <grip@nostatic.org>
4 *
5 * http://www.nostatic.org/grip
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
21 */
22
23 #include <config.h>
24 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
26 #include <stdlib.h>
27
28 #include "grip.h"
29
30 static gint TimeOut(gpointer data);
31
32 gboolean do_debug=TRUE;
33 GtkWidget* grip_app;
34
35 /* popt table */
36 static char *config_filename=NULL;
37 static char *device=NULL;
38 static char *scsi_device=NULL;
39 static int force_small=FALSE;
40 static int local_mode=FALSE;
41 static int no_redirect=FALSE;
42 static int verbose=FALSE;
43
44 G_GNUC_NORETURN static gboolean
option_version_cb(const gchar * option_name,const gchar * value,gpointer data,GError ** error)45 option_version_cb(const gchar *option_name,
46 const gchar *value,
47 gpointer data,
48 GError **error)
49 {
50 g_print("%s %s\n", PACKAGE, VERSION);
51 exit(0);
52 }
53
54 static const GOptionEntry options[] = {
55 {
56 "config",
57 'c', 0,
58 G_OPTION_ARG_STRING,
59 &config_filename,
60 N_("Specify the config file to use (in your home dir)"),
61 N_("CONFIG")
62 },
63 {
64 "device",
65 'd', 0,
66 G_OPTION_ARG_STRING,
67 &device,
68 N_("Specify the cdrom device to use"),
69 N_("DEVICE")
70 },
71 {
72 "scsi-device",
73 0, 0,
74 G_OPTION_ARG_STRING,
75 &scsi_device,
76 N_("Specify the generic scsi device to use"),
77 N_("DEVICE")
78 },
79 {
80 "small",
81 's', 0,
82 G_OPTION_ARG_NONE,
83 &force_small,
84 N_("Launch in \"small\" (cd-only) mode"),
85 NULL
86 },
87 {
88 "local",
89 'l', 0,
90 G_OPTION_ARG_NONE,
91 &local_mode,
92 N_("\"Local\" mode -- do not look up disc info on the net"),
93 NULL
94 },
95 {
96 "no-redirect",
97 0, 0,
98 G_OPTION_ARG_NONE,
99 &no_redirect,
100 N_("Do not do I/O redirection"),
101 NULL
102 },
103 {
104 "verbose",
105 'v', 0,
106 G_OPTION_ARG_NONE,
107 &verbose,
108 N_("Run in verbose (debug) mode"),
109 NULL
110 },
111 {
112 "version",
113 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
114 G_OPTION_ARG_CALLBACK,
115 option_version_cb,
116 NULL,
117 NULL
118 },
119 { NULL }
120 };
121
Debug(char * fmt,...)122 void Debug(char *fmt,...)
123 {
124 va_list args;
125 char *msg;
126
127 if(do_debug) {
128 va_start(args,fmt);
129
130 msg=g_strdup_vprintf(fmt,args);
131 if(msg) {
132 g_printerr("%s", msg);
133 g_free(msg);
134 }
135 }
136
137 va_end(args);
138 }
139
Cmain(int argc,char * argv[])140 int Cmain(int argc, char* argv[])
141 {
142 GOptionContext *context;
143
144 /* Unbuffer stdout */
145 setvbuf(stdout, 0, _IONBF, 0);
146
147 /* setup locale, i18n */
148 gtk_set_locale();
149 bindtextdomain(GETTEXT_PACKAGE,GNOMELOCALEDIR);
150 textdomain(GETTEXT_PACKAGE);
151
152 context = g_option_context_new (NULL);
153 g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
154 g_option_context_set_ignore_unknown_options (context, TRUE);
155 g_option_context_parse (context, &argc, &argv, NULL);
156
157 gtk_init(&argc, &argv);
158
159 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
160 setenv("CHARSET","UTF-8",1);
161
162 do_debug=verbose;
163
164 if(scsi_device) printf("scsi=[%s]\n",scsi_device);
165
166 /* Start a new Grip app */
167 grip_app=GripNew(device,scsi_device,config_filename,
168 force_small,local_mode,
169 no_redirect);
170
171 gtk_widget_show(grip_app);
172
173 gtk_timeout_add(1000,TimeOut,0);
174
175 gtk_main();
176
177 return 0;
178 }
179
TimeOut(gpointer data)180 static gint TimeOut(gpointer data)
181 {
182 GripUpdate(grip_app);
183
184 return TRUE;
185 }
186