<commit_before>#! /bin/bash

T=$(mktemp dzbXXX)

function _check() {
    # usage:
    #   _check <regex> <text>
    grep -EIn "$1" \
            src/*.c src/*.h \
            src/web/*.c src/web/*.h \
            src/notifier/*.c src/notifier/*.h > $T
    if [ "$?" -eq "0" ]; then
            echo "$2"
            cut -f1,2 -d: < $T
    fi
    rm -f $T
}

function warncheck() {
    _check "$1" "!! There are $2:"
}

function warnfncheck() {
    _check "$1\\(" "!! Use $2 instead of $1 here:"
}

warncheck '.{80,}'  '80+ chars lines'
warncheck ' +$'     'trailing spaces'
warncheck '//'      'C99-style comments'
warncheck '^ {4}\w' '4-spaces indentation'
warncheck '\w\* \w+[),]' '"*" adjacent to types instead of variables'
warncheck ' +,\w'   'spaces before a comma'
warncheck '\){'     'no spaces between ")" and "{"'
warncheck '}else'   'no spaces between "}" and "else"'

warnfncheck 'sprintf' 'snprintf'
warnfncheck 'atoi'    'strtol'

# from http://stackoverflow.com/a/167182/735926
warnfncheck 'strcpy' 'strncpy'
warnfncheck 'strcat' 'strncat'
warnfncheck 'gets'   'fgets'

# from http://www.ibm.com/developerworks/library/s-buffer-defend.html
warnfncheck 'vsprintf' 'vsnprintf'<commit_msg>More stylechecks<commit_after>#! /bin/bash

T=$(mktemp dzbXXX)

function _check() {
    # usage:
    #   _check <regex> <text>
    grep -EIn "$1" \
            src/*.c src/*.h \
            src/web/*.c src/web/*.h \
            src/notifier/*.c src/notifier/*.h > $T
    if [ "$?" -eq "0" ]; then
            echo "$2"
            cut -f1,2 -d: < $T
    fi
    rm -f $T
}

function warncheck() {
    _check "$1" "!! There are $2:"
}

function warnfncheck() {
    _check "$1\\(" "!! Use $2 instead of $1 here:"
}

warncheck '.{80,}'  '80+ chars lines'
warncheck ' +$'     'trailing spaces'
warncheck '//'      'C99-style comments'
warncheck '^ {4}\w' '4-spaces indentation'
warncheck '\w\* \w+[),]' '"*" adjacent to types instead of variables'
warncheck ' +,\w'   'spaces before a comma'
warncheck '\){'     'no spaces between ")" and "{"'
warncheck '}else'   'no spaces between "}" and "else"'

warnfncheck 'sprintf' 'snprintf'
warnfncheck 'atoi'    'strtol'

# from http://stackoverflow.com/a/167182/735926
warnfncheck 'strcpy' 'strncpy'
warnfncheck 'strcat' 'strncat'
warnfncheck 'gets'   'fgets'

# from http://www.ibm.com/developerworks/library/s-buffer-defend.html
warnfncheck 'vsprintf' 'vsnprintf'

# from https://github.com/leafsr/gcc-poison/blob/master/poison.h
warnfncheck 'wcscpy' 'wcsncpy'
warnfncheck 'stpcpy' 'stpncpy'
warnfncheck 'wcpcpy' 'wcpncpy'
{'fraction_non_alphanumeric': 0.18486739469578783, 'fraction_numerical': 0.0234009360374415, 'mean_word_length': 2.8112927191679047, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '876878', 'n_tokens_mistral': 1023, 'n_tokens_neox': 983, 'n_words': 241}