1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-uuidgen.c Utility program to create UUIDs
4 * Copyright (C) 2006 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <dbus/dbus-uuidgen.h>
28 #include <dbus/dbus.h>
30 static void usage (const char *name, int ecode) _DBUS_GNUC_NORETURN;
33 usage (const char *name,
37 name = "dbus-uuidgen";
39 fprintf (stderr, "Usage: %s [--ensure[=FILENAME]] [--get[=FILENAME]]\n", name);
43 static void version (void) _DBUS_GNUC_NORETURN;
48 printf ("D-Bus UUID Generator %s\n"
49 "Copyright (C) 2006 Red Hat, Inc.\n"
50 "This is free software; see the source for copying conditions.\n"
51 "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
57 get_arg (const char *arg,
63 if (strlen(arg) < strlen(option))
66 fn = arg + strlen(option);
68 if (!(*fn == '=' || *fn == ' ' || *fn == '\0'))
76 while (*fn == ' ' && *fn != '\0')
89 main (int argc, char *argv[])
93 dbus_bool_t ensure_uuid;
102 for (i = 1; i < argc; i++)
106 if (strncmp (arg, "--ensure", strlen("--ensure")) == 0)
108 get_arg (arg, "--ensure", &filename);
111 else if (strncmp (arg, "--get", strlen("--get")) == 0)
113 get_arg (arg, "--get", &filename);
116 else if (strcmp (arg, "--help") == 0)
118 else if (strcmp (arg, "--version") == 0)
124 if (get_uuid && ensure_uuid)
126 fprintf (stderr, "Can't specify both --get and --ensure\n");
130 dbus_error_init (&error);
132 if (get_uuid || ensure_uuid)
135 if (dbus_internal_do_not_use_get_uuid (filename, &uuid, ensure_uuid, &error))
137 if (get_uuid) /* print nothing on --ensure */
138 printf ("%s\n", uuid);
146 if (_dbus_create_uuid (&uuid, &error))
148 printf ("%s\n", uuid);
153 if (dbus_error_is_set (&error))
155 fprintf (stderr, "%s\n", error.message);
156 dbus_error_free (&error);