This function looks at the first character of a line and returns a symbol describing what kind of line it is. The return value will be one of:
'non-trans: Not a transaction record;
empty, a page header, or other non-encounter line.
'lost-destroyed: Lost or destroyed
'short-head: An encounter line with a
three-character head: unbanded or new band.
'short-recap: A recap without the
r encounter code; the head is nine
'long-head: A recap or long-new line;
the head is ten characters.
Here's the prologue:
;; - - - i b p - c l a s s i f y - l i n e - - - (defun ibp-classify-line (beg end) "Examines the given line and returns a symbol describing its type. Return values: 'non-trans Not a transaction record (empty, @, or #) 'lost-destroyed Lost or destroyed band transaction 'short-head Transaction with 3-character head: u or n 'short-recap Recap with no prefix, 9-character head 'long-head Transaction with 10-character head: r or g ----------------------------------------------------------------"
First we start a
let scope, and within
that scope, define a variable
containing the text of the line.
(let ((line-text (buffer-substring beg end)))
If the line is empty, it's a non-transaction line, and we are done.
(if (string= line-text "") 'non-trans
Now that we know there's at least one character on the
line, look at it, start another
scope, and set variable
prefix to that
(let ((prefix (string-to-char (substring line-text 0 1))))
The classification of the line type is done in a
cond, which contains a series of tests, each
with a corresponding result. For example, the second
line here returns the
prefix is equal to the character
n. The expression “
?n” means the character “
(cond ((= prefix ?n) 'short-head) ;; New band (short form) ((= prefix ?u) 'short-head) ;; Unbanded
If the first character is a space, this is a recap line without the encounter code.
((= prefix ? ) 'short-recap) ;; Short recaps start w/space
The next case is somewhat more complex. A short recap line can start with any character that can legally occur in a band number. This includes digits and question mark. (Letters can also occur in band numbers, but never as the first character.)
((and (<= ?0 prefix) ;; ...or a digit (<= prefix ?9)) 'short-recap) ((= prefix ??) ;; ...or a question mark 'short-recap)
The remaining line types are straightforwardly related to encounter codes.
((= prefix ?r) 'long-head) ;; Recap with 'r' prefix ((= prefix ?c) 'long-head) ;; Recap, changed band ((= prefix ?a) 'long-head) ;; Recap, double-banded ((= prefix ?g) 'long-head) ;; New band (long form) ((= prefix ?l) 'lost-destroyed) ;; Lost band ((= prefix ?d) 'lost-destroyed) ;; Destroyed band
If all the above conditions fail, we'll just call it a non-transaction line.