! STRIP - Strips ampersands (&) and backslashes from BP2 V1.6 programs ! ! Kelvin Smith, Financial Computer Systems, Inc., Stamford, CT 06902 ! ! This correctly strips "&" and "\" from files, leaving the ampersand ! ! where a statement continues onto two or more lines and leaving ! ! backslashes when embedded in a line. ! ! Q-registers used: ! ! P% - Buffer location of ampersand presently under consideration for ! ! deletion. ! ! Q% - Used to check ASCII values beyond the pointer position (offset). ! ! R% - Flag: = -1 if in the midst of multi-line comment. ! ! S% - Radix storage ! ! Start -- Force decimal; add a line feed to the beginning of the page so ! ! that if page starts with a line number, the ^EL^ED search will find it. ! [P [Q [R [S 10US ! Store current radix ! ^D ! Force decimal radix ! J @^A/Working... / !START! @10I// ! Add line feed at beginning of page ! R ! Back over it ! 0UR ! Find each line number -- if that physical line has no true statement, put ! ! a backslash at the beginning of the first physical line that does have a ! ! statement, so that we know we can take the ampersands off the empty and ! ! commenting lines (backslash will be deleted later). ! < :@S/^EL^ED/; ! Find digit at start of a line ! @S/^ES/ ! Past the space or tab ! 0UQ !LOOP! QQA-33"L ! Past any more control chars ! %Q^[ @O!LOOP! ' QQC ! Move past them ! 0A-^^!"N ! If not an exclamation point ! 0A-^^&"N ! and not an ampersand ! F< ! then don't worry about this line ! ' ' ! and find next line number ! !RPT! L ! Check next line for statement ! :@S/^N^ES/; ! Past spaces and tabs ! -1AUQ ! What character did we pass? ! QQ-^^!"E ! Exclamation point - skip this line ! @O!RPT! ' QQ-^^&"E ! Ampersand - skip this line ! @O!RPT! ' 0L ! Check beginning of line ! QQ"D ! Digit--it's a line number, so ! 2R ! start this routine over here ! | @I/\/ ! A statement - insert backslash ! ' > ! On to next line number ! ! The main body of work: Search for an ampersand; if next line starts with ! ! a backslash, delete both of them; if it starts with a comment or ampersand ! ! (i.e., blank line), check the next line to see if that one starts with a ! ! backslash and repeat the process. This way, full comment lines can be ! ! properly handled when in the middle of, for example, a multi-line MAP. ! J ! Back to start of page ! < :@S/^ES&/; ! Find an ampersand ! 0A-13"N ! If not immediately followed by CR, ! F< ! we don't want it ! ' .UP ! Mark this point ! 2C ! To start of next line ! !BEGLIN! 0UQ !CHRADV! QQA"L ! "ASCII" is -1; end of page ! @O!KILL! ! We can kill the ampersand ! ' QQA-33"L ! Space/tab/control char ! %Q^[ ! Check next character ! @O!CHRADV! ' QQC ! Move past set of control chars ! 0A-^^\"E ! Is it a backslash? ! QR"E ! If we're in the middle of a ! D ! comment, wipe out backslash ! ' @O!KILL! ! Kill the preceding ampersand ! ' 0A-^^!"E ! Exclamation point - comment line ! -1UR ! Mark that it was a comment ! L ! On to start of next line ! @O!BEGLIN! ' 0A-^^&"E ! Just an ampersand on line ! -1UR ! Treat same as comment ! L ! On to start of next line ! @O!BEGLIN! ' 0A"D ! It's a digit ! 0^Q"N ! If we're not at start of line, ! @O!LEAV! ! we're in middle of statement ! | @O!KILL! ! Start of line=line number, so ! ' ' ! kill the previous ampersand ! ::@S/THEN^ES/"T ! If the line starts with THEN ! @O!KILL! ! or ELSE, no ampersand is needed ! ' ! on previous line, so kill it. ! ::@S/ELSE^ES/"F @O!LEAV! ' !KILL! QPJ ! Back to where we found ampersand ! -2D ! Kill it and preceding space ! !LEAV! 0UR ! Clear the comment flag ! > ! A line which has only the line number on it must have an ampersand at its ! ! end. This puts those ampersands back in, since they had been deleted. ! J < :@S/^EL^ED/; ! Find a line number ! @S/^N^ED/ ! Find first non-digit ! -1A-13"E ! It's a carriage return ! R @I/ &/ ! Put ampersand before it ! | @S/^N^ES/ ! Need to do the same thing if ! -1A-13"E ! we have a few spaces/tabs ! R ! between line number and . ! @I/ &/ ' ' > ! BP2 V2 does not allow exclamation points at the beginning of a line. Add ! ! a space before each one to solve the problem. ! J < :@S/^EL!/; R 32@I// > ! Delete the line feed we added at the page's beginning. If we're not at ! ! the end of the file, pull in the next page. Otherwise, quit. ! J D ^N"E ! Not last page ! P ! Get next page ! @O!START! ! Start fresh with this one ! ' @^A/Finished / ! Tell user we're done ! QS^R ! Restore radix ! ]S ]R ]Q ]P