OUTPUT Redirection

With GPP2, it is possible to "redirect" the output stream to other files, with predefined extensions, under the program control.

The motivation is to allow the GPP developer to rearrange parts of the output code in a different way in the final output file. For instance, it may be required to arrange a "main" program followed by the procedure bodies.

With old GPP, this required using statements like PRINT1, PRINT2, etc. However, during other runs, the same post-processor may be required to use the standard output and file order as well. GPP developers often had to write the same "output" commands twice - once with OUTPUT and another time with PRINTx. GPP2 solves this problem and gives maximum flexibility through output redirection.

OUTPUT_REDIRECT <string> ;

OUTPUT_BACK ;

OUTPUT_CLOSE ;

The OUTPUT_REDIRECT statement has one argument, a constant string with exactly one letter (For example, "p" or "P"). Regular string expressions cannot be used - the string must be a constant string. The letter "s" (or "S") cannot be used - it is reserved for subroutine files.

After the first execution of the OUTPUT_REDIRECT statement, all text generated with the OUTPUT statement will be directed to a new file, sharing the same name as the main G-code output file, but with an extension "._x01", where x is the letter used in the redirection statement.

Executing the OUTPUT_BACK statement will restore the output stream back to the main G-code file, without closing the "._x01" file. If OUTPUT_REDIRECT is used again with the same letter, the data will be redirected again to the same "._x01" file.

Using the OUTPUT_BACK when no redirection is active (output is currently sent to the main file) has no effect, and a runtime warning is issued.

The OUTPUT_CLOSE statement closes the currently open redirected output file ("._x01"), so that any subsequent output will be sent to a new file, with extension "._x02". This process will repeat with each use of OUTPUT_CLOSE.

Using the OUTPUT_CLOSE when no redirection is active (output is currently sent to the main file) has no effect, and a runtime warning is issued.

The use of OUTPUT_REDIRECT can be nested, by using different letters. For instance, output can be redirected to "._a01", then redirected to "._b01", then redirected to "._c01". The behavior is like a "stack" of redirections. The first use of OUTPUT_BACK will restore redirection from "._c01" to "._b01", the next use will restore it to "._a01" and another use will restore it to the main file.

GPP2 will support up to 10 levels of nesting. It is only allowed to use any letter once inside a nesting redirection stack. Therefore, trying to redirect to "a", then to "b" and then to "a" again (without going back to the main file) will generate a runtime error.

Example

OUTPUT "Main file line 1";

OUTPUT_REDIRECT "a";                // redirect output to "._a01"

  OUTPUT "AAAAA line 1";

  OUTPUT_REDIRECT "b";         // redirect output to "._b01"

    OUTPUT "BBBBB line 1";

    OUTPUT_CLOSE;             // close file "._b01"

    OUTPUT "BBBBB line 1 to file ._b02"; // send to file "._b02"

    OUTPUT_REDIRECT "c";       // redirect output to "._c01"

      OUTPUT "CCCCC line 1";

      OUTPUT_BACK;           // restore output (to "._b02")

    OUTPUT "BBBBB line 2 to file ._b02";

    OUTPUT_BACK;             // restore output (to "._a01")

  OUTPUT "AAAAA line 2";

  OUTPUT_BACK;                // restore output (to main file)

OUTPUT "Main file line 2";

The output files generated will be as follows (assuming the main file is named tp.post):

File tp.post (main):

Main file line 1

Main file line 2

File tp.post._a01:      

AAAAA line 1

AAAAA line 2

File tp.post._b01:

BBBBB line 1

File tp.post._b02:      

BBBBB line 1 to file ._b02

BBBBB line 2 to file ._b02

File tp.post._c01:

CCCCC line 1

Some functionality may be dependent on the product package. Contact your Reseller if you require a license.