gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Better source unifier - now it is called scripts/unify-sources.sh - replaces each tab with 8 spaces - remove trailing spaces (and tabs) - warnings on long lines (i.e. on lines that are more than 80 characters) - the standard file header now turns off the space-to-tab replacement in Emacs
1 0 1
default
2 files changed with 87 insertions and 5 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -3,13 +3,13 @@
3 3
YEAR=`date +2003-%Y`
4 4
HGROOT=`hg root`
5 5

	
6
function update_file() {
6
function update_header() {
7 7
    TMP_FILE=`mktemp`
8 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 14
 * Copyright (C) "$YEAR"
15 15
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
... ...
@@ -32,21 +32,103 @@
32 32
     /\*\// && pm==1 { pm=2;}
33 33
    ' $1
34 34
	) >$TMP_FILE
35

	
36
    HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
37

	
35 38
    rm $FILE_NAME
36 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 110
if [ $# == 0 ]; then
41
    echo -n Update all source files...
111
    echo Update all source files...
42 112
    for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
43 113
    do
44 114
	update_file $HGROOT/$i
115
	((TOTAL_FILES++))
45 116
    done
46
    echo ' done.'
117
    echo '  done.'
47 118
else
48 119
    for i in $*
49 120
    do
50 121
	update_file $i
122
	((TOTAL_FILES++))
51 123
    done
52 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
0 comments (0 inline)