COIN-OR::LEMON - Graph Library

Ticket #138: scripts_1437eaaa5a5b.patch

File scripts_1437eaaa5a5b.patch, 5.7 KB (added by Peter Kovacs, 16 years ago)

Updated version of Balazs's original changeset [00e953d56f15]

  • new file scripts/check-sources.sh

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1222913319 -7200
    # Node ID 1437eaaa5a5b583f9f91479c09b732c7ec363039
    # Parent  cbe3ec2d59d2d7c539ab62f2ca6796c960795237
    New code checker script and improvements in unifier (ticket #138)
    
    The new check-sources.sh script checks the same things as unify-sources.sh,
    but it does not modify the files, just checks the conformity. It can be used
    as commit checker hg hook (for instructions see the comments in the file).
    
    The way how we enumerate the code files is changed in unify-sources.sh
    because the manifest command enumerates the already removed files, which
    raise error in the script.
    
    diff --git a/scripts/check-sources.sh b/scripts/check-sources.sh
    new file mode 100755
    - +  
     1#!/bin/bash
     2
     3# Add to your .hg/hgrc the following section.
     4# [hooks]
     5# pretxncommit.checksources = scripts/check-sources.sh
     6
     7YEAR=`date +2003-%Y`
     8HGROOT=`hg root`
     9
     10TAB=`echo -e '\t'`
     11
     12function check_header() {
     13    HEADER=\
     14"/* -*- mode: C++; indent-tabs-mode: nil; -*-
     15 *
     16 * This file is a part of LEMON, a generic C++ optimization library.
     17 *
     18 * Copyright (C) "$YEAR"
     19 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     20 * (Egervary Research Group on Combinatorial Optimization, EGRES).
     21 *
     22 * Permission to use, modify and distribute this software is granted
     23 * provided that this copyright notice appears in all copies. For
     24 * precise terms see the accompanying LICENSE file.
     25 *
     26 * This software is provided \"AS IS\" with no warranty of any kind,
     27 * express or implied, and with no claim as to its suitability for any
     28 * purpose.
     29 *
     30 */"
     31
     32    HEADER_LENGTH=$(echo "$HEADER" | wc -l)
     33    FILE_HEADER=$(cat $1 | head -n $HEADER_LENGTH)
     34
     35    [[ "$FILE_HEADER" != "$HEADER" ]]
     36}
     37
     38function check_file() {
     39    echo 'check' $1 ...
     40
     41    FILE_FAILED=NO
     42    if check_header $1
     43    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
     55    fi
     56
     57    if grep -q -E ' $' $1
     58    then
     59        echo "trailing spaces failed:"
     60        grep -n -E ' $' $1
     61        FILE_FAILED=YES
     62        GLOBAL_FAILED=YES
     63    fi
     64
     65    if grep -q -E '.{81,}' $1
     66    then
     67        echo "long lines failed:"
     68        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
     79    fi
     80
     81    if [[ $FILE_FAILED = YES ]];
     82    then
     83        ((FAILED_FILES++))
     84    fi
     85}
     86
     87FAILED_FILES=0
     88TOTAL_FILES=0
     89GLOBAL_FAILED=NO
     90
     91function changed_files() {
     92    {
     93        if [ -n "$HG_PARENT1" ]
     94        then
     95            hg status --rev $HG_PARENT1:$HG_NODE -a -m
     96        fi
     97        if [ -n "$HG_PARENT2" ]
     98        then
     99            hg status --rev $HG_PARENT2:$HG_NODE -a -m
     100        fi
     101    } | cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
     102}
     103
     104if [ $# == 0 ]; then
     105    echo Check all modified files...
     106
     107    while read FILENAME
     108    do
     109        check_file "$HGROOT/$FILENAME"
     110        ((TOTAL_FILES++))
     111    done < <(changed_files)
     112    echo '  done.'
     113else
     114    for i in $@
     115    do
     116        check_file $i
     117        ((TOTAL_FILES++))
     118    done
     119fi
     120
     121echo $FAILED_FILES out of $TOTAL_FILES files has failed.
     122
     123[[ $GLOBAL_FAILED == NO ]]
  • scripts/unify-sources.sh

    diff --git a/scripts/unify-sources.sh b/scripts/unify-sources.sh
    a b  
    2525 *
    2626 */
    2727"
    28         awk 'BEGIN { pm=0; }
     28    awk 'BEGIN { pm=0; }
    2929     pm==3 { print }
    3030     /\/\* / && pm==0 { pm=1;}
    3131     /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
    3232     /\*\// && pm==1 { pm=2;}
    3333    ' $1
    34         ) >$TMP_FILE
     34        ) >$TMP_FILE
    3535
    3636    HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES`
    3737
     
    7979    CHANGED=NO;
    8080    if [[ $HEADER_CH = YES ]];
    8181    then
    82         echo -n '  [header updated]'
    83         CHANGED=YES;
     82        echo -n '  [header updated]'
     83        CHANGED=YES;
    8484    fi
    8585    if [[ $TABS_CH = YES ]];
    8686    then
    87         echo -n ' [tabs removed]'
    88         CHANGED=YES;
     87        echo -n ' [tabs removed]'
     88        CHANGED=YES;
    8989    fi
    9090    if [[ $SPACES_CH = YES ]];
    9191    then
    92         echo -n ' [trailing spaces removed]'
    93         CHANGED=YES;
     92        echo -n ' [trailing spaces removed]'
     93        CHANGED=YES;
    9494    fi
    9595    if long_line_test $1 ;
    9696    then
    97         echo -n ' [LONG LINES]'
    98         ((LONG_LINE_FILES++))
     97        echo -n ' [LONG LINES]'
     98        ((LONG_LINE_FILES++))
    9999    fi
    100100    echo
    101101    if [[ $CHANGED = YES ]];
    102102    then
    103         ((CHANGED_FILES++))
     103        ((CHANGED_FILES++))
    104104    fi
     105}
     106
     107function list_files() {
     108    hg status -a -m -c |
     109    cut -d ' ' -f 2 | grep -E  '\.(cc|h|dox)$' | sort | uniq
    105110}
    106111
    107112CHANGED_FILES=0
     
    109114LONG_LINE_FILES=0
    110115if [ $# == 0 ]; then
    111116    echo Update all source files...
    112     for i in `hg manifest|grep -E  '\.(cc|h|dox)$'`
     117    while read i
    113118    do
    114         update_file $HGROOT/$i
    115         ((TOTAL_FILES++))
    116     done
     119        update_file $HGROOT/$i
     120        ((TOTAL_FILES++))
     121    done < <(list_files)
    117122    echo '  done.'
    118123else
    119     for i in $*
     124    for i in $@
    120125    do
    121         update_file $i
    122         ((TOTAL_FILES++))
     126        update_file $i
     127        ((TOTAL_FILES++))
    123128    done
    124129fi
    125130echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
    126131if [[ $LONG_LINE_FILES -gt 1 ]]; then
    127132    echo
    128     echo WARNING: $LONG_LINE_FILES files contains long lines!   
     133    echo WARNING: $LONG_LINE_FILES files contains long lines!
    129134    echo
    130135elif [[ $LONG_LINE_FILES -gt 0 ]]; then
    131136    echo