summaryrefslogtreecommitdiff
path: root/src/validator.c
diff options
context:
space:
mode:
authorVincent Untz <vuntz@gnome.org>2007-03-15 22:14:06 +0000
committerVincent Untz <vuntz@gnome.org>2007-03-15 22:14:06 +0000
commit4aab76b0fb470a1fcda17a6458ce210d44548478 (patch)
treed7ad4d7122b041ccb130e488d16375384fff6f4d /src/validator.c
parent818536c358d110f695c68566a23d393a19d71904 (diff)
remove mention of desktop-menu-tool kill, was useless and deprecated
2007-03-15 Vincent Untz <vuntz@gnome.org> * README: remove mention of desktop-menu-tool * acconfig.h: kill, was useless and deprecated * src/eggintl.h: kill, was useless since quite some time * autogen.sh: * configure.in: updated because of src/desktop_file.h removal * src/Makefile.am: updated for file removals/additions * src/desktop_file.[ch]: removed. We don't use this anymore (it was based on GnomeDesktopItem which nobody maintains and is too complex for what we need) * keyfileutils.[ch]: new, contains some useful functions based on GKeyFile * src/install.c: updated for changes (GnomeDesktopFile -> GKeyFile) (process_one_file): ditto also, improves a bit the --help output * src/validate.[ch]: pretty much a rewrite. This is based on GKeyFile for now, but it'll be moved to a small parser soon, so we are not limited because of the GKeyFile parser. The validator verifies more things, warns about usage of deprecated stuff, and contains some other nice improvements. It probably contains some bugs, though. * src/validator.c: updated (well, rewritten, since it's only the main() function). We also now have some command line arguments: --warn-kde to warn about usage of KDE reserved stuff --no-warn-deprecated to not warn about usage of deprecated stuff
Diffstat (limited to 'src/validator.c')
-rw-r--r--src/validator.c92
1 files changed, 65 insertions, 27 deletions
diff --git a/src/validator.c b/src/validator.c
index 042b10d..ec24c98 100644
--- a/src/validator.c
+++ b/src/validator.c
@@ -1,38 +1,76 @@
+/* validator.c: validate a desktop entry file
+ *
+ * Copyright (C) 2007 Vincent Untz <vuntz@gnome.org>
+ *
+ * A really small portion of this code comes from the old validator.c.
+ * Authors of the old validator.c are:
+ * Mark McLoughlin
+ * Havoc Pennington
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
#include "validate.h"
+static gboolean warn_kde = TRUE;
+static gboolean no_warn_deprecated = FALSE;
+static char **filename = NULL;
+
+static GOptionEntry option_entries[] = {
+ { "warn-kde", 0, 0, G_OPTION_ARG_NONE, &warn_kde, "Warn about usage of KDE extensions to the specification", NULL },
+ { "no-warn-deprecated", 0, 0, G_OPTION_ARG_NONE, &no_warn_deprecated, "Do not warn about usage of deprecated items", NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filename, NULL, "<desktop-file>" },
+ { NULL }
+};
+
int
main (int argc, char *argv[])
{
- char *contents;
- GnomeDesktopFile *df;
- GError *error;
- char *filename;
+ GOptionContext *context;
+ GError *error;
- if (argc == 2)
- filename = argv[1];
- else
- {
- g_printerr ("Usage: %s <desktop-file>\n", argv[0]);
- exit (1);
- }
-
- if (!g_file_get_contents (filename, &contents,
- NULL, NULL))
- {
- g_printerr ("%s: error reading desktop file\n", filename);
- return 1;
- }
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "Validate desktop entry files "
+ "according to the desktop entry "
+ "specification "CURRENT_SPEC_VERSION
+ ".\n"
+ "For information about this "
+ "specification, see:\n\t"
+ "http://freedesktop.org/wiki/Standards/desktop-entry-spec");
+ g_option_context_add_main_entries (context, option_entries, NULL);
error = NULL;
- df = gnome_desktop_file_new_from_string (contents, &error);
-
- if (!df)
- {
- g_printerr ("%s: parse error: %s\n", filename, error->message);
- return 1;
- }
-
- if (desktop_file_validate (df, filename))
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ g_printerr ("Error while parsing arguments: %s\n", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ /* only accept one desktop file argument */
+ if (filename == NULL || filename[0] == NULL || filename[1] != NULL) {
+ g_printerr ("See \"%s --help\" for correct usage.\n", g_get_prgname ());
+ return 1;
+ }
+
+ if (!g_file_test (filename[0], G_FILE_TEST_IS_REGULAR)) {
+ g_printerr ("%s: file does not exist\n", filename[0]);
+ return 1;
+ }
+
+ if (desktop_file_validate (filename[0], warn_kde, no_warn_deprecated))
return 0;
else
return 1;