The following scsh code (42 lines) produces the output later in this
note. I had to fix up scsh-interfaces.scm to actually export
make-string-input-port as the documentation claims (that's the bug). This
is about a factor of 5 slower than mh's folders command from which I've
snipped the following C code. Considering how ridiculously bummed the C
code is scsh isn't too bad. I should probably write a little scheme version
of this and see how it goes. Thoughts?
--Bri
----------------------------------------------------------------------
m_atoi (str)
register char *str;
{
register int i;
register char *cp;
i = 0;
cp = str;
#ifdef LOCALE
while (isdigit(*cp)) {
i *= 10;
i += *cp++ - '0';
}
#else
while (*cp) {
if (*cp < '0' || *cp > '9')
return 0;
i *= 10;
i += *cp++ - '0';
}
#endif
return i;
}
----------------------------------------------------------------------
#!/home/fir/local/bin/scsh -s
!#
(define (mh-profile)
(let ((profile-port
(open-file (string-append (getenv "HOME") "/.mh_profile") open/read))
(key-rgx (make-regexp "^(.*):[ ](.*)$")))
(let ((prof-lines (port->string-list profile-port))
(helper
(lambda (s)
(cond ((string-match key-rgx s) =>
(lambda (m)
(cons (match:substring m 1)
(match:substring m 2))))
(else s)))))
(close-input-port profile-port)
(map helper prof-lines))))
(define (mail-directory)
(string-append home-directory "/" (cdr (assoc "Path" *mh-prof*))))
(define (mh-folder-names)
(with-cwd (mail-directory) (file-match "." #f file-directory?)))
(define (mh-folder-stats fname)
(with-cwd fname
(let ((msg-list (file-match "." #f "^[0-9]+$")))
(let ((num-list
(map
(lambda (msg-num)
(read (make-string-input-port msg-num)))
msg-list)))
(cond ((not (null? num-list))
(format #t "~&~A \thas ~d messages \t(~d-~d)~%"
fname (length num-list) (apply min num-list)
(apply max num-list)))
(else
(format #t "~&~A has no messages~%" fname)))))))
(define (mh-folders)
(let ((fnames (mh-folder-names)))
(with-cwd (mail-directory)
(map mh-folder-stats fnames))
(values)
))
(define *mh-prof* (mh-profile))
(mh-folders)
----------------------------------------------------------------------
News has 96 messages (1-96)
bgess has 135 messages (1-135)
bpm has 249 messages (1-249)
chit-chat has 36 messages (1-36)
clisp has 40 messages (1-40)
compilers has 14 messages (1-14)
cs270 has 17 messages (1-17)
csmsgs has 105 messages (1-105)
ensemble has no messages
funky has no messages
funky-music has 651 messages (1-651)
funny has 9 messages (1-9)
ilisp has 38 messages (1-38)
inbox has 996 messages (1-1006)
junk has 3 messages (1-3)
multi-media has 24 messages (1-24)
net-cool has 33 messages (1-33)
outbox has 192 messages (2-331)
posts has 2 messages (1-2)
rush has no messages
scheme has 5 messages (1-5)
supercite has 2 messages (1-2)
sww has 129 messages (1-129)
urls has 26 messages (1-26)
----------------------------------------------------------------------
|