--- 2003-04-10-07/moz Thu Apr 10 07:48:16 2003 +++ latest/moz Thu Apr 24 03:12:06 2003 @@ -1,6 +1,6 @@ #!/bin/sh appname=`basename "$0"` - ver="0.2.2RC1.2003041007" + ver="0.2.2RC1.2003042403" copy="2002, 2003" mail="PointedEars@gmx.de" mail_feedback="bug-moz@PointedEars.de" @@ -39,38 +39,55 @@ mail_feedback="bug-moz@PointedEars.de" # # 0.2.2 (future) # --------------- - # * Accessing the URI in a new browser tab (Mozilla 1.0.1, 1.1 and beyond) - # * Mixing of new-window, new-tab and new-process options is possible - # * With `-k', first try SIGTERM(15) and if (and only if) this has no effect, - # send SIGKILL(9); wait [with `-remote ping()'] for Mozilla to end before - # doing anything - # * `-l' lists running `mozilla-bin' processes/threads using `ps'; - # Tests for and support of user-oriented `ps' output (`u'), - # uses Unix98 options as fallback; allow arbitrary `ps' options - # * `-m' allows to open new Compose window with predefined `To:' field - # * `-i' opens a new MailNews window - # * `-c' opens a new Compose window with empty `To:' field - # * Send error messages to stderr - # * Fixed function-in-statement-bug on `sh' (@IRIX) - # * Support SysV compliant `ps' calls (@IRIX) - # * If not running on first argument, wait for the process - # [with `-remote ping()'] before passing on to the second argument - # * _XPG=1 for `$( `$command` )' and `$(( `$expression` ))' in `sh' (@IRIX 6.5) - # * `--version': Display version information and exit - # * Speed-up Mozilla process start-up by using ping() only for first -remote - # * Allow to use local directories and filenames as URI argument; the argument - # is then preceded by file://`pwd`/ - # * Cosmetics: + # + # Enhancements: + # + # * Access a resource in a new browser tab (Mozilla 1.0.1, 1.1 and beyond). + # * Mix new-window, new-tab and new-process options + # * "Kill" a Mozilla process trying to send SIGTERM(15) and if (and only if) + # this has no effect, send SIGKILL(9); wait with `-remote ping()' for + # Mozilla to "die" before doing anything else. + # * List running `mozilla-bin' processes/threads with `ps'; Test for and + # support user-oriented `ps' output (`u'), use Unix98 options as fallback; + # allow arbitrary `ps' options as argument + # * Open a new Compose window with predefined `To:' field + # * Open a new MailNews window + # * Open a new Compose window with empty `To:' field + # * Display version information and exit + # * Use local directories and filenames as URI argument; + # (the argument is then preceded internally by file://`pwd`/) + # * Support other programs similar to Mozilla (like Phoenix) by specifying + # the start-up command; use MOZILLA_CMD environment as default or `mozilla' + # if it is not present. + # * Cosmetics # - Added status messages + # - Send error messages to stderr # - Bold-formatted title with changed tagline # - Updated and reformatted help screen - # - s/Protected/Distributed/ - # - Fixed typo in english help for `-w' option (deprecated) - # - Output is preformatted for 80 cols; - # reformats only when $COLUMNS is different (fast!) + # - Output is preformatted for 80 columns; reformats + # only when COLUMNS environment is different (fast!) # - Reformatted source not to exceed 80 cols per line (with `\') # to make it easier legible on the console + # - Workaround kate's imperfect syntax highlighting with a bunch of `# `' + # (post complains at kate.kde.org) # - Separated help source by a blank line + # - Removed unused variables + # + # Bugfixes: + # + # * If not running on first argument, wait for the process with + # `-remote ping()' before passing on to the second argument; + # speeds-up Mozilla process start-up by using ping() only for + # first `-remote' and should prevent `Unable to send command.' + # * Fixed function-in-statement bug on `sh' (IRIX 6.5) + # * Support SysV compliant `ps' calls for working `-l' on IRIX 6.5 + # * _XPG=1 for `$( `$command` )' and `$(( `$arithmetic_expression` ))' + # parameter expansion in `sh' (IRIX 6.5) + # * Fixed bug that replaces old with new URI; now opens new window + # instead in accordance with documentation + # * Cosmetics: + # - s/Protected/Distributed/ + # - Fixed typo in English help for `-w' option (deprecated) # # See the ChangeLog text file for further information. # @@ -78,8 +95,6 @@ mail_feedback="bug-moz@PointedEars.de" # # * POSIX conform parsing of options and arguments (incomplete) # * L10n: English and German (using macro function) (incomplete) - # * `-M', `--mozilla': Support other programs similar to Mozilla like Phoenix - # (incomplete) # * `-C', `--command' options to execute arbitrary Mozilla commands # * Cosmetics: # - More modular code (incomplete) @@ -111,6 +126,8 @@ Copyright (C) $copy Thomas Lahn <$mail> details." \ "Details in Datei COPYING oder unter http://www.fsf.org/copyleft/gpl.html" \ | $fold + + # ` } function help { @@ -189,7 +206,8 @@ befindet, Befehl angeben, der sich im \`\$PATH' befindet, daher wird das Programm nicht überprüfen, ob der angegebene Pfad korrekt ist." | $fmt - + + # ` # version 0.2.3 proposal # echo " --block Block the shell for the 'mozilla' process, i.e. prevent" # echo " following commands to be executed until Mozilla is \ @@ -217,7 +235,7 @@ previously used diese Funktion benutzt, bedeutet aber jetzt, dass ein neuer Browser-Tab erzeugt wird (siehe unten)." | $fmt - + echo -n " ${extd}-k${norm}, ${extd}--kill${norm} " L "Kill all Mozilla processes (first). Tries first to send" \ "Beendet (zuerst) alle Mozilla-Prozesse." | $fold @@ -230,7 +248,7 @@ L "\ zu senden, um ihn höflich um seine Beendigung zu bitten. Nur wenn das nicht funktioniert, wird an den Prozess das ziemlich ruppige SIGKILL(9)-Signal gesendet ;-)" | $fmt - + echo -n " ${extd}-l${norm}, ${extd}--list${norm} " L "List running Mozilla processes and threads and exit." \ "Zeigt laufende Mozilla-Prozesse an." | $fold @@ -244,7 +262,7 @@ L "\ "\ Standardmässig wird das benutzerorientierte Format benutzt, falls es unterstützt wird." | $fmt - + echo -n " ${extd}-n${norm}, ${extd}--new${norm} " L "Same as \`${extd}-w${norm}'. For backwards compatibility only," \ "Wie \`${extd}-w${norm}'. Nur für Abwärtskompatibilität vorhanden," | $fold @@ -362,12 +380,12 @@ $(L "\ Note that the long options are not available on this system, so you must use the short options instead. Also, optional arguments are not supported, so if you do not pass an argument to an option, you must - use \'\' instead." \ + use \"\" instead." \ "\ Beachten Sie, dass die langen Optionen auf diesem System nicht verfügbar sind, so dass Sie die kurzen Optionen verwenden müssen. Weiterhin werden optionale Argumente nicht unterstützt. Wenn Sie ein optionales Argument - nicht angeben, müssen Sie stattdessen \'\' angeben." | $fmt)" + nicht angeben, müssen Sie stattdessen \"\" angeben." | $fmt)" _XPG=0 fi echo @@ -402,7 +420,7 @@ function isMozRunning { test -z "$chk" && return 1 return 0 } - + function KillMoz { local result=0 @@ -423,12 +441,12 @@ function KillMoz { echo $rc_failed else ping=1 - mozilla -remote "ping()" 2>/dev/null + "$mozilla" -remote "ping()" 2>/dev/null error=$? test $verbose -eq 1 && echo -n $error" " >&2 while [ $error -eq 0 ] && [ $ping -le 50 ]; do let ping++ - mozilla -remote "ping()" 2>/dev/null + "$mozilla" -remote "ping()" 2>/dev/null error=$? test $verbose -eq 1 && echo -n $error" " >&2 if [ $ping -eq 25 ]; then @@ -530,7 +548,19 @@ function ListMoz { echo } - # MAIN + function RunMsg { + case $1 in + new) + echo -n `L "Starting a new Mozilla process" \ + "Starte einen neuen Mozilla-Prozess"` + shift + RunMsg $* + ;; + *) ;; + esac + } + + # ********************************** MAIN ************************************** # from /etc/rc.status # check for $COLUMNS @@ -546,45 +576,29 @@ if test "$TERM" != "raw" && stty size >/ extd="${esc}[1m" warn="${esc}[1;31m" done="${esc}[1;32m" - attn="${esc}[1;33m" norm=`echo -en "${esc}[m\017"` stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"` - - rc_done="${done}done${norm}" - rc_running="${stat}${done}running${norm}" - rc_failed="${warn}failed${norm}" - rc_missed="${warn}not found${norm}" - rc_skipped="${stat}${attn}skipped${norm}" - rc_dead="${stat}${warn}not running${norm}" - rc_unused="${stat}${extd}unused${norm}" - rc_done_up="${esc}[1A${rc_done}" - rc_failed_up="${esc}[1A${rc_failed}" - rc_reset="${norm}" - rc_save="${esc}7" - rc_restore="${esc}8" + up="[1a" else esc="" extd="" warn="" done="" - attn="" norm="" stat="... " - - rc_done="done" - rc_running="running" - rc_failed="failed" - rc_missed="missing" - rc_skipped="skipped" - rc_dead="not running" - rc_unused="unused" - rc_done_up="${rc_done}" - rc_failed_up="${rc_failed}" - rc_reset="" - rc_save="" - rc_restore="" + up="" fi + rc_done="${done}done${norm}" + rc_running="${stat}${done}running${norm}" + rc_failed="${warn}failed${norm}" + rc_dead="${stat}${warn}not running${norm}" + rc_done_up="${esc}${up}${rc_done}" + rc_failed_up="${esc}${up}${rc_failed}" + rc_reset="${norm}" + rc_save="${esc}7" + rc_restore="${esc}8" + # check for fold fold="fold -sw $COLUMNS" chk=`which fold 2>/dev/null` @@ -625,10 +639,14 @@ Title # separate word. The quotes around `$@' are essential! # We need `tmp' as the `eval set --' would nuke the return value of getopt. - echo "$*" + echo "$extd + Debug output for POSIX conform command-line + parsing (will require -vv in the release). + + Original arguments: $*" >&2 if `getopt -T >/dev/null 2>&1` ; [ $? = 4 ] ; then getopt_type=long - echo "Enhanced getopt(1)" + echo "getopt(1) type: enhanced" >&2 tmp=`getopt -o vL:hVM:Tkl::n:w:t:-m::ic \ -l verbose,locale:,help,version,mozilla:,term,kill,list,full,\ new:,win:,tab:,mailto::,inbox,compose \ @@ -636,7 +654,7 @@ new:,win:,tab:,mailto::,inbox,compose \ -- "$@"` else getopt_type=short - echo "Old getopt(1)" + echo "getopt(1) type: old" >&2 tmp=`getopt vL:hVM:Tkl:n:w:t:-m:ic "$@"` fi @@ -644,7 +662,7 @@ getopt_exit_code=$? help=0 verbose=0 version=0 - mozilla="mozilla" + mozilla=${MOZILLA_CMD:-mozilla} term="" list=0 list_style="" @@ -660,6 +678,8 @@ if [ $getopt_exit_code -eq 0 ]; then # remove "--" # for i in $tmp; do if [ "$i" != "--" ]; then tmp2="${tmp2} $i"; fi; done eval set -- "$tmp" + echo "New arguments: $*$norm + " >&2 while true ; do case "$1" in -h | --help) help=1; shift;; @@ -679,7 +699,7 @@ if [ $getopt_exit_code -eq 0 ]; then esac done test -n "$*" && args=$args" $*" - test -z "$args" -a $version -eq 0 -a $list -eq 0 && help=1 + test -z "$args" -a $version -eq 0 -a "$term" = "" -a $list -eq 0 && help=1 set -- $args else echo "getopt exited: $getopt_exit_code @@ -691,14 +711,14 @@ else fi fi - test $help -eq 1 && help && test -n "$1" && shift + test $help -eq 1 && help echo `L "Send suggestions and bug reports to" \ "Senden Sie Vorschläge und Fehlerberichte an"`" <$mail_feedback> " | $fold - # test $version -eq 1 && exit 0 - # test $help -eq 1 && exit 255 + test $version -eq 1 && exit 0 + test $help -eq 1 && exit 255 # check for term/kill kill=0 @@ -709,24 +729,27 @@ if [ "$term" = "t" ] || [ "$term" = "k" test $? -ne 0 && $sig -eq -9 && KillMoz $sig fi + error=0 + # check for list - test $list -eq 1 && ListMoz "$list_style" && exit 0 + test $list -eq 1 && ListMoz "$list_style" && set -- "" + new_win=0 if [ -n "$1" ]; then # check for Mozilla - chk=`which mozilla 2>/dev/null` - if [ $? -ne 0 ]; then + chk=`which "$mozilla" 2>/dev/null` + if [ $? -ne 0 ] && [ ! -x "$mozilla" ]; then _XPG=1 echo "${appname}: \ - $(L "The \`mozilla' executable is required for this program." \ - "Die ausführbare Datei \`mozilla' wird für dieses Programm benötigt.") + $(L "The \`${mozilla}' executable is required for this program." \ + "Die ausführbare Datei \`${mozilla}' wird für dieses Programm benötigt.") " | $fold >&2 _XPG=0 - exit 255 + set -- "" + error=255 fi - new_win=0 new_tab=0 while [ -n "$1" ]; do mailto=0 @@ -781,25 +804,24 @@ if [ -n "$1" ]; then test -d "$uri" -o -f "$uri" && uri="file://"`pwd 2>/dev/null`"/$uri" if [ -z "$chk" ]; then - echo -n `L "Starting a new Mozilla process" \ - "Starte einen neuen Mozilla-Prozess"` + RunMsg new test -n "$uri" && test $mailto -eq 1 && test $inbox -eq 0 \ && test $compose -eq 0 && echo -n " "`L "with URI" "mit dem URI"`" '$uri'" echo -n "$stat" #if [ $block -eq 1 ]; then - # mozilla "$uri" + # "$mozilla" "$uri" #else - mozilla "$uri" & + "$mozilla" $uri & #fi error=$? if [ -n "$2" ]; then ping=1 - mozilla -remote "ping()" 2>/dev/null + "$mozilla" -remote "ping()" 2>/dev/null error=$? test $verbose -eq 1 && echo -n $error" " >&2 while [ $error -ne 0 ] && [ $ping -le 50 ]; do let ping++ - mozilla -remote "ping()" 2>/dev/null + "$mozilla" -remote "ping()" 2>/dev/null error=$? test $verbose -eq 1 && echo -n $error" " >&2 if [ $ping -eq 25 ]; then @@ -818,16 +840,16 @@ if [ -n "$1" ]; then test $verbose -eq 1 && \ L "Mozilla was pinged "$ping" times until startup was complete." \ "Mozilla wurde "$ping" Mal gepingt, bevor er vollständig gestartet \ - war." | $fmt >&2 + war." | $fmt >&2 else echo $rc_failed test $verbose -eq 1 && \ L " - Mozilla was pinged "$ping" times without response. - Please check your Mozilla installation." \ + Mozilla was pinged "$ping" times without response. + Please check your Mozilla installation." \ " - Mozilla wurde "$ping" Mal erfolglos gepingt. - Bitte überprüfen Sie ihre Mozilla-Installation." | $fmt >&2 + Mozilla wurde "$ping" Mal erfolglos gepingt. + Bitte überprüfen Sie ihre Mozilla-Installation." | $fmt >&2 fi else if [ $error -eq 0 ]; then @@ -839,7 +861,7 @@ if [ -n "$1" ]; then else # check what kind of URI was given if [ -z "$cmd" ]; then - cmd="openURL($uri" + cmd="openURL("$uri test $new_win -eq 1 && cmd=$cmd", new-window" test $new_tab -eq 1 && cmd=$cmd", new-tab" cmd=$cmd")" @@ -892,15 +914,16 @@ if [ -n "$1" ]; then fi fi echo -n "$stat" - mozilla -remote "$cmd" & + "$mozilla" -remote "$cmd" & if [ $? -eq 0 ]; then echo $rc_done; else echo $rc_failed; fi fi test -n "$1" && shift - # new_win=1 + new_win=1 done fi echo test $verbose -eq 1 -o $getopt_exit_code -eq 1 \ - && L "Press any key..." "Beliebige Taste drücken ..." | $fold && read -n 1 - exit 0 + && read -rs -p "`L "Press any key..." "Beliebige Taste drücken ..." | $fold`" -n 1 && echo " + " + exit $error