root/source3/utils/debug2html.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. modechange
  2. newblock
  3. charprint
  4. main

   1 /* ========================================================================== **
   2  *                                debug2html.c
   3  *
   4  * Copyright (C) 1998 by Christopher R. Hertel
   5  *
   6  * Email: crh@ubiqx.mn.org
   7  *
   8  * -------------------------------------------------------------------------- **
   9  * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
  10  * -------------------------------------------------------------------------- **
  11  *
  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.
  16  *
  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.
  21  *
  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/>.
  24  *
  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  * -------------------------------------------------------------------------- **
  29  *
  30  * Revision 1.4  1998/11/13 03:37:01  tridge
  31  * fixes for OSF1 compilation
  32  *
  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
  40  * the same directory.
  41  *
  42  * Chris -)-----
  43  *
  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:
  46  *
  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.)
  50  *
  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.
  53  *
  54  * Chris -)-----
  55  *
  56  * ========================================================================== **
  57  */
  58 
  59 #include "debugparse.h"
  60 
  61 /* -------------------------------------------------------------------------- **
  62  * The size of the read buffer.
  63  */
  64 
  65 #define DBG_BSIZE 1024
  66 
  67 /* -------------------------------------------------------------------------- **
  68  * Functions...
  69  */
  70 
  71 static dbg_Token modechange( dbg_Token newmode, dbg_Token mode )
     /* [<][>][^][v][top][bottom][index][help] */
  72   /* ------------------------------------------------------------------------ **
  73    * Handle a switch between header and message printing.
  74    *
  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
  79    *                  (true/false, etc.)
  80    *
  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.
  83    *
  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.
  87    *
  88    * ------------------------------------------------------------------------ **
  89    */
  90   {
  91   switch( newmode )
  92     {
  93     case dbg_null:
  94     case dbg_ignore:
  95       return( mode );
  96     case dbg_message:
  97       if( dbg_message != mode )
  98         {
  99         /* Switching to message mode. */
 100         (void)printf( "<PRE>\n" );
 101         return( dbg_message );
 102         }
 103       break;
 104     default:
 105       if( dbg_message == mode )
 106         {
 107         /* Switching out of message mode. */
 108         (void)printf( "</PRE>\n\n" );
 109         return( dbg_null );
 110         }
 111     }
 112 
 113   return( mode );
 114   } /* modechange */
 115 
 116 static void newblock( dbg_Token old, dbg_Token newtok )
     /* [<][>][^][v][top][bottom][index][help] */
 117   /* ------------------------------------------------------------------------ **
 118    * Handle the transition between tokens.
 119    *
 120    *  Input:  old - The previous token.
 121    *          new - The current token.
 122    *
 123    *  Output: none.
 124    *
 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
 128    *          token.
 129    *
 130    * ------------------------------------------------------------------------ **
 131    */
 132   {
 133   switch( old )
 134     {
 135     case dbg_timestamp:
 136       (void)printf( ",</B>" );
 137       break;
 138     case dbg_level:
 139       (void)printf( "</FONT>]</B>\n   " );
 140       break;
 141     case dbg_sourcefile:
 142       (void)printf( ":" );
 143       break;
 144     case dbg_lineno:
 145       (void)printf( ")" );
 146       break;
 147     default:
 148       break;
 149     }
 150 
 151   switch( newtok )
 152     {
 153     case dbg_timestamp:
 154       (void)printf( "<B>[" );
 155       break;
 156     case dbg_level:
 157       (void)printf( " <B><FONT COLOR=MAROON>" );
 158       break;
 159     case dbg_lineno:
 160       (void)printf( "(" );
 161       break;
 162     default:
 163       break;
 164     }
 165   } /* newblock */
 166 
 167 static void charprint( dbg_Token tok, int c )
     /* [<][>][^][v][top][bottom][index][help] */
 168   /* ------------------------------------------------------------------------ **
 169    * Filter the input characters to determine what goes to output.
 170    *
 171    *  Input:  tok - The token value of the current character.
 172    *          c   - The current character.
 173    *
 174    *  Output: none.
 175    *
 176    * ------------------------------------------------------------------------ **
 177    */
 178   {
 179   switch( tok )
 180     {
 181     case dbg_ignore:
 182     case dbg_header:
 183       break;
 184     case dbg_null:
 185     case dbg_eof:
 186       (void)putchar( '\n' );
 187       break;
 188     default:
 189       switch( c )
 190         {
 191         case '<':
 192           (void)printf( "&lt;" );
 193           break;
 194         case '>':
 195           (void)printf( "&gt;" );
 196           break;
 197         case '&':
 198           (void)printf( "&amp;" );
 199           break;
 200         case '\"':
 201           (void)printf( "&#34;" );
 202           break;
 203         default:
 204           (void)putchar( c );
 205           break;
 206         }
 207     }
 208   } /* charprint */
 209 
 210 int main( int argc, char *argv[] )
     /* [<][>][^][v][top][bottom][index][help] */
 211   /* ------------------------------------------------------------------------ **
 212    * This simple program scans and parses Samba debug logs, and produces HTML
 213    * output.
 214    *
 215    *  Input:  argc  - Currently ignored.
 216    *          argv  - Currently ignored.
 217    *
 218    *  Output: Always zero.
 219    *
 220    *  Notes:  The HTML output is sent to stdout.
 221    *
 222    * ------------------------------------------------------------------------ **
 223    */
 224   {
 225   int       i;
 226   int       len;
 227   char      bufr[DBG_BSIZE];
 228   dbg_Token old   = dbg_null,
 229             newtok = dbg_null,
 230             state = dbg_null,
 231             mode  = dbg_null;
 232 
 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" );
 236 
 237   while( (!feof( stdin ))
 238       && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) )
 239     {
 240     for( i = 0; i < len; i++ )
 241       {
 242       old = newtok;
 243       newtok = dbg_char2token( &state, bufr[i] );
 244       if( newtok != old )
 245         {
 246         mode = modechange( newtok, mode );
 247         newblock( old, newtok );
 248         }
 249       charprint( newtok, bufr[i] );
 250       }
 251     }
 252   (void)modechange( dbg_eof, mode );
 253 
 254   (void)printf( "</BODY>\n</HTML>\n" );
 255   return( 0 );
 256   } /* main */

/* [<][>][^][v][top][bottom][index][help] */