home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpmug / cpmug004.ark / IOEXAMP < prev    next >
Encoding:
Text File  |  1984-04-29  |  2.8 KB  |  89 lines

  1. `
  2. This is an ACT program which reads a text file and writes another with
  3. the lines preceeded by a sequence number.  The purpose of this example
  4. is to show how the disk i/o functions were intended to be used.
  5. (Another thing this example shows is the slowness of the interpreter.)
  6. The indenting in this file is done with TAB characters, not blanks.
  7. `
  8.  
  9. @{ns|next file|{`            Process one file (top level)`
  10.     @{ns|
  11.         source|@@{rs|input file:  }|`    Request file names.`
  12.         sink|@@{rs|output file: }|
  13.         source rn|0|`            Preset initial record numbers`
  14.         sink rn|0|
  15.         input||`            Clear input and output strings`
  16.         output||
  17.         n|0`                Initialize line number`
  18.     }
  19.     @{of|@@{source}||
  20.         {`                Source file exists`
  21.             @{cf}
  22.             @{of|@@{sink}||{@{df}}}`Destroy existing sink file`
  23.             @{mf|@@{sink}||{@{ps|Full disk.|}@{ex}}}
  24.             @{do line}`        OK - start processing`
  25.         }|
  26.         {@{ps|No file "@@{source}"|}}`    Can't open source`
  27.     }
  28.     @{next file}`                Go again (exit with Control-C)`
  29. }}
  30.  
  31. @{ns|do line|{`                Process one line`
  32.     @{get line}`                Line is left in string l`
  33.     @{eq|@@{l}|e.o.f.|`            "e.o.f." comes from "read"`
  34.         {@{close}}|`            Close file; exit "do line"`
  35.         {@{put line}@{do line}}`    Output and loop`
  36.     }
  37. }}
  38.  
  39.  
  40. @{ns|get line|{`            Value is the next line, or e.o.f.`
  41.     @{in|input|@@{crlf}|`            Another line in input string?`
  42.         {@{ns|l|@@{@in}}}|`        Yes - store in l`
  43.         {@{read|10}@{get line}}`    No - read more from diskette`
  44.     }
  45. }}
  46.  
  47. @{ns|read|{`                "@{read|n}" reads the next n records`
  48.     @{ns|input|@@{@in}}`            Set input to last partial line`
  49.     @{cf}`                    Close the output file`
  50.     @{of|@@{source}|@@{source rn}}`        Open source at next record`
  51.     @{rf|input|.n.||{`            Append the next n records`
  52.         @{as|input|e.o.f.@@{crlf}}`    If eof, append "e.o.f."`
  53.     }}
  54.     @{ss|input|@@{pk|1a}}`            Remove any Control-Z chars.`
  55.     @{ns|source rn|@@{rn}}`            Save the current record number`
  56.     @{cf}`                    Close the input file`
  57.     @{of|@@{sink}|@@{sink rn}}`        Reopen the output file`
  58. }}
  59. @{ss|read|.n.}`                    Create the argument`
  60.  
  61. @{ns|put line|{`            Output line number and line`
  62.     @{ns|n|@@{ad|@@{n}|1}}`            Increment the line number`
  63.     @{ns|output|
  64.         @@{in|output}`            Unwritten part of output`
  65.         @@{@@{gc|n}}`            Pad for justification`
  66.         @@{n} @@{l}`            Line no., space, text of line`
  67.         @@{crlf}
  68.     }
  69.     @{wf|output|||{@{write err}}}`        Write, if more than 128 chars.`
  70.     @{ns|sink rn|@@{rn}}`            Save current record number`
  71. }}
  72.  
  73. @{ns|4||3| |2|  |1|   }`        Blanks for right justification`
  74.  
  75. @{ns|crlf|@@{pk|0d0a}}`            Define end-of-line`
  76.  
  77. @{ns|close|{`                Write remaining output and close file`
  78.     @{ns|output|@@{in|output}}`        Define unwritten output`
  79.     @{wf|output|@@{pk|1a}||{@{write err}}}`    Pad with Control-Z`
  80.     @{cf||{@{write err}}}
  81.     @{ps|@@{n} lines in @@{source}||}
  82. }}
  83.  
  84. @{ns|write err|{`            If error, reload the idle macro`
  85.     @{ps|Write error|}@{ex}
  86. }}
  87.  
  88. @{next file}`                Start`
  89.