libbb: unified config parser (By Vladimir Dronnikov)

mdev: use it

function                                             old     new   delta
config_read                                            -     400    +400
config_open                                            -      43     +43
config_close                                           -       9      +9
qrealloc                                              33      36      +3
compare_keys                                         735     737      +2
xstrtoull_range_sfx                                  296     295      -1
qgravechar                                           109     106      -3
get_address                                          181     178      -3
next_token                                           928     923      -5
sv_main                                             1228    1222      -6
find_main                                            418     406     -12
next_field                                            32       -     -32
make_device                                         1269    1184     -85
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 2/7 up/down: 457/-147)          Total: 310 bytes
This commit is contained in:
Denis Vlasenko
2008-07-15 21:09:30 +00:00
parent 0ed090e184
commit e559e0a757
4 changed files with 295 additions and 56 deletions

View File

@ -987,6 +987,28 @@ int bb_ask_confirmation(void) FAST_FUNC;
extern int bb_parse_mode(const char* s, mode_t* theMode) FAST_FUNC;
/*
* Uniform config file parser helpers
*/
#define PARSER_STDIO_BASED 1
#if !PARSER_STDIO_BASED
typedef struct parser_t {
char *data;
char *line;
int lineno;
} parser_t;
extern char* config_open(parser_t *parser, const char *filename) FAST_FUNC;
#else
typedef struct parser_t {
FILE *fp;
char *line;
int lineno;
} parser_t;
extern FILE* config_open(parser_t *parser, const char *filename) FAST_FUNC;
#endif
extern char* config_read(parser_t *parser, char **tokens, int ntokens, int mintokens, const char *delims, char comment) FAST_FUNC;
extern void config_close(parser_t *parser) FAST_FUNC;
/* Concatenate path and filename to new allocated buffer.
* Add "/" only as needed (no duplicate "//" are produced).
* If path is NULL, it is assumed to be "/".