1 /* ========================================================================== **
4 * Copyright (C) 1998 by Christopher R. Hertel
6 * Email: crh@ubiqx.mn.org
8 * -------------------------------------------------------------------------- **
9 * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
10 * -------------------------------------------------------------------------- **
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * -------------------------------------------------------------------------- **
27 * This program provides an example of the use of debugparse.c, and also
28 * does a decent job of converting Samba logs into HTML.
29 * -------------------------------------------------------------------------- **
33 * ========================================================================== **
38 /* -------------------------------------------------------------------------- **
39 * The size of the read buffer.
42 #define DBG_BSIZE 1024
44 /* -------------------------------------------------------------------------- **
48 static dbg_Token modechange( dbg_Token new, dbg_Token mode )
49 /* ------------------------------------------------------------------------ **
50 * Handle a switch between header and message printing.
52 * Input: new - The token value of the current token. This indicates
53 * the lexical item currently being recognized.
54 * mode - The current mode. This is either dbg_null or
55 * dbg_message. It could really be any toggle
58 * Output: The new mode. This will be the same as the input mode unless
59 * there was a transition in or out of message processing.
61 * Notes: The purpose of the mode value is to mark the beginning and end
62 * of the message text block. In order to show the text in its
63 * correct format, it must be included within a <PRE></PRE> block.
65 * ------------------------------------------------------------------------ **
74 if( dbg_message != mode )
76 /* Switching to message mode. */
77 (void)printf( "<PRE>\n" );
78 return( dbg_message );
82 if( dbg_message == mode )
84 /* Switching out of message mode. */
85 (void)printf( "</PRE>\n\n" );
93 static void newblock( dbg_Token old, dbg_Token new )
94 /* ------------------------------------------------------------------------ **
95 * Handle the transition between tokens.
97 * Input: old - The previous token.
98 * new - The current token.
102 * Notes: This is called whenever there is a transition from one token
103 * type to another. It first prints the markup tags that close
104 * the previous token, and then the markup tags for the new
107 * ------------------------------------------------------------------------ **
113 (void)printf( ",</B>" );
116 (void)printf( "</FONT>]</B>\n " );
129 (void)printf( "<B>[" );
132 (void)printf( " <B><FONT COLOR=MAROON>" );
140 static void charprint( dbg_Token tok, int c )
141 /* ------------------------------------------------------------------------ **
142 * Filter the input characters to determine what goes to output.
144 * Input: tok - The token value of the current character.
145 * c - The current character.
149 * ------------------------------------------------------------------------ **
159 (void)putchar( '\n' );
165 (void)printf( "<" );
168 (void)printf( ">" );
171 (void)printf( "&" );
174 (void)printf( """ );
183 int main( int argc, char *argv[] )
184 /* ------------------------------------------------------------------------ **
185 * This simple program scans and parses Samba debug logs, and produces HTML
188 * Input: argc - Currently ignored.
189 * argv - Currently ignored.
191 * Output: Always zero.
193 * Notes: The HTML output is sent to stdout.
195 * ------------------------------------------------------------------------ **
200 char bufr[DBG_BSIZE];
201 dbg_Token old = dbg_null,
206 (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
207 (void)printf( "<HTML>\n<HEAD>\n" );
208 (void)printf( " <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
210 while( (!feof( stdin ))
211 && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) )
213 for( i = 0; i < len; i++ )
216 new = dbg_char2token( &state, bufr[i] );
219 mode = modechange( new, mode );
220 newblock( old, new );
222 charprint( new, bufr[i] );
225 (void)modechange( dbg_eof, mode );
227 (void)printf( "</BODY>\n</HTML>\n" );