#!/bin/sh
# ./rio_add_directory <directory name> <foldernum> <fontname> <fontnum>
#
# Copyright (C) 2000  Keith Clayton (kclayton@jps.net)
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#    ---------------------------------------------------------------------- */
#
#
# Adds all the files in that directory to the rio using 
# the given font as the screen font.  Currently all fonts must reside in the
# fonts directory, which is in the same location as this script
#
# This script should handle directory names with spaces just fine. It should
# also handle file names that contain spaces.  In the directory case, enclose
# the directory name in quotes.
#

curdir=$(pwd)
command=$0
riodir=${command%rio_add_directory}
if [ $riodir = "./" ]
then 
riodir=$curdir/
fi
if [ $# = "0" ]
then
echo
echo "usage: ./rio_add_directory <directory> <folder_num> <font_name> <font_number>"
echo
echo "<directory> is the full name of the directory whose content we want to upload"
echo "<folder_num> is the index to the folder where it will be put."  
echo "<font_name> font that will be used for the text.  Must include .fon"
echo "<font_number> is the number of the font within the font file to use"
echo
exit 1
elif [ $# = "1" ] 
then
dirname=$1
foldernum="0"
fontname="defjam.fon"
fontnum="0"
echo
echo "You only entered 1 of 4 possible arguments"
echo "Using the following defaults"
echo "Directory name = "$dirname
echo "Folder number = "$foldernum
echo "Font path = "$fontname
echo "Font number = "$fontnum
echo
echo -n "Are these ok (y/n)? "
read continue
	if [ $continue = "n" ]
	then
	exit 1
	fi
elif [ $# = "2" ]
then
dirname=$1
foldernum=$2
fontname="defjam.fon"
fontnum="0"
echo
echo "You only entered 2 of 4 possible arguments"
echo "Using the following defaults"
echo "Directory name = "$dirname
echo "Folder number = "$foldernum
echo "Font path = "$fontname
echo "Font number = "$fontnum
echo
echo -n "Are these ok (y/n)? "
read continue
        if [ $continue = "n" ]
        then
        exit 1
        fi
elif [ $# = "3" ]
then
dirname=$1
foldernum=$2
fontname="$3"
fontnum="0"
echo
echo "You only entered 3 of 4 possible arguments"
echo "Using the following defaults"
echo "Directory name = "$dirname
echo "Folder number = "$foldernum
echo "Font path = "$fontname
echo "Font number = "$fontnum
echo
echo -n "Are these ok (y/n)? "
read continue
        if [ $continue = "n" ]
        then
        exit 1
        fi
elif [ $# = "4" ]
then
dirname=$1
foldernum=$2
fontname="$3"
fontnum=$4
echo
echo "Directory name = "$dirname
echo "Folder number = "$foldernum
echo "Font path = "$fontname
echo "Font number = "$fontnum
echo
echo -n "Are these ok (y/n)? "
read continue
        if [ $continue = "n" ]
        then
        exit 1
        fi
else
echo
echo "Too many arguments"
echo
echo "usage: ./rio_add_directory <directory> <folder_num> <font_name> <font_number>"
echo
echo "<directory> is the full name of the directory whose content we want to upload"
echo "<folder_num> is the index to the folder where it will be put."
echo "<font_name> font that will be used for the text. Must include .fon"
echo "<font_number> is the font number within the font file to use."
echo
exit 1
fi
searchpath="$dirname"
cd "$searchpath"
for file in *.mp3
do
if [ -f "$file" ]
then
/usr/local/bin/rio_add_song -F $foldernum -f "$fontname" -n $fontnum "$file"  
fi
done
cd "$curdir"
exit 0
