tracker-0.16.2/src/tracker-control/tracker-control.c

No issues found

  1 /*
  2  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public License
  6  * as published by the Free Software Foundation; either version 2
  7  * of the License, or (at your option) any later version.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  * GNU General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public License
 15  * along with this program; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 17  * 02110-1301, USA.
 18  */
 19 
 20 #include "config.h"
 21 
 22 #include <stdlib.h>
 23 #include <string.h>
 24 #include <time.h>
 25 #include <locale.h>
 26 #include <errno.h>
 27 #include <sys/types.h>
 28 #include <signal.h>
 29 
 30 #include <glib.h>
 31 #include <glib/gi18n.h>
 32 #include <glib/gprintf.h>
 33 #include <glib/gstdio.h>
 34 
 35 #include <libtracker-common/tracker-common.h>
 36 
 37 #include "tracker-control.h"
 38 
 39 #define ABOUT	  \
 40 	"Tracker " PACKAGE_VERSION "\n"
 41 
 42 #define LICENSE	  \
 43 	"This program is free software and comes without any warranty.\n" \
 44 	"It is licensed under version 2 or later of the General Public " \
 45 	"License which can be viewed at:\n" \
 46 	"\n" \
 47 	"  http://www.gnu.org/licenses/gpl.txt\n"
 48 
 49 static gboolean print_version;
 50 
 51 static GOptionEntry common_entries[] = {
 52 	{ "version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
 53 	  N_("Print version"),
 54 	  NULL },
 55 	{ NULL }
 56 };
 57 
 58 int
 59 main (int argc, char **argv)
 60 {
 61 	GOptionContext *context;
 62 
 63 	setlocale (LC_ALL, "");
 64 
 65 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
 66 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 67 	textdomain (GETTEXT_PACKAGE);
 68 
 69 	/* Translators: this messagge will apper immediately after the  */
 70 	/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
 71 	context = g_option_context_new (_(" - Manage Tracker processes and data"));
 72 
 73 	/* Groups */
 74 	g_option_context_add_group (context,
 75 	                            tracker_control_general_get_option_group ());
 76 	g_option_context_add_group (context,
 77 	                            tracker_control_status_get_option_group ());
 78 	g_option_context_add_group (context,
 79 	                            tracker_control_miners_get_option_group ());
 80 	/* Common options */
 81 	g_option_context_add_main_entries (context, common_entries, NULL);
 82 
 83 	g_option_context_parse (context, &argc, &argv, NULL);
 84 	g_option_context_free (context);
 85 
 86 	if (print_version) {
 87 		g_print ("\n" ABOUT "\n" LICENSE "\n");
 88 		return EXIT_SUCCESS;
 89 	}
 90 
 91 	/* General options? */
 92 	if (tracker_control_general_options_enabled ()) {
 93 		if (tracker_control_status_options_enabled ()) {
 94 			g_printerr ("%s\n",
 95 			            _("General and Status options cannot be used together"));
 96 			return EXIT_FAILURE;
 97 		}
 98 
 99 		if (tracker_control_miners_options_enabled ()) {
100 			g_printerr ("%s\n",
101 			            _("General and Miners options cannot be used together"));
102 			return EXIT_FAILURE;
103 		}
104 
105 		return tracker_control_general_run ();
106 	}
107 
108 	/* Status options? */
109 	if (tracker_control_status_options_enabled ()) {
110 		if (tracker_control_miners_options_enabled ()) {
111 			g_printerr ("%s\n",
112 			            _("Status and Miners options cannot be used together"));
113 			return EXIT_FAILURE;
114 		}
115 
116 		return tracker_control_status_run ();
117 	}
118 
119 	/* Miners options? */
120 	if (tracker_control_miners_options_enabled ()) {
121 		return tracker_control_miners_run ();
122 	}
123 
124 	/* Unknown options? */
125 	if (argc > 1) {
126 		gint i = 1;
127 
128 		g_printerr ("%s: ",
129 		            _("Unrecognized options"));
130 		for (i = 1; i < argc; i++) {
131 			g_printerr ("'%s'%s",
132 			            argv[i],
133 			            i == (argc - 1) ? "\n" : ", ");
134 		}
135 		return EXIT_FAILURE;
136 	}
137 
138 	/* No-args output */
139 	tracker_control_general_run_default ();
140 	printf ("\n");
141 
142 	tracker_control_status_run_default ();
143 	printf ("\n");
144 
145 	tracker_control_miners_run_default ();
146 
147 	return EXIT_SUCCESS;
148 }