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 3 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, see <http://www.gnu.org/licenses/>.
25 * -------------------------------------------------------------------------- **
26 * This program provides an example of the use of debugparse.c, and also
27 * does a decent job of converting Samba logs into HTML.
28 * -------------------------------------------------------------------------- **
30 * Revision 1.4 1998/11/13 03:37:01 tridge
31 * fixes for OSF1 compilation
33 * Revision 1.3 1998/10/28 20:33:35 crh
34 * I've moved the debugparse module files into the ubiqx directory because I
35 * know that 'make proto' will ignore them there. The debugparse.h header
36 * file is included in includes.h, and includes.h is included in debugparse.c,
37 * so all of the pieces "see" each other. I've compiled and tested this,
38 * and it does seem to work. It's the same compromise model I used when
39 * adding the ubiqx modules into the system, which is why I put it all into
44 * Revision 1.1 1998/10/26 23:21:37 crh
45 * Here is the simple debug parser and the debug2html converter. Still to do:
47 * * Debug message filtering.
48 * * I need to add all this to Makefile.in
49 * (If it looks at all strange I'll ask for help.)
51 * If you want to compile debug2html, you'll need to do it by hand until I
52 * make the changes to Makefile.in. Sorry.
56 * ========================================================================== **
59 #include "debugparse.h"
61 /* -------------------------------------------------------------------------- **
62 * The size of the read buffer.
65 #define DBG_BSIZE 1024
67 /* -------------------------------------------------------------------------- **
71 static dbg_Token modechange( dbg_Token newmode, dbg_Token mode )
72 /* ------------------------------------------------------------------------ **
73 * Handle a switch between header and message printing.
75 * Input: new - The token value of the current token. This indicates
76 * the lexical item currently being recognized.
77 * mode - The current mode. This is either dbg_null or
78 * dbg_message. It could really be any toggle
81 * Output: The new mode. This will be the same as the input mode unless
82 * there was a transition in or out of message processing.
84 * Notes: The purpose of the mode value is to mark the beginning and end
85 * of the message text block. In order to show the text in its
86 * correct format, it must be included within a <PRE></PRE> block.
88 * ------------------------------------------------------------------------ **
97 if( dbg_message != mode )
99 /* Switching to message mode. */
100 (void)printf( "<PRE>\n" );
101 return( dbg_message );
105 if( dbg_message == mode )
107 /* Switching out of message mode. */
108 (void)printf( "</PRE>\n\n" );
116 static void newblock( dbg_Token old, dbg_Token newtok )
117 /* ------------------------------------------------------------------------ **
118 * Handle the transition between tokens.
120 * Input: old - The previous token.
121 * new - The current token.
125 * Notes: This is called whenever there is a transition from one token
126 * type to another. It first prints the markup tags that close
127 * the previous token, and then the markup tags for the new
130 * ------------------------------------------------------------------------ **
136 (void)printf( ",</B>" );
139 (void)printf( "</FONT>]</B>\n " );
154 (void)printf( "<B>[" );
157 (void)printf( " <B><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 * ------------------------------------------------------------------------ **
227 char bufr[DBG_BSIZE];
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, DBG_BSIZE, stdin )) > 0) )
240 for( i = 0; i < len; i++ )
243 newtok = dbg_char2token( &state, bufr[i] );
246 mode = modechange( newtok, mode );
247 newblock( old, newtok );
249 charprint( newtok, bufr[i] );
252 (void)modechange( dbg_eof, mode );
254 (void)printf( "</BODY>\n</HTML>\n" );