-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffall.scm
More file actions
98 lines (88 loc) · 2.54 KB
/
diffall.scm
File metadata and controls
98 lines (88 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env guile \
-e main -s
!#
(use-modules (ice-9 popen)
(ice-9 ftw)
(ice-9 rdelim)
(srfi srfi-1)
(srfi srfi-26))
(define (interleave lst-a lst-b)
(map cons lst-a lst-b))
(define (but-last lst)
(if (> 2 (length lst))
'()
(cons (car lst) (but-last (cdr lst)))))
(define (pair-suc lst)
(if (null? lst)
'()
(interleave (but-last lst) (cdr lst))))
(define (all-files dirs)
(apply
(cut lset-union string=? <...>)
(map scandir
(filter file-exists? dirs))))
(define (lines-in-file path)
(if (not (file-exists? path))
0
(let* ((p (open-input-pipe
(string-append
"wc -l "
path
" | awk '{print $1}'")))
(pipe-str (read-line p)))
(close-pipe p)
(string->number
(string-trim-both pipe-str)))))
(define (compare-files path-a path-b)
(let* ((exists-a (file-exists? path-a))
(n-lines-a (lines-in-file path-a))
(exists-b (file-exists? path-b))
(n-lines-b (lines-in-file path-b))
(max-lines (max n-lines-a n-lines-b))
)
(cond
((not (or exists-a exists-b)) "NA")
((not exists-a) "1")
((not exists-b) "1")
(#t (let* ((diff-p (open-input-pipe
(string-append
"diff -U 0 "
path-a
" "
path-b
" | grep -c ^@")))
(diff-str (read-line diff-p)))
(close-pipe diff-p)
(if (= 0 max-lines)
"NA"
(number->string
(exact->inexact
(/ (string->number
(string-trim-both diff-str))
max-lines)))))))))
(define (display-all-diffs dir-a dir-b files)
(if (not (null? files))
(let ((file (car files)))
(display
(string-append
file
" "
dir-a
" "
dir-b
" "
(compare-files
(string-append dir-a "/" file)
(string-append dir-b "/" file))))
(newline)
(display-all-diffs dir-a dir-b (cdr files)))))
(define (main args)
(let* ((dirs (cdr args))
(dir-pairs (pair-suc dirs))
(files (filter
(lambda (fn) (not (or (string=? "." fn) (string=? ".." fn))))
(all-files dirs))))
(map
(lambda (dir-pair)
(display-all-diffs (car dir-pair) (cdr dir-pair) files))
dir-pairs)))