Okay, I'm looking @ 1 file.
shell file
Code:
#display main ticketing menu
display_menu()
{
# Called by run_menu
echo
echo "-- Theatre Self-service Ticketing --"
echo -n "1. "
echo -e '\E[1;32;40mList all Movies and Show time\E[0m'
echo -n "2. "
echo -e '\E[1;32;40mDisplay theatre鈥檚 seat \E[0m'
echo -n "q. "
echo -e '\E[1;31;47mQuit\E[0m'
echo -en "Enter your selection: "
}
# List out available movies
list_movies()
{
# Called by run_menu
old_IFS=$IFS
IFS=$'\n'
print_movie_header
for LINE in `sed -e 's/Yes/Ticket Available/g' -e 's/No/SOLD OUT/g' movielist.txt`
do
print_movie $LINE
done
IFS=$old_IFS
}
# Output header for movie listing
# Catered for both numbered and non-numbered list
print_movie_header()
{
echo -e '\E[1;32;40m'
if [ $# == "1" ];then
echo -n " "
fi
echo -n -e 'Movie Title'
set_colwidth 'Movie Title' 25
echo -n -e 'Show Time\t'
if [ $# == "1" ];then
echo -n -e "\t"
fi
echo -n 'Vacancy'
echo -e '\E[0m'
}
# Set the width of column
# $1 is the text in the column
# and $2 is the intended column width
set_colwidth()
{
STRING=$1
LENGTH=${#STRING}
for (( i=$LENGTH; i<=$2; i++))
do
echo -n " "
done
}
# Output movie entry
print_movie()
{
TIME=`echo $1 | cut -f1 -d ","`
TITLE=`echo $1 | cut -f2 -d ","`
AVAILABLE=`echo $1 | cut -f3 -d ","`
echo -n -e $TITLE
set_colwidth $TITLE 25
echo -n -e $TIME '\t'
echo $AVAILABLE
}
# Hint2
# Get current seating arrangement of
# selected movie from seating.txt
movie_data()
{
COUNT=1
old_IFS=$IFS
IFS=$'\n'
for LINE in `cat seating.txt`
do
if test $1 -eq $COUNT
then
display_seats $LINE $2
fi
THEATER[$COUNT]=$LINE
let COUNT=COUNT+1
done
IFS=$old_IFS
}
# Mark occupied seat with a X and
# seats selected by user with a red X
mark_seat()
{
# Called by display_seats
if [ $(echo "$1" | grep -c "$2$3") -gt 0 ]
then
echo -n "X"
set_colwidth "" 5
elif [ $(echo "$4" | grep -c "$2$3") -gt 0 ]
then
echo -en '\E[1;31mX\E[0m'
set_colwidth "" 5
else
set_colwidth "" 6
fi
}
# Print out theater's seating arrangement
display_seats()
{
COL=5
ROW=4
echo
echo "---------------------------------------"
echo -e '\E[1;34;47m----------------SCREEN-----------------\E[0m'
echo "---------------------------------------"
for (( x=0; x<=$ROW; x++))
do
echo -n "$x" | tr "0" " "
for (( j=0; j<=$COL; j++))
do
if [ $x == "0" ]
then
echo -n $j | tr "012345" " ABCDE"
set_colwidth "" 5
else
CURR_COL=$(echo $j | tr "12345" "ABCDE")
if [ $j == "0" ]
then
set_colwidth "" 6
else
mark_seat $1 $CURR_COL $x $2
fi
fi
done
echo ""
done
echo "---------------------------------------"
}
# Select and book seat manually
select_seat()
{
# Called by run_menu
COUNT=0
echo
echo "-- Select A Seat Manually --"
echo
old_IFS=$IFS
IFS=$'\n'
print_movie_header "numbered"
for LINE in `sed -e 's/Yes/Ticket Available/g' -e 's/No/SOLD OUT/g' movielist.txt `;do
let COUNT=COUNT+1
echo -n "$COUNT. "
print_movie $LINE
done
IFS=$old_IFS
echo
# Select movie to book
echo -en "Select Movie To Book (Enter 1 to ${COUNT}): "
read NUM
NUMERIC=0
while [ "$NUMERIC" != "1" ];do
for (( x=$COUNT; x>=1; x--))
do
if [ $NUM == "$x" ];then
NUMERIC=1
fi
done
if [ "$NUMERIC" != "1" ];then
echo -en "Invalid Movie Selected, Try Again (Enter 1 to ${COUNT}): "
read NUM
fi
done
movie_data $NUM
echo
old_IFS=$IFS
IFS=$'\n'
echo
}
# Main menu navigation
run_menu()
{
i=-1
while [ "$i" != "q" ]; do
display_menu
read i
i=`echo $i | tr '[A-Z]' '[a-z]'`
case "$i" in
"1")
list_movies
;;
"2")
select_seat
;;
"q")
echo "GoodBye, Have A Nice Day"
exit 0
;;
*)
echo "Unrecognised Input."
;;
esac
done
}
#----------------------------------------------#
# ---------PROGRAM SCRIPT START HERE---------- #
#----------------------------------------------#
if [ ! -f movielist.txt ]; then
echo "Error: Movie list is not available"
fi
run_menu
movielist.txt
Code:
1300 – 2Oct,The Social Network,No
1300 – 2Oct,The Town,Yes
1700 – 2Oct,Paranormal Activity 2,Yes
1900 – 2Oct,You Again,Yes
2100 – 2Oct,Kamui,Yes
seating.txt
Code:
0;,A2,A3,A1,A7,A9
0;,E6,E7,E8
14;,A1,D4,C3,B3,A4,E4
15;,A1,D4,E2,C3,A2
15;,A1,B2,C3,D4,A4
Can anyone explain to me the shell ?
How do you create extra table in the heading
Movie Title Time Slot Availability (how to include Book Now )
How do you also align the data to fit the header