Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/convert.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH template for conversion utilities
\ Copyright 2002,2004 - J.L. Bezemer

\ This file is not intended for standalone use.
\ You will have to define the following words:

\ Usage       ( f --) : abort" Your error message"   
\ PreProcess  ( --)   : Actions before the file is read      (optional)
\ Read-file   ( -- f) : How to read the file, e.g. refill
\ Process     ( --)   : What to do after each Read-file
\ PostProcess ( --)   : Actions after the file has been read (optional)

\ Has Usage been defined? If not, abort!
[UNDEFINED] Usage [IF]
[ABORT] [THEN]

\ Has Read-File been defined? If not, abort!
[UNDEFINED] Read-File [IF]
[ABORT] [THEN]

\ Has Process been defined? If not, abort!
[UNDEFINED] Process [IF]
[ABORT] [THEN]

\ Special imode defined? If not, assume binary mode.
[UNDEFINED] imode [IF]
input constant imode
[THEN]

\ Special omode defined? If not, assume binary mode.
[UNDEFINED] omode [IF]
output constant omode
[THEN]

[NEEDS lib/argopen.4th]

: CloseFiles close close ;             ( h h --)
                                       ( -- h h)
: OpenFiles                            \ open input and output files
  argn 3 < Usage                       \ issue message if error
  imode 1 arg-open                     \ open the input file                
  omode 2 arg-open                     \ open the output file
;

: ProcessFile                          \ process the input file line by line
[DEFINED] PreProcess [IF]
  PreProcess                           \ do any preprocessing
[THEN]
  begin
    Read-file                          \ read the file
  while
    Process                            \ process the line or buffer
  repeat
[DEFINED] PostProcess [IF]
  PostProcess                          \ do any postprocessing
[THEN]
;

: Convert OpenFiles ProcessFile CloseFiles ;

Convert



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.