19 |
Boston, MA 02111-1307, USA. */ |
Boston, MA 02111-1307, USA. */ |
20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
22 |
#include "hash.h" |
|
23 |
#include "quotearg.h" |
#include <hash.h> |
24 |
|
#include <quotearg.h> |
25 |
|
|
26 |
#include "files.h" |
#include "files.h" |
27 |
#include "muscle_tab.h" |
#include "muscle_tab.h" |
28 |
#include "getargs.h" |
#include "getargs.h" |
29 |
|
|
30 |
|
typedef struct |
31 |
|
{ |
32 |
|
const char *key; |
33 |
|
char *value; |
34 |
|
} muscle_entry; |
35 |
|
|
36 |
/* An obstack used to create some entries. */ |
/* An obstack used to create some entries. */ |
37 |
struct obstack muscle_obstack; |
struct obstack muscle_obstack; |
44 |
static bool |
static bool |
45 |
hash_compare_muscles (void const *x, void const *y) |
hash_compare_muscles (void const *x, void const *y) |
46 |
{ |
{ |
47 |
const muscle_entry_t *m1 = x; |
muscle_entry const *m1 = x; |
48 |
const muscle_entry_t *m2 = y; |
muscle_entry const *m2 = y; |
49 |
return strcmp (m1->key, m2->key) == 0; |
return strcmp (m1->key, m2->key) == 0; |
50 |
} |
} |
51 |
|
|
52 |
static unsigned int |
static unsigned int |
53 |
hash_muscle (const void *x, unsigned int tablesize) |
hash_muscle (const void *x, unsigned int tablesize) |
54 |
{ |
{ |
55 |
const muscle_entry_t *m = x; |
muscle_entry const *m = x; |
56 |
return hash_string (m->key, tablesize); |
return hash_string (m->key, tablesize); |
57 |
} |
} |
58 |
|
|
97 |
void |
void |
98 |
muscle_insert (const char *key, char *value) |
muscle_insert (const char *key, char *value) |
99 |
{ |
{ |
100 |
muscle_entry_t probe; |
muscle_entry probe; |
101 |
muscle_entry_t *entry = NULL; |
muscle_entry *entry = NULL; |
102 |
|
|
103 |
probe.key = key; |
probe.key = key; |
104 |
entry = hash_lookup (muscle_table, &probe); |
entry = hash_lookup (muscle_table, &probe); |
106 |
if (!entry) |
if (!entry) |
107 |
{ |
{ |
108 |
/* First insertion in the hash. */ |
/* First insertion in the hash. */ |
109 |
entry = XMALLOC (muscle_entry_t, 1); |
entry = XMALLOC (muscle_entry, 1); |
110 |
entry->key = key; |
entry->key = key; |
111 |
hash_insert (muscle_table, entry); |
hash_insert (muscle_table, entry); |
112 |
} |
} |
123 |
void |
void |
124 |
muscle_grow (const char *key, const char *val, const char *separator) |
muscle_grow (const char *key, const char *val, const char *separator) |
125 |
{ |
{ |
126 |
muscle_entry_t probe; |
muscle_entry probe; |
127 |
muscle_entry_t *entry = NULL; |
muscle_entry *entry = NULL; |
128 |
|
|
129 |
probe.key = key; |
probe.key = key; |
130 |
entry = hash_lookup (muscle_table, &probe); |
entry = hash_lookup (muscle_table, &probe); |
132 |
if (!entry) |
if (!entry) |
133 |
{ |
{ |
134 |
/* First insertion in the hash. */ |
/* First insertion in the hash. */ |
135 |
entry = XMALLOC (muscle_entry_t, 1); |
entry = XMALLOC (muscle_entry, 1); |
136 |
entry->key = key; |
entry->key = key; |
137 |
hash_insert (muscle_table, entry); |
hash_insert (muscle_table, entry); |
138 |
entry->value = xstrdup (val); |
entry->value = xstrdup (val); |
178 |
char* |
char* |
179 |
muscle_find (const char *key) |
muscle_find (const char *key) |
180 |
{ |
{ |
181 |
muscle_entry_t probe; |
muscle_entry probe; |
182 |
muscle_entry_t *result = NULL; |
muscle_entry *result = NULL; |
183 |
|
|
184 |
probe.key = key; |
probe.key = key; |
185 |
result = hash_lookup (muscle_table, &probe); |
result = hash_lookup (muscle_table, &probe); |
192 |
`------------------------------------------------*/ |
`------------------------------------------------*/ |
193 |
|
|
194 |
static int |
static int |
195 |
muscle_m4_output (muscle_entry_t *entry, FILE *out) |
muscle_m4_output (muscle_entry *entry, FILE *out) |
196 |
{ |
{ |
197 |
fprintf (out, "m4_define([b4_%s],\n", entry->key); |
fprintf (out, "m4_define([b4_%s],\n", entry->key); |
198 |
fprintf (out, "[[%s]])\n\n\n", entry->value); |
fprintf (out, "[[%s]])\n\n\n", entry->value); |