gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Use standard error/warning message format in the unifier script
0 1 0
default
1 file changed with 27 insertions and 9 deletions:
↑ Collapse diff ↑
Show white space 32 line context
... ...
@@ -73,51 +73,61 @@
73 73
    CHANGED=NO
74 74
    WARNED=NO
75 75
}
76 76

	
77 77
function update_end() {
78 78
    if [ $CHANGED == YES ]
79 79
    then
80 80
	((++CHANGED_FILES))
81 81
    fi
82 82
    if [ $WARNED == YES ]
83 83
    then
84 84
	((++WARNED_FILES))
85 85
    fi
86 86
}
87 87

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

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

	
99 112
function check_warning() {
100
    echo
101 113
    if [ "$2" == 'long lines' ]
102 114
    then
103
        echo -n "      $2 warning at line(s): "
104
        echo -n $(grep -n -E '.{81,}' $1 | sed "s/^\([0-9]*\)/ \1\t/g" | 
105
                  cut -f 1 | paste -s -d',')
115
        grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
106 116
    else
107
        echo -n "      $2 warning"
117
        echo "$1: warning: $2"
108 118
    fi
109 119
    WARNED=YES
110 120
}
111 121

	
112 122
function check_init() {
113 123
    echo Check source files...
114 124
    FAILED_FILES=0
115 125
    WARNED_FILES=0
116 126
    TOTAL_FILES=0
117 127
}
118 128

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

	
123 133
    if [ $FAILED_FILES -gt 0 ]
... ...
@@ -223,43 +233,51 @@
223 233
    TMP_FILE=`mktemp`
224 234
    cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
225 235

	
226 236
    "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
227 237
}
228 238

	
229 239
function long_lines_check() {
230 240
    if cat $1 | grep -q -E '.{81,}'
231 241
    then
232 242
	"$ACTION"_warning $1 'long lines'
233 243
    fi
234 244
}
235 245

	
236 246
# process the file
237 247

	
238 248
function process_file() {
249
    if [ "$ACTION" == 'update' ]
250
    then
239 251
    echo -n "    $ACTION $1..."
252
    else
253
        echo "	  $ACTION $1..."
254
    fi
240 255

	
241 256
    CHECKING="header tabs spaces long_lines"
242 257

	
243 258
    "$ACTION"_begin $1
244 259
    for check in $CHECKING
245 260
    do
246 261
	"$check"_check $1
247 262
    done
248 263
    "$ACTION"_end $1
264
    if [ "$ACTION" == 'update' ]
265
    then
249 266
    echo
267
    fi
250 268
}
251 269

	
252 270
function process_all {
253 271
    "$ACTION"_init
254 272
    while read file
255 273
    do
256 274
	process_file $file
257 275
    done < <($FILES)
258 276
    "$ACTION"_done
259 277
}
260 278

	
261 279
while [ $# -gt 0 ]
262 280
do
263 281
    
264 282
    if [ "$1" == '--help' ] || [ "$1" == '-h' ]
265 283
    then
0 comments (0 inline)