Ответ: Ответ: LIBBB: parse_config()
Vladimir Dronnikov
dronnikov at gmail.com
Tue Jul 8 21:40:14 UTC 2008
Cool!
But we need to not just process continuations and comments but also to
parse the line into some (possibly variable) amount of
whitespaces-delimited tokens.
And, as I mentioned earlier, we need to use the collected tokens in
unobtrusive way in the applets.
Can you go on and code these features?
--
Vladimir
2008/7/8, Tito <farmatito at tiscali.it>:
> On Monday 07 July 2008 22:29:38 Vladimir Dronnikov wrote:
>> Sure :)
>> But some help is needed. I am trying to convert inotifyd. mdev is
>> "saint animal". Natanael mentioned ifup/down. There is crond that uses
>> plain config. There gotta be savings en gros if we cope this together.
>>
>> --
>> Vladimir
>>
>>
>> 2008/7/7, Bernhard Fischer <rep.dot.nop at gmail.com>:
>> > On Mon, Jul 07, 2008 at 12:31:29PM -0700, dronnikov at gmail.com wrote:
>> >>A helper function for parsing vanilla config files is added.
>> >>I see mdev, crond and others can use it to uniformly process their
>> >> configs.
>> >
>> > It would be better if you would convert a few users to this new
>> > parse_config() and show the size-savings. The more you save, the more we
>> > all will like it :)
>> >
>> > Please don't forget to check that you don't accidentally introduce bugs
>> > in the course.
>> >
>> > cheers,
>> >
>
> Hi,
> just for fun I've done my own version of parse_config(),
> it returns a linked list of all the options found.
> The list is then evaluated and freed by the caller.
> At the moment there is just an indipendent executable
> to compile in test.c and a config file i used for testing.
> Usage is: ./test PATH_TO_CONFIG_FILE
> and all the options should be printed to the screen:
>
> ./test config.cfg
> option=1
> option=2
> option=corner-case1
> option=corner-case3
> option=corner-case2
> option=after_new_lines
> option 3
> option 3 3 3 3
> option abracadabra
> option=multiline-option
>
> Just my 0,2 cents....in the hope it could be somehow useful.... :-)
>
> Ciao,
> Tito
>
> /* Lines starting with "#" are ignored. Note that end-of-line
> * comments are supported.
> * Blank lines are ignored.
> * Lines may be indented freely.
> * A "\" character at the very end of the line indicates the next line
> * should be treated as a continuation of the current one.
> */
>
> llist_t *parse_config(const char *filename)
> {
> char *line;
> char *next_line;
> char *p;
> char *t;
> llist_t *option_list = NULL;
> FILE *file = fopen(filename, "r");
>
> if (file) {
> while ((line = xmalloc_fgetline(file))) {
> while ((p = last_char_is(line, '\\'))){
> /* Multi-line object */
> *p = '\0'; /* Remove '\' */
> next_line = xmalloc_fgetline(file);
> line = xasprintf("%s%s", line, (next_line) ? next_line : "");
> free(next_line);
> }
> p = skip_whitespace(line); /* Remove leading whitespace */
> if (*p && *p != '#') { /* Not a comment or indented comment */
> if ((t = strchr(p, '#'))) /* End of line comment - cut it */
> *t = '\0';
> /* What remains is an option so add it to the linked list */
> llist_add_to_end(&option_list, xstrdup(p));
> continue;
> } /* else empty line */
> free(line);
> } /*EOF */
> fclose(file);
> } /* else cannot read - return NULL */
> return option_list;
> }
>
>
More information about the busybox
mailing list