gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Improve unify-sources.sh (#186) Errors can also be accepted when the script is used as a hg hook. Sometimes it is useful (e.g. if someone else made the errors).
0 1 0
default
1 file changed with 3 insertions and 6 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -85,114 +85,111 @@
85 85
    fi
86 86
}
87 87

	
88 88
function check_action() {
89 89
    if [ "$3" == 'tabs' ]
90 90
    then
91 91
        PATTERN=$(echo -e '\t')
92 92
    elif [ "$3" == 'trailing spaces' ]
93 93
    then
94 94
        PATTERN='\ +$'
95 95
    else
96 96
        PATTERN='*'
97 97
    fi
98 98

	
99 99
    if ! diff -q $1 $2 >/dev/null
100 100
    then
101 101
        if [ "$PATTERN" == '*' ]
102 102
        then
103 103
            diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
104 104
              sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
105 105
        else
106 106
            grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
107 107
        fi
108 108
        FAILED=YES
109 109
    fi
110 110
}
111 111

	
112 112
function check_warning() {
113 113
    if [ "$2" == 'long lines' ]
114 114
    then
115 115
        grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
116 116
    else
117 117
        echo "$1: warning: $2"
118 118
    fi
119 119
    WARNED=YES
120 120
}
121 121

	
122 122
function check_init() {
123 123
    echo Check source files...
124 124
    FAILED_FILES=0
125 125
    WARNED_FILES=0
126 126
    TOTAL_FILES=0
127 127
}
128 128

	
129 129
function check_done() {
130 130
    echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
131 131
    echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
132 132

	
133
    if [ $FAILED_FILES -gt 0 ]
134
    then
135
	return 1
136
    elif [ $WARNED_FILES -gt 0 ]
133
    if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
137 134
    then
138 135
	if [ "$WARNING" == 'INTERACTIVE' ]
139 136
	then
140
	    echo -n "Are the files with warnings acceptable? (yes/no) "
137
	    echo -n "Are the files with errors/warnings acceptable? (yes/no) "
141 138
	    while read answer
142 139
	    do
143 140
		if [ "$answer" == 'yes' ]
144 141
		then
145 142
		    return 0
146 143
		elif [ "$answer" == 'no' ]
147 144
		then
148 145
		    return 1
149 146
		fi
150
		echo -n "Are the files with warnings acceptable? (yes/no) "
147
		echo -n "Are the files with errors/warnings acceptable? (yes/no) "
151 148
	    done
152 149
	elif [ "$WARNING" == 'WERROR' ]
153 150
	then
154 151
	    return 1
155 152
	fi
156 153
    fi
157 154
}
158 155

	
159 156
function check_begin() {
160 157
    ((TOTAL_FILES++))
161 158
    FAILED=NO
162 159
    WARNED=NO
163 160
}
164 161

	
165 162
function check_end() {
166 163
    if [ $FAILED == YES ]
167 164
    then
168 165
	((++FAILED_FILES))
169 166
    fi
170 167
    if [ $WARNED == YES ]
171 168
    then
172 169
	((++WARNED_FILES))
173 170
    fi
174 171
}
175 172

	
176 173

	
177 174

	
178 175
# checks
179 176

	
180 177
function header_check() {
181 178
    if echo $1 | grep -q -E 'Makefile\.am$'
182 179
    then
183 180
	return
184 181
    fi
185 182

	
186 183
    TMP_FILE=`mktemp`
187 184

	
188 185
    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
189 186
 *
190 187
 * This file is a part of LEMON, a generic C++ optimization library.
191 188
 *
192 189
 * Copyright (C) "$YEAR"
193 190
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
194 191
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
195 192
 *
196 193
 * Permission to use, modify and distribute this software is granted
197 194
 * provided that this copyright notice appears in all copies. For
198 195
 * precise terms see the accompanying LICENSE file.
0 comments (0 inline)