2001-03-18 23:32:31 +00:00
|
|
|
/*
|
|
|
|
* command line and config file parser
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CONFIG_H
|
|
|
|
#define __CONFIG_H
|
|
|
|
|
|
|
|
#define CONF_TYPE_FLAG 0
|
|
|
|
#define CONF_TYPE_INT 1
|
|
|
|
#define CONF_TYPE_FLOAT 2
|
|
|
|
#define CONF_TYPE_STRING 3
|
2001-03-19 01:49:44 +00:00
|
|
|
#define CONF_TYPE_FUNC 4
|
2001-03-19 02:29:37 +00:00
|
|
|
#define CONF_TYPE_FUNC_PARAM 5
|
2001-03-19 02:29:37 +00:00
|
|
|
#define CONF_TYPE_PRINT 6
|
2001-08-15 19:26:22 +00:00
|
|
|
#define CONF_TYPE_FUNC_FULL 7
|
2001-11-02 00:47:38 +00:00
|
|
|
#define CONF_TYPE_SUBCONFIG 8
|
|
|
|
|
2001-08-15 19:26:22 +00:00
|
|
|
|
|
|
|
#define ERR_NOT_AN_OPTION -1
|
|
|
|
#define ERR_MISSING_PARAM -2
|
|
|
|
#define ERR_OUT_OF_RANGE -3
|
|
|
|
#define ERR_FUNC_ERR -4
|
|
|
|
|
|
|
|
|
2001-03-18 23:32:31 +00:00
|
|
|
|
2001-03-19 03:45:49 +00:00
|
|
|
#define CONF_MIN (1<<0)
|
|
|
|
#define CONF_MAX (1<<1)
|
|
|
|
#define CONF_RANGE (CONF_MIN|CONF_MAX)
|
2001-03-19 02:29:37 +00:00
|
|
|
#define CONF_NOCFG (1<<2)
|
|
|
|
#define CONF_NOCMD (1<<3)
|
2001-03-18 23:32:31 +00:00
|
|
|
|
|
|
|
struct config {
|
|
|
|
char *name;
|
|
|
|
void *p;
|
2001-12-17 15:50:36 +00:00
|
|
|
unsigned int type;
|
|
|
|
unsigned int flags;
|
2001-03-18 23:32:31 +00:00
|
|
|
float min,max;
|
|
|
|
};
|
|
|
|
|
2001-08-15 19:26:22 +00:00
|
|
|
typedef int (*cfg_func_arg_param_t)(struct config *, char *, char *);
|
2001-03-19 01:49:44 +00:00
|
|
|
typedef int (*cfg_func_param_t)(struct config *, char *);
|
|
|
|
typedef int (*cfg_func_t)(struct config *);
|
|
|
|
|
2001-03-18 23:32:31 +00:00
|
|
|
/* parse_config_file returns:
|
|
|
|
* -1 on error (can't malloc, invalid option...)
|
|
|
|
* 0 if can't open configfile
|
|
|
|
* 1 on success
|
|
|
|
*/
|
|
|
|
int parse_config_file(struct config *conf, char *conffile);
|
|
|
|
|
2001-08-22 19:29:47 +00:00
|
|
|
/* parse_command_line returns:
|
2001-03-18 23:32:31 +00:00
|
|
|
* -1 on error (invalid option...)
|
|
|
|
* 0 if there was no filename on command line
|
2001-08-22 19:29:47 +00:00
|
|
|
* >=1 if there were filenames
|
2001-03-18 23:32:31 +00:00
|
|
|
*/
|
2001-08-22 19:29:47 +00:00
|
|
|
int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char ***filenames);
|
2001-03-18 23:32:31 +00:00
|
|
|
|
|
|
|
#endif /* __CONFIG_H */
|