20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
22 |
#include "quotearg.h" |
#include "quotearg.h" |
23 |
|
#include "error.h" |
24 |
#include "hash.h" |
#include "hash.h" |
25 |
#include "struniq.h" |
#include "struniq.h" |
26 |
|
|
40 |
const struniq_t |
const struniq_t |
41 |
struniq_new (const char *s) |
struniq_new (const char *s) |
42 |
{ |
{ |
43 |
/* Keep the struniqs in a printable form. */ |
struniq_t res = hash_lookup (struniqs_table, s); |
|
struniq_t res = hash_lookup (struniqs_table, |
|
|
quotearg_style (escape_quoting_style, s)); |
|
|
|
|
44 |
if (!res) |
if (!res) |
45 |
{ |
{ |
46 |
/* First insertion in the hash. */ |
/* First insertion in the hash. */ |
47 |
res = xstrdup (quotearg_style (escape_quoting_style, s)); |
res = xstrdup (s); |
48 |
hash_insert (struniqs_table, res); |
hash_insert (struniqs_table, res); |
49 |
} |
} |
50 |
return res; |
return res; |
51 |
} |
} |
52 |
|
|
53 |
|
|
54 |
|
/*---------------------------------. |
55 |
|
| Return TRUE iff S is a struniq. | |
56 |
|
`---------------------------------*/ |
57 |
|
|
58 |
|
bool |
59 |
|
struniq_assert_p (const char *s) |
60 |
|
{ |
61 |
|
if (!hash_lookup (struniqs_table, s)) |
62 |
|
{ |
63 |
|
error (0, 0, "not a struniq: %s", quotearg (s)); |
64 |
|
return false; |
65 |
|
} |
66 |
|
else |
67 |
|
{ |
68 |
|
return true; |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
/*--------------------. |
/*--------------------. |
74 |
| Print the struniq. | |
| Print the struniq. | |
75 |
`--------------------*/ |
`--------------------*/ |