#!/bin/sh

if test $# -lt 1
then
    echo -e "\nError... You must enter file path!"
    DONE=0
    exit 1

else
    if test -f temp
    then
        rm -f temp
    fi
    echo -e "\nwork in progress..."
    echo -e "\nfind codes files and store it in one file."
    find $1 -depth -name "*.c" | cat >> temp
    find $1 -depth -name "*.cpp" | cat >> temp
    find $1 -depth -name "*.cxx" | cat >> temp
    find $1 -depth -name "*.h" | cat >> temp
    find $1 -depth -name "*.hpp" | cat >> temp
    find $1 -depth -name "*.S" | cat >> temp
    find $1 -depth -name "*.asm" | cat >> temp

    echo -e "\npreparing to count the codes"
    echo -e "\nthe number of files is:\t`wc -l temp`"

    echo -e "\n Please enter the number of files now:\t"
    read numoffiles
    DONE=1
fi

if test $DONE -eq 1
then
    if test -f src
    then
        rm -f src
    fi
    COUNT=1
    while test $numoffiles -gt $COUNT
    do
    LINE=`tail +$COUNT < temp | head -n 1`
    cat $LINE | cat >> src
    COUNT=`expr $COUNT + 1`
    done
echo -e "\nComplete..."
echo -e "\nThe total numbers of codes lines is:\t`wc -l src`"
fi

