+boolean get_boolean_from_string(char *s)
+{
+ char *s_lower = getStringToLower(s);
+ boolean result = FALSE;
+
+ if (strEqual(s_lower, "true") ||
+ strEqual(s_lower, "yes") ||
+ strEqual(s_lower, "on") ||
+ get_integer_from_string(s) == 1)
+ result = TRUE;
+
+ free(s_lower);
+
+ return result;
+}
+
+int get_switch3_from_string(char *s)
+{
+ char *s_lower = getStringToLower(s);
+ int result = FALSE;
+
+ if (strEqual(s_lower, "true") ||
+ strEqual(s_lower, "yes") ||
+ strEqual(s_lower, "on") ||
+ get_integer_from_string(s) == 1)
+ result = TRUE;
+ else if (strEqual(s_lower, "auto"))
+ result = AUTO;
+
+ free(s_lower);
+
+ return result;
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* functions for generic lists */
+/* ------------------------------------------------------------------------- */
+
+ListNode *newListNode()
+{
+ return checked_calloc(sizeof(ListNode));
+}
+
+void addNodeToList(ListNode **node_first, char *key, void *content)
+{
+ ListNode *node_new = newListNode();
+
+ node_new->key = getStringCopy(key);
+ node_new->content = content;
+ node_new->next = *node_first;
+
+ if (*node_first)
+ (*node_first)->prev = node_new;
+
+ *node_first = node_new;
+}
+
+void deleteNodeFromList(ListNode **node_first, char *key,
+ void (*destructor_function)(void *))
+{
+ if (node_first == NULL || *node_first == NULL)
+ return;
+
+ if (strEqual((*node_first)->key, key))
+ {
+ checked_free((*node_first)->key);
+
+ if (destructor_function)
+ destructor_function((*node_first)->content);
+
+ if ((*node_first)->next)
+ (*node_first)->next->prev = (*node_first)->prev;
+
+ checked_free(*node_first);
+
+ *node_first = (*node_first)->next;
+ }
+ else
+ deleteNodeFromList(&(*node_first)->next, key, destructor_function);
+}
+
+ListNode *getNodeFromKey(ListNode *node_first, char *key)
+{
+ if (node_first == NULL)
+ return NULL;
+
+ if (strEqual(node_first->key, key))
+ return node_first;
+ else
+ return getNodeFromKey(node_first->next, key);
+}
+
+int getNumNodes(ListNode *node_first)
+{
+ return (node_first ? 1 + getNumNodes(node_first->next) : 0);
+}
+
+void dumpList(ListNode *node_first)
+{
+ ListNode *node = node_first;
+
+ while (node)
+ {
+ printf("['%s' (%d)]\n", node->key,
+ ((struct ListNodeInfo *)node->content)->num_references);
+ node = node->next;
+ }
+
+ printf("[%d nodes]\n", getNumNodes(node_first));
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* functions for file handling */
+/* ------------------------------------------------------------------------- */
+
+File *openFile(char *filename, char *mode)
+{
+ File *file = checked_calloc(sizeof(File));
+
+ file->file = fopen(filename, mode);
+
+ if (file->file != NULL)
+ {
+ file->filename = getStringCopy(filename);
+
+ return file;
+ }
+
+#if defined(PLATFORM_ANDROID)
+ file->asset_file = SDL_RWFromFile(filename, mode);
+
+ if (file->asset_file != NULL)
+ {
+ file->file_is_asset = TRUE;
+ file->filename = getStringCopy(filename);
+
+ return file;
+ }
+#endif
+
+ checked_free(file);
+
+ return NULL;
+}
+
+int closeFile(File *file)
+{
+ if (file == NULL)
+ return -1;
+
+ int result = 0;
+
+#if defined(PLATFORM_ANDROID)
+ if (file->asset_file)
+ result = SDL_RWclose(file->asset_file);
+#endif
+
+ if (file->file)
+ result = fclose(file->file);
+
+ checked_free(file->filename);
+ checked_free(file);
+
+ return result;
+}
+
+int checkEndOfFile(File *file)
+{
+#if defined(PLATFORM_ANDROID)
+ if (file->file_is_asset)
+ return file->end_of_file;
+#endif
+
+ return feof(file->file);
+}
+
+size_t readFile(File *file, void *buffer, size_t item_size, size_t num_items)
+{
+#if defined(PLATFORM_ANDROID)
+ if (file->file_is_asset)
+ {
+ if (file->end_of_file)
+ return 0;
+
+ size_t num_items_read =
+ SDL_RWread(file->asset_file, buffer, item_size, num_items);
+
+ if (num_items_read < num_items)
+ file->end_of_file = TRUE;
+
+ return num_items_read;
+ }
+#endif
+
+ return fread(buffer, item_size, num_items, file->file);
+}
+
+int seekFile(File *file, long offset, int whence)
+{
+#if defined(PLATFORM_ANDROID)
+ if (file->file_is_asset)
+ {
+ int sdl_whence = (whence == SEEK_SET ? RW_SEEK_SET :
+ whence == SEEK_CUR ? RW_SEEK_CUR :
+ whence == SEEK_END ? RW_SEEK_END : 0);
+
+ return (SDL_RWseek(file->asset_file, offset, sdl_whence) == -1 ? -1 : 0);
+ }
+#endif
+
+ return fseek(file->file, offset, whence);
+}
+
+int getByteFromFile(File *file)
+{
+#if defined(PLATFORM_ANDROID)
+ if (file->file_is_asset)
+ {
+ if (file->end_of_file)
+ return EOF;
+
+ byte c;
+ size_t num_bytes_read = SDL_RWread(file->asset_file, &c, 1, 1);
+
+ if (num_bytes_read < 1)
+ file->end_of_file = TRUE;
+
+ return (file->end_of_file ? EOF : (int)c);
+ }
+#endif
+
+ return fgetc(file->file);
+}
+
+char *getStringFromFile(File *file, char *line, int size)
+{
+#if defined(PLATFORM_ANDROID)
+ if (file->file_is_asset)
+ {
+ if (file->end_of_file)
+ return NULL;
+
+ char *line_ptr = line;
+ int num_bytes_read = 0;
+
+ while (num_bytes_read < size - 1 &&
+ SDL_RWread(file->asset_file, line_ptr, 1, 1) == 1 &&
+ *line_ptr++ != '\n')
+ num_bytes_read++;
+
+ *line_ptr = '\0';
+
+ if (strlen(line) == 0)
+ {
+ file->end_of_file = TRUE;
+
+ return NULL;
+ }
+
+ return line;
+ }
+#endif
+
+ return fgets(line, size, file->file);
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* functions for directory handling */
+/* ------------------------------------------------------------------------- */
+
+Directory *openDirectory(char *dir_name)
+{
+ Directory *dir = checked_calloc(sizeof(Directory));
+
+ dir->dir = opendir(dir_name);
+
+ if (dir->dir != NULL)
+ {
+ dir->filename = getStringCopy(dir_name);
+
+ return dir;
+ }
+
+#if defined(PLATFORM_ANDROID)
+ char *asset_toc_filename = getPath2(dir_name, ASSET_TOC_BASENAME);
+
+ dir->asset_toc_file = SDL_RWFromFile(asset_toc_filename, MODE_READ);
+
+ checked_free(asset_toc_filename);
+
+ if (dir->asset_toc_file != NULL)
+ {
+ dir->directory_is_asset = TRUE;
+ dir->filename = getStringCopy(dir_name);
+
+ return dir;
+ }
+#endif
+
+ checked_free(dir);
+
+ return NULL;
+}
+
+int closeDirectory(Directory *dir)
+{
+ if (dir == NULL)
+ return -1;
+
+ int result = 0;
+
+#if defined(PLATFORM_ANDROID)
+ if (dir->asset_toc_file)
+ result = SDL_RWclose(dir->asset_toc_file);
+#endif
+
+ if (dir->dir)
+ result = closedir(dir->dir);
+
+ if (dir->dir_entry)
+ freeDirectoryEntry(dir->dir_entry);
+
+ checked_free(dir->filename);
+ checked_free(dir);
+
+ return result;
+}
+
+DirectoryEntry *readDirectory(Directory *dir)