On Sep 20, 10:15 pm, "lisp9...@[EMAIL PROTECTED]
" <lisp9...@[EMAIL PROTECTED]
> wrote:
> Hi,
>
> I am writing a log parser (beginner in C) and have some questions.
>
> There are 2 types of log files which are very similar:
>
> Type 1:
> 117: SYSTEM->P0 Welcome to the server
> 444: Z1->P0 Greetings
> 812: SYSTEM->EVERYONE "Chumly" (P0) was kill #5 for "Dragon
> Master" (Z1)
> 954: P0->TEAMORANGE Help me!
>
> Type 2:
> Welcome aboard Chumly! 00:03:40
> 00:03:41: Qualax-5->TEAMORANGE Qualax-5 destroyed by "Dragon
> Master" (Z1)
> Blaster missed!!! 00:03:53
> 00:04:06: P0->TEAMPURPLE Help Needed at Zorcon-8
>
> So in Type 1 there is always an integar indicating relative time
> prefixing every line and in Type 2 there is always a 24-hour style
> timestamp but sometimes it is prefixed and other times suffixed.
>
> I thought of using strtok() but that doesn't handling quoting so if I
> encounter a message in " " it won't be able to handle it.
>
> Does anyone have any idea on the best way to tokenize this? My goal is
> to extract only certain types of messages such as the ones between
> players (eg. Z1->P0) and to the team message board (eg P0->TEAMPURPLE)
> and put these into HTML files in time increasing order.
>
> I thought of reading in one character of the log file at a time but
> then I will need lots of branch logic (if( char = 'T') && (char-next
> == 'E') etc..) and that could get quite messy and confusing. I also
> thought of storing each token as a struct field but I haven't much
> experience with structs. I was also wondering about using fixed arrays
> of chars vs arrays of char pointers. Any ideas and especially code
> snippets would be appreciated to help me get started.
You can change delimiters for strtok() between calls, which may help.
If the structure of the files is well defined, you could write a
grammar for the files and then create a parser using the grammar.
If you decide on this route, then news:comp.compilers is the place to
go with questions.
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|