disable debug
[AROS.git] / workbench / libs / uuid / uuid_parse.c
blob88e3bc94ffc0626000a4d2f0263b9aface6e30ff
1 /*
2 Copyright © 2007-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/symbolsets.h>
7 #include <aros/debug.h>
8 #include <aros/libcall.h>
9 #include <proto/exec.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <ctype.h>
15 #include "uuid_private.h"
16 #include LC_LIBDEFS_FILE
18 static char value(char chr)
20 if (isdigit(chr))
21 chr -= '0';
22 else
23 chr -= isupper(chr) ? 'A' - 10 : 'a' - 10;
24 return chr;
27 AROS_LH2(int, UUID_Parse,
28 AROS_LHA(const char *, in, A0),
29 AROS_LHA(uuid_t *, uuid, A1),
30 struct uuid_base *, UUIDBase, 7, UUID)
32 AROS_LIBFUNC_INIT
34 int i;
35 uuid_t tmp = {0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}};
37 D(bug("[UUID] UUID_Parse(%s, %p)\n", in, uuid));
39 if (strlen(in) == UUID_STRLEN)
41 for (i=0; i < 8; i++, in++)
43 if (isxdigit(*in))
45 tmp.time_low = (tmp.time_low << 4) | value(*in);
47 else return 0;
50 if (*in++ != '-')
51 return 0;
53 for (i=0; i < 4; i++, in++)
55 if (isxdigit(*in))
57 tmp.time_mid = (tmp.time_mid << 4) | value(*in);
59 else return 0;
62 if (*in++ != '-')
63 return 0;
65 for (i=0; i < 4; i++, in++)
67 if (isxdigit(*in))
69 tmp.time_hi_and_version =
70 (tmp.time_hi_and_version << 4) | value(*in);
72 else return 0;
75 if (*in++ != '-')
76 return 0;
78 if (!(isxdigit(in[0]) && isxdigit(in[1])))
79 return 0;
81 tmp.clock_seq_hi_and_reserved = (value(in[0]) << 4) | value(in[1]);
83 if (!(isxdigit(in[2]) && isxdigit(in[3])))
84 return 0;
86 tmp.clock_seq_low = (value(in[2]) << 4) | value(in[3]);
87 in +=4;
89 if (*in++ != '-')
90 return 0;
92 for (i=0; i < 6; i++, in+=2)
94 if (!(isxdigit(in[0]) && isxdigit(in[1])))
95 return 0;
97 tmp.node[i] = (value(in[0]) << 4) | value(in[1]);
100 *uuid = tmp;
101 return 1;
104 return 0;
106 AROS_LIBFUNC_EXIT
109 AROS_LH2(void, UUID_Unparse,
110 AROS_LHA(const uuid_t *, uuid, A0),
111 AROS_LHA(char *, out, A1),
112 struct uuid_base *, UUIDBase, 8, UUID)
114 AROS_LIBFUNC_INIT
116 snprintf(out, UUID_STRLEN + 1,
117 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
118 (unsigned int)uuid->time_low,
119 uuid->time_mid,
120 uuid->time_hi_and_version,
121 uuid->clock_seq_hi_and_reserved,
122 uuid->clock_seq_low,
123 uuid->node[0],uuid->node[1],uuid->node[2],
124 uuid->node[3],uuid->node[4],uuid->node[5]);
126 AROS_LIBFUNC_EXIT