home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / FCOPY.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1990-07-30  |  1.7 KB  |  51 lines

  1. ;;; --------------------------------------------------------------------------;
  2. ;;; FCOPY.LSP
  3. ;;;   Copyright (C) 1990 by Autodesk, Inc.
  4. ;;;  
  5. ;;;   Permission to use, copy, modify, and distribute this software and its
  6. ;;;   documentation for any purpose and without fee is hereby granted.  
  7. ;;;
  8. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  9. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  10. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  11. ;;;
  12. ;;; --------------------------------------------------------------------------;
  13. ;;; DESCRIPTION
  14. ;;;
  15. ;;;   This is a programming example.
  16. ;;;
  17. ;;;   This program takes two ASCII files as arguments, and copies the first   
  18. ;;;   file into the second.  If the first file does not exist, an error message 
  19. ;;;   is printed, however, if the second file does not exist, it is created.
  20. ;;;
  21. ;;;   Note that if the second file exists, its data will be overwritten.
  22. ;;;
  23. ;;;   Usage: (fcopy "infile.ext" "outfile.ext")
  24. ;;;
  25. ;;; --------------------------------------------------------------------------;
  26.  
  27. (defun fcopy (in out / ifp ofp l) 
  28.   (cond ((null (setq ifp (open in "r"))) ; try to open in for reading
  29.      (princ "Can't open ")            ; if nil print error message
  30.      (princ in) 
  31.      (princ " for reading.")
  32.     ) 
  33.     (if ifp 
  34.       (progn
  35.         (setq ofp (open out "w"))     ; else open out for writing
  36.         (while (setq l (read-line ifp)) ; read each line from in
  37.           (write-line l ofp)          ; and write it to out
  38.         ) 
  39.         (close ofp)                   ; close both files
  40.         (close ifp)
  41.       )
  42.     )
  43.   ) 
  44.   (princ)
  45.  
  46. ;;; --------------------------------------------------------------------------;
  47.  
  48.  
  49.  
  50.