Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

REBOL/Power-Tools LOOK-AT function!

 [1/1] from: robbo1mark::aol::com at: 28-Feb-2001 18:38


Everybody, here's the latest addition to the /Power-Tools family with my LOOK-AT function which is reminiscent of the Unix 'More & 'Less commands which view the contents of a file. My LOOK-AT function does the same & also has the following refinements, /START which views the first 10 lines of a file. /END which views the last 10 lines of a file. /INFO which prints information on the target file. /PAGE which allows for 20 Line Page Traversal through a file ( forwards & backwards ) IMPORTANT CAVEAT - the key polling method uses open/binary/wait which is the functionality of the last stable version of /Core. If you are using any of the beta or newer experimental version /View & /Core you will have to amend the file to poll the console with open/binary as I believe the /wait refinement has been replaced with /no-wait which works differently as the default behaviour. Enjoy and let me know what needs fixed. Should also work with URL's although I haven't been able to test this as AOL are my ASP and I can't get REBOL networking to work with them. Here's the code below. Mark Dickson look-at: func [{Views The Contents of a File or URL.} target [file! url!] /Page {Views a 20 Line Page including Forwards & Back Page Traversal.} /Start {Views a 10 Line Page at the Start of a File.} /End {Views a 10 Line Page at the Start of a File.} /Info {Views Information Detail on Target File or URL.} ] [ if false = ( exists? target) [print [newline "Target File or URL does NOT Exist!" newline ] exit ] (file: info? target) either 'directory = file/type [print [newline {Target Selection is a Directory, not a File or URL. Please Change Directory or Try Again, Thank You.^/}] exit] [ data: read/lines target lines: length? data count: 20 (if count > lines [count: lines]) peek: 10 (if peek > lines [peek: lines]) if start [loop peek [print pick data 1 data: next data] exit] if end [(data: tail data loop peek [data: back data]) loop peek [print pick data 1 data: next data] exit] if info [ print [newline "Information about Target File " target newline newline "File Size " file/size "Bytes." newline newline "Last Modified " file/date newline newline "Spans" lines "Lines." newline ] exit ] if page [ cons: open/binary/wait console:/ file-pos: index? data loop count [print pick data 1 data: next data] message: does [Print [newline {Please Press One of the Following Keys to Proceed } newline { Key - ( x ) exit ( b ) back a page ( n ) next page. } ] ] options: charset "xbn" forever [ message key: pick cons 1 either find options key [ key: to-char key switch key [ #"x" [ Print [newline "Returned to REBOL"] halt ] #"b" [remainder: lines - file-pos either count < remainder [count: 20] [ count: remainder ]loop 20 [data: back data] loop count [print pick data 1 data: next data]loop 20 [data: back data]] #"n" [ loop count [print pick data 1 data: next data]] ] ] [ ] ] ] Print [ newline "Contents of File" target newline ] foreach line data [ print line ] exit ] ]