home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2XLSP1.ZIP / READ.LSP < prev    next >
Text File  |  1988-07-19  |  1KB  |  38 lines

  1. ; read.lsp -- OS2XLISP program uses C 5.1 CRTLIB.DLL
  2. ; Andrew Schulman 1-May-1988
  3.  
  4. ; also shows new function (make-string) [entire file in one string]
  5.  
  6. (define crtlib (loadmodule "crtlib"))
  7.  
  8. (princ "File to read? ")
  9. (define the-file (read-line))
  10. (terpri)
  11.  
  12. (define _open (getprocaddr crtlib "_open"))
  13. (define _filelength (getprocaddr crtlib "_filelength"))
  14. (define _read (getprocaddr crtlib "_read"))
  15. (define _close (getprocaddr crtlib "_close"))
  16.  
  17. (define fh (c-call _open the-file (word 0) 'word))
  18. (if (= #xffff fh)
  19.     (error "Can't open file"))
  20. (format stdout "file handle = ~A\t" fh)
  21.  
  22. (define len (c-call _filelength (word fh)))
  23. (format stdout "file length = ~A\t" len)
  24.  
  25. (define buffer (make-string #\Space len))       ; or (int-char 32) or 32
  26.  
  27. (define count (c-call _read (word fh) buffer (word len)))
  28. (format stdout "bytes read = ~A\n\n" count)
  29.  
  30. (princ (subseq buffer 0 count))     ; entire file in string
  31.  
  32. ;;; parse the file rather than just print it
  33. ; (load 'enumproc)
  34. ; (print (parse (subseq buffer 0 count) " \n\t"))
  35.  
  36. (c-call _close (word fh))
  37.  
  38.