Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: Parsing?
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 1008 of 1145
Post > Topic >>

Re: Parsing?

by Barry Schwarz <schwarz45@[EMAIL PROTECTED] > Jan 12, 2008 at 04:46 PM

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.

The first task seems to be to distinguish type 1 from type 2.
Searching for the first : (using strchr) and testing the next
character for space seems to work.  Once you know it is a type 2, the
position of that : will tell you whether the time stamp is prefixed or
suffixed.  Hopefully, this will get you started.

>
> 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.
>
> Lisp 9000
> --
> comp.lang.c.moderated - moderation address: c...@[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.
-- 
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.
 




 5 Posts in Topic:
Parsing?
"lisp9000@[EMAIL PRO  2007-09-21 05:15:38 
Re: Parsing?
WillerZ <newsreplies@[  2008-01-12 16:41:39 
Re: Parsing?
Tim Brown <timbrown@[E  2008-01-12 16:42:40 
Re: Parsing?
user923005 <dcorbit@[E  2008-01-12 16:44:25 
Re: Parsing?
Barry Schwarz <schwarz  2008-01-12 16:46:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:58:57 CDT 2008.