Newer
Older
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
99
100
101
#!/bin/bash
if [ $# -lt 3 ]
then
echo "LgEval cdiff: Compile Errors from Diff Files"
echo "Copyright (c) R. Zanibbi, H. Mouchere, 2012-2014"
echo ""
echo "Usage: cdiff [-NESC^] outputPattern targetPattern <files>"
echo ""
echo "Return all lines (instances) of errors in diff files for"
echo "nodes or edges matching the provided patterns (egrep-format"
echo "regular expressions). Matching lines are written on standard output."
echo ""
echo "*Note: the pattern 'any' will match any label."
echo ""
echo "A single flag list token indicates whether to limit matches to"
echo "(N)ode label errors, (E)dge label errors, and/or files with"
echo "(S)egmentation errors or only (C)orrect segmentations. Including"
echo "^ in the flag list token will return files that do not match the"
echo "passed patterns."
exit 0
fi
# By default, return lines matching the given patterns.
FLIST=""
# Create initial list of all .diff files.
CFILES=""
FLAGS=""
if [[ $1 == -* ]]
then
# Grab flag string and shift.
FLAGS=$1
shift
fi
# Grab the patterns; shift to file list.
OUTP=$1
TARP=$2
shift
shift
# Take CFILES (current files) as all passed .diff files.
CFILES="$@"
# Indicate if we want the complement of a match.
if [[ $FLAGS == *^* ]]
then
FLIST="-v"
fi
# Note that segment error/correct seg are exclusive.
if [[ $FLAGS == *S* ]]
then
CFILES=`grep -l "^*S" $@`
elif [[ $FLAGS == *C* ]]
then
# -L flag selects inverse of the pattern ('negates' it)
CFILES=`grep -L "^*S" $@`
fi
# One or more non-comma characters: reg expression for 'any label' (*)
# Create the pattern string to use with grep, then run the filter and
# obtain the list of matching files.
ANYLABEL="[^,][^,]*"
MID=",1.0,:vs:,"
OUTLABEL=$ANYLABEL
TARLABEL=$ANYLABEL
if [ "$OUTP" != "any" ]
then
OUTLABEL="$OUTP"
fi
if [ "$TARP" != "any" ]
then
TARLABEL="$TARP"
fi
PATTERN="$OUTLABEL$MID$TARLABEL"
# Note that Node/Edge filtering is also exclusive.
if [[ $FLAGS == *N* ]]
then
PATTERN="^\*N.*$PATTERN"
elif [[ $FLAGS == *E* ]]
then
PATTERN="^\*E.*$PATTERN"
fi
# Use extended regular expressions to ease usage.
# FLIST allows the complement to be returned if desired.
CFILES=`grep $FLIST -E "$PATTERN" $CFILES`
# Write the matching file names on standard output.
for file in $CFILES
do
echo `basename $file`
done