//----------------------------------------------------------------------
//  filter.cpp
//  This program copies standard input to standard output with 
//  underlining.  Underlining is toggled on and off by input of the
//  character '\'. Command line redirection of standard input is likely.
//
//  NOTE: On some video monitors, this program will not display 
//  underlined characters.  Instead, only the underline character (_)
//  itself will appear on the screen.
//----------------------------------------------------------------------
#include <iostream.h>

typedef int Boolean;
const int TRUE = 1;
const int FALSE = 0;

int main()
{
    const char TOGGLE_CHAR = '\\';
    const char BACKSPACE = '\b';
    const char UNDERLINE = '_';

    char    inChar;
    Boolean underlining = FALSE;

    cerr << "This program filters an input file with underlining,\n"
         << "which is toggled on/off by backslash (\\) chars.\n\n";

    while (cin.get(inChar))         // Don't skip whitespace
        switch (inChar) {
            case '\n':              // Don't underline a newline
                cout << '\n';
                break;
            case TOGGLE_CHAR:
                underlining = !underlining;
                break;
            default:
                cout << inChar;
                if (underlining) {
                    cout << BACKSPACE;
                    cout << UNDERLINE;
                }
        }
    cerr << "\nFinished.\n";
    return 0;
}


