edu.northwestern.at.utils.preprocessor

## Class Preprocessor

- java.lang.Object
- - edu.northwestern.at.utils.preprocessor.Preprocessor

-     public class Preprocessor
      extends java.lang.Object

  Simple preprocessor.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `defineDirective` --- Directives ---
    `protected java.util.Map<java.lang.String,java.lang.String>` | `definedSymbols` Defined symbols.
    `protected java.lang.String` | `destFileName` Name of sestination file to receive proprocessed text.
    `protected java.lang.String` | `directiveLeadIn` Preprocessor directive lead-in string.
    `protected java.lang.String` | `endifDirective`
    `protected java.lang.String` | `ifdefDirective`
    `protected java.lang.String` | `ifndefDirective`
    `protected java.lang.String` | `includeDirective`
    `protected int` | `lineCount` Count of lines processed.
    `protected java.io.BufferedWriter` | `outputWriter` Writer to which to output preprocessed text.
    `protected boolean` | `skipState` true if skipping lines.
    `protected java.util.Stack<java.lang.Boolean>` | `skipStates` Line skip nesting state.
    `protected java.lang.String` | `sourceFileName` Name of source file to preprocess.
    `protected java.lang.String` | `undefineDirective`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Preprocessor()` Create preprocessor.
    `Preprocessor(java.lang.String leadIn)` Create preprocessor with specified directive lead-in string.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `defineSymbol(java.lang.String symbol, java.lang.String value)` Define a symbol.
    `int` | `getLineCount()` Get the number of lines preprocessed.
    `static void` | `main(java.lang.String[] args)` Main program.
    `boolean` | `preprocess(java.lang.String sourceFileName, java.lang.String destFileName)` Preprocess one file.
    `boolean` | `preprocess(java.lang.String sourceFileName, java.lang.String destFileName, boolean quiet)` Preprocess one file.
    `protected void` | `processFile(java.lang.String sourceFileName, java.io.BufferedWriter outputWriter, boolean quiet)` Process one file.
    `protected java.lang.String` | `resolve(java.lang.String s)` Replace defined symbols in string.
    `protected boolean` | `symbolDefined(java.lang.String symbol)` Check if symbol defined.
    `protected void` | `undefineSymbol(java.lang.String symbol)` Undefine a symbol.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### definedSymbols

          protected java.util.Map<java.lang.String,java.lang.String> definedSymbols

      Defined symbols.

    - #### skipState

          protected boolean skipState

      true if skipping lines.

    - #### skipStates

          protected java.util.Stack<java.lang.Boolean> skipStates

      Line skip nesting state.

    - #### lineCount

          protected int lineCount

      Count of lines processed.

    - #### outputWriter

          protected java.io.BufferedWriter outputWriter

      Writer to which to output preprocessed text.

    - #### sourceFileName

          protected java.lang.String sourceFileName

      Name of source file to preprocess.

    - #### destFileName

          protected java.lang.String destFileName

      Name of sestination file to receive proprocessed text.

    - #### directiveLeadIn

          protected java.lang.String directiveLeadIn

      Preprocessor directive lead-in string.

    - #### defineDirective

          protected java.lang.String defineDirective

      --- Directives ---

    - #### undefineDirective

          protected java.lang.String undefineDirective

    - #### includeDirective

          protected java.lang.String includeDirective

    - #### ifdefDirective

          protected java.lang.String ifdefDirective

    - #### ifndefDirective

          protected java.lang.String ifndefDirective

    - #### endifDirective

          protected java.lang.String endifDirective

  - ### Constructor Detail

    - #### Preprocessor

          public Preprocessor()

      Create preprocessor.

    - #### Preprocessor

          public Preprocessor(java.lang.String leadIn)

      Create preprocessor with specified directive lead-in string.

  - ### Method Detail

    - #### defineSymbol

          protected void defineSymbol(java.lang.String symbol,
                          java.lang.String value)

      Define a symbol.
      Parameters:
        `symbol` - The symbol to define.
        `value` - Symbol value.

    - #### undefineSymbol

          protected void undefineSymbol(java.lang.String symbol)

      Undefine a symbol.
      Parameters:
        `symbol` - Symbol to undefine.

    - #### symbolDefined

          protected boolean symbolDefined(java.lang.String symbol)

      Check if symbol defined.
      Parameters:
        `symbol` - Symbol name to check if defined.
      Returns:
        true if symbol defined (not null), false otherwise.

    - #### resolve

          protected java.lang.String resolve(java.lang.String s)

      Replace defined symbols in string.
      Parameters:
        `s` - The string containing symbols to replace.
      Returns:
        The string with defined symbols replaced by their values.

    - #### processFile

          protected void processFile(java.lang.String sourceFileName,
                         java.io.BufferedWriter outputWriter,
                         boolean quiet)
                              throws java.lang.Exception

      Process one file.
      Parameters:
        `sourceFileName` - File to preprocess.
        `outputWriter` - Output writer. Must be open.
        `quiet` - True to suppress progress messages.
      Throws:
        `java.lang.Exception` - If something goes wrong.

    - #### preprocess

          public boolean preprocess(java.lang.String sourceFileName,
                           java.lang.String destFileName,
                           boolean quiet)

      Preprocess one file.
      Parameters:
        `sourceFileName` - The source file to preprocess.
        `destFileName` - The destination file.
        `quiet` - true to suppress progress messages.
      Returns:
        true if file preprocessed successfully.

    - #### preprocess

          public boolean preprocess(java.lang.String sourceFileName,
                           java.lang.String destFileName)

      Preprocess one file.
      Parameters:
        `sourceFileName` - The source file to preprocess.
        `destFileName` - The destination file.
      Returns:
        true if file preprocessed successfully.

    - #### getLineCount

          public int getLineCount()

      Get the number of lines preprocessed.
      Returns:
        The number of lines preprocessed.

    - #### main

          public static void main(java.lang.String[] args)

      Main program.
      Parameters:
        `args` - Command line arguments.