1 /* param.c
2  * Copyright (C) 2005 Sylvain Cresto <scresto@gmail.com>
3  *
4  * This file is part of graveman!
5  *
6  * graveman! is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or
9  * (at your option) any later version.
10  *
11  * graveman! is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with program; see the file COPYING. If not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, USA.
20  *
21  * URL: http://www.nongnu.org/graveman/
22  *
23  */
24 
25 #include "graveman.h"
26 
27 GHashTable *Gparamhash = NULL;
28 
param_store_value(gchar * Aentry,gchar * Avalue)29 void param_store_value(gchar *Aentry, gchar *Avalue)
30 {
31   gpointer Loldkey, Loldval;
32   /* on commence par supprimer l'eventuelle ancienne cle */
33   if (g_hash_table_lookup_extended(Gparamhash, Aentry, &Loldkey, &Loldval) == TRUE) {
34     g_hash_table_remove(Gparamhash, Aentry);
35     g_free(Loldkey);
36     g_free(Loldval);
37   }
38 
39   g_hash_table_insert(Gparamhash, g_strdup(Aentry), g_strdup(Avalue ? Avalue : ""));
40 }
41 
42 /* renvoi une valeur de la ligne de commande */
param_get_string(gchar * Anom)43 gchar *param_get_string(gchar *Anom)
44 {
45   return (gchar *)g_hash_table_lookup(Gparamhash, Anom);
46 }
47 
48 /* renvoi un boolean de la ligne de commande */
param_get_boolean(gchar * Anom)49 gboolean param_get_boolean(gchar *Anom)
50 {
51   gchar *Lvalue = (gchar *) g_hash_table_lookup(Gparamhash, Anom);
52   return (Lvalue && *Lvalue == '1' ? TRUE : FALSE);
53 }
54 
55 /* parsing ligne de commande */
graveman_init(gint Aargc,gchar * Aargv[])56 gboolean graveman_init(gint Aargc, gchar *Aargv[]) {
57   gint i;
58   gchar *ptr;
59 
60   Gparamhash = _hash();
61 
62   for (i = 1; i <= Aargc; i++) {
63     ptr = Aargv[i-1];
64     while (*ptr=='-') ptr++;
65     if (*ptr == 'v') {
66       g_printf("%s\n", VERSION);
67       return FALSE;
68     } else if (*ptr == 'V') {
69       g_printf("%s: %s\n", _("Version"), VERSION);
70       g_printf("%s: %s\n", _("Compiled with ogg vorbis support"),
71 #ifdef ENABLE_OGG
72           _("yes")
73 #else
74           _("no")
75 #endif
76           );
77       g_printf("%s: %s\n", _("Compiled with mp3 support"),
78 #ifdef ENABLE_MP3
79           _("yes")
80 #else
81           _("no")
82 #endif
83           );
84       g_printf("%s: %s\n", _("Compiled with flac support"),
85 #ifdef ENABLE_FLAC
86           _("yes")
87 #else
88           _("no")
89 #endif
90           );
91       g_printf("%s: %s\n", _("Compiled with linux-ide devices support"),
92 #ifdef LINUX_IDE
93           _("yes")
94 #else
95           _("no")
96 #endif
97           );
98 
99       g_printf("%s: %s\n", _("Compiled with linux-scsi devices support"),
100 #ifdef LINUX_SCSI
101           _("yes")
102 #else
103           _("no")
104 #endif
105           );
106 
107       g_printf("%s %s\n", _("Compiled"),
108 #ifdef DEBUG
109           _("with debug support")
110 #else
111           _("without debug support")
112 #endif
113           );
114       return FALSE;
115     } else if (*ptr == 'h') {
116       g_printf("%s! %s\n", PACKAGE, VERSION);
117       g_printf(_("By Sylvain Cresto <scresto@gmail.com>\n\n"));
118       g_printf("  %s %s %s\n"
119                "\t-v\t\t%s\n"
120                "\t-V\t\t%s\n"
121                "\t-s\t\t%s\n"
122                "\t-c <%s>\t%s\n"
123                "\t-D <%s>\t%s\n"
124                "\t-t <%s>\t%s\n\t  %s\n\n  %s\n\n",
125                _("Usage:"), Aargv[0], _("[options]"), _("show version number."),
126                _("show compilation informations."), _("always scan devices on startup."),
127                _("files..."),
128                _("define preference-ordered set of extra configuration files to use in priority."),
129                _("dir..."),
130                _("define preference-ordered set of extra data directories to use in priority."),
131                _("themes..."),
132                _("define preference-ordered set of theme to use."),
133                _("\t\tconfiguration files, data directories and themes should be separated with a colon ':'."),
134                _("Type \"man graveman\" to get more informations."));
135       return FALSE;
136     } else if (*ptr == 's') {
137       param_store_value("scan_drives", "1");
138     } else if (*ptr == 'c') {
139       if (++i<=Aargc) {
140         param_store_value("config_file", Aargv[i-1]);
141       } else {
142         g_warning(_("ignoring invalid %s parameter without file.\n"), Aargv[i-2]);
143       }
144     } else if (*ptr == 'D' || (!strcmp(ptr, "data"))) {
145       if (++i<=Aargc) {
146         param_store_value("data_file", Aargv[i-1]);
147       } else {
148         g_warning(_("ignoring invalid %s parameter without file.\n"), Aargv[i-2]);
149       }
150     }
151   }
152 
153   /* appel a sc_init() dans support.c */
154   sc_init();
155   return TRUE;
156 }
157 
158 /*
159  * vim:et:ts=8:sts=2:sw=2
160  */
161