<commit_before>#!/bin/bash

set -e

echo "usage:"
echo "    $0 JOB"
echo "where JOB is:"
echo "    0 -- count lines [default]"
echo "    1 -- execute goimports"
echo "    2 -- generate depedency graphs"
echo "    3 -- fix links in README files"

JOB=0
if [[ $# != 0 ]]; then
    JOB=$1
    if [[ $JOB -lt 0 || $JOB -gt 3 ]]; then
        echo
        echo "Job number $1 is invalid"
        echo
        exit 1
    fi
fi

echo "current JOB = $JOB"

if [[ $JOB == 0 ]]; then
    totnfiles=0
    totnlines=0
    for f in `find . -iname "*.go"`; do
        totnfiles=$(($totnfiles+1))
        totnlines=$(($totnlines+`wc -l $f | awk '{print $1}'`))
    done
    echo
    echo "Total number of files = $totnfiles"
    echo "Total number of lines = $totnlines"
    exit 0
fi

ALL="
chk \
io \
utl \
plt \
mpi \
la  \
la/mkl \
la/oblas \
fdm \
num \
fun \
gm \
gm/msh \
gm/tri \
gm/rw \
graph \
ode \
opt \
rnd \
rnd/sfmt \
rnd/dsfmt \
tsr \
vtk \
img \
img/ocv \
"

EXTRA="
examples \
tools \
"

rungoimports() {
    pkg=$1
    for f in *.go; do
        echo $f
        goimports -w $f
    done
}

depgraph(){
    pkg=$1
    fna="/tmp/gosl/depgraph-${pkg/\//_}-A.png"
    fnb="/tmp/gosl/depgraph-${pkg/\//_}-B.svg"
    godepgraph -s github.com/cpmech/gosl/$pkg | dot -Tpng -o $fna
    graphpkg -stdout -match 'gosl' github.com/cpmech/gosl/$pkg > $fnb
    echo "file <$fna> generated"
    echo "file <$fnb> generated"
}

fixreadme() {
    pkg=$1
    #old="http://rawgit.com/cpmech/gosl/master/doc/xx${pkg/\//-}.html"
    #new="https://godoc.org/github.com/cpmech/gosl/${pkg}"
    #sed -i 's,'"$old"','"$new"',' README.md
    key="More information is available in"
    lnk="[![GoDoc](https://godoc.org/github.com/cpmech/gosl/${pkg}?status.svg)](https://godoc.org/github.com/cpmech/gosl/${pkg})"
    lnk=$(echo "$lnk" | sed 's/\//\\\//g')
    # prepend
    sed -i "/More information is available in/i $lnk \n" README.md
}

if [[ $JOB == 1 ]]; then
    ALL="$ALL $EXTRA"
fi

if [[ $JOB == 2 ]]; then
    mkdir -p /tmp/gosl
fi

idx=1
for pkg in $ALL; do
    HERE=`pwd`
    cd $pkg
    echo
    echo ">>> $idx $pkg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
    if [[ $JOB == 1 ]]; then
        rungoimports $pkg
    fi
    if [[ $JOB == 2 ]]; then
        depgraph $pkg
    fi
    if [[ $JOB == 3 ]]; then
        fixreadme $pkg
    fi
    cd $HERE
    (( idx++ ))
done
<commit_msg>Disable prepend command in script<commit_after>#!/bin/bash

set -e

echo "usage:"
echo "    $0 JOB"
echo "where JOB is:"
echo "    0 -- count lines [default]"
echo "    1 -- execute goimports"
echo "    2 -- generate depedency graphs"
echo "    3 -- fix links in README files"

JOB=0
if [[ $# != 0 ]]; then
    JOB=$1
    if [[ $JOB -lt 0 || $JOB -gt 3 ]]; then
        echo
        echo "Job number $1 is invalid"
        echo
        exit 1
    fi
fi

echo "current JOB = $JOB"

if [[ $JOB == 0 ]]; then
    totnfiles=0
    totnlines=0
    for f in `find . -iname "*.go"`; do
        totnfiles=$(($totnfiles+1))
        totnlines=$(($totnlines+`wc -l $f | awk '{print $1}'`))
    done
    echo
    echo "Total number of files = $totnfiles"
    echo "Total number of lines = $totnlines"
    exit 0
fi

ALL="
chk \
io \
utl \
plt \
mpi \
la  \
la/mkl \
la/oblas \
fdm \
num \
fun \
gm \
gm/msh \
gm/tri \
gm/rw \
graph \
ode \
opt \
rnd \
rnd/sfmt \
rnd/dsfmt \
tsr \
vtk \
img \
img/ocv \
"

EXTRA="
examples \
tools \
"

rungoimports() {
    pkg=$1
    for f in *.go; do
        echo $f
        goimports -w $f
    done
}

depgraph(){
    pkg=$1
    fna="/tmp/gosl/depgraph-${pkg/\//_}-A.png"
    fnb="/tmp/gosl/depgraph-${pkg/\//_}-B.svg"
    godepgraph -s github.com/cpmech/gosl/$pkg | dot -Tpng -o $fna
    graphpkg -stdout -match 'gosl' github.com/cpmech/gosl/$pkg > $fnb
    echo "file <$fna> generated"
    echo "file <$fnb> generated"
}

fixreadme() {
    pkg=$1
    #old="http://rawgit.com/cpmech/gosl/master/doc/xx${pkg/\//-}.html"
    #new="https://godoc.org/github.com/cpmech/gosl/${pkg}"
    #sed -i 's,'"$old"','"$new"',' README.md

    # prepend link before key
    #key="More information is available in"
    #lnk="[![GoDoc](https://godoc.org/github.com/cpmech/gosl/${pkg}?status.svg)](https://godoc.org/github.com/cpmech/gosl/${pkg})"
    #lnk=$(echo "$lnk" | sed 's/\//\\\//g')
    #sed -i "/More information is available in/i $lnk \n" README.md
}

if [[ $JOB == 1 ]]; then
    ALL="$ALL $EXTRA"
fi

if [[ $JOB == 2 ]]; then
    mkdir -p /tmp/gosl
fi

idx=1
for pkg in $ALL; do
    HERE=`pwd`
    cd $pkg
    echo
    echo ">>> $idx $pkg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
    if [[ $JOB == 1 ]]; then
        rungoimports $pkg
    fi
    if [[ $JOB == 2 ]]; then
        depgraph $pkg
    fi
    if [[ $JOB == 3 ]]; then
        fixreadme $pkg
    fi
    cd $HERE
    (( idx++ ))
done

{'fraction_non_alphanumeric': 0.2001258653241032, 'fraction_numerical': 0.011327879169288861, 'mean_word_length': 2.0900842514581983, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, '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': '2820938', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1990, 'n_words': 503}