home *** CD-ROM | disk | FTP | other *** search
- `
- This is an ACT program which reads a text file and writes another with
- the lines preceeded by a sequence number. The purpose of this example
- is to show how the disk i/o functions were intended to be used.
- (Another thing this example shows is the slowness of the interpreter.)
- The indenting in this file is done with TAB characters, not blanks.
- `
-
- @{ns|next file|{` Process one file (top level)`
- @{ns|
- source|@@{rs|input file: }|` Request file names.`
- sink|@@{rs|output file: }|
- source rn|0|` Preset initial record numbers`
- sink rn|0|
- input||` Clear input and output strings`
- output||
- n|0` Initialize line number`
- }
- @{of|@@{source}||
- {` Source file exists`
- @{cf}
- @{of|@@{sink}||{@{df}}}`Destroy existing sink file`
- @{mf|@@{sink}||{@{ps|Full disk.|}@{ex}}}
- @{do line}` OK - start processing`
- }|
- {@{ps|No file "@@{source}"|}}` Can't open source`
- }
- @{next file}` Go again (exit with Control-C)`
- }}
-
- @{ns|do line|{` Process one line`
- @{get line}` Line is left in string l`
- @{eq|@@{l}|e.o.f.|` "e.o.f." comes from "read"`
- {@{close}}|` Close file; exit "do line"`
- {@{put line}@{do line}}` Output and loop`
- }
- }}
-
-
- @{ns|get line|{` Value is the next line, or e.o.f.`
- @{in|input|@@{crlf}|` Another line in input string?`
- {@{ns|l|@@{@in}}}|` Yes - store in l`
- {@{read|10}@{get line}}` No - read more from diskette`
- }
- }}
-
- @{ns|read|{` "@{read|n}" reads the next n records`
- @{ns|input|@@{@in}}` Set input to last partial line`
- @{cf}` Close the output file`
- @{of|@@{source}|@@{source rn}}` Open source at next record`
- @{rf|input|.n.||{` Append the next n records`
- @{as|input|e.o.f.@@{crlf}}` If eof, append "e.o.f."`
- }}
- @{ss|input|@@{pk|1a}}` Remove any Control-Z chars.`
- @{ns|source rn|@@{rn}}` Save the current record number`
- @{cf}` Close the input file`
- @{of|@@{sink}|@@{sink rn}}` Reopen the output file`
- }}
- @{ss|read|.n.}` Create the argument`
-
- @{ns|put line|{` Output line number and line`
- @{ns|n|@@{ad|@@{n}|1}}` Increment the line number`
- @{ns|output|
- @@{in|output}` Unwritten part of output`
- @@{@@{gc|n}}` Pad for justification`
- @@{n} @@{l}` Line no., space, text of line`
- @@{crlf}
- }
- @{wf|output|||{@{write err}}}` Write, if more than 128 chars.`
- @{ns|sink rn|@@{rn}}` Save current record number`
- }}
-
- @{ns|4||3| |2| |1| }` Blanks for right justification`
-
- @{ns|crlf|@@{pk|0d0a}}` Define end-of-line`
-
- @{ns|close|{` Write remaining output and close file`
- @{ns|output|@@{in|output}}` Define unwritten output`
- @{wf|output|@@{pk|1a}||{@{write err}}}` Pad with Control-Z`
- @{cf||{@{write err}}}
- @{ps|@@{n} lines in @@{source}||}
- }}
-
- @{ns|write err|{` If error, reload the idle macro`
- @{ps|Write error|}@{ex}
- }}
-
- @{next file}` Start`
-