% noweb source
%
% $Id: multiple.nw,v 2.0 1996/12/17 07:56:41 gaertner Exp $
%
% History at end
%
\documentclass{article}
\usepackage{noweb}
%\usepackage{pretzel-latex}
\begin{document}

\title{Testing the generated Prettyprinter}
\maketitle

\tableofcontents

\section{Introduction}

This document explains a simple main program that tests a
prettyprinter a little more thoughrouly (sp?).

\section{Implementation}

\subsection{Overview}

The implementation will use a prettyprinter generated by
the Pretzel system. A Pretzel prettyprinter comes in the form of a
class:
 %
\begin{verbatim}
     // abstract base class of prettyprinter:

  #include<iostream>
  #include"attr.h"
  #include"output.h"

  class Pparse {
  public:
    Pparse() {};
    ~Pparse() {};
    virtual int prettyprint(istream*, ostream*) = 0;
    virtual int prettyprint(istream*, Output*) = 0;
  };

     // actual prettyprinter:

  #ifndef PPARSE_NAME
  #define PPARSE_NAME Ppparse
  #endif

  class PPARSE_NAME : public Pparse {
  public:
    PPARSE_NAME();
    ~PPARSE_NAME();
    int prettyprint(istream*, ostream*);
    int prettyprint(istream*, Output*);

    void debug_on();
    void debug_off();
  };
\end{verbatim}
 %
We'll create an instance of this class and read input from as many
files as specified at the command line.


@ Here's an overview over the implementation.

<<*>>=
/* implementation of a tester for a prettyprinter */

<<Header files to include>>
<<the main function>>

@



\subsection{Details}

We'll use a standard prettyprinter and output ASCII text to
[[stdout]].

<<Header files to include>>=
#include <stdlib.h>
#include "Ppparse.h"
#include "asciioutput.h"

@ Here's the main program. It's a loop over all the names on the
command line. Remember that [[argc]] is always one larger than the
number of elements on the command line. So we exit the loop when
[[filecount]] reaches the value of [[argc]].


<<the main function>>=
int main( int argc, char *argv[] )
{
    <<check command line and return if faulty>>

    char* filename;
    int filecount = 1;
    while (filecount < argc) {
        filename = argv[filecount];
        <<prettyprint file [[filename]]>>
        filecount++;
    }
    return(0);
}

@
<<check command line and return if faulty>>=
if (argc <= 1) {
    cerr << argv[0] << ": error -- missing file name(s)." << endl
	<< "Specify one or more files to be prettyprinted to stdout."
	<< endl;
    exit(1);
}

@ Here's where the work is done.

<<prettyprint file [[filename]]>>=
{
    Ppparse prettyprinter;
    Ascii_terminal_output outp(cout);

    cout << endl << "** Processing file " << filename << endl;

    ifstream infile;  /* file to read from */
    infile.open(filename); assert(infile!=NULL);
    prettyprinter.prettyprint(&infile, &cout);

}


@

<<Header files to include>>=
#include <iostream>
#include <fstream>
#include <assert.h>

@





\end{document}


%
% $Log: multiple.nw,v $
% Revision 2.0  1996/12/17 07:56:41  gaertner
% *** empty log message ***
%
%
%
