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 * -------------------------------------------------------------------------- **
31 * $Log: debug2html.c,v $
32 * Revision 1.2 1998/10/27 23:28:29 crh
33 * Fixed a small bug in debug2html. It wasn't properly checking EOF. The
34 * current status is "it works". I need to add some syntax error recovery
35 * and a usage message. Basic stuff.
37 * I've also modified Makefile.in. If you want to compile it you'll have to
38 * do a 'make debug2html', as I used smbtorture as a model. We can decide
39 * later if this tool is useful enough to be compiled always.
41 * BTW, a 'make realclean' fails because the bin directory isn't empty.
42 * That's because it doesn't delete optionally compiled files such as
43 * smbtorture and debug2html (and because of the CVS subdirectory, but I
44 * think that's only a problem for developers).
48 * Revision 1.1 1998/10/26 23:21:37 crh
49 * Here is the simple debug parser and the debug2html converter. Still to do:
51 * * Debug message filtering.
52 * * I need to add all this to Makefile.in
53 * (If it looks at all strange I'll ask for help.)
55 * If you want to compile debug2html, you'll need to do it by hand until I
56 * make the changes to Makefile.in. Sorry.
60 * ========================================================================== **
63 #include "debugparse.h"
65 /* -------------------------------------------------------------------------- **
66 * The size of the read buffer.
71 /* -------------------------------------------------------------------------- **
75 static dbg_Token modechange( dbg_Token new, dbg_Token mode )
76 /* ------------------------------------------------------------------------ **
77 * Handle a switch between header and message printing.
79 * Input: new - The token value of the current token. This indicates
80 * the lexical item currently being recognized.
81 * mode - The current mode. This is either dbg_null or
82 * dbg_message. It could really be any toggle
85 * Output: The new mode. This will be the same as the input mode unless
86 * there was a transition in or out of message processing.
88 * Notes: The purpose of the mode value is to mark the beginning and end
89 * of the message text block. In order to show the text in its
90 * correct format, it must be included within a <PRE></PRE> block.
92 * ------------------------------------------------------------------------ **
101 if( dbg_message != mode )
103 /* Switching to message mode. */
104 (void)printf( "<PRE>\n" );
105 return( dbg_message );
109 if( dbg_message == mode )
111 /* Switching out of message mode. */
112 (void)printf( "</PRE>\n\n" );
120 static void newblock( dbg_Token old, dbg_Token new )
121 /* ------------------------------------------------------------------------ **
122 * Handle the transition between tokens.
124 * Input: old - The previous token.
125 * new - The current token.
129 * Notes: This is called whenever there is a transition from one token
130 * type to another. It first prints the markup tags that close
131 * the previous token, and then the markup tags for the new
134 * ------------------------------------------------------------------------ **
140 (void)printf( ", " );
143 (void)printf( "</FONT>]</B>\n " );
156 (void)printf( "<B>[" );
159 (void)printf( "<FONT COLOR=MAROON>" );
167 static void charprint( dbg_Token tok, int c )
168 /* ------------------------------------------------------------------------ **
169 * Filter the input characters to determine what goes to output.
171 * Input: tok - The token value of the current character.
172 * c - The current character.
176 * ------------------------------------------------------------------------ **
186 (void)putchar( '\n' );
192 (void)printf( "<" );
195 (void)printf( ">" );
198 (void)printf( "&" );
201 (void)printf( """ );
210 int main( int argc, char *argv[] )
211 /* ------------------------------------------------------------------------ **
212 * This simple program scans and parses Samba debug logs, and produces HTML
215 * Input: argc - Currently ignored.
216 * argv - Currently ignored.
218 * Output: Always zero.
220 * Notes: The HTML output is sent to stdout.
222 * ------------------------------------------------------------------------ **
228 dbg_Token old = dbg_null,
233 (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
234 (void)printf( "<HTML>\n<HEAD>\n" );
235 (void)printf( " <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
237 while( (!feof( stdin ))
238 && ((len = fread( bufr, 1, BSIZE, stdin )) > 0) )
240 for( i = 0; i < len; i++ )
243 new = dbg_char2token( &state, bufr[i] );
246 mode = modechange( new, mode );
247 newblock( old, new );
249 charprint( new, bufr[i] );
252 (void)modechange( dbg_eof, mode );
254 (void)printf( "</BODY>\n</HTML>\n" );