COIN-OR::LEMON - Graph Library

Changeset 208:4317d277ba21 in lemon-1.0 for scripts/unify-sources.sh


Ignore:
Timestamp:
07/13/08 17:46:56 (16 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

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
File:
1 moved

Legend:

Unmodified
Added
Removed
  • scripts/unify-sources.sh

    r38 r208  
    44HGROOT=`hg root`
    55
    6 function update_file() {
     6function update_header() {
    77    TMP_FILE=`mktemp`
    88    FILE_NAME=$1
    99
    10     (echo "/* -*- C++ -*-
     10    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
    1111 *
    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.
    1313 *
    1414 * Copyright (C) "$YEAR"
     
    3333    ' $1
    3434        ) >$TMP_FILE
     35
     36    HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
     37
    3538    rm $FILE_NAME
    3639    mv $TMP_FILE $FILE_NAME
    3740}
    3841
     42function update_tabs() {
     43    TMP_FILE=`mktemp`
     44    FILE_NAME=$1
    3945
     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
     55function 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
     68function long_line_test() {
     69    cat $1 |grep -q -E '.{81,}'
     70}
     71
     72function 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
     107CHANGED_FILES=0
     108TOTAL_FILES=0
     109LONG_LINE_FILES=0
    40110if [ $# == 0 ]; then
    41     echo -n Update all source files...
     111    echo Update all source files...
    42112    for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
    43113    do
    44114        update_file $HGROOT/$i
     115        ((TOTAL_FILES++))
    45116    done
    46     echo ' done.'
     117    echo '  done.'
    47118else
    48119    for i in $*
    49120    do
    50121        update_file $i
     122        ((TOTAL_FILES++))
    51123    done
    52124fi
     125echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
     126if [[ $LONG_LINE_FILES -gt 1 ]]; then
     127    echo
     128    echo WARNING: $LONG_LINE_FILES files contains long lines!   
     129    echo
     130elif [[ $LONG_LINE_FILES -gt 0 ]]; then
     131    echo
     132    echo WARNING: a file contains long lines!
     133    echo
     134fi
Note: See TracChangeset for help on using the changeset viewer.