COIN-OR::LEMON - Graph Library

Ticket #138: scripts_80edda6f89cd.patch

File scripts_80edda6f89cd.patch, 4.4 KB (added by Peter Kovacs, 16 years ago)

Improvements (also check & unify Makefile.am files correctly)

  • scripts/check-sources.sh

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1222915108 -7200
    # Node ID 80edda6f89cdf5e5c30612a0ca757dd5f26f3163
    # Parent  1437eaaa5a5b583f9f91479c09b732c7ec363039
    Improvements in code checking and unification (ticket #138)
    
    By default check-sources.sh checks only the modified files, but using the
    "--all" (or "-a") option it checks all source files (as unify-sources.sh).
    
    The Makefile.am files are included into the checking and unification.
    
    diff --git a/scripts/check-sources.sh b/scripts/check-sources.sh
    a b  
    3636}
    3737
    3838function check_file() {
    39     echo 'check' $1 ...
     39    echo '    check' $FILENAME ...
    4040
    4141    FILE_FAILED=NO
    42     if check_header $1
     42
     43    if echo $1 | grep -q -v -E 'Makefile\.am$'
    4344    then
    44         echo "header failed"
    45         FILE_FAILED=YES
    46         GLOBAL_FAILED=YES
    47     fi
    48 
    49     if grep -q -E "$TAB" $1
    50     then
    51         echo "tabs failed:"
    52         grep -n -E "$TAB" $1
    53         FILE_FAILED=YES
    54         GLOBAL_FAILED=YES
     45        if check_header $1
     46        then
     47            echo "header failed"
     48            FILE_FAILED=YES
     49            GLOBAL_FAILED=YES
     50        fi
     51       
     52        if grep -q -E "$TAB" $1
     53        then
     54            echo "tabs failed:"
     55            grep -n -E "$TAB" $1
     56            FILE_FAILED=YES
     57            GLOBAL_FAILED=YES
     58        fi
     59    else
     60        if grep -q -E "        " $1
     61        then
     62            echo "spaces failed:"
     63            grep -n -E "        " $1
     64            FILE_FAILED=YES
     65            GLOBAL_FAILED=YES
     66        fi
    5567    fi
    5668
    5769    if grep -q -E ' $' $1
     
    6678    then
    6779        echo "long lines failed:"
    6880        grep -n -E '.{81,}' $1
    69         if [ $GLOBAL_FAILED != YES ]
    70         then
    71             echo -n "Abort commit? (yes/no) "
    72             read RESULT
    73             if [ "$RESULT" != "no" ]
    74             then
    75                 FILE_FAILED=YES
    76                 GLOBAL_FAILED=YES
    77             fi
    78         fi
     81        FILE_FAILED=YES
     82        GLOBAL_FAILED=YES
    7983    fi
    8084
    8185    if [[ $FILE_FAILED = YES ]];
     
    8892TOTAL_FILES=0
    8993GLOBAL_FAILED=NO
    9094
     95function list_files() {
     96    hg status -a -m -c |
     97    cut -d ' ' -f 2 | grep -E  '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq
     98}
     99
    91100function changed_files() {
    92101    {
    93102        if [ -n "$HG_PARENT1" ]
     
    98107        then
    99108            hg status --rev $HG_PARENT2:$HG_NODE -a -m
    100109        fi
    101     } | cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
     110    } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq
    102111}
    103112
    104113if [ $# == 0 ]; then
    105114    echo Check all modified files...
    106 
    107115    while read FILENAME
    108116    do
    109117        check_file "$HGROOT/$FILENAME"
    110118        ((TOTAL_FILES++))
    111119    done < <(changed_files)
    112120    echo '  done.'
     121elif [[ ($# == 1) && (($1 == "--all") || ($1 == "-a")) ]]; then
     122    echo Check all source files...
     123    while read FILENAME
     124    do
     125        check_file "$HGROOT/$FILENAME"
     126        ((TOTAL_FILES++))
     127    done < <(list_files)
     128    echo '  done.'
    113129else
    114     for i in $@
     130    for FILENAME in $@
    115131    do
    116         check_file $i
     132        check_file $FILENAME
    117133        ((TOTAL_FILES++))
    118134    done
    119135fi
  • scripts/unify-sources.sh

    diff --git a/scripts/unify-sources.sh b/scripts/unify-sources.sh
    a b  
    4343    TMP_FILE=`mktemp`
    4444    FILE_NAME=$1
    4545
    46     cat $1 |
    47     sed -e 's/\t/        /g' >$TMP_FILE
     46    if echo $1 | grep -q -v -E 'Makefile\.am$'
     47    then
     48        cat $1 | sed -e 's/\t/        /g' >$TMP_FILE
     49    else
     50        cat $1 | sed -e 's/        /\t/g' >$TMP_FILE
     51    fi
    4852
    4953    TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
    5054
     
    7276function update_file() {
    7377    echo -n '    update' $i ...
    7478
    75     update_header $1
     79    if echo $1 | grep -q -v -E 'Makefile\.am$'
     80    then
     81        update_header $1
     82    fi
    7683    update_tabs $1
    7784    remove_trailing_space $1
    7885
     
    8491    fi
    8592    if [[ $TABS_CH = YES ]];
    8693    then
    87         echo -n ' [tabs removed]'
     94        if echo $1 | grep -q -v -E 'Makefile\.am$'
     95        then
     96            echo -n ' [tabs removed]'
     97        else
     98            echo -n ' [spaces replaced with tabs]'
     99        fi
    88100        CHANGED=YES;
    89101    fi
    90102    if [[ $SPACES_CH = YES ]];
     
    106118
    107119function list_files() {
    108120    hg status -a -m -c |
    109     cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
     121    cut -d ' ' -f 2 | grep -E  '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq
    110122}
    111123
    112124CHANGED_FILES=0