scripts/unify-sources.sh
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 31 Mar 2009 16:05:54 +0100
changeset 497 47b376a5a2a7
parent 38 a0cd9917c5a2
child 324 e05633b02e40
child 498 a76f55d7d397
permissions -rwxr-xr-x
Small script making a release
alpar@38
     1
#!/bin/bash
alpar@38
     2
alpar@38
     3
YEAR=`date +2003-%Y`
alpar@38
     4
HGROOT=`hg root`
alpar@38
     5
alpar@208
     6
function update_header() {
alpar@38
     7
    TMP_FILE=`mktemp`
alpar@38
     8
    FILE_NAME=$1
alpar@38
     9
alpar@208
    10
    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@38
    11
 *
alpar@208
    12
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@38
    13
 *
alpar@38
    14
 * Copyright (C) "$YEAR"
alpar@38
    15
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@38
    16
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@38
    17
 *
alpar@38
    18
 * Permission to use, modify and distribute this software is granted
alpar@38
    19
 * provided that this copyright notice appears in all copies. For
alpar@38
    20
 * precise terms see the accompanying LICENSE file.
alpar@38
    21
 *
alpar@38
    22
 * This software is provided \"AS IS\" with no warranty of any kind,
alpar@38
    23
 * express or implied, and with no claim as to its suitability for any
alpar@38
    24
 * purpose.
alpar@38
    25
 *
alpar@38
    26
 */
alpar@38
    27
"
alpar@38
    28
	awk 'BEGIN { pm=0; }
alpar@38
    29
     pm==3 { print }
alpar@38
    30
     /\/\* / && pm==0 { pm=1;}
alpar@38
    31
     /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
alpar@38
    32
     /\*\// && pm==1 { pm=2;}
alpar@38
    33
    ' $1
alpar@38
    34
	) >$TMP_FILE
alpar@208
    35
alpar@208
    36
    HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
alpar@208
    37
alpar@38
    38
    rm $FILE_NAME
alpar@38
    39
    mv $TMP_FILE $FILE_NAME
alpar@38
    40
}
alpar@38
    41
alpar@208
    42
function update_tabs() {
alpar@208
    43
    TMP_FILE=`mktemp`
alpar@208
    44
    FILE_NAME=$1
alpar@38
    45
alpar@208
    46
    cat $1 |
alpar@208
    47
    sed -e 's/\t/        /g' >$TMP_FILE
alpar@208
    48
alpar@208
    49
    TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
alpar@208
    50
alpar@208
    51
    rm $FILE_NAME
alpar@208
    52
    mv $TMP_FILE $FILE_NAME
alpar@208
    53
}
alpar@208
    54
alpar@208
    55
function remove_trailing_space() {
alpar@208
    56
    TMP_FILE=`mktemp`
alpar@208
    57
    FILE_NAME=$1
alpar@208
    58
alpar@208
    59
    cat $1 |
alpar@208
    60
    sed -e 's/ \+$//g' >$TMP_FILE
alpar@208
    61
alpar@208
    62
    SPACES_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
alpar@208
    63
alpar@208
    64
    rm $FILE_NAME
alpar@208
    65
    mv $TMP_FILE $FILE_NAME
alpar@208
    66
}
alpar@208
    67
alpar@208
    68
function long_line_test() {
alpar@208
    69
    cat $1 |grep -q -E '.{81,}'
alpar@208
    70
}
alpar@208
    71
alpar@208
    72
function update_file() {
alpar@208
    73
    echo -n '    update' $i ...
alpar@208
    74
alpar@208
    75
    update_header $1
alpar@208
    76
    update_tabs $1
alpar@208
    77
    remove_trailing_space $1
alpar@208
    78
alpar@208
    79
    CHANGED=NO;
alpar@208
    80
    if [[ $HEADER_CH = YES ]];
alpar@208
    81
    then
alpar@208
    82
	echo -n '  [header updated]'
alpar@208
    83
	CHANGED=YES;
alpar@208
    84
    fi
alpar@208
    85
    if [[ $TABS_CH = YES ]];
alpar@208
    86
    then
alpar@208
    87
	echo -n ' [tabs removed]'
alpar@208
    88
	CHANGED=YES;
alpar@208
    89
    fi
alpar@208
    90
    if [[ $SPACES_CH = YES ]];
alpar@208
    91
    then
alpar@208
    92
	echo -n ' [trailing spaces removed]'
alpar@208
    93
	CHANGED=YES;
alpar@208
    94
    fi
alpar@208
    95
    if long_line_test $1 ;
alpar@208
    96
    then
alpar@208
    97
	echo -n ' [LONG LINES]'
alpar@208
    98
	((LONG_LINE_FILES++))
alpar@208
    99
    fi
alpar@208
   100
    echo
alpar@208
   101
    if [[ $CHANGED = YES ]];
alpar@208
   102
    then
alpar@208
   103
	((CHANGED_FILES++))
alpar@208
   104
    fi
alpar@208
   105
}
alpar@208
   106
alpar@208
   107
CHANGED_FILES=0
alpar@208
   108
TOTAL_FILES=0
alpar@208
   109
LONG_LINE_FILES=0
alpar@38
   110
if [ $# == 0 ]; then
alpar@208
   111
    echo Update all source files...
alpar@38
   112
    for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
alpar@38
   113
    do
alpar@38
   114
	update_file $HGROOT/$i
alpar@208
   115
	((TOTAL_FILES++))
alpar@38
   116
    done
alpar@208
   117
    echo '  done.'
alpar@38
   118
else
alpar@38
   119
    for i in $*
alpar@38
   120
    do
alpar@38
   121
	update_file $i
alpar@208
   122
	((TOTAL_FILES++))
alpar@38
   123
    done
alpar@38
   124
fi
alpar@208
   125
echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
alpar@208
   126
if [[ $LONG_LINE_FILES -gt 1 ]]; then
alpar@208
   127
    echo
alpar@208
   128
    echo WARNING: $LONG_LINE_FILES files contains long lines!    
alpar@208
   129
    echo
alpar@208
   130
elif [[ $LONG_LINE_FILES -gt 0 ]]; then
alpar@208
   131
    echo
alpar@208
   132
    echo WARNING: a file contains long lines!
alpar@208
   133
    echo
alpar@208
   134
fi