projects
/
rocksndiamonds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
869fe83
)
added sorting artwork info cache data before writing to cache file
author
Holger Schemel
<info@artsoft.org>
Thu, 4 Feb 2021 16:39:22 +0000
(17:39 +0100)
committer
Holger Schemel
<info@artsoft.org>
Thu, 4 Feb 2021 16:39:22 +0000
(17:39 +0100)
src/libgame/setup.c
patch
|
blob
|
history
diff --git
a/src/libgame/setup.c
b/src/libgame/setup.c
index e1840b1d375e92491492ed31752ecaaf59c07b48..e81498a0683f04fb5461cf4e7e0c1ce54caa979a 100644
(file)
--- a/
src/libgame/setup.c
+++ b/
src/libgame/setup.c
@@
-2326,25
+2326,51
@@
static boolean loadSetupFileData(void *setup_file_data, char *filename,
return TRUE;
}
return TRUE;
}
+static int compareSetupFileData(const void *object1, const void *object2)
+{
+ const struct ConfigInfo *entry1 = (struct ConfigInfo *)object1;
+ const struct ConfigInfo *entry2 = (struct ConfigInfo *)object2;
+
+ return strcmp(entry1->token, entry2->token);
+}
+
static void saveSetupFileHash(SetupFileHash *hash, char *filename)
{
static void saveSetupFileHash(SetupFileHash *hash, char *filename)
{
+ int item_count = hashtable_count(hash);
+ int item_size = sizeof(struct ConfigInfo);
+ struct ConfigInfo *sort_array = checked_malloc(item_count * item_size);
FILE *file;
FILE *file;
+ int i = 0;
- if (!(file = fopen(filename, MODE_WRITE)))
+ // copy string pointers from hash to array
+ BEGIN_HASH_ITERATION(hash, itr)
{
{
- Warn("cannot write configuration file '%s'", filename);
+ sort_array[i].token = HASH_ITERATION_TOKEN(itr);
+ sort_array[i].value = HASH_ITERATION_VALUE(itr);
- return;
+ i++;
+
+ if (i > item_count) // should never happen
+ break;
}
}
+ END_HASH_ITERATION(hash, itr)
- BEGIN_HASH_ITERATION(hash, itr)
+ // sort string pointers from hash in array
+ qsort(sort_array, item_count, item_size, compareSetupFileData);
+
+ if (!(file = fopen(filename, MODE_WRITE)))
{
{
- fprintf(file, "%s\n", getFormattedSetupEntry(HASH_ITERATION_TOKEN(itr),
- HASH_ITERATION_VALUE(itr)));
+ Warn("cannot write configuration file '%s'", filename);
+
+ return;
}
}
- END_HASH_ITERATION(hash, itr)
+ for (i = 0; i < item_count; i++)
+ fprintf(file, "%s\n", getFormattedSetupEntry(sort_array[i].token,
+ sort_array[i].value));
fclose(file);
fclose(file);
+
+ checked_free(sort_array);
}
SetupFileList *loadSetupFileList(char *filename)
}
SetupFileList *loadSetupFileList(char *filename)