• Aucun résultat trouvé

PREDEFINED PROCEDURES IN PASCAL/VS

Dans le document Pascal in MTS (Page 69-73)

Declarations for these procedures, except the PVCALLRC routine are provided in

*PASCALVSINCLUDE. These can be included in the user program by making use of the %INCLUDE statement and assigning one of the logical units 1 through 8 to *PASCALVSINCLUDE.

The procedures themselves are contained in *PASCALVSLIB, which must be explicitly concatenated to the object program in the $RUN command. For example, to compile

$RUN *PASCALVS SCARDS=sou SPUNCH=obj 1=*PASCALVSINCLUDE T=t and to execute,

$RUN obj+*PASCALVSLIB SCARDS=data SPRINT=output T=t

PROCEDURE DESCRIPTIONS

PVPFXGET

Procedure PVPFXGET(var pfx: String);

This procedure is an interface to the system to get the current execution prefix. A call to this procedure has the form PVPFXGET(pfx), where “pfx” is a String variable declared by the user to receive the value of the current prefix character. The execution prefix can be of length up to 120 characters. Hence “pfx” should be declared as a variable of type String with length of at least 120.

PVPFXSET

Procedure PVPFXSET(const pfx:String);

This procedure is an interface to the system to alter the execution prefix. A call to this procedure has the form PVPFXSET(pfx), where “pfx” contains the value of the new prefix. The execution prefix can be of length up to 120 characters, so “pfx” in this case has to be a String constant of length less than or equal to 120.

Pascal/VS: Predefined Procedures in Pascal/VS 69

PVCALLRC

This routine interfaces to OS/I(S) routines which set return codes. Normally when a non-Pascal routine is called from a Pascal program, it is not possible to access the return code.

This procedure enables calling non-Pascal routines and also checking the return code on exit from the routine.

To access a non-Pascal procedure “p” the declaration has the following form:

PVCALLRC(const p:Proctype; var rc:Integer;...

{parameters...for p}); Fortran;

Name of the procedure PVCALLRC... :

It is not possible to declare a Pascal/VS procedure with a variable number of parameters.

So, to be able to call PVCALLRC more than once, or to be able to access different non-Pascal routines each of which uses a different number of parameters, we need more than one declaration of the procedure. This is achieved by making use of the fact that while only the first eight letters are significant to the loader, the first 16 letters are significant to the compiler. So, to call different routines, e.g., procedures “p1”, “p2”, function “p3” (of type Integer for example), etc., the user can now declare,

Procedure PvcallrcP1(const p1: ...); Fortran;

Procedure PvcallrcP2(const p2: ...); Fortran;

Function PvcallrcP3(const p3: ...):Integer; Fortran;

. . .

Type of the parameter “p”:

“p” is declared as a Ref variable, to be resolved to a routine of the same name defined elsewhere. The Ref declaration implies that storage for that variable already exists and the compiler does not allocate any storage, so the type definition here is not used for determining the storage requirement for variables of that type. It is used because the Pascal compiler requires association of a type with a variable declaration. So, a dummy type is used and “p” is declared to be of that type, e.g.,

Type Proctype = record end;

Ref p: Proctype;

Note: Here the type Proctype is a dummy type which defines zero storage. While the type specification is unimportant, this type keeps it distinct from the types of any of the other parameters in the procedure declaration. This is further protection against accidentally overwriting “p”.

Rc is a variable of type integer; it receives the return code. Note that it is the second parameter in the procedure declaration.

The other parameters that follow are those required by the non-Pascal routine that is called.

70 Pascal/VS: Predefined Procedures in Pascal/VS

Examples of declarations and calls:

To call the system routines SETLIO or function SETPFX:

Type proctype = record end;

Ref setlio, setpfx : proctype;

(any other declarations needed by the procedure or function ...see example 3)

Procedure PVCALLRCsetlio(CONST p:proctype;

Var rc:INTEGER;CONST unit:a8; CONST fd : a16); Fortran;

Function PVCALLRCsetpfx(CONST p:proctype;

Var rc:INTEGER;CONST pfx:CHAR): CHAR; Fortran;

are the declarations and calls are of the form

PVCALLRCsetlio(setlio,rc,unit,fname);

PVCALLRCsetpfx(setpfx,rc,c);

EXAMPLES

Example 1

Use of PVPFXSET and PVPFXGET Program Change_Pfx;

{First saves the current prefix, then sets it to '**', and then restores it.}

%Include pvpfxget;

%Include pvpfxset;

Var

Savedpfx : String(120);

Begin

Pvpfxget(savedpfx); {Save}

Pvpfxset('**'); {Set}

...

Pvpfxset(savedpfx); {Restore}

End.

Pascal/VS: Predefined Procedures in Pascal/VS 71

Example 2

Use of the PVCALLRC Routines Program Callrc;

{Callrc reads two lines. The second line is copied to the file -f at the line number given on the first line. MTS logical I/O unit 99 is used.}

Const

ati = '00000002'X; { I/O modifier - indexed write}

Type

a8 = packed array(.1..8.) of char;

a80 = packed array(.1..80.) of char;

a16 = packed array(.1..16.) of char;

halfword = packed -32768..32767;

whatever = record end; {A dummy for routine names}

Ref

WRITE, SETLIO : whatever;

Procedure pvcallrcWRITE(const p:whatever; var rc: Integer;

const reg:a80; const len:halfword; const mods:Integer;

const lnum:Integer; const unit:a8); fortran;

Procedure pvcallrcSETLIO(const p:whatever; var rc: Integer;

const unit:a8; const fd:a16); fortran;

Var

rc,num: integer;

r: real;

line: a80;

Begin

readln(r); readln(line);

num := round(r*1000);

pvcallrcSETLIO(setlio,rc,'99','-f');

if rc <> 0 then Writeln(' Error from SETLIO');

pvcallrcWRITE(write,rc,line,80,ati,num,'99');

if rc <> 0 then Writeln(' Error from WRITE') End.

72 Pascal/VS: Predefined Procedures in Pascal/VS

Dans le document Pascal in MTS (Page 69-73)