%D \module
%D   [       file=verb-jv,
%D        version=2002.2.27,
%D          title=\CONTEXT\ Verbatim Macros,
%D       subtitle=Pretty \JAVA\ Verbatim,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 
%C
%C Modified on 2002-11-03 by Zeljko Vrba (mordor@fly.srk.fer.hr)
%C to support C and C++

\writestatus{loading}{Context Support Macros / Pretty C++ Verbatim}

%D This module differs from the \JAVASCRIPT\ driver in its
%D handling of comments. We also need a few more handlers: one
%D for \type {//} and \type {/*} and one for \type {*/} as
%D well as the \JAVA doc trigger \type {/**}. 

%D We build this driver on top of the \PERL\ one. Since this
%D driver looks much like the \JAVASCRIPT\ one, we don't 
%D comment it extensively. 

\ifx\undefined\setupprettyPLtype \input verb-pl \relax \fi

\unprotect

\newcount\CPPcommentlevel

\gdef\CPPsetspecials
  {\PLsetspecials
   \setpretty`\#=32
   \setpretty`\%=41
   \setpretty`\-=45 
   \setpretty`\/=43
   \setpretty`\*=44 }

\gdef\CPPsethandlers
  {\PLsethandlers
   \installprettyhandler 43 \CPPtypefourthree
   \installprettyhandler 44 \CPPtypefourfour 
   \installprettyhandler 45 \CPPtypefourfive }

\gdef\CPPsetcontrols
  {\PLsetcontrols
   \def\flushrestofverbatimline
     {\endPLtypesix
      \ifcase\CPPcommentlevel \inPLcommentfalse \fi
      \PLverbosefalse
      \PLverboseskipped=0}}

\gdef\CPPsetvariables
  {\PLsetvariables
   \global\CPPcommentlevel=0 }

\gdef\setupprettyCPPtype
  {\def\prettyidentifier{CPP}%
   \let\PLidentifiers\CPPidentifiers
   \let\PLvariables\CPPvariables
   \CPPsetvariables
   \CPPsetcontrols
   \CPPsethandlers
   \CPPsetspecials
   \PLsetdiagnostics}

\gdef\CPPtypefourthree
  {\handlenextnextpretty\doCPPtypefourthree\PLtypefourtwo}

\gdef\doCPPtypefourthree#1#2#3%
  {\getprettydata{#2}%
   \ifnum\prettytype=43
     \let\next\dodoCPPtypefourthree
   \else\ifnum\prettytype=44
     \global\advance\CPPcommentlevel 1
     \global\inPLcommenttrue
     \PLverbosecorrection
     \getprettydata{#3}%
     \ifnum\prettytype=44
       \inPLdoctrue
     \fi
     \let\next\CPPtogglecomment
   \else
     \let\next\PLtypefourtwo
   \fi\fi
   \next{#1}#2#3}

\gdef\CPPtogglecomment#1#2%
  {\ifnum\CPPcommentlevel=1
     \beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty
   \else
     \getpretties{#1}{#2}%
   \fi}

\gdef\dodoCPPtypefourthree
  {\endPLtypesix
   \handlenextnextpretty\dododoCPPtypefourthree\dodododoPLtypefourthree}

\gdef\dododoCPPtypefourthree
  {\ifnewpretty\expandafter\handlenewpretty\fi\dodododoCPPtypefourthree}

\gdef\dodododoCPPtypefourthree#1#2%
  {\ifinPLcomment
     \getpretties{#1}{#2}%
   \else
     \global\inPLcommenttrue
     \PLverbosecorrection
     \ifnaturaltextext
       \let\next\naturaltextext
     \else
       \def\next{\beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty}%
     \fi
     \expandafter\next
   \fi}

\gdef\CPPtypefourfour
  {\ifinPLdoc
     \@EA\noCPPtypefourfour
   \else
     \@EA\handlenextnextpretty\@EA\doCPPtypefourfour\@EA\PLtypefourtwo
   \fi}

\gdef\noCPPtypefourfour#1#2%
  {\getprettydata{#2}%
   \ifnum\prettytype=43
     \CPPtogglecomment{#1}#2%
     \inPLdocfalse
     \global\advance\CPPcommentlevel -1
     \ifcase\CPPcommentlevel \global\inPLcommentfalse \fi
   \else
     \ifPLdocdone 
       \getpretty{#1}%
     \else
       \beginofpretty[\!!prettyone]\getpretty{#1}\endofpretty
       \PLdocdonetrue
     \fi
     \expandafter#2%
   \fi}

\gdef\doCPPtypefourfour#1#2%
  {\getprettydata{#2}%
   \ifnum\prettytype=43
     \CPPtogglecomment{#1}#2%
     \inPLdocfalse
     \global\advance\CPPcommentlevel -1
     \ifcase\CPPcommentlevel \global\inPLcommentfalse \fi
   \else
     \endPLtypesix
     \beginofpretty[\!!prettyfour]\getpretty{#1}\endofpretty
     \expandafter#2%
   \fi}

\gdef\CPPtypefourfive % permit - in javadoc @tags 
  {\ifinPLdoc
     \@EA\PLtypesixtwo
   \else
     \@EA\PLtypefourone
   \fi}

\useprettyidentifiers \CPPidentifiers \CPPsetspecials
  goto break return continue case default if else switch
  while for do sizeof int long short char void signed
  unsigned float double bool complex struct union enum
  typedef static register auto volatile extern const
  new delete this friend using public protected private
  inline virtual explicit export throw try catch operator
  typeid mutable class typename template namespace true false
  static_cast reinterpret_cast const_cast dynamic_cast
   
% We use identifiers for # directives
\useprettyidentifiers \CPPvariables \CPPsetspecials
  #include #if #endif #elif #else #ifdef #ifndef #pragma

%D The \JAVA doc feature was requested by Robert F.~Beeger, 
%D who also provided this test class: 
%D 
%D \startCPP 
%D package de.jwamalpha.handling.web.rbdipl;
%D 
%D import java.io.IOException;
%D import java.io.PrintWriter;
%D import javax.servlet.http.HttpServlet;
%D import javax.servlet.http.HttpServletRequest;
%D import javax.servlet.http.HttpServletResponse;
%D import javax.servlet.ServletException;
%D 
%D /**
%D  * The simple login servlet
%D  *
%D  * @author Robert F. Beeger
%D  * @version 1.0
%D  */
%D 
%D public class LoginServlet extends HttpServlet
%D {
%D   // 
%D   // public interface
%D   //
%D   /**
%D    * Process the get-request.
%D    *
%D    * @param request the request
%D    * @param response the response.
%D    */
%D   protected void doGet (HttpServletRequest request, HttpServletResponse response)
%D      throws ServletException, IOException
%D   {
%D     response.setContentType("text/html");
%D     PrintWriter writer = response.getWriter();
%D     writer.println("<html>");
%D     writer.println("  <head>");
%D     writer.println("    <title>Login</title>");
%D     writer.println("  </head>");
%D     writer.println("  <body>");
%D     writer.println("    Hallo, Benutzer " + request.getParameter("username") + "!");
%D     writer.println("  </body>");
%D     writer.println("</html>");
%D     writer.flush();
%D   }
%D }
%D \stopCPP 

\protect \endinput  
