Debian Codegraph @

lab/check-comments.ss

raw
1 #!/usr/bin/env ikarus --r6rs-script
2
3 (import (ikarus))
4
5 (define (suffix? s str)
6 (let ([n1 (string-length s)] [n2 (string-length str)])
7 (and (>= n2 n1)
8 (string=? s (substring str (- n2 n1) n2)))))
9
10 (define (prefix? s str)
11 (let ([n1 (string-length s)] [n2 (string-length str)])
12 (and (>= n2 n1)
13 (string=? s (substring str 0 n1)))))
14
15
16
17
18
19 (define (scheme? str)
20 (ormap (lambda (s) (suffix? s str)) (library-extensions)))
21
22
23 (define (lsr dir)
24 (define (app x) (string-append dir "/" x))
25 (let-values ([(dirs others)
26 (partition file-directory?
27 (directory-list dir))])
28 (apply append
29 (map app (filter scheme? others))
30 (map lsr
31 (map app
32 (filter
33 (lambda (x)
34 (and (not (string=? x ".")) (not (string=? x ".."))))
35 dirs))))))
36
37
38 (define (has-comment? x)
39 (with-input-from-file x
40 (lambda ()
41 (define (S0)
42 (let ([x (read-line)])
43 (cond
44 [(eof-object? x) #f]
45 [(prefix? "#!" x) (S1)]
46 [(prefix? ";;; Copyright" x) #t]
47 [(prefix? ";;;" x) (S1)]
48 [else #f])))
49 (define (S1)
50 (let ([x (read-line)])
51 (cond
52 [(eof-object? x) #f]
53 [(prefix? ";;; Copyright" x) #t]
54 [(prefix? ";;;" x) (S1)]
55 [else #f])))
56 (S0))))
57
58 (define (check-comment x)
59 (unless (has-comment? x)
60 (printf "no comment in ~s\n" x)))
61
62 (for-each check-comment (lsr "."))
63