Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
emutools_config.h
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016-2022 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #ifndef XEMU_COMMON_EMUTOOLS_CONFIG_H_INCLUDED
19 #define XEMU_COMMON_EMUTOOLS_CONFIG_H_INCLUDED
20 
21 #define CONFIG_FILE_MAX_SIZE 0x10000
22 #define CONFIG_VALUE_MAX_LENGTH 256
23 #define OPT_NAME_MAX_LENGTH 16
24 
25 #define CONFIG_FILE_TEMPL_NAME "@%s-template.cfg"
26 #define CONFIG_FILE_USE_NAME "@%s-default.cfg"
27 
30 };
31 
32 struct xemutools_config_st;
33 
34 #define EMUCFG_PARSER_CALLBACK_RET_TYPE const char*
35 #define EMUCFG_PARSER_CALLBACK_ARG_LIST struct xemutools_config_st *opt, const char *optname, const char *optvalue
36 #define EMUCFG_PARSER_CALLBACK(name) EMUCFG_PARSER_CALLBACK_RET_TYPE name ( EMUCFG_PARSER_CALLBACK_ARG_LIST )
38 
39 #define XEMUCFG_FLAG_CLI_ONLY 1
40 #define XEMUCFG_FLAG_FIRST_ONLY 2
41 #define XEMUCFG_FLAG_DUMMY 4
42 #define XEMUCFG_FLAG_FILE_ONLY 8
43 
46  const char *name;
48  const char *help;
49  unsigned int flags;
50  union {
51  // All structs must have a pointer first!!
52  struct {
53  void *p;
54  } opt_ANY;
55  struct {
56  int *p;
57  int defval;
58  } opt_bool;
59  struct {
60  int *p;
61  int min, max;
62  int defval;
63  } opt_num;
64  struct {
65  double *p;
66  double min, max;
67  double defval;
68  } opt_float;
69  struct {
70  char **pp;
71  const char *defval;
72  } opt_str;
73  struct {
74  xemucfg_parser_callback_func_t p; // yes, even this is a pointer (function pointer)
75  } opt_proc;
76  };
77 };
78 
80  const char *optname;
81  const int defval;
82  const char *help;
83  int *store_here;
84 };
86  const char *optname;
87  const char *defval;
88  const char *help;
89  char **store_here;
90 };
92  const char *optname;
93  const int defval;
94  const char *help;
95  int *store_here;
96  int min;
97  int max;
98 };
100  const char *optname;
101  const double defval;
102  const char *help;
103  double *store_here;
104  double min;
105  double max;
106 };
108  const char *optname;
110  const char *help;
111 };
113  const char *optname;
114  const char *help;
116 };
117 
118 #define XEMUCFG_DEFINE_BOOL_OPTIONS(...) xemucfg_define_bool_option_multi( (const struct xemutools_configdef_bool_st []) { __VA_ARGS__ , {NULL} } )
119 #define XEMUCFG_DEFINE_STR_OPTIONS(...) xemucfg_define_str_option_multi( (const struct xemutools_configdef_str_st []) { __VA_ARGS__ , {NULL} } )
120 #define XEMUCFG_DEFINE_NUM_OPTIONS(...) xemucfg_define_num_option_multi( (const struct xemutools_configdef_num_st []) { __VA_ARGS__ , {NULL} } )
121 #define XEMUCFG_DEFINE_FLOAT_OPTIONS(...) xemucfg_define_float_option_multi( (const struct xemutools_configdef_float_st []) { __VA_ARGS__ , {NULL} } )
122 #define XEMUCFG_DEFINE_PROC_OPTIONS(...) xemucfg_define_proc_option_multi( (const struct xemutools_configdef_proc_st []) { __VA_ARGS__ , {NULL} } )
123 #define XEMUCFG_DEFINE_SWITCH_OPTIONS(...) xemucfg_define_switch_option_multi((const struct xemutools_configdef_switch_st[]) { __VA_ARGS__ , {NULL} } )
124 
125 extern void xemucfg_define_bool_option_multi ( const struct xemutools_configdef_bool_st p[] );
126 extern void xemucfg_define_str_option_multi ( const struct xemutools_configdef_str_st p[] );
127 extern void xemucfg_define_num_option_multi ( const struct xemutools_configdef_num_st p[] );
128 extern void xemucfg_define_float_option_multi ( const struct xemutools_configdef_float_st p[] );
129 extern void xemucfg_define_proc_option_multi ( const struct xemutools_configdef_proc_st p[] );
131 
132 extern void xemucfg_define_bool_option ( const char *optname, const int defval, const char *help, int *storage );
133 extern void xemucfg_define_str_option ( const char *optname, const char *defval, const char *help, char **storage );
134 extern void xemucfg_define_num_option ( const char *optname, const int defval, const char *help, int *storage, int min, int max );
135 extern void xemucfg_define_float_option ( const char *optname, const double defval, const char *help, double *storage, double min, double max );
136 extern void xemucfg_define_switch_option ( const char *optname, const char *help, int *storage );
137 extern void xemucfg_define_proc_option ( const char *optname, xemucfg_parser_callback_func_t cb, const char *help );
138 
139 extern int xemucfg_parse_all ( int argc, char **argv );
140 extern int xemucfg_save_config_file ( const char *filename, const char *initial_part, const char *cry );
141 extern int xemucfg_parse_config_file ( const char *filename_in, const char *open_fail_msg );
142 extern const char *xemucfg_get_default_config_file_name ( void );
143 
144 extern void xemucfg_set_str ( char **ptr, const char *value );
145 
146 extern int xemucfg_integer_list_from_string ( const char *value, int *result, int maxitems, const char *delims );
147 
148 extern int xemucfg_str2int ( const char *s, int *result );
149 extern int xemucfg_str2double ( const char *s, double *result );
150 extern int xemucfg_str2bool ( const char *s, int *result );
151 
152 extern void xemucfg_get_cli_info ( const char **exec_name_ptr, int *argc_ptr, char ***argv_ptr );
153 
154 #ifndef XEMU_RELEASE_BUILD
155 extern void xemucfg_dump_db ( const char *msg );
156 #endif
157 
158 #endif
xemucfg_define_str_option
void xemucfg_define_str_option(const char *optname, const char *defval, const char *help, char **storage)
xemutools_configdef_str_st::defval
const char * defval
Definition: emutools_config.h:87
xemutools_configdef_str_st::optname
const char * optname
Definition: emutools_config.h:86
xemutools_configdef_float_st::store_here
double * store_here
Definition: emutools_config.h:103
xemutools_config_st::max
int max
Definition: emutools_config.h:61
xemutools_config_st::p
double * p
Definition: emutools_config.h:65
xemutools_configdef_bool_st::help
const char * help
Definition: emutools_config.h:82
XEMUCFG_OPT_STR
@ XEMUCFG_OPT_STR
Definition: emutools_config.h:29
xemutools_config_st::min
int min
Definition: emutools_config.h:61
xemutools_configdef_float_st::help
const char * help
Definition: emutools_config.h:102
xemucfg_integer_list_from_string
int xemucfg_integer_list_from_string(const char *value, int *result, int maxitems, const char *delims)
xemucfg_define_bool_option
void xemucfg_define_bool_option(const char *optname, const int defval, const char *help, int *storage)
xemutools_config_st::defval
const char * defval
Definition: emutools_config.h:71
xemucfg_define_num_option
void xemucfg_define_num_option(const char *optname, const int defval, const char *help, int *storage, int min, int max)
XEMUCFG_OPT_FLOAT
@ XEMUCFG_OPT_FLOAT
Definition: emutools_config.h:29
xemutools_configdef_str_st
Definition: emutools_config.h:85
xemucfg_define_proc_option_multi
void xemucfg_define_proc_option_multi(const struct xemutools_configdef_proc_st p[])
xemucfg_define_str_option_multi
void xemucfg_define_str_option_multi(const struct xemutools_configdef_str_st p[])
xemutools_configdef_proc_st::help
const char * help
Definition: emutools_config.h:110
xemutools_configdef_float_st::min
double min
Definition: emutools_config.h:104
xemutools_configdef_str_st::store_here
char ** store_here
Definition: emutools_config.h:89
xemutools_config_st::type
enum xemutools_option_type type
Definition: emutools_config.h:47
xemutools_configdef_num_st::max
int max
Definition: emutools_config.h:97
xemucfg_define_bool_option_multi
void xemucfg_define_bool_option_multi(const struct xemutools_configdef_bool_st p[])
xemucfg_parse_all
int xemucfg_parse_all(int argc, char **argv)
xemucfg_define_switch_option_multi
void xemucfg_define_switch_option_multi(const struct xemutools_configdef_switch_st p[])
xemucfg_str2int
int xemucfg_str2int(const char *s, int *result)
xemutools_configdef_num_st::help
const char * help
Definition: emutools_config.h:94
xemutools_configdef_switch_st::help
const char * help
Definition: emutools_config.h:114
xemutools_configdef_bool_st::defval
const int defval
Definition: emutools_config.h:81
xemutools_config_st::defval
int defval
Definition: emutools_config.h:57
xemutools_option_type
xemutools_option_type
Definition: emutools_config.h:28
xemucfg_save_config_file
int xemucfg_save_config_file(const char *filename, const char *initial_part, const char *cry)
xemutools_configdef_bool_st::store_here
int * store_here
Definition: emutools_config.h:83
xemutools_configdef_num_st::optname
const char * optname
Definition: emutools_config.h:92
xemutools_configdef_proc_st
Definition: emutools_config.h:107
xemutools_configdef_num_st::store_here
int * store_here
Definition: emutools_config.h:95
xemucfg_parse_config_file
int xemucfg_parse_config_file(const char *filename_in, const char *open_fail_msg)
xemutools_configdef_num_st::defval
const int defval
Definition: emutools_config.h:93
xemucfg_define_num_option_multi
void xemucfg_define_num_option_multi(const struct xemutools_configdef_num_st p[])
xemutools_configdef_proc_st::optname
const char * optname
Definition: emutools_config.h:108
xemutools_configdef_switch_st::optname
const char * optname
Definition: emutools_config.h:113
xemutools_configdef_num_st::min
int min
Definition: emutools_config.h:96
xemutools_configdef_switch_st
Definition: emutools_config.h:112
xemutools_config_st::p
void * p
Definition: emutools_config.h:53
xemutools_config_st::opt_proc
struct xemutools_config_st::@52::@59 opt_proc
xemucfg_get_default_config_file_name
const char * xemucfg_get_default_config_file_name(void)
xemucfg_get_cli_info
void xemucfg_get_cli_info(const char **exec_name_ptr, int *argc_ptr, char ***argv_ptr)
xemucfg_define_proc_option
void xemucfg_define_proc_option(const char *optname, xemucfg_parser_callback_func_t cb, const char *help)
xemucfg_dump_db
void xemucfg_dump_db(const char *msg)
xemutools_config_st
Definition: emutools_config.h:44
xemutools_configdef_switch_st::store_here
int * store_here
Definition: emutools_config.h:115
xemutools_configdef_float_st
Definition: emutools_config.h:99
xemutools_config_st::defval
double defval
Definition: emutools_config.h:67
xemutools_configdef_bool_st
Definition: emutools_config.h:79
xemutools_config_st::flags
unsigned int flags
Definition: emutools_config.h:49
xemucfg_define_float_option_multi
void xemucfg_define_float_option_multi(const struct xemutools_configdef_float_st p[])
xemutools_configdef_float_st::optname
const char * optname
Definition: emutools_config.h:100
xemutools_configdef_proc_st::cb
const xemucfg_parser_callback_func_t cb
Definition: emutools_config.h:109
xemucfg_str2double
int xemucfg_str2double(const char *s, double *result)
EMUCFG_PARSER_CALLBACK_ARG_LIST
#define EMUCFG_PARSER_CALLBACK_ARG_LIST
Definition: emutools_config.h:35
XEMUCFG_OPT_BOOL
@ XEMUCFG_OPT_BOOL
Definition: emutools_config.h:29
xemucfg_define_float_option
void xemucfg_define_float_option(const char *optname, const double defval, const char *help, double *storage, double min, double max)
xemutools_config_st::opt_float
struct xemutools_config_st::@52::@57 opt_float
xemutools_config_st::opt_ANY
struct xemutools_config_st::@52::@54 opt_ANY
xemutools_config_st::next
struct xemutools_config_st * next
Definition: emutools_config.h:45
xemutools_configdef_num_st
Definition: emutools_config.h:91
xemutools_configdef_bool_st::optname
const char * optname
Definition: emutools_config.h:80
xemutools_config_st::opt_str
struct xemutools_config_st::@52::@58 opt_str
value
int value
Definition: dma65.c:90
XEMUCFG_OPT_PROC
@ XEMUCFG_OPT_PROC
Definition: emutools_config.h:29
xemutools_config_st::p
xemucfg_parser_callback_func_t p
Definition: emutools_config.h:74
xemutools_config_st::p
int * p
Definition: emutools_config.h:56
xemutools_configdef_float_st::defval
const double defval
Definition: emutools_config.h:101
xemucfg_define_switch_option
void xemucfg_define_switch_option(const char *optname, const char *help, int *storage)
xemutools_config_st::name
const char * name
Definition: emutools_config.h:46
xemutools_config_st::help
const char * help
Definition: emutools_config.h:48
xemutools_configdef_float_st::max
double max
Definition: emutools_config.h:105
xemutools_config_st::pp
char ** pp
Definition: emutools_config.h:70
xemutools_config_st::opt_num
struct xemutools_config_st::@52::@56 opt_num
XEMUCFG_OPT_NUM
@ XEMUCFG_OPT_NUM
Definition: emutools_config.h:29
xemutools_configdef_str_st::help
const char * help
Definition: emutools_config.h:88
EMUCFG_PARSER_CALLBACK_RET_TYPE
#define EMUCFG_PARSER_CALLBACK_RET_TYPE
Definition: emutools_config.h:34
xemucfg_parser_callback_func_t
EMUCFG_PARSER_CALLBACK_RET_TYPE(* xemucfg_parser_callback_func_t)(EMUCFG_PARSER_CALLBACK_ARG_LIST)
Definition: emutools_config.h:37
xemutools_config_st::opt_bool
struct xemutools_config_st::@52::@55 opt_bool
xemucfg_str2bool
int xemucfg_str2bool(const char *s, int *result)
xemucfg_set_str
void xemucfg_set_str(char **ptr, const char *value)
xemutools_config_st::min
double min
Definition: emutools_config.h:66