home *** CD-ROM | disk | FTP | other *** search
- ;;; tst-annotate.el --GnuTest Annotation Package
- ;;; Copyright (c) 1987 Wang Institute of Graduate Studies
-
- ;;; Andy Bliven <bliven@wanginst>
- ;;; and Mike Vilot <vilot@wanginst>
-
- (provide 'tst-annotate)
-
- ;;; ---------------------------------------------------------------------------
- ;;; Private Variables--
-
- (defvar tst-ann-tricorder nil
- "* The Annotation Database. A recursive alist implementing a
- database indexed by line-number and attribute-name. Intended to be
- accessed only through the tst-ann-* functions."
- ) ; defvar tst-ann-tricorder
-
-
- ;;; ---------------------------------------------------------------------------
- ;;; Public Functions--
-
- (defun tst-ann-append (line-id attribute value)
- "Appends VALUE to the list of values for the <LINE-ID ATTRIBUTE> key."
- (let ((oldvalue (tst-ann-get line-id attribute)))
- (if (nlistp oldvalue)
- (error "value must be a list"))
- (tst-ann-put line-id attribute (append oldvalue value))
- ) ; let
- )
-
- (defun tst-ann-format (line-id attribute)
- "Returns a string of format \"LINE-ID: ATTRIBUTE = value\""
- (let ((value (tst-ann-get line-id attribute)))
- (if (null value)
- "" ; return "" for undefined
- ;; else
- (concat
- (prin1-to-string line-id) ": "
- (prin1-to-string attribute) " = "
- (prin1-to-string value)
- ) ; concat
- ) ; if
- ) ; let
- )
-
- (defun tst-ann-format-line (line-id)
- "Returns the concatenation of tst-ann-format for every attribute in LINE-ID."
- (mapconcat
- '(lambda (attr)
- (tst-ann-format line-id attr))
- (tst-ann-get-attributes line-id)
- "\n"
- ) ; concat
- )
-
- (defun tst-ann-get (line-id attribute)
- "Retrieves a value for <LINE-ID ATTRIBUTE> key."
- (tst-alist-get (tst-alist-get tst-ann-tricorder line-id) attribute)
- )
-
- (defun tst-ann-get-attributes (line-id)
- "Returns a list of attributes defined for LINE-ID."
- (mapcar 'car (tst-alist-get tst-ann-tricorder line-id))
- )
-
- (defun tst-ann-get-lines ()
- "Returns a list of lines defined in the anotation database."
- (mapcar 'car tst-ann-tricorder)
- )
-
- (defun tst-ann-get-db ()
- "Get database value."
- tst-ann-tricorder
- )
-
- (defun tst-ann-inc (line-id attribute)
- "Increments the (assumed numeric) value for <LINE-ID ATTRIBUTE> key."
- (let ((value (car (tst-ann-get line-id attribute))))
- (if (not (numberp value))
- (error "value must be numeric"))
- (tst-ann-put line-id attribute (list (1+ value)))
- )
- )
-
- (defun tst-ann-put (line-id attribute value)
- "Associates <LINE-ID ATTRIBUTE> key with VALUE."
- (let ((attr-alist (assoc line-id tst-ann-tricorder)))
- (if (null attr-alist)
- (progn
- (setq tst-ann-tricorder
- (tst-alist-put tst-ann-tricorder line-id nil))
- (setq attr-alist
- (assoc line-id tst-ann-tricorder))
- ) ; progn
- ) ; if
- (setq attr-alist (tst-alist-put attr-alist attribute value))
- value
- ) ; let
- )
-
- (defun tst-ann-remove (line-id)
- "Removes all data associated with LINE-ID from the database."
- (setq tst-ann-tricorder
- (delq tst-ann-tricorder
- (assoc line-id tst-ann-tricorder)))
- )
-
- (defun tst-ann-remove-attribute (line-id attribute)
- "Removes all data associated with both LINE-ID and ATTRIBUTE from the
- database."
- (tst-ann-put line-id attribute nil)
- )
-
- (defun tst-ann-set-db (value)
- "Set database to VALUE (either nil or obtained from tst-ann-get-db)."
- (setq tst-ann-tricorder value)
- )
-
-
- ;;; ---------------------------------------------------------------------------
- ;;; ALIST FUNCTIONS
-
- ;;; This is a collection of functions for operating on association
- ;;; lists (alists).
-
- ;;; SPECIFICATION: Axiomatic specification of type alist
- ;;;
-
- ;;; types--
- ;;; A = association list
- ;;; K = key
- ;;; V = value
-
- ;;; signatures--
- ;;; c pre: -> A "creates a new alist"
- ;;; post: A -> "deletes an alist"
- ;;; c put: A x K x V -> A "associate a value with a key"
- ;;; get: A x K -> V "retrieve the value associated with a key"
- ;;; rem: A x K -> A "remove a key from the list"
- ;;; c app: A x K x V -> A "append a key to the list"
-
- ;;; rules--
- ;;; (post (pre)) = nil "successful termination"
- ;;; (post (put A K1 V)) = (post A)
- ;;; (post (app A K1 V)) = (post A)
- ;;; (get (pre) K) = nil
- ;;; (get (put A K1 V) K2) = (if (= K1 K2) V (get A K2))
- ;;; (get (app A K1 V) K2) = (if (= K1 K2) (append (get A K1) V)
- ;;; (get A K2))
- ;;; (rem (pre) K1) = nil
- ;;; (rem (put A K1 V) K2) = (if (= K1 K2) (rem A K2) (put (rem A K2) K1 V))
- ;;; (rem (app A K1 V) K2) = (if (= K1 K2) (rem A K2) (app (rem A K2) K1 V))
-
- ;;; implementation--
- ;;; an ALIST is represented as a Lisp list, each element of which is a
- ;;; list whose first element is the KEY and the remainder is the VALUE.
-
-
- ;;; ----------------------------------------------------------------------
- ;;; Alist Functions--
-
- (defun tst-alist-get (alist key)
- "generic routine to retrieve from an ALIST the value for KEY."
- (cdr (assoc key alist))
- ) ; defun tst-alist-get
-
- (defun tst-alist-put (alist key value)
- "Enter into ALIST a <KEY VALUE> pair. Returns the revised alist; use
- (setq alist (tst-alist-put alist key value)."
-
- (cond ((assoc key alist) (setcdr (assoc key alist) value) alist)
- (t (tst-alist-app alist key value))
- ) ; cond
- ) ; defun tst-alist-put
-
- (defmacro tst-alist-rem (alist key)
- "Delete from ALIST the element (KEY value)."
- (list 'setq alist (list 'delq (list 'assoc key alist) alist))
- ) ; defmacro
-
- (defun tst-alist-app (alist key value)
- "Append the <KEY VALUE> pair to ALIST. Returns a new alist--
- use (setq alist (tst-alist-app alist key value))."
- (nreverse ; by making the tail the head
- (cons ; after inserting the new item
- (cons key value) ; which is a list
- (nreverse alist) ; placed before the old tail
- ) ; cons
- ) ; nreverse
- ) ; defun tst-alist-app
-
-
- ;;; ---------------------------------------------------------------------------
- ;;; LIST PRETTY-PRINT FUNCTIONS
-
- (defun tst-alist-print (list)
- "Print LIST using prin1 with regular indentation and lots of newlines."
- (interactive "xExpression: ")
- (tst-alist-print-element list (current-column))
- nil
- )
-
- (defun tst-alist-print-element (list indent)
- (cond
- ((atom list) (princ list))
- ((stringp list) (prin1 list))
- ((vectorp list)
- (princ "[")
- (tst-alist-print-interior list (1+ indent))
- (princ "]"))
- ((listp list)
- (princ "(")
- (tst-alist-print-interior list (1+ indent))
- (princ ")"))
- (t (error "what are you trying to print?"))
- )
- (current-column)
- )
-
- (defun tst-alist-print-interior (list indent)
- (let (next)
- (cond
- ((atom list) (tst-alist-print-element list indent))
- ((null (cdr list)) (tst-alist-print-element (car list) indent))
- (t (setq next (tst-alist-print-element (car list) indent))
- (cond
- ((atom (car list)) ; special case for list of atoms
- (princ " ")
- (setq indent (1+ next))
- ) ; (atom (car list))
- (t ; normal case--newline between elements
- (princ "\n")
- (tst-alist-print-spaces indent)
- ) ; t
- ) ; cond
- (tst-alist-print-interior (cdr list) indent)
- ) ; t
- ) ; cond
- ) ; let
- )
-
-
- (defun tst-alist-print-spaces (n)
- (interactive "nColumn:")
- (princ (substring " " 0 n))
- nil
- )
-
- echo shar: "a missing newline was added to 'tst-annotate.el'"
-