home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume11
/
test.el
/
part01
/
tst-equal.el
< prev
next >
Wrap
Lisp/Scheme
|
1987-09-08
|
32KB
|
1,155 lines
;;; tst-equal.el -- A number of definitions of equality
;;; Lorri Menard, Wang Institute of Graduate Studies
;;; Don Zaremba, Wang Institute of Graduate Studies
;;; Copyright 1987 Wang Institute of Graduate Studies
;;;
(provide 'tst-equal)
(defvar tst-equ-log-all-compares "t"
"* If not nil then all comparisons are logged into the buffer
*equal-log*."
)
(defvar tst-equ-max-line-diffs "15"
"* Maximum number of different lines to log when comparing
buffer contents line-by-line. "
)
(defvar tst-equ-state-functions '(tst-equ-session
tst-equ-buffers
tst-equ-processes
tst-equ-windows)
"* A list of functions to be executed when comparing objects
of type state."
)
(defvar tst-equ-buff-state-functions '(tst-equ-point
tst-equ-mark
tst-equ-contents
tst-equ-modified
tst-equ-file
tst-equ-local-vars)
"* A list of functions to be executed when comparing objects
of type buffer-state."
)
(defconst tst-equ-indent 3)
(defmacro tst-equ-level1 ()
(insert "*") (indent-to tst-equ-indent))
(defmacro tst-equ-level2 ()
(insert "**") (indent-to (* tst-equ-indent 2)))
(defmacro tst-equ-level3 ()
(insert "***") (indent-to (* tst-equ-indent 3)))
(defmacro tst-equ-level4 ()
(insert "****") (indent-to (* tst-equ-indent 4)))
(defmacro tst-equ-level5 ()
(insert "*****") (indent-to (* tst-equ-indent 5)))
(defmacro tst-equ-level6 ()
(insert "******") (indent-to (* tst-equ-indent 6)))
(defmacro tst-equ-level7 ()
(insert "*******") (indent-to (* tst-equ-indent 7)))
(defmacro tst-equ-level8 ()
(insert "********") (indent-to (* tst-equ-indent 8)))
(defmacro tst-equ-level9 ()
(insert "*********") (indent-to (* tst-equ-indent 9)))
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; A number of equality testing functions follow. Each is of the
; form tst-equ-state-component (state1 state2). Each compares a particular
; component from the two states and returns t if equal, else nil.
; As a side effect the buffer *equal-log* is updated with the results
; of the comparison
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-state (tst-equ-state1 tst-equ-state2 name)
"Compares for equality the complete state of a pair of sessions.
The two parameters STATE1 and STATE2 must be complete states
as returned by tst-reg-capture-state. The results of the comparison
are written into buffer *equal-log*. NAME is used to identify the test.
Four major components are compared: session, buffers, windows, and
processes. "
(interactive "XState variable 1:
XState variable 2:
sName of this test:")
(let (ss-fun-vector function-name tst-equ-result tst-equ-startpoint temppoint)
(message "Comparing states...")
(setq ss-fun-vector tst-equ-state-functions)
(setq tst-equ-result t); let's be optomistic
; set up the log buffer
(get-buffer-create "*equal-log*")
(set-buffer "*equal-log*")
(outline-mode)
(tst-equ-level1)
(setq tst-equ-startpoint (point)) ;save "here"
(insert "State comparison: " name)
(newline)
(newline)
(while ss-fun-vector
(progn
(setq function-name (car ss-fun-vector))
(setq ss-fun-vector (cdr ss-fun-vector))
(newline)
;;; (insert " " (prin1-to-string function-name))
(newline)
(if (not (funcall function-name tst-equ-state1 tst-equ-state2))
(setq tst-equ-result nil); set return value if failed
); fi
); ngrop
); elihw
; if we failed and a hook exist then run iot
(if (and (not tst-equ-result) 'tst-equ-state-hook)
(run-hooks 'tst-equ-state-hook))
(if (not tst-equ-result)
(progn
(setq temppoint (point))
(goto-char tst-equ-startpoint)
(insert "?")
(goto-char (1+ temppoint))
); ngorp
);fi
(message "Comparing states... done")
tst-equ-result
); tel
); nufed tst-equ-state
(defun tst-equ-session (state1 state2)
"Compares the session components from two states. The
two parameters STATE1 and STATE2 must be complete states
as returned by tst-reg-capture-state. The session components
include: global-bound-syms. "
(interactive "P")
(let (sess1 sess2 syms1 syms2 ss-startpoint ss-gs-startpoint temppoint el1 el2)
(message "Comparing state of sessions...")
(goto-char (point-max)) ; .. of output buffer
(tst-equ-level2)
(setq ss-startpoint (point))
(insert "Sessions state")
(newline)
(setq sess1 (cadr (assoc 'session state1)))
(setq sess2 (cadr (assoc 'session state2)))
(tst-equ-level3)
(setq ss-gs-startpoint (point))
(insert "Global symbols")
(newline)
(setq syms1 (cadr (assoc 'global-bound-syms sess1)))
(setq syms2 (cadr (assoc 'global-bound-syms sess2)))
(if (not (setq tst-equ-result (equal syms1 syms2)))
(progn
(while (and syms1 syms2)
(setq el1 (car syms1))
(setq syms1 (cdr syms1))
(setq el2 (assoc (car el1) syms2))
;; (debug "nil" el1 el2)
(if el2
(setq syms2 (delq el2 syms2))
;; (list 'setq syms2 (list 'delq (list 'assoc (car el1) syms2)
;; syms2))
(progn ;else ..
(indent-to (* tst-equ-indent 4))
(insert "?")
(insert (prin1-to-string (car el1)) " not found in second state")
(newline)
); ngorp
); fi
(tst-equ-diff-element el1 el2)
); wlihw
(if syms1
(progn
(while syms1
(setq el1 (car syms1))
(setq syms1 (cdr syms1))
(indent-to (* tst-equ-indent 4))
(insert "?")
(insert (prin1-to-string (car el1)) " not found in second state")
(newline)
); elihw
); ngorp
); fi
(if syms2
(progn
(while syms2
(setq el2 (car syms2))
(setq syms2 (cdr syms2))
(indent-to (* tst-equ-indent 4))
(insert "?")
(insert (prin1-to-string (car el2)) " not found in first state")
(newline)
); elihw
);ngorp
); fi
); ngorp
; else .. nevermind.
); fi
(if (not tst-equ-result)
(progn
(setq temppoint (point))
(goto-char ss-startpoint)
(insert "?")
; if ever there are more things in a session, these two lines need to
; be separate.
(goto-char ss-gs-startpoint)
(insert "?")
;
(goto-char (1+ temppoint))
);
); fi
tst-equ-result
); tel
)
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-buffers (tst-equ-buffers1 tst-equ-buffers2)
"Compares the buffers components from two states. The
two parameters STATE1 and STATE2 must be complete states
as returned by tst-reg-capture-state. Compares each buffer for
equality with its corresponding buffer (by name) in the other
state. tst-equ-buffer-state is called for each pair of buffers. "
(interactive "P")
; Local Variables
(let (buffers1 buffers2 buff1 buff-name buff2 tst-equ-result buf1names
bs-startpoint temppoint)
(message "Comparing state of buffers...")
(setq tst-equ-result t)
(setq buffers1 (cadr (assoc 'buffers tst-equ-buffers1))); get the first value
(setq buffers2 (cadr (assoc 'buffers tst-equ-buffers2))); get the second value
; set up the log buffer
(goto-char (point-max))
(tst-equ-level2)
(setq bs-startpoint (point))
(insert "Buffers state")
(newline)
(while buffers1
(progn
(setq buff1 (car buffers1))
(setq buffers1 (cdr buffers1))
; get the name of the 1st buffer and use it to find the second
(setq buff-name (cadr (assoc 'buf-state-name buff1)))
(setq buf1names (cons buff-name buf1names))
; create a log entry for this buffer
; now locate the second buffer
(setq buff2 (tst-equ-find-buffer-with-name tst-equ-buffers2 buff-name))
(if (not buff2)
(progn
(newline)
(indent-to (* tst-equ-indent 2))
(insert "?")
(insert buff-name " not found in second state")
(newline)
(setq tst-equ-result nil)
); ngorp
; else
(progn
; now compare them and set tst-equ-result
(if (not (tst-equ-buffer-state buff1 buff2))
(setq tst-equ-result nil)
) ; fi
) ; ngorp
); fi
); ngrop
); elihw
;;; now that we have checked for everything from the first state,
;;; want to see if there are any buffers in the second state that are
;;; not in the first one. Remember the list "buf1names" that was built
;;; during the first while loop? Well, we'll member this list instead
;;; of "tst-equ-find-buffer-with-name"ing it, because this seems more efficient.
(while buffers2
(progn
(setq buff2 (car buffers2))
(setq buffers2 (cdr buffers2))
(setq buff-name (cadr (assoc 'buf-state-name buff2)))
(if (not (member buff-name buf1names))
(progn
(newline)
(indent-to (* tst-equ-indent 4))
(insert "?")
(insert buff-name " not found in first state")
(newline)
(setq tst-equ-result nil)
); ngorp
); fi
); ngorp
); elihw
; if we failed and a hook exist then run it
(if (and (not tst-equ-result) 'tst-equ-buffers-hook)
(run-hooks 'tst-equ-buffers-hook))
(if (not tst-equ-result)
(progn
(setq temppoint (point))
(goto-char bs-startpoint)
(insert "?")
(goto-char (1+ temppoint))
); nprog
); fi
tst-equ-result
) ; let
) ; defun tst-equ-buffers
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-windows (tst-equ-windows1 tst-equ-windows2)
"Compares the window components from two states. The
two parameters STATE1 and STATE2 must be complete states
as returned by tst-reg-capture-state."
(interactive "P")
; Local Variables
(let (window1 window2 tst-equ-result start-point saved-point)
(message "Comparing state of windows ...")
(setq window1 (cadr (assoc 'windows tst-equ-windows1)))
(setq window2 (cadr (assoc 'windows tst-equ-windows2)))
(setq tst-equ-result t)
(tst-equ-level2)
(setq start-point (point))
(insert "Window state")
(newline)
(setq tst-equ-result (tst-equ-wstates window1 window2 ))
; if we failed and a hook exist then run iot
(if (and (not tst-equ-result) 'tst-equ-windows-hook)
(run-hooks 'tst-equ-windows-hook))
; if we still fail the out a ?
(if (not tst-equ-result)
(progn
(setq saved-point (point))
(goto-char start-point)
(insert "?")
(goto-char (1+ saved-point))
); ngorp
); if
tst-equ-result
) ; let
); defun
(defun tst-equ-wstates (wstate1 wstate2)
"Check the equality of two windows"
(let (sibling leftc-edges start-point tst-equ-result tresult obj1 obj2 assoc-list
label-list component label childs1 childs2 cl1 cl2 cr1 cr2)
(setq tst-equ-result t)
; check for spilt windows
(if (assoc 'split wstate1)
(progn
(setq childs1 (cadr (assoc 'children wstate1)))
(setq childs2 (cadr (assoc 'children wstate2)))
; Save the children
(setq cl1 (car childs1))
(setq cl2 (car childs2))
(setq cr1 (car (cdr childs1)))
(setq cr2 (car (cdr childs2)))
; Now do the comparisons
(setq tresult (tst-equ-wstates cl1 cl2))
(setq tst-equ-result (and tresult (tst-equ-wstates cr1 cr2)))
); progn
); if split
; else not spilt so compare windows
(progn
; first set up the assoc and label list
(setq assoc-list '(window-edges window-buffer window-start window-point
current-window))
(setq label-list '(edges buffer start point current))
; setup *equal-log* buffer
(newline)
(tst-equ-level3)
(setq start-point (point))
(insert "window")
(newline)
; loop thru the full assoc list
(while assoc-list
(progn
(setq component (car assoc-list))
(setq assoc-list (cdr assoc-list))
(setq label (car label-list))
(setq label-list (cdr label-list))
; now get the two objects and compare them
(tst-equ-level4)
(setq obj1 (cadr (assoc component wstate1)))
(setq obj2 (cadr (assoc component wstate2)))
(setq tresult (equal obj1 obj2))
(if (not tresult)
(progn
(insert "?")
(setq tst-equ-result nil)
); ngorp
; else
(insert " ")
); if
(insert (prin1-to-string component) ": ")
(tst-equ-log-diff tresult obj1 obj2)
); progn after the while
); while assoc-list
tst-equ-result
); progn
); let
); defun
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-processes (state1 state2)
"Compares the process components from two states. The
two parameters STATE1 and STATE2 must be complete states
as returned by tst-reg-capture-state. The session components
include: command exit-status filter name sentinel status. "
(interactive "P")
; Local Variables
(let (proc1 proc2 p1 p2 c1 c2 tst-equ-result proc-list component start-point
saved-point)
(message "Comparing state of processes...")
(setq proc-list '(command exit-status filter name sentinel status))
(setq proc1 (cadr (assoc 'processes state1)))
(setq proc2 (cadr (assoc 'processes state2)))
(setq tst-equ-result t)
(tst-equ-level2)
(setq start-point (point))
(insert "Processes state")
(newline)
(while proc1
(progn
(setq p1 (car proc1))
(setq proc1 (cdr proc1))
(setq p2 (car proc2))
(setq proc2 (cdr proc2))
(setq proc-list '(command exit-status filter name
sentinel status process-mark))
(newline)
(while proc-list
(progn
(setq component (car proc-list))
(setq proc-list (cdr proc-list))
(setq c1 (cadr (assoc component p1)))
(setq c2 (cadr (assoc component p2)))
(setq cresult (equal c1 c2))
(tst-equ-level3)
(if (not cresult)
(progn
(insert "?")
(setq tst-equ-result nil)
); ngorp
; else
(insert " ")
); fi
(insert (prin1-to-string component) ": ")
(tst-equ-log-diff cresult c1 c2)
); ngorp
); elihw
); ngorp
); while proc1
; if we failed and a hook exist then run iot
(if (and (not tst-equ-result) 'tst-equ-processes-hook)
(run-hooks 'tst-equ-processes-hook))
(if (not tst-equ-result)
(progn
(setq saved-point (point))
(goto-char start-point)
(insert "?")
(goto-char (1+ saved-point))
); ngorp
); fi
tst-equ-result
); tel
); nufed
(defun tst-equ-buffer-state (buff-state1 buff-state2)
"Compares two buffers for equality. The two parameters
BUFFER1 and BUFFER2 must be buffer states as returned
by tst-equ-find-buffer. The following components are
compared by default: point mark contents file local-variables.
This can be modified by changing the elemetns in the variable
tst-equ-buff-state-functions. "
(interactive "P")
; Variables
(let (bs-fun-vector function-name tst-equ-result saved-beg msg
fname
saved-end tst-equ-buffer-state-startpoint)
(get-buffer-create "*equal-log*")
(set-buffer "*equal-log*")
(outline-mode)
(goto-char (point-max))
(newline)
(tst-equ-level2)
(setq tst-equ-buffer-state-startpoint (point))
(insert "Comparison of buffers named: " )
(insert (cadr (assoc 'buf-state-name buff-state1)))
(newline)
(setq msg (concat "Comparing state of buffer "
(cadr (assoc 'buf-state-name buff-state1))))
(message msg)
(setq bs-fun-vector tst-equ-buff-state-functions)
(setq tst-equ-result t) ; let's be optomistic
(while bs-fun-vector
(progn
(setq function-name (car bs-fun-vector))
(setq bs-fun-vector (cdr bs-fun-vector))
(tst-equ-level3)
(setq saved-beg (point))
(setq fname (prin1-to-string function-name))
(setq fname (substring fname (match-end
(string-match "tst-equ-" fname)) nil))
(insert fname ": ")
; (newline)
(if (not (funcall function-name buff-state1 buff-state2))
(progn
(setq tst-equ-result nil) ; set return value if failed
(setq saved-end (point))
(goto-char saved-beg)
(insert "?")
(goto-char (1+ saved-end))
); ngorp
); fi
); progn
); while
(if (not tst-equ-result)
(progn
(setq temppoint (point))
(goto-char tst-equ-buffer-state-startpoint)
(insert "?")
(goto-char (1+ temppoint))
); ngorp
); fi
tst-equ-result
) ; let
) ; defun tst-equ-buffer-state
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-contents (buff-state1 buff-state2)
"Compares the contents component from two buffer states. "
(interactive "P")
; Local Variables
(let (tst-equ-contents1 tst-equ-contents2 tst-equ-result)
(setq tst-equ-contents1 (cadr (assoc 'buf-state-contents buff-state1)))
(setq tst-equ-contents2 (cadr (assoc 'buf-state-contents buff-state2)))
(setq tst-equ-result (string-equal tst-equ-contents1 tst-equ-contents2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-contents-hook)
(run-hooks 'tst-equ-contents-hook))
(if (not tst-equ-result)
(progn
(indent-to (* tst-equ-indent 4))
(insert "contents not equal")
); ngorp
(progn
(indent-to (* tst-equ-indent 4))
(insert "contents equal")
); ngorp
); fi
(newline)
tst-equ-result
) ; let
) ; defun tst-equ-contents
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-contents-region (buff-state1 buff-state2)
"Compares the contents component from two buffer states between
point and mark. "
(interactive "P")
; Local Variables
(let (tst-equ-contents-region1 tst-equ-contents-region2
buf-point buf-mark tst-equ-result)
(setq tst-equ-contents-region1 (cadr (assoc 'buf-state-contents buff-state1)))
(setq buf-point (cadr (assoc 'buf-state-point buff-state1)))
(setq buf-mark (cadr (assoc 'buf-state-mark buff-state1)))
(setq tst-equ-contents-region1
(substring tst-equ-contents-region1 buf-point buf-mark))
(setq tst-equ-contents-region2 (cadr (assoc 'buf-state-contents buff-state2)))
(setq buf-point (cadr (assoc 'buf-state-point buff-state2)))
(setq buf-mark (cadr (assoc 'buf-state-mark buff-state2)))
(setq tst-equ-contents-region2
(substring tst-equ-contents-region2 buf-point buf-mark))
(setq tst-equ-result (string-equal
tst-equ-contents-region1 tst-equ-contents-region2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-contents-region-hook)
(run-hooks 'tst-equ-contents-region-hook))
(if (not tst-equ-result)
(progn
(indent-to (* tst-equ-indent 4))
(insert "contents not equal")
); ngorp
(progn
(indent-to (* tst-equ-indent 4))
(insert "contents equal")
); ngorp
); fi
(newline)
tst-equ-result
) ; let
) ; defun tst-equ-contents-region
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-contents-line (buff-state1 buff-state2)
"Compares the contents component from two buffer states. Comparison
is performed line by line. Will run a hook named 'tst-equ-line-hook
that can access the strings tst-equ-line1 and tst-equ-line2. Hook is
called only if the comparison fails but can set tst-equ-result to t if
it wants."
(interactive "P")
; Local Variables
(let (c1 c2 tst-equ-line1 tst-equ-line2 tst-equ-result more1 more2
start1 end1 start2 end2 final-result found-so-far)
(setq c1 (cadr (assoc 'buf-state-contents buff-state1))); get the first value
(setq c2 (cadr (assoc 'buf-state-contents buff-state2))); get the second value
(setq final-result t more1 t more2 t)
(setq start1 0 start2 0 found-so-far 0); starting index in strings
(while (and more1 more2)
(progn
(setq end1 (string-match "\n" c1 start1))
(if (not end1)
(setq more1 nil); we hit end-of-contents
; else
(progn
(setq tst-equ-line1 (substring c1 start1 end1 ))
(setq start1 (match-end 0))
); ngorp
); fi
(setq end2 (string-match "\n" c2 start2))
(if (not end2)
(setq more2 nil); we hit end-of-contents
; else
(progn
(setq tst-equ-line2 (substring c2 start2 end2 ))
(setq start2 (match-end 0))
); ngorp
); fi
; now do the comparison if we have two lines
(if (and more1 more2)
(progn
(setq tst-equ-result (string-equal tst-equ-line1 tst-equ-line2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-line-hook)
(run-hooks 'tst-equ-line-hook))
; but test again in case hook modified result
(if (not tst-equ-result)
(progn
(setq final-result nil)
(tst-equ-log-diff-line tst-equ-line1 tst-equ-line2)
(setq found-so-far (+ 1 found-so-far))
(if (>= found-so-far tst-equ-max-line-diffs)
(progn
; i want to just get out of here.
(setq more1 nil)
(setq more2 nil) ;fake 'em into leaving
); ngorp
); fi
); ngorp
); fi
); ngorp
); fi
); ngorp
); elihw
final-result
) ; let
) ; defun tst-equ-contents-line
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-point (buff-state1 buff-state2)
"Compares the point component from two buffer states. "
(interactive "P")
; Local Variables
(let (tst-equ-point1 tst-equ-point2 tst-equ-result)
(setq tst-equ-point1 (cadr (assoc 'buf-state-point buff-state1)))
(setq tst-equ-point2 (cadr (assoc 'buf-state-point buff-state2)))
(setq tst-equ-result (equal tst-equ-point1 tst-equ-point2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-point-hook)
(run-hooks 'tst-equ-point-hook))
(tst-equ-log-diff tst-equ-result (int-to-string tst-equ-point1)
(int-to-string tst-equ-point2))
tst-equ-result
) ; let
) ; defun tst-equ-point
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-mark (buff-state1 buff-state2)
"Compares the mark component from two buffer states. "
(interactive "P")
; Local Variables
(let (tst-equ-mark1 tst-equ-mark2 tst-equ-result)
(setq tst-equ-mark1 (cadr (assoc 'buf-state-mark buff-state1)))
(setq tst-equ-mark2 (cadr (assoc 'buf-state-mark buff-state2)))
(setq tst-equ-result (equal tst-equ-mark1 tst-equ-mark2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-mark-hook)
(run-hooks 'tst-equ-mark-hook))
(tst-equ-log-diff tst-equ-result tst-equ-mark1 tst-equ-mark2)
tst-equ-result
) ; let
) ; defun tst-equ-mark
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-modified (buff-state1 buff-state2)
"Compares the modified component from two buffer states. "
(interactive "P")
; Local Variables
(let (tst-equ-modified1 tst-equ-modified2 tst-equ-result)
(setq tst-equ-modified1 (cadr (assoc 'buf-state-modified buff-state1)))
(setq tst-equ-modified2 (cadr (assoc 'buf-state-modified buff-state2)))
(setq tst-equ-result (equal tst-equ-modified1 tst-equ-modified2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-modified-hook)
(run-hooks 'tst-equ-modified-hook))
(tst-equ-log-diff tst-equ-result tst-equ-modified1 tst-equ-modified2)
tst-equ-result
) ; let
) ; defun tst-equ-modified
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-file (buff-state1 buff-state2)
"Compares the file component from two buffer states. "
(interactive "P")
; Local Variables
(let (tst-equ-file1 tst-equ-file2 tst-equ-result)
(setq tst-equ-file1 (cadr (assoc 'buf-state-file buff-state1))); get the first value
(setq tst-equ-file2 (cadr (assoc 'buf-state-file buff-state2))); get the second value
(setq tst-equ-result (equal tst-equ-file1 tst-equ-file2))
; if a hook exist and we failed the compare then run the hook ..
(if (and (not tst-equ-result) 'tst-equ-file-hook)
(run-hooks 'tst-equ-file-hook))
(tst-equ-log-diff tst-equ-result tst-equ-file1 tst-equ-file2)
tst-equ-result
) ; let
) ; defun tst-equ-file
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-diff-element (el1 el2)
" Logs differences between the two elements based on the type of
element that it is. (keymap, vector, string, list)"
(let ()
(cond ((keymapp (cdr el1)) (tst-equ-log-keymap el1 el2))
((syntax-table-p (cdr el1)) (tst-equ-log-syntable el1 el2))
((stringp (cdr el1)) (tst-equ-log-string el1 el2))
((atom (cdr el1)) (tst-equ-log-atom el1 el2))
((arrayp (cdr el1)) (tst-equ-log-array el1 el2))
(t (tst-equ-log-fubar el1 el2))
); dnoc
); tel
); defun tst-equ-diff-element
(defun tst-equ-log-fubar (el1 el2)
" Generic equal-comparer for elements of a symbol"
(let ()
(if (not (equal el1 el2))
(progn
; (debug nil "in fubar" el1 el2)
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car el1)))
(if (cdr el1)
(insert ": "(prin1-to-string (cdr el1)) " "
(prin1-to-string (cdr el2)))
); fi
(newline)
); ngorp
); fi
); tel
); defun tst-equ-log-fubar
(defun tst-equ-log-string (el1 el2)
(let ()
(if (not (equal el1 el2))
(progn
; (debug nil "In string" (car el1))
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car el1)))
(newline)
); ngorp
); fi
); tel
); defun tst-equ-log-string
(defun tst-equ-log-atom (el1 el2)
(let ()
(if (not (equal el1 el2))
(progn
; (debug nil "in atom" el1 el2)
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car el1))
" " (prin1-to-string (cdr el1))
" " (prin1-to-string (cdr el2)))
(newline)
); ngorp
); fi
); tel
); defun tst-equ-log-atom
(defun tst-equ-log-syntable (a1 a2)
" Outputs the differences between two syntax tables in the form:
element_number : value1 value2"
(let (e1 e2 index)
; (debug nil "In syntable" (car el1))
(if (not (equal a1 a2))
(while (not (= index 256))
(setq e1 (aref a1 index))
(setq e2 (aref a2 index))
(if (not (equal e1 e2))
(progn
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string index) ": "
(prin1-to-string e1) " " (prin1-to-string e2))
(newline)
);ngorp
); fi
(+1 index)
); elihw
); fi
); tel
); defun tst-equ-log-syntable
(defun tst-equ-log-keymap (a1 a2)
" Outputs only the fact that two keymaps do not match. Has the potential
for future enhancements (like, describing which keys don't match"
; (debug nil "in keymap" (car el1))
(if (not (equal a1 a2))
(progn
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car a1)))
); ngorp
);fi
); defun tst-equ-log-keymap
; (let (e1 e2 index)
; (while (not (= index 256))
; (setq e1 (aref a1 index))
; (setq e2 (aref a2 index))
; (if (not (equal e1 e2))
; (progn
; (indent-to (* tst-equ-indent 4))
; (insert (prin1-to-string index) ": "
; (prin1-to-string e1) " " (prin1-to-string e2))
; (newline)
; );ngorp
; ); fi
; (+1 index)
; ); elihw
;
; ); tel
;); defun tst-equ-log-syntable
(defun tst-equ-log-diff (equal-flag v1 v2)
"Logs differences in *equal-log* buffer. "
(let ()
(if (or tst-equ-log-all-compares (not equal-flag))
(progn
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string v1) " " (prin1-to-string v2))
(newline)
); ngorp
);fi
) ; let
) ; defun tst-equ-log-diff
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-log-diff-line (line1 line2)
"Logs differences in *equal-log* buffer. "
(let ()
(goto-char (point-max))
(newline)
(indent-to (* tst-equ-indent 4))
(insert "1: " line1)
(newline)
(indent-to (* tst-equ-indent 4))
(insert "2: " line2)
(newline)
) ; let
) ; defun tst-equ-log-diff-line
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-find-buffer-with-name (state name )
"Return a buff-state of the buffer from STATE with name NAME."
; Variables
(let (buffers buff-state buff-name found)
(setq found nil)
(setq buffers (cadr (assoc 'buffers state)))
(while (not found)
(progn
(setq buff-state (car buffers))
(setq buffers (cdr buffers))
(setq buff-name (cadr (assoc 'buf-state-name buff-state)))
(if (equal buff-name name)
(setq found t)
; else
(progn
(if (not buffers)
(progn
(setq found t)
(setq buff-state nil)
); progn
); fi
); ngrop
); if
); progn
); while
buff-state
) ; let
) ; defun tst-equ-find-buffer-with-name
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(defun tst-equ-named-buff-states (state1 name1 state2 name2)
" Compares, from STATE1, the state of the buffer who's name is
NAME1 with, from STATE2, the state of the buffer who's name
is NAME2. If STATE2 is nil, then a buffer of NAME2 is expected
in STATE1. "
(interactive "P")
; Variables
(let (buff-state-1 buff-state-2)
; first locate the buffers
(setq buff-state-1 (tst-equ-find-buffer-with-name state1 name1))
(if state2
(setq buff-state-2 (tst-equ-find-buffer-with-name state2 name2))
; else
(setq buff-state-2 (tst-equ-find-buffer-with-name state1 name2))
) ; if
(tst-equ-buffer-state buff-state-1 buff-state-2)
) ; let
) ; defun tst-equ-named-buff-states
(defun tst-equ-local-vars (b1 b2)
" Compares the values of the local variables in two buffers and
logs the ones that are different."
(interactive "P")
(let (vars1 vars2 var1 var2 tst-equ-result firsttime)
(setq tst-equ-result t) ;default to "all equal "
(setq firsttime nil) ;still just my first time ...
(setq vars1 (cadr (assoc 'buf-state-local-vars b1)))
(setq vars2 (cadr (assoc 'buf-state-local-vars b2)))
(while vars1 ;go through the b1 vars first.
(setq var1 (car vars1)) ;get the next variable
(setq vars1 (cdr vars1)) ;.. and set the list to the tail
(setq var2 (assoc (car var1) vars2)) ; find this variable in b2
(if var2
(progn
(if (not (equal var1 var2))
(progn
(if (not firsttime)
(progn
(indent-to (* tst-equ-indent 3))
(insert "local variables not equal ")
(newline)
(setq firsttime t)
); ngorp
); fi
(setq tst-equ-result nil)
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car var1))
" " (prin1-to-string (cdr var1))
" " (prin1-to-string (cdr var2)))
(newline)
); ngorp
);fi
); ngorp
; else
(progn
(setq tst-equ-result nil)
(if (not firsttime)
(progn
(insert "?")
(indent-to (* tst-equ-level 3))
(insert "local variables not equal ")
(newline)
(setq firsttime t)
); ngorp
); fi
(indent-to (* tst-equ-level 4))
(insert (prin1-to-string (car var1)) "not found in second buffer ")
(newline)
); ngorp (of else)
); fi [if vars2]
); elihw
(setq vars1 (cadr (assoc 'buf-state-local-vars b1)))
(while vars2
(setq var2 (car vars2)) ;get the next variable
(setq vars2 (cdr vars2)) ;.. and set the list to the tail
(setq var1 (assoc (car var2) vars1))
(if (not var1)
(progn
(setq tst-equ-result nil)
(if (not firsttime)
(progn
(indent-to (* tst-equ-indent 4))
(insert "local variables not equal:")
(newline)
(setq firsttime t)
); ngorp
); fi
(indent-to (* tst-equ-indent 4))
(insert (prin1-to-string (car var2)) " not found in first buffer " )
(newline)
); ngorp (of else)
); fi
); elihw
(if tst-equ-result
(progn
(indent-to (* tst-equ-indent 4))
(insert "local variables are equal ")
(newline)
); ngorp
); fi
tst-equ-result ;return the tst-equ-result
); tel
); defun tst-equ-local-vars