# Copyright 1989, 1990 Michael DeCorte

# split prefix max_size file
# splits the named file into chunks named prefix.N.split
# where each chunk is less than max_size

if [ $# != 3 ]
then
        exit 1
fi

# just in case the file is length 0 make sure that there is at least
# one file.
touch  ${1}1000split

(cat $3 ; echo )| \
${awk} "BEGIN {
        file_prefix = \"$1\";
        max_size = $2
"'        

# to account for the mail header
        max_size -= 2000;

# I start at 1000 so that ls * will give them back in the right order
        fileno=1000;
        filesize=0;
        file=file_prefix fileno "split"
        while (getline)
        {
               if (((filesize + length($0) + 1) > max_size) && (max_size > 0))
               {
                       fileno++;
                       filesize=0
                       file=file_prefix fileno "split"
               }
               filesize += length($0) + 1;
               print $0 >> file;
        }
}'

