diff --git a/scripts/update-copyright-header.sh b/scripts/unify-sources.sh rename from scripts/update-copyright-header.sh rename to scripts/unify-sources.sh --- a/scripts/update-copyright-header.sh +++ b/scripts/unify-sources.sh @@ -3,13 +3,13 @@ YEAR=`date +2003-%Y` HGROOT=`hg root` -function update_file() { +function update_header() { TMP_FILE=`mktemp` FILE_NAME=$1 - (echo "/* -*- C++ -*- + (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) "$YEAR" * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -32,21 +32,103 @@ /\*\// && pm==1 { pm=2;} ' $1 ) >$TMP_FILE + + HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` + rm $FILE_NAME mv $TMP_FILE $FILE_NAME } +function update_tabs() { + TMP_FILE=`mktemp` + FILE_NAME=$1 + cat $1 | + sed -e 's/\t/ /g' >$TMP_FILE + + TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` + + rm $FILE_NAME + mv $TMP_FILE $FILE_NAME +} + +function remove_trailing_space() { + TMP_FILE=`mktemp` + FILE_NAME=$1 + + cat $1 | + sed -e 's/ \+$//g' >$TMP_FILE + + SPACES_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` + + rm $FILE_NAME + mv $TMP_FILE $FILE_NAME +} + +function long_line_test() { + cat $1 |grep -q -E '.{81,}' +} + +function update_file() { + echo -n ' update' $i ... + + update_header $1 + update_tabs $1 + remove_trailing_space $1 + + CHANGED=NO; + if [[ $HEADER_CH = YES ]]; + then + echo -n ' [header updated]' + CHANGED=YES; + fi + if [[ $TABS_CH = YES ]]; + then + echo -n ' [tabs removed]' + CHANGED=YES; + fi + if [[ $SPACES_CH = YES ]]; + then + echo -n ' [trailing spaces removed]' + CHANGED=YES; + fi + if long_line_test $1 ; + then + echo -n ' [LONG LINES]' + ((LONG_LINE_FILES++)) + fi + echo + if [[ $CHANGED = YES ]]; + then + ((CHANGED_FILES++)) + fi +} + +CHANGED_FILES=0 +TOTAL_FILES=0 +LONG_LINE_FILES=0 if [ $# == 0 ]; then - echo -n Update all source files... + echo Update all source files... for i in `hg manifest|grep -E '\.(cc|h|dox)$'` do update_file $HGROOT/$i + ((TOTAL_FILES++)) done - echo ' done.' + echo ' done.' else for i in $* do update_file $i + ((TOTAL_FILES++)) done fi +echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. +if [[ $LONG_LINE_FILES -gt 1 ]]; then + echo + echo WARNING: $LONG_LINE_FILES files contains long lines! + echo +elif [[ $LONG_LINE_FILES -gt 0 ]]; then + echo + echo WARNING: a file contains long lines! + echo +fi