ff7476fb1c9da8b595fdf8a162dcb9c65d814b0d
[oweals/cde.git] / cde / programs / dtopen / dtopen.src
1 XCOMM!/bin/ksh
2 XCOMM
3 XCOMM dtopen - provide an interface for some useful applications.
4 XCOMM
5 XCOMM #############################################################
6 XCOMM #set -x           # uncomment for debugging
7 XCOMM ###############################################################
8 XCOMM Init
9
10 DTOPEN="dtopen"                   # Identity crisis
11 APPNAME="$(basename $0)"        # the app to locate/run
12
13 XCOMM apps to look for, given an action (based on APPNAME - see MAIN)
14
15 XCOMM image viewing
16 if [ -z "$DTOPEN_VIMAGE" ]
17 then
18     VIMAGE="xv display gimp"
19 else
20     VIMAGE="$DTOPEN_VIMAGE"
21 fi
22
23 XCOMM video viewing
24 if [ -z "$DTOPEN_VVIDEO" ]
25 then
26     VVIDEO="vlc ffplay"
27 else
28     VVIDEO="$DTOPEN_VVIDEO"
29 fi
30
31 XCOMM postscript viewing
32 if [ -z "$DTOPEN_VPS" ]
33 then
34     VPS="mgv gv"
35 else
36     VPS="$DTOPEN_VPS"
37 fi
38
39 XCOMM PDF viewing
40 if [ -z "$DTOPEN_VPDF" ]
41 then
42     VPDF="okular xpdf"
43 else
44     VPDF="$DTOPEN_VPDF"
45 fi
46
47 XCOMM ##############################################################
48 XCOMM ## Utility Functions
49
50 XCOMM ## Find the path of a program
51 FindProg()
52 {
53     # FindProg "program"
54     # - returns full path, or ""
55
56     whence $1
57
58     return 0
59 }
60
61 XCOMM ## Show an error message
62 ErrorMsg()
63 {
64     # ErrorMsg "Title "Message" ["OK"]
65     # use dterror.ds to display it...
66
67     if [ -z "$3" ]
68     then    # default to 'OK'
69         OKM="OK"
70     else
71         OKM="$3"
72     fi
73
74     CDE_INSTALLATION_TOP/bin/dterror.ds "$2" "$1" "$OKM"
75
76     return 0
77 }
78
79 XCOMM ## do a simple command
80 DoSimpleCmd()
81 {
82     # DoSimpleCmd "commands" args
83
84     didone=0
85     cmds="$1"
86     shift
87     args="$*"
88
89     for i in $cmds
90     do
91         thecmd="$(FindProg $i)"
92
93         if [ ! -z "$thecmd" ]
94         then    # it's there
95             $thecmd "$args"
96             didone=1
97             break
98         fi
99     done
100
101     if [ $didone -eq 0 ]
102     then    # couldn't find a viewer
103         ErrorMsg "Helper not found" \
104                  "${DTOPEN}: Could not find any of the following\ncommands for this file type:\n\n$cmds"
105     fi
106
107     return 0
108 }
109
110
111 XCOMM ##################################################################
112 XCOMM ## MAIN
113
114 XCOMM # We'll just look at our args and decide what to do...
115
116 XCOMM # Commands we'll recognize
117
118 COMMANDS="dtopen_image dtopen_pdf dtopen_ps dtopen_video"
119
120 case $APPNAME in
121     dtopen_image)
122         DoSimpleCmd "$VIMAGE" $*
123         ;;
124     dtopen_pdf)
125         DoSimpleCmd "$VPDF" $*
126         ;;
127     dtopen_ps)
128         DoSimpleCmd "$VPS" $*
129         ;;
130     dtopen_video)
131         DoSimpleCmd "$VVIDEO" $*
132         ;;
133     *)
134         # Unknown
135         ErrorMsg "${DTOPEN}: Unknown Helper Application" \
136                   "\"$APPNAME\" is not a recognized Helper Application.  \nKnown Helper Applications are:\n\n$COMMANDS"
137         ;;
138 esac
139
140 XCOMM # Fini
141 exit 0