JES: Just Educational Services

Jonathan E. Sisk's
Pick/BASIC: A Programmer's Guide

Chapter 2 - The Related TCL Processes

Click to enlarge

This chapter will explain the most important TCL (Terminal Control Language), system-level procedures you will have to deal with in order to begin programming in PICK/BASIC. These include using the Editor, creating and maintaining files, and compiling and running your programs.

The PICK Editor

The Editor is the process through which programs are entered into the computer. It allows the creation, update, and deletion of items in a file. A brief tutorial on the most essential Editor commands is provided in this chapter.

In general, editors fall into two categories. There are line editors, like the one about to be discussed, and there are full-screen editors. A line editor is much more primitive in design. In line editors, you must position the "line pointer" to the line (attribute) that you want to affect using a positioning command such as "G" (goto line), "U" (move up), and "N" (move down). With a full-screen editor, you use the numeric keypad or the arrow keys to position to the line that you want to alter.

If your system has JET, or one of its derivatives such as ULTIWORD or WORDMATE, then you actually have a full-screen editor available. Invoking the JET editor is accomplished by using the command "JET-EDIT" in place of the "ED" command. JET has its own set of commands, many of which are similar to the commands in the Pick line editor. If you decide to try the JET editor, press the "?" key once it is activated to obtain a list of all of the available JET commands.

Activating The Editor

The following commands are essential for the use of the Editor throughout the course of this book:

ED or EDIT

Either of these verbs may be used at the TCL prompt character ( > ) to activate the Editor. It always has the general form:

>ED filename item-id <cr>

to edit an individual item in a file, or

>ED filename item-id item-id item-id. <cr>

to edit multiple items in a file, or

>ED filename * <cr> 

to edit all the items in a file, or

>SELECT filename {with selection criteria... } < cr >
n ITEMS SELECTED.
>ED filename <cr>

The ED command does not require the itemlist specification when following a SELECT or SSELECT command.

Before entering the Editor, the requested filename is searched for the specified item-id. If the item-id is found, the line pointer is left at the "top" of the item. If it is not found, then a "NEW ITEM" message appears and the line pointer is positioned to the top of an otherwise empty item. Once the Editor has been invoked, there are a number of commands available; the next several sections describe those that are used the most often.

Inserting New Lines

The Insert Editor command inserts one or more lines:

I

For an example, examine the terminal dialogue in Fig. 2-1. Note that while you are in "insert mode," each new line (attribute) is given a line number. To get out of insert mode, press the carriage return key while the cursor is positioned immediately to the right of a "plus" (+) sign. This returns control to the Editor command mode.


>ED filename item-id
NEW ITEM
TOP
· I<cr>
001+* this is line 1 <cr>
002+* this is line 2 <cr>
003+<cr>

Fig. 2-1. Using the Insert command.


Replacing Existing Lines

To replace a portion or all of an attribute, or a range of attributes, use the Replace command:

R

For example:

.R/PRINT/CRT

replaces, on the current line, the first occurrence of the word "PRINT" with "CRT." The command

.RU999/PRINT/CRT 

replaces, in the next 999 lines, all occurrences of "PRINT" with "CRT."

Listing Items to the Screen

To list a specified number of lines on the screen, use the List command:

L

See Fig. 2-2 for an example of using the List command. The "EOI 011" message means that the "End Of Item" has occurred at line 11. There are no more attributes or lines after this message.

The Shortcut Way to List Items. Most versions of Pick allow "prestored" commands in the Editor:

P

Normally, the only one that is defined automatically is P0 (zero), and it issues an "L22" command. To test this, enter the P command at the Editor command prompt (Fig. 2-3).


>ED filename item-id <cr>
TOP
.L22<cr>
001 * this is line 1
002 * this is line 2
003 * and so on...
*
*
011 * this is the last line...
EOI 011

Fig. 2-2. Using the List command.



>ED filename item-id <cr>
TOP
.P<cr>
001 * this is line 1
002 * this is line 2
003 * and so on...
*
*
011 * this is the last line...
EOI 011

Fig. 2-3. Using the Editor's prestored commands.


Deleting Lines

To delete one or more lines, use the Delete command:

DE
or
DEn

For example:

014 * this line needs to go away... .
.DE<cr>

This does away with the current line, which in this case is line 14. Or, you can use the DE command on multiple lines:

014 * this line is going away...
.DE3<cr>

This deletes line 14 and the next two lines, for a total of three lines.

Moving the Line Pointer

To move the pointer to a particular line n, use the Goto command:

Gn
or
n

For example:

014 * this is line 14
.G7<cr>
007 * this is line 7

The "G" is optional. You may also simply enter the line number:

014 * this is line 14
.7<cr>
007 * this is line 7

Reviewing Changes: The F Command

To review changes in an item, use the Flip command:

F

This command "flips" Editor buffers. Get used to this. You must use this command before you may review any changes that have been made to an item:

014 * this is line 14
.F<cr>
TOP
.

Saving and Exiting

The File command is used to save (or resave) the item being entered or modified. Entering

FI 

files the item, saving all changes made. For example:

014 * this is line 14
.FI<cr>
'item-id' filed.

Exiting without Saving Changes

To abort the edit of an item, use the Exit command. Entering

EX

exits the item without saving any changes. For example:

014 * this is line 14
.EX<cr>
'item-id' exited.

Note: Unlike other systems, the Editor doesn't have the logic (in most versions of Pick) to warn you to save the item before exiting, if any changes have been made. Be careful! Some implementations now ask "ARE YOU SURE? (Y/N)" when using the EX (and FD) commands.

Deleting an Item

This command deletes the current item from the file:

FD

Some versions of the Editor ask if you are "sure" you want to do this; most other versions don't. Caveat emptier. A TCL command called "RECOVER-FD" typically is available to recover a deleted item, but there's a catch. The only time it works is if you use it to try to recover the last item that was edited and deleted.

GETTING INTO THE SYSTEM

Now we will walk through the process of getting into the system, creating your account and files, and entering your programs.

Logging On

To begin a session, the first thing to do is "log on" to the system. Every Pick system has an account called "SYSPROG." This very powerful account contains the commands used to do most of the system administration functions, such as backups, restores, and maintenance.

Find a terminal, turn it on, and enter "SYSPROG" at the "Logon Please" message.

LOGON PLEASE:SYSPROG<cr>

If the next prompt is "PASSWORD?", then you must find out what the password is and enter it before you may continue.

After a brief introductory message, which typically welcomes you to the system and tells you the current system time and date, the computer displays the TCL (Terminal Control Language) prompt. On all systems other than the Microdata (McDonnell Douglas) version of Pick, TCL is indicated by the ">" prompt character. Microdata uses the ":" symbol as its prompt character.

The activity generated by entering a command at the TCL prompt is referred to as a process. While the Pick system is capable of handling multiple processes within an account, for safety's sake you are encouraged to create your own account. This will protect you from the other users of your system, and vice versa.

Creating Your Own Account

Enter the following command at the TCL prompt character:

 >CREATE-ACCOUNT<cr>

Before we continue, an explanatory disclaimer is required. The "CREATE-ACCOUNT" procedure varies operationally among different implementations of Pick. This means that the questions asked of you by the CREATE-ACCOUNT process may be in a different order or format, but essentially the same information is needed by all the different versions.

ACCOUNT NAME?your.account.name<cr>

The name of your account is up to you. There are certain characters to avoid in your account name (or 'any item-id, for that matter). These characters include: spaces, arrow keys, single or double quotes, slashes or backslashes, and never any control characters. Enter your account name and press Return. If you can't think of one, use "CLASS" as your account name.

L/RET CODES?<cr>

This cryptic prompt is for the security (retrieval) codes for this account. Retrieval codes are better left alone. Press Return.

L/UPD CODES?<cr>

This is for the entry of the update codes. Ignore this for now. Maybe forever. Press Return.

MOD, SEP?29,1<cr>

This prompt allows you to specify the size (modulo) of the MD (Master Dictionary) file in the account you are about to create. Normally, there is a default value here of "29,1." If not, enter 29,1 and press Return. This means that 29 contiguous frames will be set aside for the new MD. This will most likely be adequate for the next decade or two, or until you add lots of items to the MD, in which case you might consider increasing the modulo. Choosing modulo is not trivial. Fortunately, that's why there is normally a default provided here.

PASSWORD?<cr>

An account password is up to you. If you use it, you will be asked for it each time you log on to your account.

PRIVILEGES?SYS2<cr>

The privilege level is important. Privilege level two (SYS2) allows access to anything that is in or available to the account. That's what you want. A detailed explanation of privilege levels is found in Exploring the Pick Operating System or the standard Pick System reference manuals.

This is normally all the information that you need to enter. One or two more questions may be asked of you. Do the best you can. It's not likely that you'll hurt anything. If the process completes normally, control returns to TCL. If not, consult your system manuals for troubleshooting.

Now it's time to try your new account. Enter this:

>LOGTO your-new-account

The LOGTO command allows you to leave the current account to access another. Control normally returns to TCL on the new account.

Creating Your Work Files

Before getting into the PICK/BASIC tutorial, some work files must be created. These will hold the data, programs, and PRO Cs created during the tutorials. These files are established with the CREATE-FILE command (see Fig. 24).

The CREATE-FILE command places a new file in the current account. The numbers following the filename indicate the starting disk address, modulo, and separation for the dictionary and DATA levels of the file, respectively. For the sake of brevity, the messages output from the following CREATE-FILE commands have been left out.


>CREATE-FILE BP 11,1 29,1 <cr>
[417]	FILE 'BP' CREATED. BASE = fid. MOD = 11. SEPAR = 1
[417]	FILE 'BP' CREATED. BASE = fid. M0D = 29. SEPAR = 1

Fig. 2-4. An example of the CREATE-FILE command.


>CREATE-FILE STAFF 7,1 11,1 <cr>
>CREATE-FILE PROCS 1,1 11,1 <cr>
>CREATE-FILE STATES 1,1 11,1 <cr>

The numbers following the filename specify the size of the file. These are called the modulo and separation, and a detailed explanation of these is found in Exploring the Pick Operating System.

Preparing the Source File

The file in which PICK/BASIC programs reside needs to have a minor operation performed prior to being able to compile programs. This is accomplished by using the Editor to change the "D-pointer" (the file definition item) in the MD. Note: readers with Ultimate or McDonnell Douglas computer systems do not need to do this!

Here are the steps involved in preparing the BP file pointer:

>ED MD BP<cr>
TOP
.l<cr>
001 D
.R/D/DC<cr>
001 DC
.FI
'BP' FILED.

The reason that this has to be done is that PICK/BASIC object code has to be handled differently than "normal" data items. Source code refers to the human-readable list of instructions to perform as a program. In the Pick System, source code resides in the DATA section of files. Object code is produced by compiling source code into executable, machine-readable code. When a program is compiled, a "pointer" item is placed in the dictionary of the source file1· This pointer item tells the system where the object code will be found for execution. The name of the pointer item is the same as the source program item. Incidentally, this is exactly the same way that "lists" are handled with the SAVE-LIST command.

Note for Ultimate Users: Ultimate Corporation added a verb called UPDATE-FILE in release 122, when "security" was implemented. This was ostensibly to prevent users from damaging file definition items (D-pointers). This change does not have to be done to source files on Ultimate systems, because any file may contain source and/or object code. However, if you do feel like doing this to a file, you must use the UPDATE-FILE verb; otherwise, you may damage or even destroy the file!


>ED BP HELLO<cr>
NEW ITEM
TOP
.I<cr>
001+IF TIME() < 43200 THEN PRINT "GOOD MORNING"<cr>
002+IF TIME() >= 43200 THEN PRINT "GOOD AFTERNOON"<cr>
003+END<cr>
004+<cr>
TOP
.FI<cr>
'HELLO' FILED.

Fig. 2-5. Entering the HELLO program example.


The ED Command and HELLO Program

PICK/BASIC programs are typically entered through the standard Pick Editor, although any editor will do. The Pick Editor is activated with the ED or EDIT command, Follow the instructions in Fig. 2-5, and enter the program shown. This program is now ready to be compiled, which must be done before it may be run.

Note: The instructions in this program test the current system "time." In Chapter 1, the internal representation of time was discussed. The important point to remember is that time is stored internally as the integer number of seconds past midnight: "43200" is 12:00 (noon), which is 12 (hours) multiplied by 3600 (seconds per hour).

The command line "ED BP HELLO" entered at the TCL command prompt (>) instructs the Pick System to activate the Editor. The program goes into the file called "BP," and its item-id is (or will be) "HELLO."

PICK/BASIC Program Names (item-IDs)

Since Pick stores individual programs as items (records) in a single program file and Pick does not limit the length of the item-id2 (program name), you may use descriptive item-ids. One warning, however: Never use a program name that has the same name as the source file in which it will reside! These are some invalid program names:

>ED BP BP
or
>ED AR.BP AR.BP

Actually, the Pick system will let you get away with this--for the moment. It catches up with you later when it destroys your file. The next section discusses the BASIC command, which is used to compile source code into (executable) object code. Normally, when a compile takes place, a pointer to the object code of the program is placed in the dictionary level of the source file, using the same item-id as the source item. If there is a program with the same name as the file, there is a potential danger of the object pointer writing over the file pointer (the pointer to the DATA section of the file). If this happens, all your program source items will be lost! Some versions of Pick have built-in protective mechanisms to prevent this problem.

COMPILING PROGRAMS: THE BASIC COMMAND

The BASIC command activates the PICK/BASIC compiler to translate the source code into object code. The following examples illustrate the BASIC command and some of its available options.

>BASIC BP HELLO<cr>
***
'HELLO' COMPILED. 1 FRAMES USED.

Each * represents one source line successfully compiled into executable object code. A listing of the program may be produced with the L option:

>BASIC BP HELLO (L)<cr>
001 IF TIME() < 43200 THEN PRINT "GOOD MORNING"
002 IF TIME() > 43200 THEN PRINT "GOOD AFTERNOON"
003 END
'HELLO' COMPILED. 1 FRAMES USED.

The listing may be routed to a printer by including the P option:

>BASIC BP HELLO (LP)<cr>

Other options are available. These options are discussed in Appendix B.

ACTIVATING PROGRAMS: THE RUN AND CATALOG COMMANDS

There are two ways to load and execute a compiled program. The first is the use of the RUN verb:

>RUN BP HELLO<cr>
GOOD MORNING

(Unless it's after 12:00 P.M., of course, in which case the program displays "GOOD AFTERNOON" ).

The second way is to CATALOG the program. This effectively makes a verb out of the program:

>CATALOG BP HELLO<cr>
'HELLO' CATALOGED. 
>HELLO<cr>
GOOD MORNING

The rule with regard to cataloging programs is [hat the only programs which must be cataloged are those which are considered "external" subroutines. While all of your programs do not have to be cataloged, it's still a good idea. Note that external subroutines do not have to be cataloged on Ultimate systems, unless the subroutine resides in a different file from the program that calls it.

From now on in the tutorials, compile all of your programs with the BASIC command, and then CATALOG each program.

IF IT DIDN'T WORK

If you had any problem with the example called "HELLO," check the code using the Editor. It must be entered exactly as it appears in the text.

There are many possible reasons why programs don't compile. Here is a partial list of the most common compile failures:

1) Functions or instructions are misspelled. For example: PRONT "HELLO THERE"

2) Quotation marks, used in printing or assigning "Literals" are "unbalanced," meaning, an odd number exists. For example:

PRINT "HELLO THERE

3) A GOTO or GOSUB statement which instructs the program to transfer control to a nonexistent statement label. For example:

001    10 PRINT "HELLO"
002      GOTO 99
003    END

4) An IF-THEN or IF-THEN-ELSE statement isn't properly terminated with an END directive. Or, worse, is terminated with too many END directives. For example:

IF QTY.ON.HAND < REORDER.POINT THEN
  PRINT "PRODUCT NEEDS TO BE REORDERED!"
(HERE IS WHERE THE "END" STATEMENT SHOULD HAVE BEEN)

and the code goes on...

This has the unpleasant side effect of using the next END directive that the compiler encounters as the terminator for the THEN initiator. Don't worry about this for now. The proper way to prevent this problem is explained in Chapter 4, at the end of the narrative on Example 2.

Again, the programs in this book were tested and they worked on our test machines. The most important thing to do is to compare your program listing line-by-line with the program listings from the book. You may find that you left out a character or two here and there. Don't feel bad if your programs don't always compile the first time; it happens to everybody.

Previous chapter Next chapter Top

 

Creative Commons License
Jonathan E. Sisk's "Pick/BASIC: A Programmer's Guide" by Jonathan E. Sisk is licensed under a Creative Commons Attribution 3.0 Unported License.
Based on a work at jes.com.