alpar@38: #!/bin/bash alpar@38: alpar@538: YEAR=`date +%Y` alpar@38: HGROOT=`hg root` alpar@38: alpar@538: function hg_year() { alpar@538: if [ -n "$(hg st $1)" ]; then alpar@538: echo $YEAR alpar@538: else alpar@538: hg log -l 1 --template='{date|isodate}\n' $1 | alpar@538: cut -d '-' -f 1 alpar@538: fi alpar@538: } alpar@538: alpar@208: function update_header() { alpar@38: TMP_FILE=`mktemp` alpar@38: FILE_NAME=$1 alpar@38: alpar@208: (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@38: * alpar@208: * This file is a part of LEMON, a generic C++ optimization library. alpar@38: * alpar@538: * Copyright (C) 2003-"$(hg_year $1)" alpar@38: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@38: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@38: * alpar@38: * Permission to use, modify and distribute this software is granted alpar@38: * provided that this copyright notice appears in all copies. For alpar@38: * precise terms see the accompanying LICENSE file. alpar@38: * alpar@38: * This software is provided \"AS IS\" with no warranty of any kind, alpar@38: * express or implied, and with no claim as to its suitability for any alpar@38: * purpose. alpar@38: * alpar@38: */ alpar@38: " alpar@38: awk 'BEGIN { pm=0; } alpar@38: pm==3 { print } alpar@38: /\/\* / && pm==0 { pm=1;} alpar@38: /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;} alpar@38: /\*\// && pm==1 { pm=2;} alpar@38: ' $1 alpar@38: ) >$TMP_FILE alpar@208: alpar@208: HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` alpar@208: alpar@38: rm $FILE_NAME alpar@38: mv $TMP_FILE $FILE_NAME alpar@38: } alpar@38: alpar@208: function update_tabs() { alpar@208: TMP_FILE=`mktemp` alpar@208: FILE_NAME=$1 alpar@38: alpar@208: cat $1 | alpar@208: sed -e 's/\t/ /g' >$TMP_FILE alpar@208: alpar@208: TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` alpar@208: alpar@208: rm $FILE_NAME alpar@208: mv $TMP_FILE $FILE_NAME alpar@208: } alpar@208: alpar@208: function remove_trailing_space() { alpar@208: TMP_FILE=`mktemp` alpar@208: FILE_NAME=$1 alpar@208: alpar@208: cat $1 | alpar@208: sed -e 's/ \+$//g' >$TMP_FILE alpar@208: alpar@208: SPACES_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` alpar@208: alpar@208: rm $FILE_NAME alpar@208: mv $TMP_FILE $FILE_NAME alpar@208: } alpar@208: alpar@208: function long_line_test() { alpar@208: cat $1 |grep -q -E '.{81,}' alpar@208: } alpar@208: alpar@208: function update_file() { alpar@208: echo -n ' update' $i ... alpar@208: alpar@208: update_header $1 alpar@208: update_tabs $1 alpar@208: remove_trailing_space $1 alpar@208: alpar@208: CHANGED=NO; alpar@208: if [[ $HEADER_CH = YES ]]; alpar@208: then alpar@208: echo -n ' [header updated]' alpar@208: CHANGED=YES; alpar@208: fi alpar@208: if [[ $TABS_CH = YES ]]; alpar@208: then alpar@208: echo -n ' [tabs removed]' alpar@208: CHANGED=YES; alpar@208: fi alpar@208: if [[ $SPACES_CH = YES ]]; alpar@208: then alpar@208: echo -n ' [trailing spaces removed]' alpar@208: CHANGED=YES; alpar@208: fi alpar@208: if long_line_test $1 ; alpar@208: then alpar@208: echo -n ' [LONG LINES]' alpar@208: ((LONG_LINE_FILES++)) alpar@208: fi alpar@208: echo alpar@208: if [[ $CHANGED = YES ]]; alpar@208: then alpar@208: ((CHANGED_FILES++)) alpar@208: fi alpar@208: } alpar@208: alpar@208: CHANGED_FILES=0 alpar@208: TOTAL_FILES=0 alpar@208: LONG_LINE_FILES=0 alpar@38: if [ $# == 0 ]; then alpar@208: echo Update all source files... alpar@38: for i in `hg manifest|grep -E '\.(cc|h|dox)$'` alpar@38: do alpar@38: update_file $HGROOT/$i alpar@208: ((TOTAL_FILES++)) alpar@38: done alpar@208: echo ' done.' alpar@38: else alpar@38: for i in $* alpar@38: do alpar@38: update_file $i alpar@208: ((TOTAL_FILES++)) alpar@38: done alpar@38: fi alpar@208: echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. alpar@208: if [[ $LONG_LINE_FILES -gt 1 ]]; then alpar@208: echo alpar@208: echo WARNING: $LONG_LINE_FILES files contains long lines! alpar@208: echo alpar@208: elif [[ $LONG_LINE_FILES -gt 0 ]]; then alpar@208: echo alpar@208: echo WARNING: a file contains long lines! alpar@208: echo alpar@208: fi