10 %TITLE "AMPERS - COMMAND TO RIGHT ALIGN AMPERSANDS IN A PROGRAM" %IDENT "V01.00" %SBTTL "Overall description" ! ! ENVIRONMENT SPECIFICATION: ! OPTION & TYPE = EXPLICIT, & SIZE = INTEGER LONG, & SIZE = REAL DOUBLE, & SCALE = 4% REM ------------------------------------------------------------------ A PRIMARY PROGRAM PART OF THE CARL'S SYSTEM LIBRARY (SYL) DEVELOPED BY AND FOR C A R L ' S G R O C E R Y C O M P A N Y , I N C . COPYRIGHT (C) 1983 BY CARL'S GROCERY COMPANY, INC. This software is the sole property of Carl's Grocery Company, Inc., and is intended soley for its use. It may not be copied. ----------------------------------------------------------------- FACILITY: SYL, the system library for Carl's software packages contains standard routines and functions, used by all the packages, and in program developement. ABSTRACT: This program will go through any stream ascii file submitted to it and move all trailing ampersands in column positions under seventy-eight to position seventy-eight. (For improving the appearance of Basic programs. AUTHOR : Buz Waitz CREATION DATE: 01 July 1983 20 %PAGE %SBTTL "Environment" ! ! ENVIRONMENT: ! ! VAX-11 user mode ! VARIANT ASSUMPTIONS: ! NONE ! ! INTERACTIVE MODE FOR THIS PROGRAM: ! ! Operating modes for this program are as follows %LET %YES = -1 %LET %NO = 0 ! Normal terminal I/O mode is primarily for batch operations ! (This mode is set to no if any other mode is set to yes) %LET %NORMAL = %NO ! TDMS mode, screen mode is preferred for interactive operations %LET %TDMS = %NO ! Utility (command type) mode is preferred for simple interaction %LET %UTILITY = %YES REM PRIVILEGE, PROTECTION AND PRIORITY This program requires only that you have write privilege for the file you wish modified. 30 %PAGE %SBTTL "Modification history" REM MODIFICATION AND DEVELOPMENT HISTORY VER# P.EXT DATE CODER NATURE OF CHANGE ------ ----- ------ ----- ---------------- 31! X00.00 070183 BW Creation date 32! V01.00 070583 BW Release date 490 %PAGE %SBTTL "Full description" REM FUNCTIONAL DESCRIPTION: This program is adapted from one written by Craig Zemke for Plycom services in July of 1981. It is instituted as a DCL command. There is one parameter passed, the filespec of the program to be processed. That program is then input line by line. If the last character in the line is an ampersand, then the ampersand is placed in the seventy-eighth column, unless the line is longer than that, in which case the ampersand is placed one space beyond the rest of the text. Other than the end of the file, a control C is the only error trapped for, in which case the temporary file is deleted. All other errors are passed through unprocessed. IMPLICIT INPUTS: This program relies on the CLI to provide the filespec of the file to be input. IMPLICIT OUTPUTS: A new version of the input file will be created, one version number higher than the old. SIDE EFFECTS: Premature termination of the program may result in the temporary file remaining as temporary until the next invocation of this program using the previous filespec, or until that temporary file is explicitly deleted. COMMAND SYNTAX: AMPERS [filespec] Command qualifiers Defaults None. None. 500 %PAGE %SBTTL "Declarations" ! ! DATATYPE SPECIFICATION: ! ! none ! ! INITIALIZING INCLUDE FILES: ! ! none ! ! EQUATED SYMBOLS: ! ! Set up constants for program identification DECLARE STRING CONSTANT & PROGRAM_ID = "AMPERS", & PROGRAM_NAME = "PROGRAM TO RIGHT ALIGN AMPERSANDS" ! Set up constants for relational tests DECLARE INTEGER CONSTANT ! to test for true or false & NO = 0%, & YES = NOT NO DECLARE BYTE CONSTANT ! to test entry and exit & ACTIVATED = 1, ! flags as on or active & FAILURE = -1, ! flags as operation failure & NORMAL = 0 ! normal entry or exit & ! Set up channel assignments DECLARE BYTE CONSTANT & INPUT_FILE = "1"B, ! file to be cleaned up & TEMP_FILE = "2"B ! temporary work file ! Set page width DECLARE BYTE CONSTANT & PAGE_WIDTH = "78"B ! width for use with EDT ! ! LOCAL STORAGE: ! ! Set up entry and exit flags DECLARE & BYTE & Batch_process ! flags batch & ! Standard work variables DECLARE ! declare work variables & INTEGER & Work_integer, ! variable of default integer & ! type & REAL & Work_real, ! real number variable of & ! default precision & STRING & Work_string ! dynamic string variable ! Program specific variables DECLARE & BYTE & Pos_ampers, ! position of the ampersand & ! in the line & Pos_period, ! position of the period in & ! the filespec string & LONG & End_of_file, ! used to signal end of file & STRING & File_name, ! file to be right aligned & Left_line, ! left portion of input line & Line_in, ! line of text from input file& Right_line, ! right portion of input line & Temporary_file ! temporary file filespec ! ! GLOBAL STORAGE: ! ! none ! ! EXTERNAL REFERENCES: ! ! none ! ! INTERNAL REFERENCES: ! ! none 989 %PAGE %SBTTL "Begin process initialization" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo PROCESS INITIALIZATION oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 990 - 998 contain process initialization sections. 990 %PAGE %SBTTL "Process initialization" !+ ! Set up global error handler, control C trap, and default entry/exit !- ON ERROR GOTO Master_error_handler Work_integer = CTRLC !+ ! Calls to initializing subroutines !- GOSUB Device_file_read ! read device file GOSUB Security_routines ! security check 999 %PAGE %SBTTL "Begin main processing" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN PROCESSING oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 1000 - 7999 contain primary processes. Lines 8000 - 8997 contain program wrap up and exit control. 1000 %PAGE %SBTTL "Process control - program root module" 1010 !+ ! Get filespec from CLI !- CALL CLI$GET_VALUE('Filespec',File_name) 1100 !+ ! Parse filename and build temporary filename !- ! Parse for filename break Pos_period = POS(File_name, ".", 1) ! If there is no extension default to BAS IF Pos_period = NO THEN Pos_period = LEN(File_name) + 1 Work_string = File_name + ".BAS" File_name = Work_string ELSE END IF ! Build temporary file name Temporary_file = SEG$(File_name, 1, (Pos_period - 1)) + ".TMP" 1200 !+ ! Open input and temporary files !- OPEN File_name AS FILE INPUT_FILE, & ALLOW NONE, & ACCESS MODIFY OPEN Temporary_file FOR OUTPUT AS FILE TEMP_FILE, & ALLOW NONE, & ACCESS MODIFY MARGIN #TEMP_FILE, 132 1300 !+ ! Reformat the input file !- ! Begin looping through, creating the temporary file End_of_file = NO UNTIL End_of_file = YES ! Input a line from the input file LINPUT #INPUT_FILE, Line_in ! Locate any ampersands and if there are non just print the ! line and go on to the next one. Pos_ampers = POS(Line_in, "&", 1) IF Pos_ampers = 0 THEN PRINT #TEMP_FILE, Line_in GOTO End_of_loop ELSE END IF ! Parse out the input line, and if, after parsing, text ! remains to the right of the ampersand, just print the ! line and go on to the next. Input_line_parsing: Left_line = TRM$(SEG$(Line_in, 1, (Pos_ampers - 1))) Right_line = TRM$(SEG$(Line_in, (Pos_ampers + 1), & LEN(Line_in))) IF LEN(Right_line) > 0 ! if there is text to the right ! then look for another ampers THEN Work_integer = POS(Line_in, "&", Pos_ampers) ! If there is one, then reset and parse again IF Work_integer > Pos_ampers THEN Pos_ampers = Work_integer GOTO Input_line_parsing ! Otherwise just print the line and go on to the next ELSE PRINT #TEMP_FILE, Line_in GOTO End_of_loop END IF ELSE END IF ! Now handle if this is a line ended by an ampersand IF LEN(Left_line) => (PAGE_WIDTH - 1) THEN PRINT #TEMP_FILE, Left_line; " &" ELSE PRINT #TEMP_FILE, Left_line; PRINT #TEMP_FILE, TAB(PAGE_WIDTH); "&" END IF ! End of loop; go back for next line End_of_loop: Pos_ampers = 0 ! reset the ampers position NEXT 1400 !+ ! Close and rename files !- CLOSE #TEMP_FILE CLOSE #INPUT_FILE NAME Temporary_file AS File_name 8000 %PAGE %SBTTL "Process termination - wrap up and exit" 8900 ! ! EXIT ! %IF %NORMAL = %YES %THEN PRINT "--EOJ-- "; PROGRAM_ID; " "; TIME$(0%) PRINT %ELSE %END %IF 8998 ! Exit program GOTO Program_end 8999 %PAGE %SBTTL "Begin local support routines" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN LOCAL SUPPORT ROUTINES oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 9000 - 9999 contain system standard subroutines, the first of which is the device file read (line 9000). Lines 10000 - 24997 contain program specific subroutines. 9000 %PAGE %SBTTL "Internal routine: Device_file_read" Device_file_read: ! There is no device file for this program RETURN 24998 PRINT "Program has fallen through support routine section" STOP 24999 %PAGE %SBTTL "Begin local functions" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN LOCAL FUNCTIONS oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 25000 - 29997 contain local program functions. 29998 PRINT "Program has fallen through local function section" STOP 29999 %PAGE %SBTTL "Begin directed entry and exit" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN DIRECTED ENTRY AND EXIT oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 30000 - 30499 contain any entry control and verification process for chain entry and utility mode programs. Lines 30500 - 30997 contain chain exit processing. 30999 %PAGE %SBTTL "Begin common error handling" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN COMMON ERROR HANDLING oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 31000 - 31997 contain common error handling routines, the first of which is the control C handler. 31000 %PAGE %SBTTL "Error handling routines" Master_error_handler: SELECT ERR CASE = 28 ! Reset the control C trap and exit Work_integer = CTRLC CLOSE #INPUT_FILE CLOSE #TEMP_FILE KILL Temporary_file RESUME 8000 CASE = 11 ! End of input file RESUME 1400 CASE ELSE ! Return control to system error handler ON ERROR GOTO 0 END SELECT 31998 PRINT "Program has fallen through common error handling section" STOP 31999 %PAGE %SBTTL "Begin security section" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo BEGIN SECURITY SECTION oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Lines 32000 - 32765 contain any security handling routines. 32000 %PAGE %SBTTL "Internal routine: Security_routines" Security_routines: ! No security routines are performed RETURN 32765 PRINT "Program has fallen through security section" STOP 32766 %PAGE %SBTTL "Program end" REM oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo PROGRAM END oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 32767! Program_end: END