1 #!/bin/bash |
1 #!/bin/bash |
2 |
2 |
3 YEAR=`date +2003-%Y` |
3 YEAR=`date +2003-%Y` |
4 HGROOT=`hg root` |
4 HGROOT=`hg root` |
5 |
5 |
6 function update_file() { |
6 function update_header() { |
7 TMP_FILE=`mktemp` |
7 TMP_FILE=`mktemp` |
8 FILE_NAME=$1 |
8 FILE_NAME=$1 |
9 |
9 |
10 (echo "/* -*- C++ -*- |
10 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*- |
11 * |
11 * |
12 * This file is a part of LEMON, a generic C++ optimization library |
12 * This file is a part of LEMON, a generic C++ optimization library. |
13 * |
13 * |
14 * Copyright (C) "$YEAR" |
14 * Copyright (C) "$YEAR" |
15 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
15 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
16 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
16 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
17 * |
17 * |
30 /\/\* / && pm==0 { pm=1;} |
30 /\/\* / && pm==0 { pm=1;} |
31 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;} |
31 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;} |
32 /\*\// && pm==1 { pm=2;} |
32 /\*\// && pm==1 { pm=2;} |
33 ' $1 |
33 ' $1 |
34 ) >$TMP_FILE |
34 ) >$TMP_FILE |
|
35 |
|
36 HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` |
|
37 |
35 rm $FILE_NAME |
38 rm $FILE_NAME |
36 mv $TMP_FILE $FILE_NAME |
39 mv $TMP_FILE $FILE_NAME |
37 } |
40 } |
38 |
41 |
|
42 function update_tabs() { |
|
43 TMP_FILE=`mktemp` |
|
44 FILE_NAME=$1 |
39 |
45 |
|
46 cat $1 | |
|
47 sed -e 's/\t/ /g' >$TMP_FILE |
|
48 |
|
49 TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` |
|
50 |
|
51 rm $FILE_NAME |
|
52 mv $TMP_FILE $FILE_NAME |
|
53 } |
|
54 |
|
55 function remove_trailing_space() { |
|
56 TMP_FILE=`mktemp` |
|
57 FILE_NAME=$1 |
|
58 |
|
59 cat $1 | |
|
60 sed -e 's/ \+$//g' >$TMP_FILE |
|
61 |
|
62 SPACES_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` |
|
63 |
|
64 rm $FILE_NAME |
|
65 mv $TMP_FILE $FILE_NAME |
|
66 } |
|
67 |
|
68 function long_line_test() { |
|
69 cat $1 |grep -q -E '.{81,}' |
|
70 } |
|
71 |
|
72 function update_file() { |
|
73 echo -n ' update' $i ... |
|
74 |
|
75 update_header $1 |
|
76 update_tabs $1 |
|
77 remove_trailing_space $1 |
|
78 |
|
79 CHANGED=NO; |
|
80 if [[ $HEADER_CH = YES ]]; |
|
81 then |
|
82 echo -n ' [header updated]' |
|
83 CHANGED=YES; |
|
84 fi |
|
85 if [[ $TABS_CH = YES ]]; |
|
86 then |
|
87 echo -n ' [tabs removed]' |
|
88 CHANGED=YES; |
|
89 fi |
|
90 if [[ $SPACES_CH = YES ]]; |
|
91 then |
|
92 echo -n ' [trailing spaces removed]' |
|
93 CHANGED=YES; |
|
94 fi |
|
95 if long_line_test $1 ; |
|
96 then |
|
97 echo -n ' [LONG LINES]' |
|
98 ((LONG_LINE_FILES++)) |
|
99 fi |
|
100 echo |
|
101 if [[ $CHANGED = YES ]]; |
|
102 then |
|
103 ((CHANGED_FILES++)) |
|
104 fi |
|
105 } |
|
106 |
|
107 CHANGED_FILES=0 |
|
108 TOTAL_FILES=0 |
|
109 LONG_LINE_FILES=0 |
40 if [ $# == 0 ]; then |
110 if [ $# == 0 ]; then |
41 echo -n Update all source files... |
111 echo Update all source files... |
42 for i in `hg manifest|grep -E '\.(cc|h|dox)$'` |
112 for i in `hg manifest|grep -E '\.(cc|h|dox)$'` |
43 do |
113 do |
44 update_file $HGROOT/$i |
114 update_file $HGROOT/$i |
|
115 ((TOTAL_FILES++)) |
45 done |
116 done |
46 echo ' done.' |
117 echo ' done.' |
47 else |
118 else |
48 for i in $* |
119 for i in $* |
49 do |
120 do |
50 update_file $i |
121 update_file $i |
|
122 ((TOTAL_FILES++)) |
51 done |
123 done |
52 fi |
124 fi |
|
125 echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. |
|
126 if [[ $LONG_LINE_FILES -gt 1 ]]; then |
|
127 echo |
|
128 echo WARNING: $LONG_LINE_FILES files contains long lines! |
|
129 echo |
|
130 elif [[ $LONG_LINE_FILES -gt 0 ]]; then |
|
131 echo |
|
132 echo WARNING: a file contains long lines! |
|
133 echo |
|
134 fi |