2012-04-21 23:13:50 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 01:37:37 +01:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
2013-03-11 07:13:11 +01:00
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-01-08 00:57:44 +01:00
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-01-08 00:57:44 +01:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-01-08 00:57:44 +01:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 23:31:57 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-01-08 00:57:44 +01:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-01-09 17:49:43 +01:00
|
|
|
#include "file_list.h"
|
|
|
|
#include "../rgui.h"
|
|
|
|
|
2012-05-06 04:04:33 +02:00
|
|
|
struct rgui_file
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
|
|
|
char *path;
|
2013-03-09 19:05:11 +01:00
|
|
|
unsigned type;
|
2012-06-30 04:49:50 -04:00
|
|
|
size_t directory_ptr;
|
2012-01-08 00:57:44 +01:00
|
|
|
};
|
|
|
|
|
2013-03-12 01:03:07 +01:00
|
|
|
void rgui_list_push(void *userdata,
|
2013-03-09 19:05:11 +01:00
|
|
|
const char *path, unsigned type, size_t directory_ptr)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
2013-03-12 01:03:07 +01:00
|
|
|
rgui_list_t *list = (rgui_list_t*)userdata;
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
return;
|
|
|
|
|
2013-03-11 03:31:19 +01:00
|
|
|
if (list->size >= list->capacity)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
|
|
|
list->capacity++;
|
|
|
|
list->capacity *= 2;
|
2012-05-06 04:04:33 +02:00
|
|
|
list->list = (struct rgui_file*)realloc(list->list, list->capacity * sizeof(struct rgui_file));
|
2012-01-08 00:57:44 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 03:31:19 +01:00
|
|
|
list->list[list->size].path = strdup(path);
|
|
|
|
list->list[list->size].type = type;
|
|
|
|
list->list[list->size].directory_ptr = directory_ptr;
|
|
|
|
list->size++;
|
2012-01-08 00:57:44 +01:00
|
|
|
}
|
|
|
|
|
2012-05-06 04:04:33 +02:00
|
|
|
void rgui_list_pop(rgui_list_t *list)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
2013-03-11 03:40:44 +01:00
|
|
|
if (!(list->size == 0))
|
2013-03-11 03:31:19 +01:00
|
|
|
free(list->list[--list->size].path);
|
2012-01-08 00:57:44 +01:00
|
|
|
}
|
|
|
|
|
2012-05-06 04:04:33 +02:00
|
|
|
void rgui_list_free(rgui_list_t *list)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
2013-03-11 03:31:19 +01:00
|
|
|
for (size_t i = 0; i < list->size; i++)
|
2012-01-08 00:57:44 +01:00
|
|
|
free(list->list[i].path);
|
|
|
|
free(list->list);
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
2012-05-06 04:04:33 +02:00
|
|
|
void rgui_list_clear(rgui_list_t *list)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
2013-03-11 03:31:19 +01:00
|
|
|
for (size_t i = 0; i < list->size; i++)
|
2012-01-08 00:57:44 +01:00
|
|
|
free(list->list[i].path);
|
2013-03-11 03:31:19 +01:00
|
|
|
list->size = 0;
|
2012-01-08 00:57:44 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 03:22:45 +01:00
|
|
|
void rgui_list_get_at_offset(const rgui_list_t *list, size_t index,
|
2013-03-09 19:05:11 +01:00
|
|
|
const char **path, unsigned *file_type, size_t *directory_ptr)
|
2012-01-08 00:57:44 +01:00
|
|
|
{
|
|
|
|
if (path)
|
|
|
|
*path = list->list[index].path;
|
|
|
|
if (file_type)
|
|
|
|
*file_type = list->list[index].type;
|
2012-06-30 04:49:50 -04:00
|
|
|
if (directory_ptr)
|
|
|
|
*directory_ptr = list->list[index].directory_ptr;
|
2012-01-08 00:57:44 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 03:22:45 +01:00
|
|
|
void rgui_list_get_last(const rgui_list_t *list,
|
|
|
|
const char **path, unsigned *file_type, size_t *directory_ptr)
|
|
|
|
{
|
2013-03-11 03:31:19 +01:00
|
|
|
if (list->size > 0)
|
|
|
|
rgui_list_get_at_offset(list, list->size - 1, path, file_type, directory_ptr);
|
2013-03-11 03:22:45 +01:00
|
|
|
}
|