1 ;;; -*- Mode:LISP; Package:MACSYMA -*-
3 ; ** (c) Copyright 1980 Massachusetts Institute of Technology **
5 (macsyma-module fileop
)
7 ;;; Some simple primitives for looking at files and directories from
8 ;;; Macsyma. Printf prints a file; Listf lists a user's files;
9 ;;; Qlistf lists only the names of the files.
11 (comment Macsyma user functions
)
13 (DEFMSPEC $printfile
(file) (SETQ file
(CDR file
))
14 (setq file
(open (filestrip file
)))
15 (princ "Printing file ")
16 (fileprint (truename file
))
18 (do ((in (tyi file -
1) (tyi file -
1)))
19 ((= in -
1) (close file
) '$done
)
21 (cond ((= in
12.
) (princ "^L")) ;Otherwise Lisp does randomness.
22 ((= in
3)) ;Don't confuse lusers.
25 (DEFMSPEC $listfiles
(dir) (SETQ dir
(CDR dir
))
27 File directory listing./
30 (dirsorted dir
'(credate link characters undumped pack
)))
33 (DEFMSPEC $qlistfiles
(dir) (SETQ dir
(CDR dir
))
34 (princ "Quick listing./
36 (mapc '(lambda (x) (princ (cadar x
))
43 (DEFMSPEC $filelist
(dir) (SETQ dir
(CDR dir
))
45 (mapcar '(lambda (x) (dollarify (list (cadar x
) (caddar x
))))
46 (dirsorted dir nil
))))
48 (DEFMSPEC $filelength
(file) (SETQ file
(CDR file
))
49 (filelength (filestrip file
)))
51 (comment The internal functions
)
53 ;; Tries to find the user's files: if he uses a multiple-user directory,
54 ;; his login name is assumed to be the first filename.
55 (defun real-directory (dir)
56 (setq dir
(car (mergef (list (fullstrip dir
)) ())))
57 (list (cond ((and (eq (car dir
) 'dsk
)
58 (memq (cadr dir
) '(users users1 sdrc jonpoe plasma
59 kad ucb lrc lrc1 bellab ball
)))
60 (list dir
(status userid
) '*))
61 (t (list dir
'* '*)))))
63 ;; Fileline prints the line for each file.
64 (defun fileline (spec)
65 ;; spec: (((dsk macrak) rpart 345) credate (...) characters 234235)
66 (fileprint (car spec
))
67 (cond ((get spec
'link
) (linkprint (get spec
'link
)))
69 (dateprint (get spec
'credate
))
71 (princ (get spec
'characters
))
73 (and (get spec
'undumped
) (princ '/!))
74 (and (equal 13.
(get spec
'pack
)) (princ " (secondary)"))))
77 ;; Linkprint handles links:
78 ;; [MYFILE,1,DSK,LUSER] --saved on tape #177
79 ;; [MYFILE,34,DSK,LUSER] --linked to file [HISFLE,BIG,DSK,SHARE]
80 (defun linkprint (linkname)
81 (cond ((and (eq (cadar linkname
) 'backup
) ;((dsk backup) tape ...)
82 (eq (cadr linkname
) 'tape
))
83 (princ "--saved on tape #")
84 (princ (caddr linkname
)))
85 (t (princ "--linked to file ")
86 (fileprint linkname
))))
88 ;; Prints date as 7/23/80
89 (defun dateprint (date) ;(year month day)
96 ;; Returns a Directory in the standard order.
97 (defun dirsorted (dir specs
)
98 (cond ((sort (sort (directory (real-directory dir
) specs
)
99 '(lambda (x y
) (alphalessp (caddar x
) (caddar y
)))) ;fn2
100 '(lambda (x y
) (alphalessp (cadar x
) (cadar y
))))) ;fn1
101 (t (merror "No files found")
105 (defun tabover (n) (do ((i (- n
(charpos t
) 1) (1- i
)))
109 ;;; FILES: A library for doing fancier file manipulation from Macsyma
111 (DECLARE (*EXPR FILESTRIP DOLLARIFY
))
113 ;;; (FILEFORM <file> <function-name>)
114 ;;; <file> should be either ((MLIST ...) <fn1> <fn2> ...)
115 ;;; or |& ... filename ... | or it will be an error
116 ;;; <function-name> is the name of the function to cite if an error
118 ;;; If the function does not err out, it will return a lisp filespec.
119 ;;; in Macsyma FILESTRIP form.
121 (DEFUN FILEFORM
(X FUN
)
122 (COND ((AND ($LISTP X
)
123 (APPLY 'AND
(MAPCAR 'ATOM
(CDR X
))))
126 (MERROR "~M got a bad file specification. Try [fn1,fn2,dev,dir]."
129 ;;; RENAMEFILE(oldname,newname);
130 ;;; A Macsyma FSUBR - works only renaming files in the same directory.
131 ;;; Accepts exactly 2 Macsyma-style filespecs.
133 (DEFMSPEC $RENAMEFILE
(ARG-LIST)
134 (SETQ ARG-LIST
(CDR ARG-LIST
))
135 (COND ((NOT (= (LENGTH ARG-LIST
) 2.
))
137 "Syntax is RENAMEFILE(oldname,newname); - Wrong number of args")))
138 (LET ((FILE1 (FILEFORM (CAR ARG-LIST
) 'RENAMEFILE
))
139 (FILE2 (FILEFORM (CADR ARG-LIST
) 'RENAMEFILE
)))
140 (SETQ FILE2
(MERGEF (NCONS (CDDR FILE1
)) FILE2
))
141 (COND ((NOT (PROBEF FILE1
))
142 (MERROR "~M Can't rename a non-existent file!" FILE1
)))
143 (COND ((PROBEF FILE2
)
144 (MERROR "~M Can't rename to an already existing file!"
145 (APPEND (CDR FILE2
) (CAR FILE2
)))))
146 (LET ((NEWFILE (RENAMEF FILE1 FILE2
)))