 |
» |
|
|
 |
The following example sorts the data file DATA. The entries
in DATA are sorted using an altered collating sequence that is explicitly
specified in the program. The sequence contains all displayable
ASCII characters and alters the order of the alphabetic characters to
AaBbCc ....The output file is called FRUIT. DATA - a file of fruit names banana Apple Grapes grapes Pear peach orange
|
 |
 |
 |
Example 4-1 SORTALT Program  |
program SORTALT (input,output); {This program reads the file DATA, sorts by fruit name, } {outputs to the file FRUIT, and uses an altered sequence.} var dataFileNum : INTEGER; fruitFileNum: INTEGER; status : INTEGER; procedure HPFOPEN ; intrinsic; procedure HPSORTINIT; intrinsic; procedure HPSORTEND; intrinsic; procedure FCLOSE; intrinsic; procedure OPEN_FILES; const designator = 2; domain = 3; access = 11; record_Size = 19; var datafile : packed array [1..10] of CHAR; fruitfile : packed array [1..10] of CHAR; permanent : INTEGER; new : INTEGER; write : INTEGER; size : INTEGER; begin datafile := '%DATA%'; permanent := 1; HPFOPEN (dataFileNum, status, designator, datafile, domain, permanent) ; new := 4; write := 1; size := 80; fruitfile := '%FRUIT%'; HPFOPEN (fruitFileNum, status, designator, fruitfile, domain, new, access, write, record_size, size); end; Procedure DO_SORT; var inputfiles : array [1..2] of INTEGER; outputfile : array [1..2] of INTEGER; outputOption : INTEGER; numKeys : INTEGER; keys : array [1..4] of INTEGER; altseq : packed array [1..96] of CHAR; Begin inputfiles [1] := dataFileNum; inputfiles [2] := 0; outputfile [1] := fruitFileNum; {From HPFOPEN} outputfile [2] := 0; OutputOption := 0; {Output record format same as input record format} numKeys := 1; {one key} keys[1] := 1; {key begins} keys[2] := 20; {key length} keys[3] := 0; {byte data} keys[4] := 0; {ascending order} altseq := ' '; altseq[1] := CHR(0); {Data = ASCII, Sequence is altered} altseq[2] := CHR(93); {94 characters in altered ASCII sequence} {Put sequence in Altseq.Sequence contains all displayable ASCII characters} strmove (15, '!"#$%&'')(*+,-./', 1, altseq, 3); strmove (16, '0123456789::<=>?', 1, altseq, 18); strmove (16, '@AaBbCcDdEeFfGgH', 1, altseq, 34); strmove (16, 'hIiJjKkLlMmNnOoP', 1, altseq, 50); strmove (16, 'pQqRrSsTtUuVvWwX', 1, altseq, 66); strmove (15, 'xYyZz[\]^_{|}~', 1, altseq, 81); HPSORTINIT (status, inputfiles, outputfile, outputOption,,, numKeys, keys, altseq,,,statistics,,); {Check for errors in HPSORTINIT} HPSORTEND (Status, ); {Check for errors in HPSORTINIT} end; Procedure CLOSE_FILES; var disposition : SHORTINT; securityCode : SHORTINT; Begin disposition := 0; securityCode := 0; FCLOSE (dataFileNum, disposition, securityCode); disposition := 1; FCLOSE (fruitFileNum, disposition, securityCode); end; begin {main} OPEN_FILES; DO_SORT; CLOSE_FILES; end. |
 |
When this program is executed, the output is written to FRUIT.
To view FRUIT: :print fruit Apple banana Grapes grapes peach Pear orange
|