Re: glib / String handling difficult



2006/1/9, Juhana Sadeharju <kouhia nic funet fi>:
>
> Hello. I have always found string handling quite difficult in C.
> It also looks like sed, awk, perl etc. cannot handle all of my
> simple needs. Glib could be improved.

I thought the same.

> I need often an extractor which finds something from
> an arbitrary data. I have routines file2buffer(), which
> loads a file to buffer, and bufferfind(), which searches
> for a string in the buffer. The file could be a html page
> downloaded with wget or a mixed binary and ascii file.
>
> Now more difficult example. I need to parse "12 pages" in
> a middle of a html page. For example, sscanf("%i pages",) yields
> nothing even there is only one "<number> pages" in the file.
> Now I first find the "pages" and move back over the "12" but
> this is not simple.
>
> The lexicar scanner in glib is nice, but a similar parser would
> be needed as well. A parser to which the rules are feeded at
> runtime -- not compiled as with flex/bison.
>  p = parser_new();
>  parser_add_rule(p,"rule : token otherrule", callback);
>  parser_add_rule(p,"rule : alttoken anotherrule", altcallback);
>  <etc.>
>  parser_prepare(p); // converts rules to efficient execution data structure
>  parser_input(p,text);

I thing this is a little offtopic,but...
I don't know anything about parsers theory, but I have created
something like that. I have a program that reads all words and symbols
from a file, and convert it to integers. Something like "this is a
phrase" is a number too, so I can manage a word, symbol or phrase with
a single int.I change the language rules(what is a symbol, or phrase)
at runtime. But it will take a long,long time to be stable, because of
being so low level.

> Then in my application, I could mix the bufferfind() with several
> miniparsers. And I could define miniparsers as needed in app's
> dialog without compiling anything.

I want to do a xorg.conf reader/writer, but I'm using this thing too
to understand structures from c header files for another program.
                                                                      
       Jose Hevia



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]