]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/id128-print.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
8 #include "id128-print.h"
10 #include "pretty-print.h"
11 #include "terminal-util.h"
13 int id128_pretty_print(sd_id128_t id
, bool pretty
) {
15 _cleanup_free_
char *man_link
= NULL
, *mod_link
= NULL
;
19 printf(SD_ID128_FORMAT_STR
"\n",
20 SD_ID128_FORMAT_VAL(id
));
24 on
= ansi_highlight();
27 if (terminal_urlify("man:systemd-id128(1)", "systemd-id128(1)", &man_link
) < 0)
30 if (terminal_urlify("https://docs.python.org/3/library/uuid.html", "uuid", &mod_link
) < 0)
34 "%s" SD_ID128_FORMAT_STR
"%s\n\n"
36 "%s%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%s\n\n"
38 "%s#define MESSAGE_XYZ SD_ID128_MAKE(",
39 on
, SD_ID128_FORMAT_VAL(id
), off
,
40 on
, SD_ID128_FORMAT_VAL(id
), off
,
43 for (i
= 0; i
< 16; i
++)
44 printf("%02x%s", id
.bytes
[i
], i
!= 15 ? "," : "");
45 printf(")%s\n\n", off
);
47 printf("As Python constant:\n"
49 ">>> %sMESSAGE_XYZ = uuid.UUID('" SD_ID128_FORMAT_STR
"')%s\n",
51 on
, SD_ID128_FORMAT_VAL(id
), off
);
56 int id128_print_new(bool pretty
) {
60 r
= sd_id128_randomize(&id
);
62 return log_error_errno(r
, "Failed to generate ID: %m");
64 return id128_pretty_print(id
, pretty
);