utils/debug2html.c

説明を見る。
00001 /* ========================================================================== **
00002  *                                debug2html.c
00003  *
00004  * Copyright (C) 1998 by Christopher R. Hertel
00005  *
00006  * Email: crh@ubiqx.mn.org
00007  *
00008  * -------------------------------------------------------------------------- **
00009  * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
00010  * -------------------------------------------------------------------------- **
00011  *
00012  *  This program is free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; either version 2 of the License, or
00015  *  (at your option) any later version.
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public License
00023  *  along with this program; if not, write to the Free Software
00024  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  *
00026  * -------------------------------------------------------------------------- **
00027  * This program provides an example of the use of debugparse.c, and also
00028  * does a decent job of converting Samba logs into HTML.
00029  * -------------------------------------------------------------------------- **
00030  *
00031  * Revision 1.4  1998/11/13 03:37:01  tridge
00032  * fixes for OSF1 compilation
00033  *
00034  * Revision 1.3  1998/10/28 20:33:35  crh
00035  * I've moved the debugparse module files into the ubiqx directory because I
00036  * know that 'make proto' will ignore them there.  The debugparse.h header
00037  * file is included in includes.h, and includes.h is included in debugparse.c,
00038  * so all of the pieces "see" each other.  I've compiled and tested this,
00039  * and it does seem to work.  It's the same compromise model I used when
00040  * adding the ubiqx modules into the system, which is why I put it all into
00041  * the same directory.
00042  *
00043  * Chris -)-----
00044  *
00045  * Revision 1.1  1998/10/26 23:21:37  crh
00046  * Here is the simple debug parser and the debug2html converter.  Still to do:
00047  *
00048  *   * Debug message filtering.
00049  *   * I need to add all this to Makefile.in
00050  *     (If it looks at all strange I'll ask for help.)
00051  *
00052  * If you want to compile debug2html, you'll need to do it by hand until I
00053  * make the changes to Makefile.in.  Sorry.
00054  *
00055  * Chris -)-----
00056  *
00057  * ========================================================================== **
00058  */
00059 
00060 #include "debugparse.h"
00061 
00062 /* -------------------------------------------------------------------------- **
00063  * The size of the read buffer.
00064  */
00065 
00066 #define DBG_BSIZE 1024
00067 
00068 /* -------------------------------------------------------------------------- **
00069  * Functions...
00070  */
00071 
00072 static dbg_Token modechange( dbg_Token newmode, dbg_Token mode )
00073   /* ------------------------------------------------------------------------ **
00074    * Handle a switch between header and message printing.
00075    *
00076    *  Input:  new   - The token value of the current token.  This indicates
00077    *                  the lexical item currently being recognized.
00078    *          mode  - The current mode.  This is either dbg_null or
00079    *                  dbg_message.  It could really be any toggle
00080    *                  (true/false, etc.)
00081    *
00082    *  Output: The new mode.  This will be the same as the input mode unless
00083    *          there was a transition in or out of message processing.
00084    *
00085    *  Notes:  The purpose of the mode value is to mark the beginning and end
00086    *          of the message text block.  In order to show the text in its
00087    *          correct format, it must be included within a <PRE></PRE> block.
00088    *
00089    * ------------------------------------------------------------------------ **
00090    */
00091   {
00092   switch( newmode )
00093     {
00094     case dbg_null:
00095     case dbg_ignore:
00096       return( mode );
00097     case dbg_message:
00098       if( dbg_message != mode )
00099         {
00100         /* Switching to message mode. */
00101         (void)printf( "<PRE>\n" );
00102         return( dbg_message );
00103         }
00104       break;
00105     default:
00106       if( dbg_message == mode )
00107         {
00108         /* Switching out of message mode. */
00109         (void)printf( "</PRE>\n\n" );
00110         return( dbg_null );
00111         }
00112     }
00113 
00114   return( mode );
00115   } /* modechange */
00116 
00117 static void newblock( dbg_Token old, dbg_Token newtok )
00118   /* ------------------------------------------------------------------------ **
00119    * Handle the transition between tokens.
00120    *
00121    *  Input:  old - The previous token.
00122    *          new - The current token.
00123    *
00124    *  Output: none.
00125    *
00126    *  Notes:  This is called whenever there is a transition from one token
00127    *          type to another.  It first prints the markup tags that close
00128    *          the previous token, and then the markup tags for the new
00129    *          token.
00130    *
00131    * ------------------------------------------------------------------------ **
00132    */
00133   {
00134   switch( old )
00135     {
00136     case dbg_timestamp:
00137       (void)printf( ",</B>" );
00138       break;
00139     case dbg_level:
00140       (void)printf( "</FONT>]</B>\n   " );
00141       break;
00142     case dbg_sourcefile:
00143       (void)printf( ":" );
00144       break;
00145     case dbg_lineno:
00146       (void)printf( ")" );
00147       break;
00148     default:
00149       break;
00150     }
00151 
00152   switch( newtok )
00153     {
00154     case dbg_timestamp:
00155       (void)printf( "<B>[" );
00156       break;
00157     case dbg_level:
00158       (void)printf( " <B><FONT COLOR=MAROON>" );
00159       break;
00160     case dbg_lineno:
00161       (void)printf( "(" );
00162       break;
00163     default:
00164       break;
00165     }
00166   } /* newblock */
00167 
00168 static void charprint( dbg_Token tok, int c )
00169   /* ------------------------------------------------------------------------ **
00170    * Filter the input characters to determine what goes to output.
00171    *
00172    *  Input:  tok - The token value of the current character.
00173    *          c   - The current character.
00174    *
00175    *  Output: none.
00176    *
00177    * ------------------------------------------------------------------------ **
00178    */
00179   {
00180   switch( tok )
00181     {
00182     case dbg_ignore:
00183     case dbg_header:
00184       break;
00185     case dbg_null:
00186     case dbg_eof:
00187       (void)putchar( '\n' );
00188       break;
00189     default:
00190       switch( c )
00191         {
00192         case '<':
00193           (void)printf( "&lt;" );
00194           break;
00195         case '>':
00196           (void)printf( "&gt;" );
00197           break;
00198         case '&':
00199           (void)printf( "&amp;" );
00200           break;
00201         case '\"':
00202           (void)printf( "&#34;" );
00203           break;
00204         default:
00205           (void)putchar( c );
00206           break;
00207         }
00208     }
00209   } /* charprint */
00210 
00211 int main( int argc, char *argv[] )
00212   /* ------------------------------------------------------------------------ **
00213    * This simple program scans and parses Samba debug logs, and produces HTML
00214    * output.
00215    *
00216    *  Input:  argc  - Currently ignored.
00217    *          argv  - Currently ignored.
00218    *
00219    *  Output: Always zero.
00220    *
00221    *  Notes:  The HTML output is sent to stdout.
00222    *
00223    * ------------------------------------------------------------------------ **
00224    */
00225   {
00226   int       i;
00227   int       len;
00228   char      bufr[DBG_BSIZE];
00229   dbg_Token old   = dbg_null,
00230             newtok = dbg_null,
00231             state = dbg_null,
00232             mode  = dbg_null;
00233 
00234   (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
00235   (void)printf( "<HTML>\n<HEAD>\n" );
00236   (void)printf( "  <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
00237 
00238   while( (!feof( stdin ))
00239       && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) )
00240     {
00241     for( i = 0; i < len; i++ )
00242       {
00243       old = newtok;
00244       newtok = dbg_char2token( &state, bufr[i] );
00245       if( newtok != old )
00246         {
00247         mode = modechange( newtok, mode );
00248         newblock( old, newtok );
00249         }
00250       charprint( newtok, bufr[i] );
00251       }
00252     }
00253   (void)modechange( dbg_eof, mode );
00254 
00255   (void)printf( "</BODY>\n</HTML>\n" );
00256   return( 0 );
00257   } /* main */

Sambaに対してSat Aug 29 21:23:28 2009に生成されました。  doxygen 1.4.7