Program File Management [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
Program File Management
A program file is a file that contains an HP Business BASIC/XL program.
The program is stored in a file in one of the following formats:
BASIC SAVE A binary program file that contains a correct HP
Business BASIC/XL program. It can be stored and
retrieved more efficiently than an ASCII or BASIC DATA
file. It does not have to be converted to ASCII or
BASIC DATA format when it is stored, or have the syntax
checked when it is retrieved. A program is to be
compiled must be stored in this form.
_______________________________________________________
NOTE "Clean" BASIC SAVE files from time to time by
saving the program in that file to an ASCII file
from the interpreter, using GET to bring the ASCII
file into the interpreter and then using RESAVE to
store the file to the BASIC SAVE file. This is
necessary because the interpreter does not do
complete "garbage collection" when program lines
are deleted or modified.
_______________________________________________________
ASCII An ASCII program file has fixed-length 80-byte records.
Each program line is a series of one or more records.
If a line exceeds the record length, the record ends
with a continuation character (&) and the line continues
in the next record. An ASCII file looks like the output
of the LIST;NONAME command.
BASIC DATA A BASIC DATA file has fixed length 128-word records.
In an ASCII or BASIC DATA file, a line that exceeds 500 characters is
truncated and an asterisk is substituted for the 500th character. An
error occurs when the line is accessed.
Table 2-5 explains the program file management commands and statements
and shows which of them are compilable.
Table 2-5. File Management Commands and Statements
-------------------------------------------------------------------------------------------------
| | | | |
| Statement or Command | Compilable | File Type | Effect |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| GET | No | BASIC SAVE | Replaces current program |
| | | | with program in specified |
| | | | disk file. |
| | | | |
| | | | Can execute program, |
| | | | starting at any line in |
| | | | the main program. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| GET | No | ASCII | Retrieves program from |
| | | | specified disk file, one |
| | | BASIC DATA | line at a time. Syntaxes |
| | | | each line. Converts |
| | | | syntactically illegal |
| | | | lines to comments. Can |
| | | | replace all or part of |
| | | | current program. |
| | | | |
| | | | Can execute program, |
| | | | starting at any line in |
| | | | the main program. |
| | | | |
| | | | Renumbers new lines. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| GET SUB | No | BASIC SAVE | Adds specified subunit(s) |
| | | | to current program. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| LINK | No | ASCII | Same as GET for ASCII and |
| | | | BASIC DATA files, except: |
| | | BASIC DATA | cannot replace busy |
| | | | lines, execution must |
| | | | resume in program unit |
| | | | that executed LINK |
| | | | statement, does not |
| | | | affect variables. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| MERGE | No | ASCII | Same as LINK, except: |
| | | | replaces current line |
| | | BASIC DATA | only if retrieved line |
| | | | has or receives same line |
| | | | number, execution resumes |
| | | | at line following MERGE |
| | | | statement. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| RESAVE | No | Any | Stores current program in |
| | | | existing or new disk |
| | | | file. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| RUN | No | Any | Executes current or |
| | | | specified program, |
| | | | beginning at first or |
| | | | specified line. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| RUNONLY | Yes | BASIC SAVE | Protects interpreted HP |
| | | | Business BASIC/XL program |
| | | | from listing and |
| | | | modification, but allows |
| | | | execution. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| SAVE | No | Any | Stores current program in |
| | | | new disk file. |
| | | | |
-------------------------------------------------------------------------------------------------
The term fname appears in the syntax specifications of several file
management commands and statements. For a description of fname, see
"File Identification," in chapter 6.
GET Statement
The GET statement retrieves a program from a disk file and can execute
it. The file type greatly affects the result of the GET statement, as
stated in Table 2-6.
Syntax
GET fname [, line_num][; execution_line]
Parameters
fname The file name of the file containing the program that is
to be retrieved. The file is in the BASIC SAVE, ASCII,
or BASIC DATA format.
line_num Line number to be assigned to the first retrieved line.
execution_line Line identifier at which to begin execution subsequent
to completing execution of the GET statement.
See Table 2-6 for more information on all of the above.
Table 2-6. How File Type Affects GET Statement
-----------------------------------------------------------------------------------------------
| | | |
| Affected | fname Is BASIC SAVE File | fname Is ASCII Or BASIC DATA File |
| Parameter | | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| fname | Program specified by fname | Program specified by fname is |
| | replaces current program and its | retrieved line by line. Each line |
| | variables. Common blocks remain | is checked for correct syntax. |
| | only if they are declared by the | Syntactically illegal lines are |
| | new program. | converted to comments. The GET |
| | | stops if it retrieves a command |
| | | (it does not execute the command). |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| line_num | Ignored. | Current program lines from |
| | | line_num to the end of the program |
| | | are deleted. Default for line_num |
| | | is one. Lines before line_num are |
| | | not affected. First retrieved |
| | | line is renumbered line_num; if |
| | | its old line number was n, then |
| | | the number (line_num - n) is added |
| | | to every line number in the |
| | | retrieved lines (their own line |
| | | numbers and the line numbers that |
| | | they reference). |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| execution_line | If execution_line is specified, | If execution_line is specified, |
| | the new program begins executing | the resulting program begins |
| | at that line. The line must be in | executing at that line. The line |
| | the main program. If | must be in the main program. |
| | execution_line is not specified, | |
| | and a program executed the GET | |
| | statement, then the new program | |
| | begins executing at its first | |
| | line. If execution_line is not | |
| | specified, and the GET command was | |
| | executed, control returns to the | |
| | terminal. | |
| | | |
-----------------------------------------------------------------------------------------------
Examples
The contents of Filea and Fileb are:
Filea (BASIC SAVE) Fileb (ASCII)
---------------------------------------------------------------------------------------
10 PRINT "Program A" 10 PRINT "Program B"
20 CALL A_sub 20 CALL B_sub
30 PRINT "END of Program A" 30 PRINT "End of Program B"
40 STOP 40 STOP
100 SUB A_sub 100 SUB B_sub
110 PRINT "In subprogram A_sub" 110 PRINT "In subprogram B_sub"
120 SUBEND 120 SUBEND
Example 1
The following examples show the effect of the GET statement of an ASCII
file while there is a program in the interpreter. Lines beginning with
line_num are deleted from the first program.
>GET "Filea"
>LIST
! Filea
10 PRINT "Program A"
20 CALL A_sub
30 PRINT "End of Program A"
40 STOP
100 SUB A_sub
110 PRINT "In subprogram A_sub"
120 SUBEND
>GET "Fileb",40
>LIST
! FileA
10 PRINT "Program A"
20 CALL A_sub
30 PRINT "End of Program A"
40 PRINT "Program B"
50 CALL B_sub
60 PRINT "End of Program B"
70 STOP
130 SUB B_sub
140 PRINT "In subprogram B_sub"
150 SUBEND
>
Example 2
The following example shows the effect of a programmatic GET of an ASCII
file. Because the GET specifies line 120, Program A is left intact, and
Program B becomes part of A_sub.
>GET "Filea"
>LIST
! Filea
10 PRINT "Program A"
20 CALL A_sub
30 PRINT "End of Program A"
40 STOP
100 SUB A_sub
110 PRINT "In subprogram A_sub"
120 SUBEND
>15 GET "Fileb",120;20 !First line of Fileb is 120, execution &
skips to 20
>16 PRINT "This line should be skipped."
>LIST
! Filea
10 PRINT "Program A"
15 GET "Fileb", 120;20 !First line of Fileb is 120, execution skips to 20
16 PRINT "This line should be skipped."
20 CALL A_sub
30 PRINT "End of Program A"
40 STOP
100 SUB A_sub
110 PRINT "In subprogram A_sub"
120 SUBEND
>RUN
Program A
In subprogram A_sub
Program B
In subprogram B_sub
End of Program B
>LIST
! Filea
10 PRINT "Program A"
15 GET "Fileb", 120;20 !First line of Fileb is 120, execution skips to 20
16 PRINT "This line should be skipped."
20 CALL A_sub
30 PRINT "End of Program A"
40 STOP
100 SUB A_sub
110 PRINT "In subprogram A_sub"
120 PRINT "Program B"
130 CALL B_sub
140 PRINT "End of Program B"
150 STOP
210 SUB B_sub
220 PRINT "In subprogram B_sub"
230 SUBEND
>
GET SUB Statement
The GET SUB statement retrieves specified subunits from a BASIC SAVE file
and adds them to the current program. Current program lines are not
affected. If the current program executed the GET SUB statement,
execution continues at the line following the GET SUB statement.
The GET SUB statement retrieves subunits from BASIC SAVE files only. Use
the MERGE statement to retrieve subunits from ASCII and BASIC DATA files.
Syntax
GET SUB fname [, first_line [,increment] ] [; first_sub [, last_sub] ]
Parameters
fname BASIC SAVE file containing subunits to be retrieved.
first_line A numeric literal that is the line number assigned to
the first retrieved line. If not specified, the default
value is the last line number + 1.
increment A numeric literal that is the increment used for
renumbering the retrieved lines. If not specified, the
default value for the increment is 10.
first_sub A numeric literal that is the number of the first
subunit to retrieve from the fname file. The first
subprogram or multi-line function in the fname file is
designated number 1. If no value is specified, the
value of first_sub is one. If the value of first_sub is
greater than the highest numbered subunit in the fname
file, then an error occurs.
last_sub A numeric literal that is the number of the last subunit
to retrieve from the fname file. If last_sub is greater
than the number of the last subunit in the fname file,
then all subunits from first_sub through the last
subunit in the fname file are retrieved. If no value is
specified, the value is the highest numbered subunit in
the fname file.
Examples
Consider a BASIC SAVE file named SUBFILE.
10 ! A file of subunits
20 SUB Subunit_1
30 SUBEND
40 SUB Subunit_2
50 SUBEND
60 SUB Subunit_3
70 SUBEND
80 SUB Subunit_4
90 SUBEND
The following program statement retrieves Subunit_1 through Subunit_4.
Numbering of the first line of Subunit_1 begins at the highest line
number in the current program + 1. The line numbers of subsequent lines
are incremented by 10.
10 GET SUB "SUBFILE"
10 GET SUB "SUBFILE" ;1 !Retrieves Subunit_1 through Subunit_4
10 GET SUB "SUBFILE" ;2,4 !Retrieves Subunit_2 through Subunit_4
10 GET SUB "SUBFILE" ;3,3 !Retrieves Subunit_3
10 GET SUB "SUBFILE",100,10 ;3 !Retrieves Subunit_3 and Subunit_4
and begins numbering at line 100 with
lines subsequently incremented by 10.
LINK Statement
The LINK statement is identical to the GET statement for ASCII and BASIC
DATA files, except in the following ways:
* Busy lines in the current program cannot be replaced (see "Busy Lines
and Busy Subunits" for the definition of "busy").
* Execution must resume within the program unit that executed the LINK
statement.
* The LINK statement does not affect local or common variables in the
current program. Redeclarations are ignored.
Syntax
LINK fname [, line_num] [; execution_line]
Parameters
fname The filename of the file containing the program in the
ASCII or BASIC DATA file format that is to be retrieved.
line_num Line number to be assigned to the first retrieved line.
If this parameter is not specified, retrieved lines are
not renumbered.
execution_line Line identifier that program resumes execution at after
file is retrieved. Must belong to the program unit that
executed the LINK statement. Default is the line
following the LINK statement (or the line that replaced
the LINK statement).
Execution does not resume after a LINK command unless
execution_line is specified.
Examples
LINK "File1" !File1 is retrieved
LINK "File2",200 !File2 is retrieved, the first line is 200
LINK "File3",300;330 !File3 is retrieved, the first line is 330,
! the current program resumes at line 300
LINK "File4";150 !File4 is retrieved, the current program
!resumes at line 150
MERGE Statement
The MERGE statement is identical to the LINK statement, except in the
following ways:
* A current line is replaced only if its line number belongs to a
retrieved line. The retrieved line may have the same line number if
it has been renumbered.
* If a subunit header (a SUB or DEF statement) is inserted anywhere
except immediately before another subunit header, it becomes a
comment and a warning is issued.
* If a subunit header is replaced by anything but another subunit
header, an error occurs. Lines retrieved before the error occurred
remain in the program.
Syntax
MERGE fname [, line_num][; execution_line]
Parameters
fname The filename of the file containing the program stored
in the ASCII or BASIC DATA file to be retrieved.
line_num Line number to be assigned to the first retrieved line.
Retrieved lines are not renumbered if this parameter is
not specified.
execution_line Line identifier where execution resumes after the file
is retrieved. The default is the line following the
MERGE statement (or the line following the line that
replaced the MERGE statement).
Execution does not resume after a MERGE command unless
execution_line is specified.
Examples
MERGE "File1" !File1 is retrieved
MERGE "File2",100 !File2 is retrieved, the first line is line 100
MERGE "File3",250;250 !File3 is retrieved, the first line is line 250
!and the current program resumes at line 250
MERGE "File4";600 !File4 is retrieved, and the current program
!resumes at line 600
RESAVE Statement
The RESAVE statement stores the current program in an existing or a new
disk file. It can store a file in the ASCII, BASIC DATA, or BASIC SAVE
formats.
Syntax
[LIST ]
RESAVE [BDATA] [fname [, line_range_list][; NOMSG]]
If neither LIST nor BDATA is specified, the program is stored in the
format of the existing file if the file already exists. If fname refers
to a new file, and neither LIST nor BDATA is specified, the default is
type BASIC SAVE.
Parameters
LIST Stores program in ASCII format. If the file exists, it
must be an ASCII file.
BDATA Stores program in BASIC DATA format. If the file
exists, it must be a BASIC DATA file.
fname This specifies a new or existing file. RESAVE
overwrites an existing file. If fname does not exist,
RESAVE creates it and issues a warning that the file did
not exist.
fname defaults to the file name of the current program
as determined by the most recent GET or NAME command if
this parameter is not specified.
line_range_ If the program is to be stored in ASCII or BASIC DATA
list format, line_range_list is as explained in "Specifying
Line Ranges."
If the program is to be stored in program format, a
program unit is the smallest unit that can be specified,
and the main program is always stored, whether it is
specified or not. If a ln_spec1 is a line number or
label, it must belong to the first line of a program
unit; if ln_spec2 is a line number or label, it must
belong to the last line of a program unit. If ln_spec1
and ln_spec2 do not belong to the same program unit, all
program units between them are stored.
NOMSG Suppresses messages issued by RESAVE. The WARNINGS ON
and WARNINGS OFF statements do not affect these
messages.
Examples
RESAVE "File6" !File 6 is the same type as the existing file
RESAVE LIST "File7" !File 7 is in ASCII format
RESAVE BDATA "File8" !File 8 is a BASIC DATA file
RESAVE "File9",MAIN,5000/5999 !File 9 is a main program, lines 5000/5999
RESAVE "File10",Sub1/Sub6;NOMSG !File 10 is Sub1/Sub6, and no
!RESAVE messages are issued
RUN Command
The RUN Command executes the current program or retrieves a program from
a disk file and executes it. Execution begins at the specified line or
the first program line. The RUN command is a command-only statement.
That is, it can only be issued at the interpreter prompt and can not be
placed in a program.
Syntax
[{,} ]
RUN [fname] [{;} line_id] [; INFO=str_expr]
Parameters
fname The name of the disk file containing the program to be
retrieved and executed. This program replaces the
program that is in the interpreter when the RUN command
is issued. The current program in the interpreter's
workspace is executed if fname is not specified. If
fname specifies a nonexistent file, an error occurs, and
the current program is not overwritten.
line_id The line number or line label in the main program at
which to begin execution. The default is the first
program line. If line_id is a line number that is not
in the program, execution begins at the line with the
next higher line number.
str_expr Assigns the value, a string, to be returned by a call to
the INFO$ function. (See chapter 5).
The RUN command retrieves a disk file the way that the GET statement
does, except that the RUN command removes all common declarations; the
GET statement does not.
Before executing the program, the RUN command allocates space for
variables, initializes them, and resets the following parameters in the
interpreter:
Program execution Stopped
Numeric output format Standard
DEFAULT OFF
Random number seed PI/180
ERRL 0
ERRN 0
BREAK Enabled
Automatic line numbering Off
Options Options specified in configuration file
Note that the RUN, HOP, and STEP commands stop any program that is
executing when the command is entered. Then program execution begins as
specified.
Example
RUN !Runs the current program
RUN "File1" !Runs program File1
RUN "File2";200 !Runs program File2, execution begins at line 200
RUN "File3",200 !Runs program File3, execution begins at line 200
RUN;1200 !Runs the current program, execution begins at
!line 1200
RUN;INFO="TEST CODE" !Runs the current program, the INFO$ function
!returns TEST CODE
RUN "File1"; INFO="Name" !Runs program File1, the INFO$ function
!returns Name
RUN "File2";200;INFO="1985" !Runs File2, execution begins at line 200,
!the INFO$ function returns 1985
RUN "File3",200;INFO="West" !Runs File3, execution begins at line 200,
!the INFO$ function returns WEST
RUN;1200;INFO="yellow" !Runs the current program, execution begins
!at line 1200, the INFO$ function
!returns yellow
Consider the execution of the following program sequence with and without
the INFO option:
1000 !
1010 IF INFO$="DEBUG" THEN
1020 PRINT "Just before assignment to Sum"
1030 PRINT " Subtotal_1 = ";Subtotal_1
1040 PRINT " Subtotal_2 = ";Subtotal_2
1050 ENDIF
1060 !
1070 Sum=Subtotal_1+Subtotal_2
1080 PRINT "The total is: ";Sum
>RUN
The total is: 1169.04
>RUN;INFO="DEBUG"
Just before assignment to Sum
Subtotal_1 = 475.53
Subtotal_2 = 693.51
The total is: 1169.04
RUNONLY Statement
The RUNONLY statement protects an interpreted HP Business BASIC/XL
program from listing and modification, but allows its execution.
Run-only status cannot be reversed. Once a program is protected with the
RUNONLY statement, it can only be run with the GET statement.
Syntax
RUNONLY fname
Parameters
fname The file name of the file that will be protected. This
file must be a BASIC SAVE file.
When a run-only program is retrieved, it begins executing at its first
line unless another run-only program retrieved it and specified a
starting line.
Example
RUNONLY "File1" !Protects File1
RUNONLY "File2.lab" !Protects File2 in the group lab
SAVE Statement
The SAVE statement stores the current program in the interpreter's work
space in a new disk file. The SAVE statement can store a file in any
format.
Syntax
[LIST ]
SAVE [BDATA] [fname [, line_range_list][; NOMSG]]
If neither LIST nor BASIC DATA is specified, the program is stored in the
BASIC SAVE format.
Parameters
LIST Stores program in ASCII format.
BDATA Stores program in BASIC DATA format.
fname This must specify a new file.
fname defaults to the file name of the current program
as determined by the most recent GET or NAME command if
this parameter is not specified.
line_range_ If the program is to be stored in ASCII or BASIC DATA
list format, line_range_list has the syntax explained in
"Specifying Line Ranges" earlier in this chapter.
If the program is to be stored in program format, a
program unit is the smallest unit that can be specified,
and the main program is always stored, whether it is
specified or not. If ln_spec1 is a line number or
label, it must belong to the first line of a program
unit; if ln_spec2 is a line number or label, it must
belong to the last line of a program unit. If ln_spec1
and ln_spec2 do not belong to the same program unit, all
program units between them are stored.
NOMSG Suppresses messages issued by SAVE. The WARNINGS ON and
WARNINGS OFF statements do not affect these messages.
Examples
SAVE "File1" !Saves File1 as type BASIC SAVE
SAVE LIST "File2" !Saves File2 as type ASCII
SAVE BDATA "File3" !Saves File3 as type BASIC DATA
SAVE "File4",MAIN,5000/5999 !Saves File4 as a main program, with
!lines 5000/5999
SAVE "File5",Sub1/Sub6;NOMSG !Saves File 5 as Sub1/Sub6, any SAVE
!messages are suppressed.
MPE/iX 5.0 Documentation