| version 1.3, 2001/10/10 19:23:13 |
version 1.4, 2001/10/11 13:27:34 |
|
|
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <string.h> |
#include <string.h> |
| |
|
| |
#include "str/strdyn.h" |
| #include "cfg.h" |
#include "cfg.h" |
| |
|
| |
static char *default_cmdline_stop_str[2] = { "--", NULL }; |
| |
static char *default_cfgfile_stop_str[2] = { "[", NULL }; |
| |
static char *default_cfgfile_comment_str[3] = { "#", ";", NULL }; |
| |
|
| |
|
| CFG_CONTEXT cfg_get_context( |
CFG_CONTEXT cfg_get_context( |
| const struct cfg_option *options |
struct cfg_option *options |
| ) |
) |
| { |
{ |
| CFG_CONTEXT con; |
CFG_CONTEXT con; |
| Line 16 CFG_CONTEXT cfg_get_context( |
|
| Line 22 CFG_CONTEXT cfg_get_context( |
|
| |
|
| memset(con, '\0', sizeof(*con)); |
memset(con, '\0', sizeof(*con)); |
| |
|
| |
con->line_stop_str = |
| |
strdyn_add_ar(con->line_stop_str, default_cmdline_stop_str); |
| |
con->file_stop_str = |
| |
strdyn_add_ar(con->file_stop_str, default_cfgfile_stop_str); |
| |
con->comment_str = |
| |
strdyn_add_ar(con->comment_str, default_cfgfile_comment_str); |
| |
|
| |
if (con->line_stop_str == NULL |
| |
|| con->file_stop_str == NULL |
| |
|| con->comment_str == NULL) |
| |
return NULL; |
| |
|
| return con; |
return con; |
| } |
} |
| |
|
| CFG_CONTEXT cfg_get_cmdline_context( |
CFG_CONTEXT cfg_get_cmdline_context( |
| const int argc, |
int argc, |
| const char **argv, |
char **argv, |
| const struct cfg_option *options |
struct cfg_option *options |
| ) |
) |
| { |
{ |
| CFG_CONTEXT con; |
CFG_CONTEXT con; |
| Line 37 CFG_CONTEXT cfg_get_cmdline_context( |
|
| Line 55 CFG_CONTEXT cfg_get_cmdline_context( |
|
| } |
} |
| |
|
| CFG_CONTEXT cfg_get_cfgfile_context( |
CFG_CONTEXT cfg_get_cfgfile_context( |
| const int begin_pos, |
int begin_pos, |
| const int end_pos, |
int end_pos, |
| const char *filename, |
char *filename, |
| const struct cfg_option *options |
struct cfg_option *options |
| ) |
) |
| { |
{ |
| CFG_CONTEXT con; |
CFG_CONTEXT con; |
| Line 56 CFG_CONTEXT cfg_get_cfgfile_context( |
|
| Line 74 CFG_CONTEXT cfg_get_cfgfile_context( |
|
| |
|
| void cfg_set_cmdline_context( |
void cfg_set_cmdline_context( |
| const CFG_CONTEXT con, |
const CFG_CONTEXT con, |
| const int argc, |
int argc, |
| const char **argv |
char **argv |
| ) |
) |
| { |
{ |
| con->type = CFG_CMDLINE; |
con->type = CFG_CMDLINE; |
| Line 68 void cfg_set_cmdline_context( |
|
| Line 86 void cfg_set_cmdline_context( |
|
| |
|
| void cfg_set_cfgfile_context( |
void cfg_set_cfgfile_context( |
| const CFG_CONTEXT con, |
const CFG_CONTEXT con, |
| const int begin_pos, |
int begin_pos, |
| const int end_pos, |
int end_pos, |
| const char *filename |
char *filename |
| ) |
) |
| { |
{ |
| con->type = CFG_CFGFILE; |
con->type = CFG_CFGFILE; |
| Line 85 void cfg_free_context( |
|
| Line 103 void cfg_free_context( |
|
| ) |
) |
| { |
{ |
| |
|
| |
cfg_clear_cmdline_stop_str(con); |
| |
cfg_clear_cfgfile_stop_str(con); |
| |
cfg_clear_cfgfile_comment_str(con); |
| |
|
| free((void *) con); |
free((void *) con); |
| } |
} |
| |
|
| #if defined(SELF) || defined(SELFTEST) || defined(SELF_CFG) |
#if defined(SELF) || defined(SELFTEST) || defined(SELF_CFG) |
| |
|
| int main(void) { |
int main(int argc, char **argv) { |
| |
|
| |
CFG_CONTEXT con; |
| int nice; |
int nice; |
| |
|
| struct cfg_option options[] = { |
struct cfg_option options[] = { |
|
| Line 122 int main(void) { |
|
| CFG_END_OF_LIST |
CFG_END_OF_LIST |
| }; |
}; |
| |
|
| /* |
con = cfg_get_cmdline_context(argc, argv, options); |
| options = (struct cfg_option *) options; |
|
| */ |
puts("x"); |
| |
|
| |
cfg_free_context(con); |
| |
|
| return 0; |
return 0; |
| } |
} |