merge the formfield patch from ooo-build
[ooovba.git] / shell / source / unix / misc / open-url.sh
blobbe414d0e111c5bae1216ff2e1169c2f97e0a6f8e
1 #!/bin/sh
3 # tries to locate the executable specified
4 # as first parameter in the user's path.
5 which() {
6 if [ ! -z "$1" ]; then
7 for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
8 if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
9 echo "$i/$1"
10 break;
12 done
16 # checks for the original mozilla start script(s)
17 # and restrict the "-remote" semantics to those.
18 run_mozilla() {
19 if file "$1" | grep "script" > /dev/null && grep "NPL" "$1" > /dev/null; then
20 "$1" -remote 'ping()' 2>/dev/null >/dev/null
21 if [ $? -eq 2 ]; then
22 "$1" "$2" &
23 else
24 "$1" -remote "openURL($2, new-window)" &
26 else
27 "$1" "$2" &
31 # checks the browser value for a %s as defined in
32 # http://www.catb.org/~esr/BROWSER/index.html
33 run_browser() {
34 echo "$1|$2" | awk '
36 FS="|";
37 $syscmd="";
38 if (index($1,"%s") > 0) {
39 $syscmd=sprintf($1,$2);
40 } else {
41 $syscmd=sprintf("%s \"%s\"",$1,$2);
43 system($syscmd " &");
44 }' > /dev/null
47 # special handling for mailto: uris
48 if echo $1 | grep '^mailto:' > /dev/null; then
49 # check $MAILER variable
50 if [ ! -z "$MAILER" ]; then
51 $MAILER "$1" &
52 exit 0
53 else
54 # mozilla derivates may need -remote semantics
55 for i in thunderbird mozilla netscape; do
56 mailer=`which $i`
57 if [ ! -z "$mailer" ]; then
58 run_mozilla "$mailer" "$1"
59 exit 0
61 done
62 # handle all non mozilla mail clients below
63 # ..
65 else
66 # check $BROWSER variable
67 if [ ! -z "$BROWSER" ]; then
68 $BROWSER "$1" &
69 exit 0
70 else
71 # mozilla derivates may need -remote semantics
72 for i in firefox mozilla netscape; do
73 browser=`which $i`
74 if [ ! -z "$browser" ]; then
75 run_mozilla "$browser" "$1"
76 exit 0
78 done
79 # handle all non mozilla browers below
80 # ..
83 exit 1