(setq SCCS-auxfns1 "@(#)auxfns1.l 1.1 10/2/80")
;--- msg - arg1 ... arguments of the form described below
; N - print out a newline (terpr)
; (B n) - print out n blanks
; (P p) - henceforth print on port p
; atom - patom this exactly (no evaluation)
; other - evaluate and patom this expression.
`(progn ,@(msgmake (cdr lis) 'nil))))
(eval-when (eval compile load)
(cond ((null forms) `((drain ,@outport)))
((and (eq 'B thisform) (setq thisform '" ") nil))
((eq 'N thisform) (cons `(terpr ,@outport)
(msgmake (cdr forms) outport)))
((atom thisform) (cons `(patom ',thisform
(msgmake (cdr forms) outport)))
((eq 'P (car thisform)) (msgmake (cdr forms)
((eq 'B (car thisform)) (cons `(printblanks ,@(cdr thisform)
(msgmake (cdr forms) outport)))
(t (cons `(patom ,thisform ,@outport)
(msgmake (cdr forms) outport)))))
; ==============================================
; sets the linelength (actually just varib linel) to the
; if numb is not given, the current line length is returned
; =================================================
(cond ((null form) linel )
((numberp (car form)) (setq linel (car form)))
; ========================================
; returns the number of characters left on the current line
; =======================================
(lambda (port) (- linel (nwritn port))))
((lessp n 0) (cons nil x))
(t (nthcdr (1- n) (cdr x) )))))
;r lambda: (nthrest numb list)
;- returns:the rest of the list beginning at the numb'th element.
;- for convience, (nthrest 0 list) equals (nthrest 1 list)
;- equals list. This is designed to be similar to nthelem
;- which returns the nth element of a list.
(cond ((lessp number 2) list)
(t (nthrest (1- number) (cdr list))))))
;;==============================
; acts much like assq, it looks for val in the cdr of elements of
; the alist and returns the element if found.
; fix this when the compiler works
(eval-when nil (def assqr
(do ((al alist (cdr al)))
(cond ((eq val (cdar al)) (return (car al))))))))
; (listp 'x) is t if x is a non-atom or nil
(def listp (lambda (val) (or (dtpr val) (null val))))
;--- memcar - VAL : lispval
; returns t if VAL found as the car of a top level element.
;temporarily turn this off till the compiler can handle it.
(eval-when nil (def memcar
(cond ((equal (caar ll) a) (return (cdar ll))))))))
; =================================
; the list listl is searched for a list
; with cdr equal to val. if found, the
; car of that list is returned.
; ==================================
;fix this when compiler works ok
(eval-when nil (def memcdr
(cond ((equal (cdar ll) a) (return (caar l))))))))
;this looks like funcall, so we will just use it
(eval (cons (eval (car $x$)) (cdr $x$)))))
(putd 'apply* (getd 'funcall))
; =======================================
; pretty printer top level routine pp
; calling form- (pp arg1 arg2 ... argn)
; the args may be names of functions, atoms with associated values
; an atom - it is assumed to be a function name, if there is no
; function property associated with it,then it is assumed
; to be an atom with a value
; (P port)- port is the output port where the results of the
; pretty printing will be sent.
; poport is the default if no (P port) is given.
; (F fname)- fname is a file name to write the results in
; (A atmname) - means, treat this as an atom with a value, dont
; check if it is the name of a function.
(declare (special $outport$ $fileopen$ ))
; printret is like print yet it returns the value printed, this is used
`(progn (print ,@(cdr $l$)) ,(cadr $l$))))
(prog ($outport$ $cur$ $fileopen$ $prl$ $atm$ funcdef)
(setq $outport$ poport) ; default port
; check if more to do, if not close output file if it is
toploop (cond ((null (setq $cur$ (car $xlist$)))
(cond ((equal 'P (car $cur$)) ; specifying a port
(condclosefile) ; close file if open
(setq $outport$ (eval (cadr $cur$))))
((equal 'F (car $cur$)) ; specifying a file
(condclosefile) ; close file if open
(setq $outport$ (outfile (cadr $cur$))
((equal 'A (car $cur$)) ; declaring atomness
(setq $cur$ (cadr $cur$))
((eq 'V (car $cur$)) ; print value only
(setq $cur$ (cadr $cur$))
(t (msg N "bad arg to pp: " (or $cur$))))
midstuff ; process the atom or function
(setq $prl$ (eval $cur$)))
((or $atm$ (null (getd $cur$))) ; check if is atom
(cond ((boundp $cur$) ; yes, see if bound
(setq $prl$ (list 'setq $cur$ (list 'quote
(t (msg N "pp: atom " (or $cur$) " is unbound")
((bcdp (setq funcdef (getd $cur$))) ; is a fcn, see if bcd
(msg N "pp: function " (or $cur$) " is machine coded (bcd) ")
(setq $prl$ (list 'def $cur$ (get $cur$ 'original)))))
(t (setq $prl$ (list 'def $cur$ funcdef))))
(setq $atm$ nil) ; clear flag
botloop (setq $xlist$ (cdr $xlist$))
(setq $fileopen$ nil)))))
; these routines are meant to be used by pp but since
; some people insist on using them we will set $outport$ to nil
(cond ((not (boundp '$outport$)) (setq $outport$ poport)))
(lessp (+ m (flatc l (charcnt $outport$)))
(return (printret l $outport$)))
(cond ((member (car l) '(lambda nlambda))
(setq f (equal (printret (car l) $outport$) 'prog))
(cond ((cdr (setq l (cdr l)))
(cond ((or (null h) (atom (cadr l)))
(cond ((null (setq l (cdr l))) (1+ m))
((atom l) (setq n nil) (plus 4 m (pntlen l)))
(return (printret l $outport$)))))))
(def $dinc (lambda () (- (linelength $outport$) (charcnt $outport$))))
(cond ((greaterp (setq n (- n (nwritn $outport$))) 0)
(patom '" " $outport$))))))
; ========================================
; returns the number of characters left on the current line
; =======================================
(lambda (port) (- linel (nwritn port))))
(def $patom1 (lambda (x) (patom x $outport$)))