SYSTEM Function

The SYSTEM function returns status information about the operator’s terminal, the current output device, the tape drive, the floppy disk drive, or a variety of other system variables.

Format

SYSTEM(expr)

Parameter(s)

expr

An expression evaluating to a system function code, as listed in the table of system function codes.

Description

The SYSTEM function checks on the status of the system function specified. This table lists the system function codes accepted by the SYSTEM function, and the significance of the returned values. If expr evaluates to a number not listed below, 0 is assumed.

Code

Function

0

Following a READT, WRITET, WEOF or REWIND statement, SYSTEM(0) returns one of these error codes:

0

Record just read from tape is the same size as the current tape blocksize or minus the size of the record (in bytes) just read from tape. When in the ON ERROR clause, SYSTEM(0) indicates the reason for the error.

1

Tape or floppy disk unit is not attached.

2

EOF read from tape or floppy disk unit.

3

Attempt was made to write a null string to tape or floppy disk.

4

Attempt was made to write a null string to tape or floppy disk.

10

Attempt was made to read a binary item.

11

Attempt to write a record longer than the current tape blocksize.

12

The end of reel has been reached.

These error codes apply to the READT, WRITET, WEOF, and REWIND statements according to this table.

4

Indicates the validity of SYSTEM(0) if the statement was successful.

6

Indicates the validity of SYSTEM(0) if the statement was unsuccessful and the ELSE clause was executed.

 

 

READT

WRITET

WEOF

REWIND

0

4

 

 

 

1

6

6

6

6

2

6

 

 

 

3

 

4

 

 

4

 

4

 

 

10

4

 

 

 

11

 

4

 

 

12

 

4

 

 

After a LOCKED clause in a READU has been executed, SYSTEM(0) returns the number of the port that has the item locked.

If the ELSE clause of a LOCK statement is taken, SYSTEM(0) returns the number of the port that has the lock set.

After a ICONV(date,D) type of conversion, SYSTEM(0) is 0 if the conversion worked, and 1 if the date being converted was invalid.

After opening a file, SYSTEM(0) is 1 if the file is a DF file; 2 if the file is access protected; -1 if the file is update protected, and is not able to be updated; 0 if the file is able to be updated.

After attempting a READ type statement (except when the LOCKED clause of a READU/MATREADU is active), SYSTEM(0) is -1 if the file is update protected; 0 if the file is able to be updated. If the item the user is attempting to read is a binary item that cannot be processed using mvBASIC, the ELSE clause is taken and SYSTEM(0) is set to 10 to distinguish this case.

After failing a CONNECT and taking the ELSE clause, SYSTEM(0) indicates the reason for failure:

-2

Indicates the port was logged on.

-3

Indicates the user was already connected to a different line.

-4

Indicates an invalid line number was specified.

A value of 0 or higher is the line number of the port currently connected to the line, preventing the user from connecting.

After failing a WAKEUP and taking the ELSE clause, SYSTEM(0) indicates the reason for failure:

-1

Indicates the process is already active.

-2

Indicates the process is locked.

-3

Indicates the process is not logged on.

-4

Indicates an invalid line number was specified.

-5

Indicates the process is in the system debugger.

After a PRINT statement, SYSTEM(0) returns a value of 0, unless headings or footings are active and the user just entered a character at the end of a page. In this case, SYSTEM(0) returns the ASCII value of the character entered. In particular, if the user entered the CTRL+X character, SYSTEM(0) returns 24; if the user pressed ENTER, SYSTEM(0) returns 13.

After a SLEEP statement, SYSTEM(0) returns -1 if the sleep terminated normally or the number of the port that woke up the process.

If an INPUT statement is terminated by the user entering a control character (CONTROL+CHARS TERMINATE), SYSTEM(0) contains the decimal value of the control character typed.

If data is entered to an INPUT@ statement with trailing spaces, the spaces are removed and SYSTEM(0) returns a value of 32 to indicate the fact.

In the ELSE clause of an INPUT statement, SYSTEM(0) returns either -1 if the input timed out, or the number of the port that woke up the process.

After a BLOCK or UNBLOCK command, SYSTEM(0) returns these values:

0

Indicates the command worked.

1

Indicates a bad line exists within the structure.

2

Indicates a comma is missing within the structure.

3

Indicates a bad binary field (more than 6 bytes long) exists.

After an ATTACH or DETACH statement, SYSTEM(0) returns these values:

0

Indicates the command worked.

1

Indicates an invalid tape type was specified.

2

Indicates the system does not have the device/unit specified configured.

3

Indicates the tape unit was not attached, and therefore could not be detached.

4

Indicates that the tape device/unit is currently being used by someone else, and therefore cannot be attached.

 

Code

Function

1

Returns information about a previous statement (see below). 0 if program output is being sent to the terminal, 1 if program output is being sent to a printer device.

2

Current column width on the screen.

3

Current number of lines on the screen.

4

Number of lines remaining on current page of output.

5

Current page number.

6

umber of lines already printed on current page of output.

7

Single character representing the terminal type code. See the TERM command for possible values.

8

Current tape or floppy disk record length.

9

Current number of charge units.

10

0 if the secondary output buffer is empty, 1 if it contains data.

11

1 if the unassigned external select-list is present, 0 otherwise.

12

System time in milliseconds.

13

Number of characters waiting in the user’s type-ahead buffer.

14

Number of characters waiting in the active type-ahead buffer.

15

Options used to invoke execution of current program, in the form:

options^n^m

where ^ is an attribute mark (CHAR(254))

and:

options

Letter options used:

n

First number specified.

m

Second number specified.

18

User’s process number.

19

Account name on which the user is logged in, taken from the SYSTEM Dictionary.

21

System privilege level (0, 1, 2 or 3).

22

Current SP-ASSIGN options, forms queue and number of copies (separated by attribute marks).

23

System serial number (if supported).

24

Maximum frame number on the system.

25

Total No. of frames in the overflow table.

26

No. of linked frames in the overflow table.

27

No. of lines configured.

28

1 - if this is a Phantom process; 0 otherwise.

29

0 if there is no complete SAVE currently active, otherwise the process number of the SAVE process.

30

Always 0.

31

Null is returned.

32

Status bits from last tape command, (8 digit binary number):

WRITE PROT:EOT:BOT:EOF:PARITY:NO DATA:NO MEDIA:READY

33

0 - if break key enabled

1 - if break key disabled from mvBASIC

2 - if break key disabled from TCL

3 - if disabled from both.

34

0 - if RETURN will abort

1 - if it will satisfy a CALL

2 - if it will satisfy a GOSUB

35

Current program line number.

36

Name of the calling program if in a subroutine.

37

0 if not in a Proc, 1 if in a Proc.

38

Always 0.

39

1 if HEADING/FOOTING is currently active.

40

Name of the currently executing program.

41

File system’s base frame.

42

First workspace frame for process zero.

43

First extended workspace frame for process zero.

44

Size of each extended workspace (in frames).

45

Always 0.

46

Currently assigned print queue number.

47

Always 0.

48

Name of this network node.

49

Null is returned.

50

Version number of this copy of the operating system.

51

Always 0.

52

Always 0.

53

Always 0.

54

Always 0.

55

Number of execute levels that may be pushed by this program.

56

Always 0.

57

Console process# (-1 is none active).

58

Foreign language code for this process (E = English)

59

0 if R91, 1 if Power95 on a PowerPC, 2 if mvBase.

60

Returns the idle time in seconds of the specified process. The syntax is SYSTEM(60, <process>) where <process> is the target process number.

101

Line number of the line linked to the current process. If no line is linked, -1 is returned.

102

Current open Spooler print file numbers, in the form:

n1^n2^n3^ ...

where ^ is an attribute mark (CHAR(254))

and:

n1

Spooler entry number for print file 0.

n2

Spooler entry number for print file 1.

n3

Spooler entry number for print file 2.

and so on. A null entry number (determined by two adjacent attribute marks) signifies that the corresponding print file is available for the current program.

103

Current Execution Level.

116

1 if the program was invoked by a Proc, 0 if otherwise.

117

Current system privilege level. 0 if SYS0 (no privileges), 1 if SYS1, 2 if SYS2, and 3 if SYS3.

120

1 if the current program is cataloged, 0 otherwise.

121

Current SP-ASSIGN options, in the form:

options^f^c

where ^ is an attribute mark (CHAR(254)) and:

options

Spooler options currently set.

f

Current form queue number.

c

Current number of copies set.

126

System identification number.

The SYSTEM function may be very useful for programs which create reports and perform tape or floppy disk handling.

Examples

In this application the program needs to log to SYSPROG to use the PROTOCOL command. The user is asked for the SYSPROG password, and the user’s current account name is saved in the NAME variable through SYSTEM(19). After the PROTOCOL command is used, the user is returned to his or her original account.

PRINT "SYSPROG PASSWORD"

INPUT PASSWD

IF PASSWD <> "" THEN

   DATA PASSWD

END

NAME = SYSTEM(19)

EXECUTE "LOGTO SYSPROG"

EXECUTE "PROTOCOL ":LINE:" (C)"

EXECUTE "LOGTO ":NAME

END

In the next application, a WRITET statement is used to write a record onto a tape. Although the response of 4 to a SYSTEM(0) function is reserved for data strings longer than the tape record length, the WRITET statement avoids this eventuality by truncating the data and printing an error message. The SYSTEM(8) function is therefore used to determine if the data is too long, and to truncate the data into the appropriate number of segments if necessary. In the ELSE clause of the WRITET statement the SYSTEM(0) function is then used to determine the error code and print the corresponding message.

MAX.LEN = SYSTEM(8)

REC.LEN = LEN(CURR.REC)

NO.OF.SEGS = REC.LEN / MAX.LEN

NO.OF.SEGS = INT(NO.OF.SEGS)

IF REM(REC.LEN,MAX.LEN) THEN

   NO.OF.SEGS + = 1

END

FOR I = 1 TO NO.OF.SEGS

   BEGIN.COL = (MAX.LEN * (I-1)) + 1

   SEGMENT = CURR.REC[BEGIN.COL, MAX.LEN]

   WRITET SEGMENT ELSE   

      ERROR.CODE = SYSTEM(0)

      BEGIN CASE

      CASE ERROR.CODE = 1

         PRINT "ERROR! TAPE NOT ATTACHED"

         GOSUB EXIT

      CASE ERROR.CODE = 2

         PRINT "ERROR! EOF READ FROM TAPE"

         GOSUB EXIT

      CASE ERROR.CODE = 3

         PRINT ID:": ITEM IS EMPTY"

      END CASE

   END

NEXT I

The next example prints a string of asterisks across the screen:

COLS=SYSTEM(2)

PRINT STR("*",COLS)

In the next example the PROCWRITE statement is used only if the program was called from a Proc, determined by SYSTEM(116).

IF SYSTEM(116) THEN

   PROCWRITE FILELIST

END

Finally, if the programmer needed to determine if the I option to RUN was used, the code might read:

EXEC.STRING = SYSTEM(15)

LETTERS = EXEC.STRING<1>

IF COUNT(LETTERS, "I") THEN …

See Also

Statement and Function Reference