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>
31 usage (char *name, int ecode)
34 name = "dbus-uuidgen";
36 fprintf (stderr, "Usage: %s [--ensure[=FILENAME]] [--get[=FILENAME]]\n", name);
43 printf ("D-Bus UUID Generator %s\n"
44 "Copyright (C) 2006 Red Hat, Inc.\n"
45 "This is free software; see the source for copying conditions.\n"
46 "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
52 get_arg (const char *arg,
58 if (strlen(arg) < strlen(option))
61 fn = arg + strlen(option);
63 if (!(*fn == '=' || *fn == ' ' || *fn == '\0'))
71 while (*fn == ' ' && *fn != '\0')
84 main (int argc, char *argv[])
88 dbus_bool_t ensure_uuid;
97 for (i = 1; i < argc; i++)
101 if (strncmp (arg, "--ensure", strlen("--ensure")) == 0)
103 get_arg (arg, "--ensure", &filename);
106 else if (strncmp (arg, "--get", strlen("--get")) == 0)
108 get_arg (arg, "--get", &filename);
111 else if (strcmp (arg, "--help") == 0)
113 else if (strcmp (arg, "--version") == 0)
119 if (get_uuid && ensure_uuid)
121 fprintf (stderr, "Can't specify both --get and --ensure\n");
125 dbus_error_init (&error);
127 if (get_uuid || ensure_uuid)
130 if (dbus_internal_do_not_use_get_uuid (filename, &uuid, ensure_uuid, &error))
132 if (get_uuid) /* print nothing on --ensure */
133 printf ("%s\n", uuid);
140 if (dbus_internal_do_not_use_create_uuid (&uuid))
142 printf ("%s\n", uuid);
147 dbus_set_error (&error, DBUS_ERROR_NO_MEMORY, "No memory");
151 if (dbus_error_is_set (&error))
153 fprintf (stderr, "%s\n", error.message);
154 dbus_error_free (&error);