Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / uuid / uuid_parse.c
blob68d1a874423444b89f0460fd4af1c1caefd2c350
1 /*
2 Copyright © 2007-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
8 #include <aros/symbolsets.h>
9 #include <aros/debug.h>
10 #include <aros/libcall.h>
11 #include <proto/exec.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <ctype.h>
17 #include "uuid_private.h"
18 #include LC_LIBDEFS_FILE
20 static char value(char chr)
22 if (isdigit(chr))
23 chr -= '0';
24 else
25 chr -= isupper(chr) ? 'A' - 10 : 'a' - 10;
26 return chr;
29 AROS_LH2(int, UUID_Parse,
30 AROS_LHA(const char *, in, A0),
31 AROS_LHA(uuid_t *, uuid, A1),
32 struct uuid_base *, UUIDBase, 7, UUID)
34 AROS_LIBFUNC_INIT
36 int i;
37 uuid_t tmp = {0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}};
39 D(bug("[UUID] UUID_Parse(%s, %p)\n", in, uuid));
41 if (strlen(in) == UUID_STRLEN)
43 for (i=0; i < 8; i++, in++)
45 if (isxdigit(*in))
47 tmp.time_low = (tmp.time_low << 4) | value(*in);
49 else return 0;
52 if (*in++ != '-')
53 return 0;
55 for (i=0; i < 4; i++, in++)
57 if (isxdigit(*in))
59 tmp.time_mid = (tmp.time_mid << 4) | value(*in);
61 else return 0;
64 if (*in++ != '-')
65 return 0;
67 for (i=0; i < 4; i++, in++)
69 if (isxdigit(*in))
71 tmp.time_hi_and_version =
72 (tmp.time_hi_and_version << 4) | value(*in);
74 else return 0;
77 if (*in++ != '-')
78 return 0;
80 if (!(isxdigit(in[0]) && isxdigit(in[1])))
81 return 0;
83 tmp.clock_seq_hi_and_reserved = (value(in[0]) << 4) | value(in[1]);
85 if (!(isxdigit(in[2]) && isxdigit(in[3])))
86 return 0;
88 tmp.clock_seq_low = (value(in[2]) << 4) | value(in[3]);
89 in +=4;
91 if (*in++ != '-')
92 return 0;
94 for (i=0; i < 6; i++, in+=2)
96 if (!(isxdigit(in[0]) && isxdigit(in[1])))
97 return 0;
99 tmp.node[i] = (value(in[0]) << 4) | value(in[1]);
102 *uuid = tmp;
103 return 1;
106 return 0;
108 AROS_LIBFUNC_EXIT
111 AROS_LH2(void, UUID_Unparse,
112 AROS_LHA(const uuid_t *, uuid, A0),
113 AROS_LHA(char *, out, A1),
114 struct uuid_base *, UUIDBase, 8, UUID)
116 AROS_LIBFUNC_INIT
118 snprintf(out, UUID_STRLEN, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
119 uuid->time_low,
120 uuid->time_mid,
121 uuid->time_hi_and_version,
122 uuid->clock_seq_hi_and_reserved,
123 uuid->clock_seq_low,
124 uuid->node[0],uuid->node[1],uuid->node[2],
125 uuid->node[3],uuid->node[4],uuid->node[5]);
127 AROS_LIBFUNC_EXIT