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 * Revision 1.4 1998/11/13 03:37:01 tridge
32 * fixes for OSF1 compilation
34 * Revision 1.3 1998/10/28 20:33:35 crh
35 * I've moved the debugparse module files into the ubiqx directory because I
36 * know that 'make proto' will ignore them there. The debugparse.h header
37 * file is included in includes.h, and includes.h is included in debugparse.c,
38 * so all of the pieces "see" each other. I've compiled and tested this,
39 * and it does seem to work. It's the same compromise model I used when
40 * adding the ubiqx modules into the system, which is why I put it all into
45 * Revision 1.1 1998/10/26 23:21:37 crh
46 * Here is the simple debug parser and the debug2html converter. Still to do:
48 * * Debug message filtering.
49 * * I need to add all this to Makefile.in
50 * (If it looks at all strange I'll ask for help.)
52 * If you want to compile debug2html, you'll need to do it by hand until I
53 * make the changes to Makefile.in. Sorry.
57 * ========================================================================== **
60 #include "debugparse.h"
62 /* -------------------------------------------------------------------------- **
63 * The size of the read buffer.
66 #define DBG_BSIZE 1024
68 /* -------------------------------------------------------------------------- **
72 static dbg_Token
modechange( dbg_Token
new, dbg_Token mode
)
73 /* ------------------------------------------------------------------------ **
74 * Handle a switch between header and message printing.
76 * Input: new - The token value of the current token. This indicates
77 * the lexical item currently being recognized.
78 * mode - The current mode. This is either dbg_null or
79 * dbg_message. It could really be any toggle
82 * Output: The new mode. This will be the same as the input mode unless
83 * there was a transition in or out of message processing.
85 * Notes: The purpose of the mode value is to mark the beginning and end
86 * of the message text block. In order to show the text in its
87 * correct format, it must be included within a <PRE></PRE> block.
89 * ------------------------------------------------------------------------ **
98 if( dbg_message
!= mode
)
100 /* Switching to message mode. */
101 (void)printf( "<PRE>\n" );
102 return( dbg_message
);
106 if( dbg_message
== mode
)
108 /* Switching out of message mode. */
109 (void)printf( "</PRE>\n\n" );
117 static void newblock( dbg_Token old
, dbg_Token
new )
118 /* ------------------------------------------------------------------------ **
119 * Handle the transition between tokens.
121 * Input: old - The previous token.
122 * new - The current token.
126 * Notes: This is called whenever there is a transition from one token
127 * type to another. It first prints the markup tags that close
128 * the previous token, and then the markup tags for the new
131 * ------------------------------------------------------------------------ **
137 (void)printf( ",</B>" );
140 (void)printf( "</FONT>]</B>\n " );
153 (void)printf( "<B>[" );
156 (void)printf( " <B><FONT COLOR=MAROON>" );
164 static void charprint( dbg_Token tok
, int c
)
165 /* ------------------------------------------------------------------------ **
166 * Filter the input characters to determine what goes to output.
168 * Input: tok - The token value of the current character.
169 * c - The current character.
173 * ------------------------------------------------------------------------ **
183 (void)putchar( '\n' );
189 (void)printf( "<" );
192 (void)printf( ">" );
195 (void)printf( "&" );
198 (void)printf( """ );
207 int main( int argc
, char *argv
[] )
208 /* ------------------------------------------------------------------------ **
209 * This simple program scans and parses Samba debug logs, and produces HTML
212 * Input: argc - Currently ignored.
213 * argv - Currently ignored.
215 * Output: Always zero.
217 * Notes: The HTML output is sent to stdout.
219 * ------------------------------------------------------------------------ **
224 char bufr
[DBG_BSIZE
];
225 dbg_Token old
= dbg_null
,
230 (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
231 (void)printf( "<HTML>\n<HEAD>\n" );
232 (void)printf( " <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
234 while( (!feof( stdin
))
235 && ((len
= fread( bufr
, 1, DBG_BSIZE
, stdin
)) > 0) )
237 for( i
= 0; i
< len
; i
++ )
240 new = dbg_char2token( &state
, bufr
[i
] );
243 mode
= modechange( new, mode
);
244 newblock( old
, new );
246 charprint( new, bufr
[i
] );
249 (void)modechange( dbg_eof
, mode
);
251 (void)printf( "</BODY>\n</HTML>\n" );