# HG changeset patch
# User Alpar Juttner <alpar@cs.elte.hu>
# Date 1215964016 -3600
# Node ID 4317d277ba21d108a1e925fccf496ec8565a840a
# Parent  574b963d02752d633c352469ba3dd9a8d4480642
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

diff -r 574b963d0275 -r 4317d277ba21 scripts/unify-sources.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/unify-sources.sh	Sun Jul 13 16:46:56 2008 +0100
@@ -0,0 +1,134 @@
+#!/bin/bash
+
+YEAR=`date +2003-%Y`
+HGROOT=`hg root`
+
+function update_header() {
+    TMP_FILE=`mktemp`
+    FILE_NAME=$1
+
+    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) "$YEAR"
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided \"AS IS\" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+"
+	awk 'BEGIN { pm=0; }
+     pm==3 { print }
+     /\/\* / && pm==0 { pm=1;}
+     /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
+     /\*\// && 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 Update all source files...
+    for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
+    do
+	update_file $HGROOT/$i
+	((TOTAL_FILES++))
+    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
diff -r 574b963d0275 -r 4317d277ba21 scripts/update-copyright-header.sh
--- a/scripts/update-copyright-header.sh	Sun Jul 13 16:35:05 2008 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#!/bin/bash
-
-YEAR=`date +2003-%Y`
-HGROOT=`hg root`
-
-function update_file() {
-    TMP_FILE=`mktemp`
-    FILE_NAME=$1
-
-    (echo "/* -*- C++ -*-
- *
- * This file is a part of LEMON, a generic C++ optimization library
- *
- * Copyright (C) "$YEAR"
- * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
- * (Egervary Research Group on Combinatorial Optimization, EGRES).
- *
- * Permission to use, modify and distribute this software is granted
- * provided that this copyright notice appears in all copies. For
- * precise terms see the accompanying LICENSE file.
- *
- * This software is provided \"AS IS\" with no warranty of any kind,
- * express or implied, and with no claim as to its suitability for any
- * purpose.
- *
- */
-"
-	awk 'BEGIN { pm=0; }
-     pm==3 { print }
-     /\/\* / && pm==0 { pm=1;}
-     /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
-     /\*\// && pm==1 { pm=2;}
-    ' $1
-	) >$TMP_FILE
-    rm $FILE_NAME
-    mv $TMP_FILE $FILE_NAME
-}
-
-
-if [ $# == 0 ]; then
-    echo -n Update all source files...
-    for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
-    do
-	update_file $HGROOT/$i
-    done
-    echo ' done.'
-else
-    for i in $*
-    do
-	update_file $i
-    done
-fi