[Freeciv-Dev] (PR#8694) a user for specvec
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8694 >
This patch takes the only user of athing (in registry.c) and changes it
to use specvec.
jason
Index: utility/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/registry.c,v
retrieving revision 1.62
diff -u -r1.62 registry.c
--- utility/registry.c 5 May 2004 20:39:16 -0000 1.62
+++ utility/registry.c 7 May 2004 01:12:25 -0000
@@ -172,6 +172,9 @@
#define SAVE_TABLES TRUE /* set to 0 for old-style savefiles */
#define SECF_DEBUG_ENTRIES FALSE/* LOG_DEBUG each entry value */
+#define SPECVEC_TAG astring
+#include "specvec.h"
+
/* An 'entry' is a single value, either a string or integer;
* Whether string or int is determined by whether svalue is NULL.
*/
@@ -390,7 +393,7 @@
int i;
struct astring base_name = ASTRING_INIT; /* for table or single entry */
struct astring entry_name = ASTRING_INIT;
- struct athing columns_tab; /* astrings for column headings */
+ struct astring_vector columns_tab; /* astrings for column headings */
struct astring *columns = NULL; /* -> columns_tab.ptr */
if (!inf) {
@@ -402,7 +405,7 @@
} else {
sf->filename = NULL;
}
- ath_init(&columns_tab, sizeof(struct astring));
+ astring_vector_init(&columns_tab);
sb = sf->sb;
if (filename) {
@@ -455,23 +458,25 @@
if (table_state) {
i = -1;
do {
+ int num_columns = astring_vector_size(&columns_tab);
+
i++;
inf_discard_tokens(inf, INF_TOK_EOL); /* allow newlines */
if (!(tok = inf_token_required(inf, INF_TOK_VALUE))) {
return FALSE;
}
- if (i<columns_tab.n) {
+ if (i < num_columns) {
astr_minsize(&entry_name, base_name.n + 10 + columns[i].n);
my_snprintf(entry_name.str, entry_name.n_alloc, "%s%d.%s",
base_name.str, table_lineno, columns[i].str);
} else {
astr_minsize(&entry_name,
- base_name.n + 20 + columns[columns_tab.n-1].n);
+ base_name.n + 20 + columns[num_columns - 1].n);
my_snprintf(entry_name.str, entry_name.n_alloc, "%s%d.%s,%d",
base_name.str, table_lineno,
- columns[columns_tab.n - 1].str,
- (int) (i - columns_tab.n + 1));
+ columns[num_columns - 1].str,
+ (int) (i - num_columns + 1));
}
pentry = new_entry(sb, entry_name.str, tok);
entry_list_insert_back(&psection->entries, pentry);
@@ -507,10 +512,10 @@
}
{ /* expand columns_tab: */
int j, n_prev;
- n_prev = columns_tab.n_alloc;
- ath_minnum(&columns_tab, (i+1));
- columns = columns_tab.ptr;
- for(j=n_prev; j<columns_tab.n_alloc; j++) {
+ n_prev = astring_vector_size(&columns_tab);
+ astring_vector_reserve(&columns_tab, i + 1);
+ columns = columns_tab.vector.ptr;
+ for (j = n_prev; j < i + 1; j++) {
astr_init(&columns[j]);
}
}
@@ -560,10 +565,10 @@
astr_free(&base_name);
astr_free(&entry_name);
- for(i=0; i<columns_tab.n_alloc; i++) {
+ for (i = 0; i < astring_vector_size(&columns_tab); i++) {
astr_free(&columns[i]);
}
- ath_free(&columns_tab);
+ astring_vector_free(&columns_tab);
secfilehash_build(sf, allow_duplicates);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8694) a user for specvec,
Jason Short <=
|
|