L
lisp9000
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.
Lisp 9000
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.
Lisp 9000