TITLE:Back-to-Basics: System

ISSUE:Multi-value Solutions Aug '98

AUTHOR:Nathan Rector

COMPANY:Natec Systems

EMAIL:nater@northcoast.com

HTTP:www.northcoast.com/~nater/

Syntax: var = SYSTEM(number)

The BASIC command SYSTEM() provides an interface to a number of system variables. The SYSTEM() command give you valuable information about what is going on after executing different BASIC or TCL commands depending on the number specified. Since each SYSTEM() variable is different, please look at each one for how they work:

 

0 Context-oriented status information.

After a tape-handling error, system(0) returns:

1 if not attached.

2 null variable.

3 attempt to write null string.

5 EOT encountered.

6 tape write protected.

7 tape unit not ready.

8 unrecoverable parity error.

9 block transfer error.

10 binary item read. Value 10 actually has nothing to do with tape and is relevent to all "read"-type statements. It is set when an "indirect" (or "pointer") item is read.

11 record truncated.

12 unrecoverable write error.

13 unrecoverable read error.

14 no tape media inserted.

15 tape subsystem not ready.

READT BLOCK ELSE

CRT "ERROR# ": SYSTEM(0)

END

 

readu, readvu and matreadu statements

If these statement contain a LOCKED clauses, then system(0) returns the port.number that has the item locked. ie:

READU INV.ITEM FROM INV.FILE, INV.NO LOCKED

CRT "PORT ": SYSTEM(0) :" HAS THIS RECORD LOCKED"

END THEN

CRT "THE RECORD IS FOUND"

END ELSE

CRT "THE RECORD DOES NOT EXIST"

END

On AP/Unix implementations, system(0) returns the value of "errno" after a C function call. On 6.2 and above, this is no longer supported and system(41) should be used instead.

1 - Returns 1 if the system printer is "on", meaning that a "printer on" statement has been issued or that the program was activated with a (p) option. Otherwise, a 0 (zero) is returned, meaning that output is being directed to the terminal.

 

CRT SYSTEM(1) ;* will return a 0

*

PRINTER ON

PRINT SYSTEM(1) ;* will return a 1

PRINTER CLOSE

PRITNER OFF

2 - Returns the current output device page width as defined by the "term" command.

3 - Returns the current output device page length as defined by the "term" command.

4 - Returns the number of lines remaining to print on the current page, based on the current terminal characteristics previously defined with the "term" command.

5 - Returns the current page number.

6 - Returns the current line number (Not the "port" number -- the actual number of lines printed).

 

PAGE.WIDTH = SYSTEM(2)

PAGE.DEPTH = SYSTEM(3)

*

PRINTER ON

FOR I = 1 TO 100

IF SYSTEM(4) = 2 THEN

* only one line left inpage

PRINT "Page Depth: ": PAGE.DEPTH

PRINT "Page ": SYSTEM(5) :CHAR(12) ;* formfeed

END

*

PRINT SPACE(PAGE.WIDTH / 2) : I :" ": SYSTEM(6) ;* line currently on

NEXT I

PRINTER CLOSE

PRINTER OFF

System 2,3,4,5 and 6 will not register any CRT statements. It will only work on PRINT statements that do not use @(x,y).

7 - Returns the terminal "type" code, as defined by the "term" command.

8 - Returns the block size at which the tape was last attached.

9 - Returns the current cpu millisecond count.

10 - Checks the current stack (ston) condition. Returns 1 (one) if the stack is on, or 0 (zero), if not.

*

IF NOT(SYSTEM(10)) THEN

* input stack is not on. display the label

CRT "Input TODAYS date"

END

INPUT TODAY

 

11 - Checks for an externally-generated active list.

In R83, it returns "0" if there is no active list, or "1" (one) if an active list exists.

In AP, it returns "0" if there is no active list, or "n" (the actual number of items selected), if an active list exists.

This has nothing to do with the internal (Pick/BASIC) "select" statement, which requires a "readnext" to determine if any items were selected.

ie:

EXECUTE \SELECT EMPLOYEE\

IF SYSTEM(11) THEN

CRT "ACTIVE LIST"

END ELSE

CRT "LIST NOT ACTIVE"

END

12 - Returns the system time in milliseconds.

13 - Forces an rqm (terminates timeslice) and returns a 1. Deactivates the process in the scheduling queue until its next turn.

FOR I = 1 TO 100

X = SYSTEM(12) ;* does the same thing as RQM

NEXT I

 

14 - Returns the number of bytes in the terminal type-ahead input buffer. If you want to process a loop statement, but allows the user to exit the loop when every they wish this option comes in handy.

X = ""

LOOP

UNTIL X = "END" DO

CRT "Loop"

*

IF SYSTEM(14) THEN

* someone has pressed a key on the keyboard

INPUT X

END

REPEAT

 

15 - Returns the TCL verb option{s} that are in effect.

TEST

001 *

002 CRT "Options: ": SYSTEM(15) ;* returns anything after the ( at TCL

003 END

>TEST (N

Options: N

16 - Returns the current process or EXECUTE level. Some systems can only have so many nested EXECUTE statements. SYSTEM(16) will tell you how many EXECUTEs have been done.

TEST

001 *

002 CRT SYSTEM(16)

003 EXECUTE \TEST\

004 END

Warning: This program will continue to run until a break key is hit or it crashes when it processes too many nested EXECUTE statements

 

17 - Returns the message numbers (item-ids) returned by the previous "execute" statement, separated by attribute marks.

EXECUTE \CREATE-FILE BLANK 1 1\

EXECUTE \SELECT BLANK\

CRT SYSTEM(17) ;* returns 401. (error code for no items)