#!/bin/sh

###############################################################################
#									      #
#         UNIX Interactive Tools 4.3.1  per file type action script	      #
#			       Global version				      #
#	    Copyright (c) 1993, 1994 Tudor Hulubei & Andrei Pitis	      #
#									      #
###############################################################################

#
# This script executes a different action for each file type specified.
# The script tries to match (using uitmatch) the second parameter against
# the patterns given as command line arguments to uitmatch (see below).
# uitmatch returns 0 if the parameter doesn't match or the number in the
# list of the pattern that matched.
# If you want to add new file types & actions to this script, just add a
# new pattern after the last pattern in the list and a corresponding
# action to the 'case' statement.
#
# For grater flexibility, uitaction's first parameter is the name of the
# directory where the file resides. So, you can get the complete file
# name appending the file base name to the file path just like that: $1/$2
#
# If you enhance this script, please send me a patch (tudor@ulise.cs.pub.ro).
# I'll include it in the next release.
#

if [ "$#" -ne 2 -o ! -d "$1" -o ! -f "$2" ]
then
    echo $0: UIT internal script >&2
    exit 255
fi

type=0

if [ -f .uitaction ]
then
    ./.uitaction $1 $2
    type=$?
fi

if [ $type != 0 ]
then
    exit 0
fi


uitmatch $2 "*.cc" "*.c" "*.l" "*.y" "*.h" "*.s" "*.S" "*.o" "*.a" "*.sa"   \
	    "Makefile" "makefile"					    \
	    "*.tar.gz" "*.tgz" "*.tar.z" "*.tar.Z" "*.taz" "*.tar" "*.gz"   \
	    "*.z" "*.Z"							    \
	    "*.doc" "*.txt"						    \
	    "*.gif" "*.jpg" "*.tif" "*.bmp"

type=$?

case $type in
0)		more    $2;;				# no match
1)		c++ -O2 $2;;				# *.cc
2)		cc  -O2 $2;;				# *.c
3)		lex     $2;;				# *.l
4)		yacc -d $2;;				# *.y
5)		more    $2;;				# *.h
6  | 7)		cc      $2;;				# *.s, *.S
8)		objdump -hnrt $2 | more;;		# *.o
9  | 10)	ar -tv        $2 | more;;		# *.a, *.sa
11 | 12)	make;;					# Makefile, makefile
13 | 14 | 15 | 16 | 17)					# *.tar.gz 	\
		(echo "Compressed file info:";		# *.tgz		\
		gunzip -l $2;				# *.tar.z	\
		echo;					# *.tar.z	\
		echo "Tar file info:";			# *.tar.Z	\
		gunzip -c $2 | tar tvf - ) | more;;
18)		tar tvf   $2 | more;;			# *.tar
19 | 20 | 21)	gunzip -c $2 | more;;			# *.gz, *.z, *.Z
22 | 23)	more      $2;;				# *.doc, *.txt
24 | 25)	zgv	  $2;;				# *.gif, *.jpg
26)							# *.tif		\
		echo;							\
		echo "No *.tif viewer specified.";			\
		echo "Please edit the uitaction script.";;
27)							# *.bmp		\
		echo;							\
		echo "No *.bmp viewer specified.";			\
		echo "Please edit the uitaction script.";;
esac

echo
echo "Press any key ..."

exit 0
