Please enable JavaScript to view this site.

A-Shell Reference

Written June 2020

XOPEN #ch, fspec$, mode, recsiz {, flags}

XOPEN is an alternative to the traditional OPEN statement, offering the following advantages:

Replacement of the literal compiler keywords (e.g. WAIT'RECORD) with a flexible flags parameter, allowing a single generic, parameterized, XOPEN statement to be used for all variations.
Elimination of the requirement for the recnovar to remain in scope, by eliminating it entirely. Instead, you can specify the record number explicitly using the XREAD, XWRITE, XUNLOKR or SET'RECNO statements.

Parameters

ch  (Num)  [in]

an integer expression (>0) specifying the file channel which will be needed for subsequent I/O operations on the file.

fspec  (String)  [in]

string expression containing file specification, in native or AMOS syntax. May contain embedded %env% variables, e.g. "%temp%\myfile.dat".  If no directory information is included, the search path consists of the current directory, followed by the [p,0] directory.

mode  (literal keyword)  [in]

specifies the file access mode, and must be one of the following (case insensitive) compiler keywords:

Symbol

Description

RANDOM

When LOKSER enabled, requests exclusive access; otherwise same as RANDOM'FORCED

RANDOM'FORCED

Shared access

 

Note that unlike with the traditional OPEN, here the you can specify RANDOM and then use the flags argument to change it to RANDOM'FORCED, thereby eliminating the need for two separate literal variations of the XOPEN statement in your code.

recsiz  (Num)  [in]

integer expression specifying the record size—i.e. the number of bytes transferred in each subsequent READ and WRITE operations. See SPAN'BLOCKS below.

flags  (B,4 or numeric expression)  [in]

flags optionally specifies zero or more of the following modifiers:

Symbol

Value

Meaning

FDVF_FORCED

&h0010

Convert RANDOM to RANDOM'FORCED (shared)

FDVF_EXCLUSIVE

&h0800

Convert INDEXED to INDEXED'EXCLUSIVE

FDVF_READONLY

&h1000

READONLY

FDVF_SPANBLOCKS

&h2000

SPAN'BLOCKS

FDVF_W_RECORD

&h4000

WAIT'RECORD

FDVF_W_FILE

&h8000

WAIT'FILE

Definition file: ashinc:addsfdv.def

 

Note that if flags is expressed as a variable, it must be of type B,4. Since flags occupies the same position as recnovar in the traditional OPEN statement, requiring it to be of type B,4 here reduces the chance of accidentally confusing the two statements in your coding.

Example

XOPEN makes it possible to create a generic function for opening random files, such as the following:

call Fn'XOPEN'Random(ch=CH, fspec$="test.dat", recsiz=128, flags=FDVF_FORCED+FDVF_W_RECORD+FDVF_FILE)

XREAD #CH, 1    ! read rec # 1

...

Function Fn'XOPEN'Random(ch as b2:inputonly, fspec$ as s260:inputonly, recsiz as b2:inputonly, flags as b4:inputonly) as i4

    XOPEN #ch, fspec$, RANDOM, recsiz, flags

EndFunction

 

The above function could easily be upgraded to trap errors and deal file locking conflicts, including logging, user interfacing, etc., allowing you to implement all of that logic in a single place with more modularity than would otherwise be possible with the traditional OPEN statement.

See Also

OPEN