gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Fix the faulty merge of unify-sources.sh in [586b65073025]
0 1 0
default
1 file changed with 4 insertions and 0 deletions:
↑ Collapse diff ↑
Ignore white space 384 line context
1 1
#!/bin/bash
2 2

	
3 3
YEAR=`date +%Y`
4 4
HGROOT=`hg root`
5 5

	
6 6
function hg_year() {
7 7
    if [ -n "$(hg st $1)" ]; then
8 8
        echo $YEAR
9
    else
10
        hg log -l 1 --template='{date|isodate}\n' $1 |
11
        cut -d '-' -f 1
12
    fi
9 13
}
10 14

	
11 15
# file enumaration modes
12 16

	
13 17
function all_files() {
14 18
    hg status -a -m -c |
15 19
    cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
16 20
    while read file; do echo $HGROOT/$file; done
17 21
}
18 22

	
19 23
function modified_files() {
20 24
    hg status -a -m |
21 25
    cut -d ' ' -f 2 | grep -E  '(\.(cc|h|dox)$|Makefile\.am$)' |
22 26
    while read file; do echo $HGROOT/$file; done
23 27
}
24 28

	
25 29
function changed_files() {
26 30
    {
27 31
        if [ -n "$HG_PARENT1" ]
28 32
        then
29 33
            hg status --rev $HG_PARENT1:$HG_NODE -a -m
30 34
        fi
31 35
        if [ -n "$HG_PARENT2" ]
32 36
        then
33 37
            hg status --rev $HG_PARENT2:$HG_NODE -a -m
34 38
        fi
35 39
    } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | 
36 40
    sort | uniq |
37 41
    while read file; do echo $HGROOT/$file; done
38 42
}
39 43

	
40 44
function given_files() {
41 45
    for file in $GIVEN_FILES
42 46
    do
43 47
	echo $file
44 48
    done
45 49
}
46 50

	
47 51
# actions
48 52

	
49 53
function update_action() {
50 54
    if ! diff -q $1 $2 >/dev/null
51 55
    then
52 56
	echo -n " [$3 updated]"
53 57
	rm $2
54 58
	mv $1 $2
55 59
	CHANGED=YES
56 60
    fi
57 61
}
58 62

	
59 63
function update_warning() {
60 64
    echo -n " [$2 warning]"
61 65
    WARNED=YES
62 66
}
63 67

	
64 68
function update_init() {
65 69
    echo Update source files...
66 70
    TOTAL_FILES=0
67 71
    CHANGED_FILES=0
68 72
    WARNED_FILES=0
69 73
}
70 74

	
71 75
function update_done() {
72 76
    echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
73 77
    echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
74 78
}
75 79

	
76 80
function update_begin() {
77 81
    ((TOTAL_FILES++))
78 82
    CHANGED=NO
79 83
    WARNED=NO
80 84
}
81 85

	
82 86
function update_end() {
83 87
    if [ $CHANGED == YES ]
84 88
    then
85 89
	((++CHANGED_FILES))
86 90
    fi
87 91
    if [ $WARNED == YES ]
88 92
    then
89 93
	((++WARNED_FILES))
90 94
    fi
91 95
}
92 96

	
93 97
function check_action() {
94 98
    if [ "$3" == 'tabs' ]
95 99
    then
96 100
        if echo $2 | grep -q -v -E 'Makefile\.am$'
97 101
        then
98 102
            PATTERN=$(echo -e '\t')
99 103
        else
100 104
            PATTERN='        '
101 105
        fi
102 106
    elif [ "$3" == 'trailing spaces' ]
103 107
    then
104 108
        PATTERN='\ +$'
105 109
    else
106 110
        PATTERN='*'
107 111
    fi
108 112

	
109 113
    if ! diff -q $1 $2 >/dev/null
110 114
    then
111 115
        if [ "$PATTERN" == '*' ]
112 116
        then
113 117
            diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
114 118
              sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
115 119
        else
116 120
            grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
117 121
        fi
118 122
        FAILED=YES
119 123
    fi
120 124
}
121 125

	
122 126
function check_warning() {
123 127
    if [ "$2" == 'long lines' ]
124 128
    then
125 129
        grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
126 130
    else
127 131
        echo "$1: warning: $2"
128 132
    fi
129 133
    WARNED=YES
130 134
}
131 135

	
132 136
function check_init() {
133 137
    echo Check source files...
134 138
    FAILED_FILES=0
135 139
    WARNED_FILES=0
136 140
    TOTAL_FILES=0
137 141
}
138 142

	
139 143
function check_done() {
140 144
    echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
141 145
    echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
142 146

	
143 147
    if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
144 148
    then
145 149
	if [ "$WARNING" == 'INTERACTIVE' ]
146 150
	then
147 151
	    echo -n "Are the files with errors/warnings acceptable? (yes/no) "
148 152
	    while read answer
149 153
	    do
150 154
		if [ "$answer" == 'yes' ]
151 155
		then
152 156
		    return 0
153 157
		elif [ "$answer" == 'no' ]
154 158
		then
155 159
		    return 1
156 160
		fi
157 161
		echo -n "Are the files with errors/warnings acceptable? (yes/no) "
158 162
	    done
159 163
	elif [ "$WARNING" == 'WERROR' ]
160 164
	then
161 165
	    return 1
162 166
	fi
163 167
    fi
164 168
}
165 169

	
166 170
function check_begin() {
167 171
    ((TOTAL_FILES++))
168 172
    FAILED=NO
169 173
    WARNED=NO
170 174
}
171 175

	
172 176
function check_end() {
173 177
    if [ $FAILED == YES ]
174 178
    then
175 179
	((++FAILED_FILES))
176 180
    fi
177 181
    if [ $WARNED == YES ]
178 182
    then
179 183
	((++WARNED_FILES))
180 184
    fi
181 185
}
182 186

	
183 187

	
184 188

	
185 189
# checks
186 190

	
187 191
function header_check() {
188 192
    if echo $1 | grep -q -E 'Makefile\.am$'
189 193
    then
190 194
	return
191 195
    fi
192 196

	
193 197
    TMP_FILE=`mktemp`
194 198

	
195 199
    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
196 200
 *
197 201
 * This file is a part of LEMON, a generic C++ optimization library.
198 202
 *
199 203
 * Copyright (C) 2003-"$(hg_year $1)"
200 204
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
0 comments (0 inline)