2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-01-08 00:08:18 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
2010-12-30 00:50:37 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2010-12-30 00:50:37 +00: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 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2010-12-30 00:50:37 +00: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 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2010-12-30 00:50:37 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-12-29 13:27:44 +00:00
|
|
|
#ifndef __CONFIG_FILE_H
|
|
|
|
#define __CONFIG_FILE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-12-24 12:46:12 +00:00
|
|
|
#include "../boolean.h"
|
2011-01-09 14:50:30 +00:00
|
|
|
#include <stdio.h>
|
2011-08-25 14:15:34 +00:00
|
|
|
#include <stddef.h>
|
2010-12-29 13:27:44 +00:00
|
|
|
|
|
|
|
typedef struct config_file config_file_t;
|
|
|
|
|
2010-12-29 16:52:53 +00:00
|
|
|
/////
|
|
|
|
// Config file format
|
|
|
|
// - # are treated as comments. Rest of the line is ignored.
|
|
|
|
// - Format is: key = value. There can be as many spaces as you like in-between.
|
|
|
|
// - Value can be wrapped inside "" for multiword strings. (foo = "hai u")
|
2011-10-17 17:11:31 +00:00
|
|
|
//
|
|
|
|
// - #include includes a config file in-place.
|
|
|
|
// Path is relative to where config file was loaded unless an absolute path is chosen.
|
|
|
|
// Key/value pairs from an #include are read-only, and cannot be modified.
|
2010-12-29 16:52:53 +00:00
|
|
|
|
2011-10-17 17:11:31 +00:00
|
|
|
// Loads a config file. Returns NULL if file doesn't exist.
|
|
|
|
// NULL path will create an empty config file.
|
2010-12-29 13:27:44 +00:00
|
|
|
config_file_t *config_file_new(const char *path);
|
2010-12-29 16:52:53 +00:00
|
|
|
// Frees config file.
|
2010-12-29 13:27:44 +00:00
|
|
|
void config_file_free(config_file_t *conf);
|
|
|
|
|
2011-10-17 17:11:31 +00:00
|
|
|
// All extract functions return true when value is valid and exists.
|
|
|
|
// Returns false otherwise.
|
|
|
|
|
|
|
|
bool config_entry_exists(config_file_t *conf, const char *entry);
|
2010-12-29 16:52:53 +00:00
|
|
|
|
|
|
|
// Extracts a double from config file.
|
2010-12-29 13:27:44 +00:00
|
|
|
bool config_get_double(config_file_t *conf, const char *entry, double *in);
|
2012-01-12 23:08:55 +00:00
|
|
|
// Extracts a float from config file.
|
|
|
|
bool config_get_float(config_file_t *conf, const char *entry, float *in);
|
2010-12-29 16:52:53 +00:00
|
|
|
// Extracts an int from config file.
|
2010-12-29 13:27:44 +00:00
|
|
|
bool config_get_int(config_file_t *conf, const char *entry, int *in);
|
2012-01-11 00:04:17 +00:00
|
|
|
// Extracts an uint from config file.
|
|
|
|
bool config_get_uint(config_file_t *conf, const char *entry, unsigned *in);
|
2012-03-04 12:55:35 +00:00
|
|
|
// Extracts an uint64 from config file.
|
|
|
|
bool config_get_uint64(config_file_t *conf, const char *entry, uint64_t *in);
|
|
|
|
// Extracts an unsigned int from config file treating input as hex.
|
2011-05-27 00:25:26 +00:00
|
|
|
bool config_get_hex(config_file_t *conf, const char *entry, unsigned *in);
|
2010-12-29 16:52:53 +00:00
|
|
|
// Extracts a single char. If value consists of several chars, this is an error.
|
2010-12-29 13:27:44 +00:00
|
|
|
bool config_get_char(config_file_t *conf, const char *entry, char *in);
|
2010-12-29 16:52:53 +00:00
|
|
|
// Extracts an allocated string in *in. This must be free()-d if this function succeeds.
|
2010-12-29 13:27:44 +00:00
|
|
|
bool config_get_string(config_file_t *conf, const char *entry, char **in);
|
2011-08-25 14:15:34 +00:00
|
|
|
// Extracts a string to a preallocated buffer. Avoid memory allocation.
|
|
|
|
bool config_get_array(config_file_t *conf, const char *entry, char *in, size_t size);
|
2010-12-29 16:52:53 +00:00
|
|
|
// Extracts a boolean from config. Valid boolean true are "true" and "1". Valid false are "false" and "0". Other values will be treated as an error.
|
2010-12-29 13:27:44 +00:00
|
|
|
bool config_get_bool(config_file_t *conf, const char *entry, bool *in);
|
|
|
|
|
2011-10-17 17:11:31 +00:00
|
|
|
// Setters. Similar to the getters. Will not write to entry if the entry
|
|
|
|
// was obtained from an #include.
|
2011-01-09 01:58:26 +00:00
|
|
|
void config_set_double(config_file_t *conf, const char *entry, double value);
|
2012-01-30 14:14:30 +00:00
|
|
|
void config_set_float(config_file_t *conf, const char *entry, float value);
|
2011-01-09 01:58:26 +00:00
|
|
|
void config_set_int(config_file_t *conf, const char *entry, int val);
|
2012-03-04 12:55:35 +00:00
|
|
|
void config_set_uint64(config_file_t *conf, const char *entry, uint64_t val);
|
2011-01-09 01:58:26 +00:00
|
|
|
void config_set_char(config_file_t *conf, const char *entry, char val);
|
|
|
|
void config_set_string(config_file_t *conf, const char *entry, const char *val);
|
|
|
|
void config_set_bool(config_file_t *conf, const char *entry, bool val);
|
2011-01-09 14:50:30 +00:00
|
|
|
|
|
|
|
// Write the current config to a file.
|
2011-01-09 01:58:26 +00:00
|
|
|
bool config_file_write(config_file_t *conf, const char *path);
|
|
|
|
|
2011-01-09 14:50:30 +00:00
|
|
|
// Dump the current config to an already opened file. Does not close the file.
|
|
|
|
void config_file_dump(config_file_t *conf, FILE *file);
|
2011-10-17 17:11:31 +00:00
|
|
|
// Also dumps inherited values, useful for logging.
|
|
|
|
void config_file_dump_all(config_file_t *conf, FILE *file);
|
2010-12-29 13:27:44 +00:00
|
|
|
|
|
|
|
#endif
|
2011-10-17 17:11:31 +00:00
|
|
|
|