Version 2 of Output Filtering by Ron Newcomb begins here. "Specify rules to modify any and all game output. Recommended usage is solving capitalization, punctuation, and whitespace issues. Includes Eric Eve's Text Capture." "Special thanks to JDC, Aaron Reed, and Jon Ingold." Part 1 -include Eric's extension Include Text Capture by Eric Eve. Use maximum capture buffer length of at least 5000. Output filtering is a truth state that varies. Output filtering is usually true. [ Part 2 - Define Four Phrases (in place of Part 1 - Define Four Phrases in Text Capture by Eric Eve) To start capturing text: (- if ( 1 == (+ output filtering +) ) { (+ flush output rule +)(); } StartCapture(); -). To stop capturing text: (- EndCapture(); if ( 1 == (+ output filtering +) ) { (+ flush output rule +)(); } -). To say the/-- captured text: (- PrintCapture(); -). To decide whether text capturing is active: (- (capture_active > 0) -). ] Part 3 - Extension Output Filtering Chapter - Extension Output Filtering Section - Basics Use banner text filtering translates as (- Constant BANNER_FILTERING; -). Use no blank lines translates as (- Constant DISABLE_BLANK_LINE_REGEX; -). Use output filter debugging translates as (- Constant DEBUG_OUTPUT_FILTERING; -). The game's response is indexed text that varies. [ ANALOGOUS TO "THE PLAYER'S COMMAND" ] To decide whether (ts - a truth state) is on: if ts is true, decide yes; otherwise decide no. To decide whether (ts - a truth state) is off: if ts is false, decide yes; otherwise decide no. To start output filtering: if output filtering is false begin; now output filtering is true; [must be true when calling rule] follow the Capture Game Output rule; end if. To stop output filtering: if output filtering is true begin; follow the Format Game Output rule; [ flush current saved contents ] now output filtering is false; [must be true when calling rule] end if. Section - Rules that use the basics The last before printing the banner text (this is the Start Banner Text Filtering rule): if not using banner text filtering option, follow the Format Game Output rule. The first after printing the banner text (this is the Finish Banner Text Filtering rule): if using the banner text filtering option, follow the Format Game Output rule; follow the Capture Game Output rule; [always turn it on after banner text regardless, so the initial room description will be properly capitallized] The first after reading a command (this is the Capture Game Output rule): if output filtering is true, start capturing text. The last before reading a command (this is the Format Game Output rule): if output filtering is true begin; stop capturing text; change the game's response to "[run paragraph on][captured text]"; follow the output processing rulebook; say the filtered game's response; end if. [and leave it off for the command line and parsing; the Capture rule will turn it on again] First when play begins (this is the Initializing Output Filtering rule): follow the Capture Game Output rule. Section - a debugging verb to turn output filtering on/off - not for release Understand "output filtering" as toggling output filtering. Toggling output filtering is an action out of world applying to nothing. Carry out toggling output filtering: if output filtering is true, stop output filtering; otherwise start output filtering; say "output filtering is now [bold type][output filtering][roman type]."; Section - Autocapitalize the sentence after a room heading even though the heading doesn't end in a period This is the flush output rule: say run paragraph on; follow the Format Game Output rule; say run paragraph on; follow the Capture Game Output rule. The flush output rule is listed after the room description heading rule in the carry out looking rules. The flush output rule is listed before the room description body text rule in the carry out looking rules. Chapter - The Output Processing Rulebook's default rules The output processing rules are a rulebook. An output processing rule (this is the Autocapitalization rule): replace the regular expression "(<\.\?\!>)(<\s'{\<}>+)(\l)" in the game's response with "\1\2\u3"; replace the regular expression "^(<\s'{\<}>*)(\l)" in the game's response with "\1\u2". [for the very first letter of the captured text] [NOTE: in the above, \1 is a lower-case L in the regex and the number One in the replacement! I7's font shows them identically. ] [ to type ¶ on Mac keyboard, hold Option, type 7 ] [ to type ¶ on Win keyboard, hold ALT, type 0182, release ALT ] An output processing rule (this is the Paragraph Break rule): if not using no blank lines option, replace the regular expression "\[BLANK LINE]" in the game's response with "\n\n\[BLANK LINE]"; replace the regular expression "\n{3,}" in the game's response with "\n\n"; [ single-function search should be faster, and ensure it's "3 or more" not "2 or more"!! ] replace the regular expression "\n{2,}$" in the game's response with "\n"; [ the command prompt tends to print its own line break before itself, so we enforce only one break beforehand ] if not using no blank lines option, replace the regular expression "\[BLANK LINE]" in the game's response with "\n". Chapter - I6 helper routines for Output Filtering To say bold type: (- bold_on(); -). To say italic type: (- italic_on(); -). To say roman type: (- roman_on(); -). To say blank line: say "[bracket]BLANK LINE[close bracket]". To say the/-- filtered (itext - indexed text): (- SayGameResponse(({itext})); -). Include (- [ bold_on; if (capture_active > 0) print "{"; else style bold; ]; [ italic_on; if (capture_active > 0) print "<"; else style underline; ]; [ roman_on; if (capture_active > 0) print "}"; else style roman; ]; [ SayGameResponse indt ch i dsize; if ((indt==0) || (BlkType(indt) ~= INDEXED_TEXT_TY)) return; dsize = BlkValueExtent(indt); for (i=0:i OUTPUT FILTERING (O/o)utput filtering is now (TRUE/FALSE). When starting filtering, the debugging verb's output will be captured and processed the same as any other output. For example, the letter O would be capitalized. Debugging filter problems sometimes requires looking at the actual ZSCII codes being printed out. This can be accomplished with a use option. Note that bold and italic text is still processed, and spaces and newlines are actually printed in lieu of their ZSCII code, for greater readability of the debugging output. *: Use output filter debugging. Section : Important technical notes Very lengthy passages may exceed the size of the buffer set aside for this extension. It can be increased by raising the number in: *: Use maximum capture buffer length of at least 5000. No changes are needed to existing code in order to use bold and italic type, but there are two known issues. First, this extension uses the { open brace, the } close brace, and the < less-than symbol to temporarily represent the textual styles. If a work wishes to print these, then modifying the appropriate Inform 6 part of this extension would be necessary. Second, due to a limitation of regular expressions in Inform, altering the number of blank lines cannot be done with the Z-machine. Example: * Navel Gazing - Tests extension, highlights limitations. *: "navel gazing" Include Output Filtering by Ron Newcomb. [Use no blank lines.] [Use output filter debugging. ] [Use banner text filtering.] When play begins, change the command prompt to "[bold type][if output filtering is on]on[otherwise]off[end if][roman type]>". Before printing the banner text, say "once upon a time...[line break][line break]". room heading is a room. "you notice the room heading was capitalized. and the first sentence was capitalized in spite of the room heading not ending in a period, exclamation mark, or question mark. " A horse is a supporter in room heading. "[line break][line break]here appears to be two spurious leading line breaks (removed), a horse with no name...[blank line]...and exactly one extra blank line. you can also see [bold type]bold[roman type] and [italic type]italic[roman type] text here." Has-whispered is a truth state that varies. Has-whispered is false. Understand "whisper" as a mistake ("the horse whispers his name back to you. he also mentions that all variables of yours will now be set long before any text is printed. This means say phrases with side effects, such as the [learn Argo]'learn Argo' code, essentially occur at the beginning of the enclosing phrase."). To say learn Argo: now has-whispered is true. An output processing rule (this is the Known Name rule): if has-whispered is true, replace the regular expression "\b(a|the)\s+horse" in the game's response with "Argo", case insensitively. Understand "breaks" as a mistake ("and then (break)[line break]something (2 breaks)[line break][line break][bold type]really[roman type] happened! (3 breaks)[line break][line break][line break]"). Understand "speak" as a mistake ("'capitalize me when I'm talking to you!'[line break][line break]'all my [italic type]friends[roman type] use [italic type]screenplay[roman type] style, and [italic type]they[roman type] don't capitalize!'[line break][line break]'we don't care what your friends do or don't use. you will capitalize after double-quotation marks!'"). Test me with " l/ breaks / speak / whisper / output filtering / l / breaks / speak / whisper ".