#!/bin/sh

###############################################################################
#									      #
#           GNU Interactive Tools 4.3.5 per file type action script	      #
#				Global version				      #
#		Copyright (C) 1994 Free Software Foundation, Inc.	      #
#		    Written by Tudor Hulubei and Andrei Pitis.		      #
#									      #
###############################################################################

#
# This script executes a different action for each file type specified.
# The script tries to match (using gitmatch) the second parameter against
# the patterns given as command line arguments to gitmatch (see below).
# gitmatch 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, gitaction'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@cs.pub.ro).
# I'll include it in the next release.
#

name=`basename $0`

if test "$#" -ne 2 -o ! -d "$1" -o ! -f "$2"; then
    echo "$name: UIT internal script" >&2
    exit 255
fi

type=0

if test -f .gitaction; then
    ./.gitaction $1 $2
    type=$?
fi

if test $type != 0; then
    exit 0
fi


gitmatch $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"							    \
	    "*.texi" "*.texinfo" "*.man"					    \
	    "*.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)	makeinfo  $2;;				# *.texi, *.texinfo
24)		nroff -man $2;;				# *.man
25 | 26)	more      $2;;				# *.doc, *.txt
27 | 28)	zgv	  $2;;				# *.gif, *.jpg
29)							# *.tif		\
		echo;							\
		echo "No *.tif viewer specified.";			\
		echo "Please edit the gitaction script.";;
30)							# *.bmp		\
		echo;							\
		echo "No *.bmp viewer specified.";			\
		echo "Please edit the gitaction script.";;
esac

echo
echo "Press any key ..."

exit 0
