Rename *ll* and *ul* to ll and ul in make-defint-assumptions
[maxima.git] / archive / share / trash / dskuse.lisp
blob887aa32c8e94929358f8a127b06cdb8975008640
1 ;;; -*- LISP -*-
3 ;;; Compiler declarations. IOTA is a function for binding I/O
4 ;;; streams. See documentation in MC:LIBDOC;IOTA >
6 (EVAL-WHEN (EVAL COMPILE)
7 (COND ((NOT (STATUS FEATURE IOTA))
8 (LOAD '((DSK LIBLSP) IOTA FASL)))))
10 ;;; More compiler stuff. Macsyma builtins.
12 (DECLARE (*EXPR STRIPDOLLAR))
14 ;;; These two MACRO's are just for CONS'ing up silly Macsyma structure
16 ;; (MLIST-SIMP <thing1> <thing2> ...)
17 ;; returns ((MLIST SIMP) <thing1> <thing2> ...)
19 (DEFUN MLIST-SIMP MACRO (X)
20 `(CONS '(MLIST SIMP) (LIST . ,(CDR X))))
22 ;; (MTIMES-BLOCKS <n>)
23 ;; returns ((MTIMES SIMP) <n> $BLOCKS) which will display as
24 ;; "<n> BLOCKS" when Macsyma's display routines are run.
26 (DEFUN MTIMES-BLOCKS MACRO (X)
27 `(LIST '(MTIMES SIMP) ,(CADR X) '$BLOCKS))
29 ;;; Returns info about the total number of blocks free in the system.
30 ;;; expects an arg of an already open file object which is open to
31 ;;; a file directory (file with name .FILE. (DIR) on any directory.)
33 (DEFUN STATUS-GLOBAL-DSKUSE (STREAM)
34 (READLINE STREAM)
35 (DO ((C (TYI STREAM) (TYI STREAM))
36 (L ()))
37 ((= C 13.) (LIST* '(MLIST SIMP) '|&TOTAL FREE BLOCKS| (NREVERSE L)))
38 (COND ((= C 35.)
39 (PUSH (APPEND '((MLIST SIMP))
40 ((LAMBDA (PACK)
41 (COND ((= PACK 13.)
42 (LIST '|&SECONDARY PACK|
43 PACK))
45 (LIST '|&PRIMARY PACK|
46 PACK))))
47 (STATUS-DSKUSE\AUX STREAM 61.))
48 (NCONS
49 (MTIMES-BLOCKS
50 (STATUS-DSKUSE\AUX STREAM 32.)
51 )))
52 L)))))
54 ;;; STATUS-DSKUSE\AUX
55 ;;; This function TYI's from STREAM until a character whose fixnum
56 ;;; value is TERM is seen (eats the TERM character, too).
57 ;;; Returns the readlisted form of the characters seen before TERM.
59 (DEFUN STATUS-DSKUSE\AUX (STREAM TERM)
60 (DO ((C (TYI STREAM) (TYI STREAM))
61 (L () (CONS C L)))
62 ((= C TERM)
63 (LET ((BASE 10.)) (READLIST (NREVERSE L))))))
65 ;;; STATUS-USER-DSKUSE
66 ;;; Returns info about a user's disk use. The file object corresponding
67 ;;; to the user's file directory must already be open and the first two
68 ;;; lines should already have been READLINE'd.
69 ;;; NAME= STRIPDOLLAR'd name
70 ;;; USERNAME= Un-STRIPDOLLAR'd name
71 ;;; DIRNAME= Un-STRIPDOLLAR'd dirname
72 ;;; ALL-FLAG= a flag which if non-null means count all files in the
73 ;;; directory - if NIL means just to count files with FN1 the
74 ;;; same as NAME.
75 ;;; STREAM= a file object open to the directory
77 (DEFUN STATUS-USER-DSKUSE (NAME USERNAME DIRNAME ALL-FLAG STREAM)
78 (DO ((C (PROGN (TYI STREAM) (TYI STREAM))
79 (PROGN (TYI STREAM) (TYI STREAM)))
80 (DIR-PRIMARY-DSKUSE 0.)
81 (DIR-SECONDARY-DSKUSE 0.)
82 (USR-PRIMARY-DSKUSE 0.)
83 (USR-SECONDARY-DSKUSE 0.))
84 ((= C 12.)
85 (LIST* (MLIST-SIMP '|&DIRECTORY BLOCK USAGE|
86 DIRNAME
87 (MLIST-SIMP '&PRIMARY
88 (MTIMES-BLOCKS
89 DIR-PRIMARY-DSKUSE))
90 (MLIST-SIMP '&SECONDARY
91 (MTIMES-BLOCKS
92 DIR-SECONDARY-DSKUSE)))
93 (COND ((NOT ALL-FLAG)
94 (NCONS
95 (MLIST-SIMP '|&USER BLOCK USAGE|
96 USERNAME
97 (MLIST-SIMP '&PRIMARY
98 (MTIMES-BLOCKS
99 USR-PRIMARY-DSKUSE))
100 (MLIST-SIMP
101 '&SECONDARY
102 (MTIMES-BLOCKS
103 USR-SECONDARY-DSKUSE))))))))
104 (TYI STREAM) ; TYI second space
105 (LET ((SPEC (READLIST (DELETE 32.
106 (LIST (TYI STREAM) (TYI STREAM)
107 (TYI STREAM) (TYI STREAM))))))
108 (COND ((NOT (NUMBERP SPEC))
109 (READLINE STREAM))
111 (COND ((= SPEC 13.)
112 ((LAMBDA (V)
113 (SETQ USR-SECONDARY-DSKUSE
114 (+ USR-SECONDARY-DSKUSE (CAR V)))
115 (SETQ DIR-SECONDARY-DSKUSE
116 (+ DIR-SECONDARY-DSKUSE (CDR V))))
117 (STATUS-USER-DSKUSE\PARSE-LINE STREAM
118 ALL-FLAG
119 NAME)))
121 ((LAMBDA (V)
122 (SETQ USR-PRIMARY-DSKUSE
123 (+ USR-PRIMARY-DSKUSE (CAR V)))
124 (SETQ DIR-PRIMARY-DSKUSE
125 (+ DIR-PRIMARY-DSKUSE (CDR V))))
126 (STATUS-USER-DSKUSE\PARSE-LINE STREAM
127 ALL-FLAG
128 NAME)))))))))
130 ;;; STATUS-USER-DSKUSE\PARSE-LINE
131 ;;; Reads an individual line from the dir and returns a CONS whose
132 ;;; CAR is user use and CDR is directory use by the file in question.
133 ;;; (Links count as 0).
135 ;;; STREAM= the file directory file object already opened and in position
136 ;;; ALL= flag saying whether or not to count files that don't have an FN1
137 ;;; the same as the value of NAME
138 ;;; NAME = a value to compare the FN1 to if ALL is non-NIL.
140 (DEFUN STATUS-USER-DSKUSE\PARSE-LINE (STREAM ALL NAME)
141 (LET ((FN1 (STATUS-USER-DSKUSE\PARSE-LINE\AUX STREAM))
142 (SIZE (PROG2 (STATUS-USER-DSKUSE\PARSE-LINE\AUX STREAM)
143 (LET ((IBASE 10.)) (READ STREAM))
144 (READLINE STREAM))))
145 (COND ((OR ALL (EQ FN1 NAME))
146 (CONS SIZE SIZE))
148 (CONS 0. SIZE)))))
150 ;;; STATUS-USER-DSKUSE\PARSE-LINE\AUX
151 ;;; Reads 7 characters from STREAM, but only looks at first 6.
152 ;;; Implodes all 6 except for trailing spaces and returns as a symbol.
154 ;;; STREAM= file object being read from.
156 (DEFUN STATUS-USER-DSKUSE\PARSE-LINE\AUX (STREAM)
157 (DO ((C (TYI STREAM) (TYI STREAM))
158 (I 0. (1+ I))
159 (L () (CONS C L)))
160 ((> I 5.)
161 (DO ((L L (CDR L)))
162 ((NOT (= (CAR L) 32.)) (IMPLODE (NREVERSE L)))))))
164 ;;; $FULLDISKUSE
166 ;;; Syntax is:
168 ;;; FULLDISKUSE();
170 ;;; which will default to the user's name, or
172 ;;; FULLDISKUSE(<name>);
174 ;;; <name> will not be evaluted.
176 ;;; Returns:
178 ;;; [[TOTAL FREE BLOCKS, [<pack-type>, <pack-number>, <n> BLOCKS],
179 ;;; [<pack-type>, <pack-number>, <n> BLOCKS], ...]
180 ;;; [DIRECTORY BLOCK USAGE, <directory-name>
181 ;;; [PRIMARY, <n> BLOCKS],
182 ;;; [SECONDARY, <n> BLOCKS]]
183 ;;; [USER BLOCK USAGE, <user-name>,
184 ;;; [PRIMARY, <n> BLOCKS],
185 ;;; [SECONDARY, <n> BLOCKS]]]
187 ;;; If the user has his own directory, the last element of the list
188 ;;; (USER BLOCK USAGE) is omitted since it would be the same as
189 ;;; DIRECTORY BLOCK USAGE.
191 ;;; <pack-type> ::= "PRIMARY PACK" or "SECONDARY PACK"
192 ;;; <pack-number> ::= a fixnum
193 ;;; <n> ::= a fixnum
195 ;;; Occurances of `<n> BLOCKS' are in the form of a Macsyma
196 ;;; multiplication between a fixnum <n> and the Macsyma symbol BLOCKS.
199 (DEFUN $FULLDISKUSE FEXPR (SPECS)
200 (DECLARE (SPECIAL NAME))
201 (LET* ((USERNAME (COND ((ATOM SPECS)
202 (IMPLODE (CONS '$ (EXPLODEC (STATUS USERID)))))
204 (CAR SPECS))))
205 (NAME (STRIPDOLLAR USERNAME))
206 (DIR (COND ((ATOM SPECS) (STATUS HSNAME))
207 (T (STATUS HSNAME NAME))))
208 (DIRNAME (IMPLODE (CONS '$ (EXPLODEC DIR))))
209 (ALL (COND ((EQ NAME DIR) T) (T ()))))
210 (IOTA ((STREAM `((DSK ,DIR) |.FILE.| |(DIR)|) '(IN ASCII)))
211 (LIST* '(MLIST SIMP)
212 (STATUS-GLOBAL-DSKUSE STREAM)
213 (STATUS-USER-DSKUSE NAME USERNAME
214 DIRNAME ALL STREAM)))))
216 ;;; PRINTDISKUSE
217 ;;; Takes args just like FULLDISKUSE.
218 ;;; Prints in English nicely formatted the disk use for a user.
220 (DEFUN $PRINTDISKUSE FEXPR (X)
221 (LET ((USAGE (APPLY '$FULLDISKUSE X))
222 (PRIMARY 0.)
223 (SECONDARY 0.)
224 (BASE 10.)
225 (*NOPOINT T))
226 (CURSORPOS 'A TYO)
227 (MAPCAR (FUNCTION
228 (LAMBDA (X)
229 (COND ((EQ (CADR X) '|&PRIMARY PACK|)
230 (SETQ PRIMARY
231 (+ PRIMARY (CADR (CADDDR X)))))
233 (SETQ SECONDARY
234 (+ SECONDARY (CADR (CADDDR X))))))))
235 (CDDADR USAGE))
236 (PRINC (+ PRIMARY SECONDARY) TYO)
237 (PRINC '| Total Free Disk Blocks: | TYO)
238 (TERPRI TYO)
239 (PRINC '| | TYO)
240 (PRINC PRIMARY TYO)
241 (PRINC '| on Primary Pack and | TYO)
242 (PRINC SECONDARY TYO)
243 (PRINC '| on Secondary Pack.| TYO)
244 (TERPRI TYO)
245 (LET ((DIRUSE (CDR (CADDR USAGE)))
246 (USRUSE (CDR (CADDDR USAGE))))
247 (PRINC '|Directory use by the | TYO)
248 (PRINC (STRIPDOLLAR (CADR DIRUSE)) TYO)
249 (PRINC '| directory:| TYO)
250 (TERPRI TYO)
251 (PRINC '| | TYO)
252 (PRINC (CADR (CADDR (CADDR DIRUSE))) TYO)
253 (PRINC '| blocks on Primary Pack and | TYO)
254 (PRINC (CADR (CADDR (CADDDR DIRUSE))) TYO)
255 (PRINC '| blocks on Secondary Pack.| TYO)
256 (TERPRI TYO)
257 (COND ((CDDDR USAGE)
258 (PRINC '|Usage by | TYO)
259 (PRINC (STRIPDOLLAR (CADR USRUSE)) TYO)
260 (PRINC '|:| TYO)
261 (TERPRI TYO)
262 (PRINC '| | TYO)
263 (PRINC (CADR (CADDR (CADDR USRUSE))) TYO)
264 (PRINC '| blocks on Primary Pack and | TYO)
265 (PRINC (CADR (CADDR (CADDDR USRUSE))) TYO)
266 (PRINC '| blocks on Secondary Pack.| TYO)
267 (TERPRI TYO))))
268 '$DONE))
270 ;;; DISKFREE
271 ;;; DISKFREE(TRUE); or just DISKFREE(); returns total free blocks on
272 ;;; both packs.
273 ;;; DISKFREE(PRIMARY); returns blocks free on primary pack.
274 ;;; DISKFREE(SECONDARY); returns blocks free on secondary pack.
275 ;;; DISKFREE(<n>); returns the free blocks on pack <n>
276 ;;; return value is a fixnum times the symbol blocks.
278 (DEFUN $DISKFREE FEXPR (X)
279 (COND ((> (LENGTH X) 1.)
280 (CURSORPOS 'A TYO)
281 (PRINC '|;Too many args given to DISKFREE.| TYO)
282 (ERR)))
283 (SETQ X (OR (CAR X) '$TRUE))
284 (COND ((NOT (MEMBER X '($TRUE $PRIMARY $SECONDARY 0. 1. 13.)))
285 (CURSORPOS 'A TYO)
286 (PRINC '|;Illegal arg to DISKFREE| TYO)
287 (TERPRI TYO)
288 (PRINC '|;Valid args are 0, 1, 13, TRUE, PRIMARY, SECONDARY.|
289 TYO)
290 (ERR)))
291 (IOTA ((STREAM '|DSK:USERS;.FILE. (DIR)| 'IN))
292 (READLINE STREAM)
293 (DO ((C (TYI STREAM) (TYI STREAM))
294 (DSKUSE 0.))
295 ((= C 13.) (MTIMES-BLOCKS DSKUSE))
296 (COND ((= C 35.)
297 (LET ((PACK (STATUS-DSKUSE\AUX STREAM 61.))
298 (AMOUNT (STATUS-DSKUSE\AUX STREAM 32.)))
299 (COND ((OR (AND (MEMQ X '($PRIMARY $TRUE))
300 (NOT (= PACK 13.)))
301 (AND (MEMQ X '($SECONDARY $TRUE))
302 (= PACK 13.))
303 (EQUAL PACK X))
304 (SETQ DSKUSE (+ DSKUSE AMOUNT))))))))))
306 ;;; DISKUSE
307 ;;; Returns the amount of disk space a user is taking up (in blocks)
308 ;;; as a fixnum times the symbol BLOCKS. Takes args like FULLDISKUSE.
310 (DEFUN $DISKUSE FEXPR (X)
311 (MTIMES-BLOCKS
312 (APPLY '+
313 (MAPCAR (FUNCTION (LAMBDA (X) (CADR (CADDR X))))
314 ((LAMBDA (INFO)
315 (CDDDR (OR (CADDDR INFO)
316 (CADDR INFO))))
317 (APPLY '$FULLDISKUSE X))))))