1
/* validator.c: validate a desktop entry file
2
* vim: set ts=2 sw=2 et: */
5
* Copyright (C) 2007, 2008 Vincent Untz <vuntz@gnome.org>
7
* A really small portion of this code comes from the old validator.c.
8
* The old validator.c was Copyright (C) 2002, 2004 Red Hat, Inc.
10
* Mark McLoughlin <mark@skynet.ie>
11
* Havoc Pennington <hp@pobox.com>
13
* This program is free software; you can redistribute it and/or
14
* modify it under the terms of the GNU General Public License
15
* as published by the Free Software Foundation; either version 2
16
* of the License, or (at your option) any later version.
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program; if not, write to the Free Software
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
31
static gboolean warn_kde = FALSE;
32
static gboolean no_hints = FALSE;
33
static gboolean no_warn_deprecated = FALSE;
34
static char **filename = NULL;
36
static GOptionEntry option_entries[] = {
37
{ "no-hints", 0, 0, G_OPTION_ARG_NONE, &no_hints, "Do not output hints to improve desktop file", NULL },
38
{ "no-warn-deprecated", 0, 0, G_OPTION_ARG_NONE, &no_warn_deprecated, "Do not warn about usage of deprecated items", NULL },
39
{ "warn-kde", 0, 0, G_OPTION_ARG_NONE, &warn_kde, "Warn if KDE extensions to the specification are used", NULL },
40
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filename, NULL, "<desktop-file>..." },
45
main (int argc, char *argv[])
47
GOptionContext *context;
52
context = g_option_context_new (NULL);
53
g_option_context_set_summary (context, "Validate desktop entry files "
54
"according to the Desktop Entry "
55
"specification "CURRENT_SPEC_VERSION
57
"For information about this "
58
"specification, see:\n\t"
59
"http://freedesktop.org/wiki/Specifications/desktop-entry-spec");
60
g_option_context_add_main_entries (context, option_entries, NULL);
63
if (!g_option_context_parse (context, &argc, &argv, &error)) {
64
g_printerr ("Error while parsing arguments: %s\n", error->message);
69
g_option_context_free (context);
71
if (filename == NULL || filename[0] == NULL) {
72
g_printerr ("See \"%s --help\" for correct usage.\n", g_get_prgname ());
77
for (i = 0; filename[i]; i++) {
78
if (!g_file_test (filename[i], G_FILE_TEST_IS_REGULAR)) {
79
g_printerr ("%s: file does not exist\n", filename[i]);
81
} else if (!desktop_file_validate (filename[i], warn_kde, no_warn_deprecated, no_hints))