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

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


\ 4tH ASCII cleaning utility
\ Copyright 2003,2004 - Hansoft & Partners

[needs lib/istype.4th]

  9 constant tab
 10 constant lf

/char string buffer
                                       \ emit char if c1 = c2
: ?emit over = if dup emit then ;      ( c1 c2 -- c1)
                                       \ duplicate char if char is printable
: char? dup is-print                   ( c -- c -n | c c )
  if dup else -1 then ;

: Usage abort" Usage: ascii7 infile outfile" ;

: Read-file buffer /char accept ;      \ read a character

: Process
    buffer c@                          \ put it on the stack
    lf    ?emit                        \ emit if it is a LF
    tab   ?emit                        \ emit if it is a TAB
    char? ?emit                        \ emit if it is printable
    drop                               \ now drop it
;

[needs lib/convert.4th]

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.