home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / blktoseq.seq < prev    next >
Text File  |  1987-12-13  |  3KB  |  69 lines

  1. \ BLKTOSEQ.SEQ  Conversion program, moves .BLK to .SEQ. by Tom Zimmer
  2.  
  3. handle cnvhcb                   \ Input file to convert
  4. handle outhcb                   \ output file we are converting to.
  5.  
  6. create crlf 13 c, 10 c,         \ line terminator
  7.  
  8. create blockbuf 1024 allot      \ Block conversion buffer
  9.        blockbuf 1024 erase
  10.  
  11. variable lastln
  12. variable altoff                 \ Offset to shaddow or ALT screen.
  13.  
  14. : convblk       ( n1 --- )      \ convert a block to a sequence of lines.
  15.                 1024 um* ( 64. d+ ) cnvhcb movepointer  \ set input pointer
  16.                 blockbuf dup 1024 ( 64 - ) cnvhcb hread \ read a block
  17.                 over + swap
  18.                 do      \ i c@ ascii \ <>
  19.                     ( if  ) i 64 -trailing dup >r
  20.                         lastln @ over or 0=
  21.                         if      2drop
  22.                         else           outhcb hwrite drop
  23.                                 crlf 2 outhcb hwrite drop
  24.                         then    r> lastln !
  25.                     ( then )
  26.             64 +loop    ;
  27.  
  28. : commentblk    ( n1 --- )      \ convert comment block and code block
  29.                 " comment:" outhcb hwrite drop
  30.                      crlf 2 outhcb hwrite drop
  31.                 convblk
  32.                 " comment;" outhcb hwrite drop
  33.                      crlf 2 outhcb hwrite drop ;
  34.  
  35. : convfile      ( --- )                 \ convert file from BLK to SEQ
  36.                 cnvhcb endfile 1024 um/mod swap
  37.                 if      1+              \ include end of last block.
  38.                 then    altoff off
  39.                 cnvhcb handle>ext " .BLK" caps-comp 0=  \ Is files ext .BLK?
  40.                 if      2/ dup altoff !                 \ then set shadow
  41.                 then    0                               \ offset to Alt scrn
  42.                 do      i convblk altoff @              \ if altoff <>0
  43.                         if      i altoff @ + commentblk \ write comment scrn
  44.                         then
  45.                         ." ." ?cr
  46.                 loop ;
  47.  
  48. : conv          ( --- name )
  49.                 70 rmargin !                            \ set right margin
  50.                 cnvhcb !hcb cnvhcb 1+ c@ ascii . =      \ of null filename
  51.                 if      cr ." Name of file to convert? " \ prompt for filenam
  52.                         query cnvhcb !hcb               \ stuff in cnvhcb
  53.                 then
  54.                 cnvhcb outhcb $>handle          \ duplicate in outhcb
  55.                 " SEQ" ">$ outhcb $>ext         \ and change ext to .SEQ
  56.                 cr ." Converting from " cnvhcb count type \ anounce conversn
  57.                    ."  to " outhcb count type
  58.                 cnvhcb handle>ext " .SEQ" caps-comp 0=  \ check input <> .SEQ
  59.                 abort" Cannot convert .SEQ to .SEQ "    \ error if it is
  60.                 cr cnvhcb hopen abort" Open file error" \ open input file
  61.                 outhcb hcreate abort" Create ERROR!"    \ make output file
  62.                 0.0 outhcb movepointer                  \ reset file pointer
  63.                 lastln on
  64.                 convfile                                \ convert the file
  65.                 cnvhcb hclose drop                      \ close in
  66.                 outhcb hclose drop ;                    \ close out
  67.  
  68. only forth also definitions
  69.