/* ========================================================================== **
 *                                debug2html.c
 *
 * Copyright (C) 1998 by Christopher R. Hertel
 *
 * Email: crh@ubiqx.mn.org
 *
 * -------------------------------------------------------------------------- **
 * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
 * -------------------------------------------------------------------------- **
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see 
\n" );
        return( dbg_message );
        }
      break;
    default:
      if( dbg_message == mode )
        {
        /* Switching out of message mode. */
        (void)printf( "\n\n" );
        return( dbg_null );
        }
    }
  return( mode );
  } /* modechange */
static void newblock( dbg_Token old, dbg_Token newtok )
  /* ------------------------------------------------------------------------ **
   * Handle the transition between tokens.
   *
   *  Input:  old - The previous token.
   *          new - The current token.
   *
   *  Output: none.
   *
   *  Notes:  This is called whenever there is a transition from one token
   *          type to another.  It first prints the markup tags that close
   *          the previous token, and then the markup tags for the new
   *          token.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  switch( old )
    {
    case dbg_timestamp:
      (void)printf( "," );
      break;
    case dbg_level:
      (void)printf( "]\n   " );
      break;
    case dbg_sourcefile:
      (void)printf( ":" );
      break;
    case dbg_lineno:
      (void)printf( ")" );
      break;
    default:
      break;
    }
  switch( newtok )
    {
    case dbg_timestamp:
      (void)printf( "[" );
      break;
    case dbg_level:
      (void)printf( " " );
      break;
    case dbg_lineno:
      (void)printf( "(" );
      break;
    default:
      break;
    }
  } /* newblock */
static void charprint( dbg_Token tok, int c )
  /* ------------------------------------------------------------------------ **
   * Filter the input characters to determine what goes to output.
   *
   *  Input:  tok - The token value of the current character.
   *          c   - The current character.
   *
   *  Output: none.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  switch( tok )
    {
    case dbg_ignore:
    case dbg_header:
      break;
    case dbg_null:
    case dbg_eof:
      (void)putchar( '\n' );
      break;
    default:
      switch( c )
        {
        case '<':
          (void)printf( "<" );
          break;
        case '>':
          (void)printf( ">" );
          break;
        case '&':
          (void)printf( "&" );
          break;
        case '\"':
          (void)printf( """ );
          break;
        default:
          (void)putchar( c );
          break;
        }
    }
  } /* charprint */
int main( int argc, char *argv[] )
  /* ------------------------------------------------------------------------ **
   * This simple program scans and parses Samba debug logs, and produces HTML
   * output.
   *
   *  Input:  argc  - Currently ignored.
   *          argv  - Currently ignored.
   *
   *  Output: Always zero.
   *
   *  Notes:  The HTML output is sent to stdout.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  int       i;
  int       len;
  char      bufr[DBG_BSIZE];
  dbg_Token old   = dbg_null,
            newtok = dbg_null,
            state = dbg_null,
            mode  = dbg_null;
  (void)printf( "\n" );
  (void)printf( "\n\n" );
  (void)printf( "