~elementary-os/ubuntu-package-imports/desktop-file-utils-xenial

« back to all changes in this revision

Viewing changes to src/validator.c

  • Committer: RabbitBot
  • Date: 2016-01-17 16:50:38 UTC
  • Revision ID: rabbitbot@elementary.io-20160117165038-3yu4qhcpf1rjfh01
Initial import, version 0.22-1ubuntu3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* validator.c: validate a desktop entry file
 
2
 * vim: set ts=2 sw=2 et: */
 
3
 
 
4
/*
 
5
 * Copyright (C) 2007, 2008 Vincent Untz <vuntz@gnome.org>
 
6
 *
 
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.
 
9
 * It was written by:
 
10
 *  Mark McLoughlin <mark@skynet.ie>
 
11
 *  Havoc Pennington <hp@pobox.com>
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
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,
 
26
 * USA.
 
27
 */
 
28
 
 
29
#include "validate.h"
 
30
 
 
31
static gboolean   warn_kde = FALSE;
 
32
static gboolean   no_hints = FALSE;
 
33
static gboolean   no_warn_deprecated = FALSE;
 
34
static char     **filename = NULL;
 
35
 
 
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>..." },
 
41
  { NULL }
 
42
};
 
43
 
 
44
int
 
45
main (int argc, char *argv[])
 
46
{
 
47
  GOptionContext *context;
 
48
  GError         *error;
 
49
  int i;
 
50
  gboolean all_valid;
 
51
 
 
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
 
56
                                         ".\n"
 
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);
 
61
 
 
62
  error = NULL;
 
63
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
 
64
    g_printerr ("Error while parsing arguments: %s\n", error->message);
 
65
    g_error_free (error);
 
66
    return 1;
 
67
  }
 
68
 
 
69
  g_option_context_free (context);
 
70
 
 
71
  if (filename == NULL || filename[0] == NULL) {
 
72
    g_printerr ("See \"%s --help\" for correct usage.\n", g_get_prgname ());
 
73
    return 1;
 
74
  }
 
75
 
 
76
  all_valid = TRUE;
 
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]);
 
80
      all_valid = FALSE;
 
81
    } else if (!desktop_file_validate (filename[i], warn_kde, no_warn_deprecated, no_hints))
 
82
      all_valid = FALSE;
 
83
  }
 
84
 
 
85
  if (!all_valid)
 
86
    return 1;
 
87
 
 
88
  return 0;
 
89
}