Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!usc!samsung!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Blocks vs Text files Message-ID: <755.UUL1.3#5129@willett.UUCP> Date: 9 Apr 90 01:28:38 GMT Organization: Latest link in the ForthNet chain. (Pgh, PA) Lines: 57 Category 10, Topic 6 Message 34 Sun Apr 08, 1990 F.SERGEANT [Frank] at 12:20 CDT There have been some recent messages about converting block files to text files. Some C program solutions have been presented. This seems especially appropriate to me, as I think someone with a C bent would be more likely to want the block files converted. Be that as it may (as my grandmother would say), it is easy to do the conversion in Forth. This is very easy in Pygmy which allows easy access to a number of files at the same time. It should be do-able in F83 which allows access to an output file & an input file (see OPEN & FROM). Here's one approach just to illustrate the idea. As usual this is untested, although I have used similar code successfully on several occasions (not that I have a C bent, you understand). VARIABLE OUTPUT-POINTER VARIABLE STARTING-OUTPUT-BLOCK# : C@+ ( a - a+1 c) COUNT ; : TEXT! ( c -) OUTPUT-POINTER @ 1024 U/MOD ( c offset-into-blk relative-blk#) STARTING-OUTPUT-BLOCK# @ + ( c offset-into-blk absolute-blk#) BLOCK + ( c a) C! ( ) UPDATE 1 OUTPUT-POINTER +! ; : LINE-TO-TEXT ( a -) 64 -TRAILING ( a #) FOR C@+ ( a+1 c) TEXT! NEXT DROP ( ) $0D TEXT! $0A TEXT! ; : BLOCK-TO-TEXT ( blk# -) BLOCK ( a) 16 ( ie #lines-per-screen) FOR ( a) DUP LINE-TO-TEXT 64 + NEXT DROP ; : BLOCKS-TO-TEXT ( from-1st-blk# from-last-blk# starting-output-blk#) OUTPUT-POINTER OFF STARTING-OUTPUT-BLOCK# ! ( 1st last) OVER - 1+ ( 1st #) FOR ( blk#) DUP BLOCK-TO-TEXT 1+ NEXT DROP FLUSH ; Note in the above that 7 FOR ... NEXT would loop 7 times and that 0 FOR ... NEXT would bypass the loop altogether. You will have to adjust the code if you are using the more common FOR NEXT or if you are using DO LOOP. However, to speed it up if space permits, or if you have trouble accessing more than one file at a time, you could build the output file in RAM and then write it all at once to disk (Pygmy's MSAVE or F83's SAVE). Another approach I've used is to write a word to call DOS to write one char sequentially to a file. -- Frank ----- This message came from GEnie via willett through a semi-automated process. Report problems to: 'uunet!willett!dwp' or 'willett!dwp@gateway.sei.cmu.edu'