previous next top complete contents complete index framed top this page unframed
Figure 47–1. scan (GENERIC)
| STRING PROCEDURE scan (MODIFIES STRING source; STRING scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (MODIFIES STRING source; BITS scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(textFile) source; STRING scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(textFile) source; BITS scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (MODIFIES STRING source; INTEGER scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(textFile) source; INTEGER scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(dataFile) source; STRING scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(dataFile) source; BITS scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); STRING PROCEDURE scan (POINTER(dataFile) source; INTEGER scanCtrl; OPTIONAL BITS ctrlBits; PRODUCES OPTIONAL INTEGER brkChr; OPTIONAL POINTER($area) area); |
A file or STRING (the “source”) is scanned as directed by scanCtrl and ctrlBits. area specifies the destination area for the resulting STRING if new STRING text is generated; see Section 29.4.
Characters (the “scanned characters”) are removed from the source while or until any of a set of characters (the “scan characters”) is encountered in the source. The scanned characters are returned as the result STRING. Thus, scan allows the programmer to scan up to (or over) any one of a set of characters.
scanCtrl indicates what scan characters are to guide the scan. There are three ways to specify the scan characters:
The BITS and INTEGER forms of scanCtrl are more efficient for scan characters that are used repeatedly, since the STRING form involves some overhead that depends on the length of scanCtrl.
$cScan is a more efficient version of scan when source is a STRING and scanCtrl consists of a single character; see Section 32.74.
brkChr is the “break character”, the character that causes the scan to terminate (“break”). The break character is often useful for determining the action following a scan.
In the file forms, if the file is opened for PDF I/O, the characters read from the file may be translated from the PDF to the host character set.
The valid predefined BITS constants that may be set in ctrlBits are:
End-of-source breaks the scan, with the result STRING equal to the STRING scanned up to the end-of-source, and brkChr equal to -1. -1 is not a valid character code.
Example 47–2. Use of scan
WHILE s DOB scans s for all identifiers, and writes each to logFile (assuming letters and lettersAndDigits are BITS assigned values as in Example 47–5).
s := scan(f,".") s is assigned all characters from the current position of f up to the first period. The period is retained as the next character of the file, and is not put into s. |
MAINSAIL Language Manual, Section 47.2