#!/bin/sh

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

#
# 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.
#

#
# The original patch sent by Verdoolaege Sven had 'less' instead of more.
# I don't know if all Unix systems have 'less', but I am pretty sure they
# have 'more', so I've put 'more' back, for the sake of portability.
# If I am wrong, please email me.  Anyway, if you really want 'less', feel
# free to change :-)
#

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"							    \
            "*.zip" "*.arj" "*.rar"                                         \
	    "*.texi" "*.texinfo" "*.man"				    \
	    "*.doc" "*.txt" "*.lsm"					    \
	    "*.gif" "*.jpg" "*.jpeg" "*.tif" "*.bmp"                        \
            "*.mpg"                                                         \
            "*.mod" "*.s3m" "*.voc" "*.wav"                                 \
            "*.ps" "*.dvi" "*.tex"					    \
	    "*.1"  "*.2"  "*.3"  "*.4"  "*.5" 				    \
	    "*.6"  "*.7"  "*.8"  "*.9"  "*.n"				    \
	    "*.1x" "*.2x" "*.3x" "*.4x" "*.5x"				    \
	    "*.6x" "*.7x" "*.8x" "*.9x" "*.nx"				    \
	    "*.1X" "*.2X" "*.3X" "*.4X" "*.5X"				    \
	    "*.6X" "*.7X" "*.8X" "*.9X" "*.nX"				    \
	    "*.1.Z"  "*.2.Z"  "*.3.Z"  "*.4.Z"  "*.5.Z"			    \
	    "*.6.Z"  "*.7.Z"  "*.8.Z"  "*.9.Z"	"*.n.Z"			    \
	    "*.1x.Z" "*.2x.Z" "*.3x.Z" "*.4x.Z" "*.5x.Z"		    \
	    "*.6x.Z" "*.7x.Z" "*.8x.Z" "*.9x.Z"	"*.nx.Z"		    \
	    "*.1X.Z" "*.2X.Z" "*.3X.Z" "*.4X.Z" "*.5X.Z"		    \
	    "*.6X.Z" "*.7X.Z" "*.8X.Z" "*.9X.Z"	"*.nX.Z"		    \
	    "*.1.z"  "*.2.z"  "*.3.z"  "*.4.z"  "*.5.z"			    \
	    "*.6.z"  "*.7.z"  "*.8.z"  "*.9.z"	"*.n.z"			    \
	    "*.1x.z" "*.2x.z" "*.3x.z" "*.4x.z" "*.5x.z"		    \
	    "*.6x.z" "*.7x.z" "*.8x.z" "*.9x.z"	"*.nx.z"		    \
	    "*.1X.z" "*.2X.z" "*.3X.z" "*.4X.z" "*.5X.z"		    \
	    "*.6X.z" "*.7X.z" "*.8X.z" "*.9X.z"	"*.nX.z"		    \
	    "*.1.gz"  "*.2.gz"  "*.3.gz"  "*.4.gz"  "*.5.gz"		    \
	    "*.6.gz"  "*.7.gz"  "*.8.gz"  "*.9.gz"  "*.n.gz"		    \
	    "*.1x.gz" "*.2x.gz" "*.3x.gz" "*.4x.gz" "*.5x.gz"		    \
	    "*.6x.gz" "*.7x.gz" "*.8x.gz" "*.9x.gz" "*.nx.gz"		    \
	    "*.1X.gz" "*.2X.gz" "*.3X.gz" "*.4X.gz" "*.5X.gz"		    \
	    "*.6X.gz" "*.7X.gz" "*.8X.gz" "*.9X.gz" "*.nX.gz"

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)	(echo "Compressed file info:";		# *.tar.gz	\
		gunzip -l  $2;				# *.tgz		\
		echo;							\
		echo "Tar file info:";					\
		gunzip -c  $2 | tar tvf - ) | more;;
15 | 16 | 17)	(echo "Compressed file info:";		# *.tar.z	\
		gunzip -l  $2;				# *.tar.Z	\
		echo;					# *.taz		\
		echo "Tar file info:";					\
		uncompress -c  $2 | tar tvf - ) | more;;
18)		tar tvf    $2 | more;;			# *.tar
19)		gunzip -c  $2 | more;;			# *.gz
20 | 21)	uncompress -c  $2 | more;;		# *.z, *.Z
22)		unzip -v   $2 | more;;			# *.zip
23)		unarj l    $2 | more;;			# *.arj
24)		unrar l    $2 | more;;			# *.rar
25 | 26)	makeinfo   $2;;				# *.texi, *.texinfo
27)		nroff -man $2 | more;;			# *.man
28 | 29 | 30)	more       $2;;				# *.doc, *.txt
31 | 32 | 33)	zgv	   $2;;				# *.gif, *.jpg, *.jpeg
34)							# *.tif		\
		echo;							\
		echo "No *.tif viewer specified.";			\
		echo "Please edit the gitaction script.";;
35)							# *.bmp		\
		echo;							\
		echo "No *.bmp viewer specified.";			\
		echo "Please edit the gitaction script.";;
36)		if [ $DISPLAY ]; then mpeg_play $2; 
                                 else mpeg_vga $2;fi;;  # *.mpg
37 | 38)	s3mod $2 &;;                            # *.mod *.s3m
39 | 40)	vplay $2 &;;				# *.voc
41)		if [ $DISPLAY ]; then (ghostview $2 &);fi;;	# *.ps
42)		if [ $DISPLAY ]; then (xdvi $2 &);fi;;		# *.dvi 
43)		latex $2;;
44  | 45  | 46  | 47  | 48  | 49  | 50  | 51  | 52  | 53  |\
54  | 55  | 56  | 57  | 58  | 59  | 60  | 61  | 62  | 63  |\
64  | 65  | 66  | 67  | 68  | 69  | 70	| 71  | 72  | 73)
		nroff -man $2 | more;;
74  | 75  | 76  | 77  | 78  | 79  | 80  | 81  | 82  | 83  |\
84  | 85  | 86  | 87  | 88  | 89  | 90  | 91  | 92  | 93  |\
94  | 95  | 96  | 97  | 98  | 99  | 100 | 101 | 102 | 103 |\
104 | 105 | 106	| 107 | 108 | 109 | 110 | 111 | 112 | 113 |\
114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |\
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133)
		uncompress -c $2 | nroff -man | more;;
134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |\
144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |\
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163)  
		gunzip -c $2 | nroff -man | more;;
esac

echo
echo "Press any key ..."

exit 0
