Attached is a heavily rewritten set of helper functions for parsing config files.
The main function is prototyped as char* config_read(PARSER *parser, char comment, const char *delims, int ntokens, char **tokens); As one can see, tunable are not only delimiters but also comment char. This should fit a lot of config files schemes. No comment stripping is performed when !comment. Also tried to attack the problem of subsequent delimiters: whether they should be treated as one (case A) (likely when delimiters are whitespaces), or as separates (as, e.g., : in /etc/passwd) (case B). The sign of ntokens controls this: ntokens > 0 orders case A, ntokens < 0 -- case B. The special case of ntokens == 0 orders to just return the valuable lines from config file. An example of usage is included in parse_config.c. N.B. A simple format string can someday be added to perform tokens typecasting. That way we would be able to reduce calls to strto*()s outside config parsing procedure. Please, try, comment and consider applying. TIA, -- Vladimir
parse.patch
Description: Binary data
_______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
