Translation update done using Pootle.
[gammu.git] / gammu-detect / main.c
blob60520dd583ac8de88e330b836dafbe10806db83a
1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; either version 2 of the License, or
4 * (at your option) any later version.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 * Copyright (c) 2010 - 2011 Michal Cihar <michal@cihar.com>
18 #include <glib.h>
19 #include <glib-object.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
26 #include <gammu.h> /* For PRINTF_STYLE and locales */
27 #include "../helper/locales.h" /* For gettext */
29 #include "config.h"
30 #include "main.h"
32 #ifdef GUDEV_FOUND
33 #include "udev.h"
34 #endif
35 #ifdef BLUEZ_FOUND
36 #include "bluez.h"
37 #endif
38 #ifdef WIN32
39 #include "win32-serial.h"
40 #endif
42 gint debug = 0;
43 #ifdef GUDEV_FOUND
44 gint no_udev = 0;
45 #endif
46 #ifdef BLUEZ_FOUND
47 gint no_bluez = 0;
48 #endif
49 #ifdef WIN32
50 gint no_win32_serial = 0;
51 #endif
52 gint show_version = 0;
54 static GOptionEntry entries[] = {
55 {"debug", 'd', 0, G_OPTION_ARG_NONE, &debug, N_("Show debugging output for detecting devices."), NULL},
56 {"version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Show version information and compiled in features."), NULL},
57 #ifdef GUDEV_FOUND
58 {"no-udev", 'u', 0, G_OPTION_ARG_NONE, &no_udev, N_("Disables scanning of udev."), NULL},
59 #endif
60 #ifdef BLUEZ_FOUND
61 {"no-bluez", 'b', 0, G_OPTION_ARG_NONE, &no_bluez, N_("Disables scanning using Bluez."), NULL},
62 #endif
63 #ifdef WIN32
64 {"no-win32-serial", 'w', 0, G_OPTION_ARG_NONE, &no_win32_serial, N_("Disables scanning of Windows serial ports."), NULL},
65 #endif
66 {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, "", NULL}
69 void print_version(void)
71 printf(_("Gammu-detect version %s"), GAMMU_VERSION);
72 printf("\n");
73 printf(_("Built %s on %s using %s"), __TIME__, __DATE__, GetCompiler());
74 printf("\n");
75 printf("\n");
76 printf("%s\n", _("Compiled in features:"));
77 #ifdef GUDEV_FOUND
78 printf(" - %s\n", _("udev probing"));
79 #endif
80 #ifdef BLUEZ_FOUND
81 printf(" - %s\n", _("Bluez probing"));
82 #endif
83 #ifdef WIN32
84 printf(" - %s\n", _("Windows serial port probing"));
85 #endif
86 printf("\n");
87 printf("%s\n", _("Copyright (C) 2010 - 2011 Michal Cihar <michal@cihar.com> and other authors."));
88 printf("\n");
89 printf("%s\n", _("License GPLv2: GNU GPL version 2 <http://creativecommons.org/licenses/GPL/2.0/>."));
90 printf("%s\n", _("This is free software: you are free to change and redistribute it."));
91 printf("%s\n", _("There is NO WARRANTY, to the extent permitted by law."));
92 printf("\n");
93 printf("%s\n", _("Check <http://wammu.eu/gammu/> for updates."));
94 printf("\n");
97 void print_config(const gchar *device, const gchar *name, const gchar *connection)
99 static gint section = 0;
101 if (section == 0) {
102 g_print("; %s\n", _("Configuration file generated by gammu-detect."));
103 g_print("; %s\n", _("Please check The Gammu Manual for more information."));
104 g_print("\n");
105 g_print("[gammu]\n");
106 } else {
107 g_print("[gammu%d]\n", section);
110 section++;
112 g_print("device = %s\n", device);
113 if (name != NULL) {
114 g_print("name = %s\n", name);
116 if (connection != NULL) {
117 g_print("connection = %s\n", connection);
119 g_print("\n");
122 int main(int argc, char *argv[])
124 GError *error = NULL;
125 GSM_Error gerror;
126 INI_Section *cfg = NULL;
127 char *locales_path = NULL;
129 GOptionContext *context;
131 gerror = GSM_FindGammuRC(&cfg, NULL);
132 if (gerror == ERR_NONE) {
133 locales_path = INI_GetValue(cfg, "gammu", "gammuloc", FALSE);
134 } else {
135 locales_path = NULL;
137 GSM_InitLocales(locales_path);
138 #ifdef LIBINTL_LIB_FOUND
139 if (locales_path != NULL) {
140 bindtextdomain("gammu", locales_path);
141 } else {
142 #if defined(LOCALE_PATH)
143 bindtextdomain("gammu", LOCALE_PATH);
144 #else
145 bindtextdomain("gammu", ".");
146 #endif
148 textdomain("gammu");
149 #endif
151 if (cfg != NULL) {
152 INI_Free(cfg);
155 g_type_init();
157 context = g_option_context_new("");
158 g_option_context_add_main_entries(context, entries, "gammu");
159 if (!g_option_context_parse(context, &argc, &argv, &error)) {
160 g_printerr(_("option parsing failed: %s\n"), error->message);
161 exit(1);
164 if (show_version) {
165 print_version();
166 return 0;
169 #ifdef GUDEV_FOUND
170 if (!no_udev) {
171 udev_detect();
173 #endif
174 #ifdef BLUEZ_FOUND
175 if (!no_bluez) {
176 bluez_detect();
178 #endif
179 #ifdef WIN32
180 if (!no_win32_serial) {
181 win32_serial_detect();
183 #endif
185 return 0;
188 /* How should editor hadle tabs in this file? Add editor commands here.
189 * vim: noexpandtab sw=8 ts=8 sts=8: