For example, here's the password-file-checker from "The AWK Programming
Language", in AWK.
BEGIN {
FS = ";" }
NF != 7 {
printf("line %d, does not have 7 fields: %s\n", NR, $0)}
$1 ~ /[^A-Za-z0-9]/ {
printf("line %d, nonalphanumeric user id: %s\n", NR, $0)}
$2 == "" {
printf("line %d, no password: %s\n", NR, $0)}
$3 ~ /[^0-9]/ {
printf("line %d, nonnumeric user id: %s\n", NR, $0)}
$4 ~ /[^0-9]/ {
printf("line %d, nonnumeric group id: %s\n", NR, $0)}
$6 !~ /^\// {
printf("line %d, invalid login directory: %s\n", NR, $0)}
And here's the same program written in CLAWK:
(defawk checkpass ()
(BEGIN
(setq *FS* ";"))
((/= *NF* 7)
(format t "~%line ~D, does not have 7 fields: ~S" *NR* $0))
((~ $1 #/[^A-Za-z0-9]/)
(format t "~%line ~D, nonalphanumeric user id: ~S" *NR* $0))
(($== $2 "")
(format t "~%line ~D, no password: ~S" *NR* $0))
((~ $3 #/[^0-9]/)
(format t "~%line ~D, nonnumeric user id: ~S" *NR* $0))
((~ $4 #/[^0-9]/)
(format t "~%line ~D, nonnumeric group id: ~S" *NR* $0))
((!~ $6 #/^\//)
(format t "~%line ~D, invalid login directory: ~S" *NR* $0)) )
The interesting thing about the library, from the CL point of view,
is probably the regex matcher, and the utility library that the AWK
stuff is built on, the match, split, scan, and such, since that's
all available without using the funky defawk macro.
I've been using it on my (sadly) AWK-free lispm, but I've tested it
and it works on clisp and Lispworks 4.2 as well.
I have not checked the code thourougly yet. However, if you do not do
fancy READTABLE tricks, CLAWK will bomb in MCL, since that
implementation uses (or at least it did) #\$ for something pathname
related. This is why the INFIX package uses #I(..) instead of the TeXy $..$.
Cheers
--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.
> I have not checked the code thourougly yet. However, if you do not
> do fancy READTABLE tricks, CLAWK will bomb in MCL, since that
> implementation uses (or at least it did) #\$ for something pathname
> related. This is why the INFIX package uses #I(..) instead of the
> TeXy $..$.
MCL has a readmacro #$, which is used to look up the equivalent of
foreign constants from a database.
Symbols that start with $ should be fine (though the #$ macro creates
symbols whose names start with $, they are all in the CCL package).
John Wiseman