/contrib/groff/contrib/groffer/groffer2.sh
https://bitbucket.org/freebsd/freebsd-head/ · Shell · 5854 lines · 4370 code · 361 blank · 1123 comment · 359 complexity · 56f108a0a126ad0a9df7a8b9539c98fa MD5 · raw file
Large files are truncated click here to view the full file
- #! /bin/sh
- # groffer - display groff files
- # Source file position: <groff-source>/contrib/groffer/groffer2.sh
- # Installed position: <prefix>/lib/groff/groffer/groffer2.sh
- # This file should not be run independently. It is called by
- # `groffer.sh' in the source or by the installed `groffer' program.
- # Copyright (C) 2001,2002,2003,2004,2005
- # Free Software Foundation, Inc.
- # Written by Bernd Warken
- # Last update: 22 August 2005
- # This file is part of `groffer', which is part of `groff'.
- # `groff' is free software; you can redistribute it and/or modify it
- # under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2, or (at your option)
- # any later version.
- # `groff' is distributed in the hope that it will be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with `groff'; see the files COPYING and LICENSE in the top
- # directory of the `groff' source. If not, write to the Free Software
- # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
- # USA.
- ########################################################################
- # Test of rudimentary shell functionality
- ########################################################################
- ########################################################################
- # Test of `unset'
- #
- export _UNSET;
- export _foo;
- _foo=bar;
- _res="$(unset _foo 2>&1)";
- if unset _foo >${_NULL_DEV} 2>&1 && \
- test _"${_res}"_ = __ && test _"${_foo}"_ = __
- then
- _UNSET='unset';
- eval "${_UNSET}" _foo;
- eval "${_UNSET}" _res;
- else
- _UNSET=':';
- fi;
- ########################################################################
- # Test of `test'.
- #
- if test a = a && test a != b && test -f "${_GROFFER_SH}"
- then
- :;
- else
- echo '"test" did not work.' >&2;
- exit "${_ERROR}";
- fi;
- ########################################################################
- # Test of `echo' and the `$()' construct.
- #
- if echo '' >${_NULL_DEV}
- then
- :;
- else
- echo '"echo" did not work.' >&2;
- exit "${_ERROR}";
- fi;
- if test _"$(t1="$(echo te)" &&
- t2="$(echo '')" &&
- t3="$(echo 'st')" &&
- echo "${t1}${t2}${t3}")"_ \
- != _test_
- then
- echo 'The "$()" construct did not work' >&2;
- exit "${_ERROR}";
- fi;
- ########################################################################
- # Test of sed program; test in groffer.sh is not valid here.
- #
- if test _"$(echo red | sed -e 's/r/s/')"_ != _sed_
- then
- echo 'The sed program did not work.' >&2;
- exit "${_ERROR}";
- fi;
- ########################################################################
- # Test of function definitions.
- #
- _t_e_s_t_f_u_n_c_()
- {
- return 0;
- }
- if _t_e_s_t_f_u_n_c_ 2>${_NULL_DEV}
- then
- :;
- else
- echo 'Shell '"${_SHELL}"' does not support function definitions.' >&2;
- exit "${_ERROR}";
- fi;
- ########################################################################
- # debug - diagnostic messages
- ########################################################################
- export _DEBUG_STACKS;
- _DEBUG_STACKS='no'; # disable stack output in each function
- #_DEBUG_STACKS='yes'; # enable stack output in each function
- export _DEBUG_LM;
- _DEBUG_LM='no'; # disable landmark messages
- #_DEBUG_LM='yes'; # enable landmark messages
- export _DEBUG_KEEP_FILES;
- _DEBUG_KEEP_FILES='no' # disable file keeping in temporary dir
- #_DEBUG_KEEP_FILES='yes' # enable file keeping in temporary dir
- export _DEBUG_PRINT_PARAMS;
- _DEBUG_PRINT_PARAMS='no'; # disable printing of all parameters
- #_DEBUG_PRINT_PARAMS='yes'; # enable printing of all parameters
- export _DEBUG_PRINT_SHELL;
- _DEBUG_PRINT_SHELL='no'; # disable printing of the shell name
- #_DEBUG_PRINT_SHELL='yes'; # enable printing of the shell name
- export _DEBUG_PRINT_TMPDIR;
- _DEBUG_PRINT_TMPDIR='no'; # disable printing of the temporary dir
- #_DEBUG_PRINT_TMPDIR='yes'; # enable printing of the temporary dir
- export _DEBUG_USER_WITH_STACK;
- _DEBUG_USER_WITH_STACK='no'; # disable stack dump in error_user()
- #_DEBUG_USER_WITH_STACK='yes'; # enable stack dump in error_user()
- # determine all --debug* options
- case " $*" in
- *\ --debug*)
- case " $* " in
- *' --debug '*)
- # _DEBUG_STACKS='yes';
- # _DEBUG_LM='yes';
- _DEBUG_KEEP_FILES='yes';
- _DEBUG_PRINT_PARAMS='yes';
- _DEBUG_PRINT_SHELL='yes';
- _DEBUG_PRINT_TMPDIR='yes';
- _DEBUG_USER_WITH_STACK='yes';
- ;;
- esac;
- d=' --debug-all --debug-keep --debug-lm --debug-params --debug-shell '\
- '--debug-stacks --debug-tmpdir --debug-user ';
- for i
- do
- case "$i" in
- --debug-s)
- echo 'The abbreviation --debug-s has multiple options: '\
- '--debug-shell and --debug-stacks.' >&2
- exit "${_ERROR}";
- ;;
- esac;
- case "$d" in
- *\ ${i}*)
- # extract whole word of abbreviation $i
- s="$(cat <<EOF | sed -n -e 's/^.* \('"$i"'[^ ]*\) .*/\1/p'
- $d
- EOF
- )"
- case "$s" in
- '') continue; ;;
- --debug-all)
- _DEBUG_STACKS='yes';
- _DEBUG_LM='yes';
- _DEBUG_KEEP_FILES='yes';
- _DEBUG_PRINT_PARAMS='yes';
- _DEBUG_PRINT_SHELL='yes';
- _DEBUG_PRINT_TMPDIR='yes';
- _DEBUG_USER_WITH_STACK='yes';
- ;;
- --debug-keep)
- _DEBUG_PRINT_TMPDIR='yes';
- _DEBUG_KEEP_FILES='yes';
- ;;
- --debug-lm)
- _DEBUG_LM='yes';
- ;;
- --debug-params)
- _DEBUG_PRINT_PARAMS='yes';
- ;;
- --debug-shell)
- _DEBUG_PRINT_SHELL='yes';
- ;;
- --debug-stacks)
- _DEBUG_STACKS='yes';
- ;;
- --debug-tmpdir)
- _DEBUG_PRINT_TMPDIR='yes';
- ;;
- --debug-user)
- _DEBUG_USER_WITH_STACK='yes';
- ;;
- esac;
- ;;
- esac;
- done
- ;;
- esac;
- if test _"${_DEBUG_PRINT_PARAMS}"_ = _yes_
- then
- echo "parameters: $@" >&2;
- fi;
- if test _"${_DEBUG_PRINT_SHELL}"_ = _yes_
- then
- if test _"${_SHELL}"_ = __
- then
- if test _"${POSIXLY_CORRECT}"_ = _y_
- then
- echo 'shell: bash as /bin/sh (none specified)' >&2;
- else
- echo 'shell: /bin/sh (none specified)' >&2;
- fi;
- else
- echo "shell: ${_SHELL}" >&2;
- fi;
- fi;
- ########################################################################
- # Environment Variables
- ########################################################################
- # Environment variables that exist only for this file start with an
- # underscore letter. Global variables to this file are written in
- # upper case letters, e.g. $_GLOBAL_VARIABLE; temporary variables
- # start with an underline and use only lower case letters and
- # underlines, e.g. $_local_variable .
- # [A-Z]* system variables, e.g. $MANPATH
- # _[A-Z_]* global file variables, e.g. $_MAN_PATH
- # _[a-z_]* temporary variables, e.g. $_manpath
- # Due to incompatibilities of the `ash' shell, the name of loop
- # variables in `for' must be single character
- # [a-z] local loop variables, e.g. $i
- ########################################################################
- # read-only variables (global to this file)
- ########################################################################
- # function return values; `0' means ok; other values are error codes
- export _ALL_EXIT;
- export _BAD;
- export _GOOD;
- export _NO;
- export _OK;
- export _YES;
- _GOOD='0'; # return ok
- _BAD='1'; # return negatively, error code `1'
- # $_ERROR was already defined as `7' in groffer.sh.
- _NO="${_BAD}";
- _YES="${_GOOD}";
- _OK="${_GOOD}";
- # quasi-functions, call with `eval', e.g `eval "${return_ok}"'
- export return_ok;
- export return_good;
- export return_bad;
- export return_yes;
- export return_no;
- export return_error;
- export return_var;
- return_ok="func_pop; return ${_OK}";
- return_good="func_pop; return ${_GOOD}";
- return_bad="func_pop; return ${_BAD}";
- return_yes="func_pop; return ${_YES}";
- return_no="func_pop; return ${_NO}";
- return_error="func_pop; return ${_ERROR}";
- return_var="func_pop; return"; # add number, e.g. `eval "${return_var} $n'
- export _DEFAULT_MODES;
- _DEFAULT_MODES='x,ps,tty';
- export _DEFAULT_RESOLUTION;
- _DEFAULT_RESOLUTION='75';
- export _DEFAULT_TTY_DEVICE;
- _DEFAULT_TTY_DEVICE='latin1';
- # _VIEWER_* viewer programs for different modes (only X is necessary)
- # _VIEWER_* a comma-separated list of viewer programs (with options)
- export _VIEWER_DVI; # viewer program for dvi mode
- export _VIEWER_HTML_TTY; # viewer program for html mode in tty
- export _VIEWER_HTML_X; # viewer program for html mode in X
- export _VIEWER_PDF; # viewer program for pdf mode
- export _VIEWER_PS; # viewer program for ps mode
- export _VIEWER_X; # viewer program for X mode
- _VIEWER_DVI='kdvi,xdvi,dvilx';
- _VIEWER_HTML_TTY='lynx';
- _VIEWER_HTML_X='konqueror,mozilla,netscape,galeon,opera,amaya,arena';
- _VIEWER_PDF='kghostview --scale 1.45,ggv,xpdf,acroread,kpdf';
- _VIEWER_PS='kghostview --scale 1.45,ggv,gv,ghostview,gs_x11,gs';
- _VIEWER_X='gxditview,xditview';
- # Search automatically in standard sections `1' to `8', and in the
- # traditional sections `9', `n', and `o'. On many systems, there
- # exist even more sections, mostly containing a set of man pages
- # special to a specific program package. These aren't searched for
- # automatically, but must be specified on the command line.
- export _MAN_AUTO_SEC_LIST;
- _MAN_AUTO_SEC_LIST="'1' '2' '3' '4' '5' '6' '7' '8' '9' 'n' 'o'";
- export _MAN_AUTO_SEC_CHARS;
- _MAN_AUTO_SEC_CHARS='[123456789no]';
- export _SPACE_SED;
- _SPACE_SED='['"${_SP}${_TAB}"']';
- export _SPACE_CASE;
- _SPACE_CASE='[\'"${_SP}"'\'"${_TAB}"']';
- export _PROCESS_ID; # for shutting down the program
- _PROCESS_ID="$$";
- ############ the command line options of the involved programs
- #
- # The naming scheme for the options environment names is
- # $_OPTS_<prog>_<length>[_<argspec>]
- #
- # <prog>: program name GROFFER, GROFF, or CMDLINE (for all
- # command line options)
- # <length>: LONG (long options) or SHORT (single character options)
- # <argspec>: ARG for options with argument, NA for no argument;
- # without _<argspec> both the ones with and without arg.
- #
- # Each option that takes an argument must be specified with a
- # trailing : (colon).
- # exports
- export _OPTS_GROFFER_SHORT_NA;
- export _OPTS_GROFFER_SHORT_ARG;
- export _OPTS_GROFFER_LONG_NA;
- export _OPTS_GROFFER_LONG_ARG;
- export _OPTS_GROFF_SHORT_NA;
- export _OPTS_GROFF_SHORT_ARG;
- export _OPTS_GROFF_LONG_NA;
- export _OPTS_GROFF_LONG_ARG;
- export _OPTS_X_SHORT_ARG;
- export _OPTS_X_SHORT_NA;
- export _OPTS_X_LONG_ARG;
- export _OPTS_X_LONG_NA;
- export _OPTS_MAN_SHORT_ARG;
- export _OPTS_MAN_SHORT_NA;
- export _OPTS_MAN_LONG_ARG;
- export _OPTS_MAN_LONG_NA;
- export _OPTS_MANOPT_SHORT_ARG;
- export _OPTS_MANOPT_SHORT_NA;
- export _OPTS_MANOPT_LONG_ARG;
- export _OPTS_MANOPT_LONG_NA;
- export _OPTS_CMDLINE_SHORT_NA;
- export _OPTS_CMDLINE_SHORT_ARG;
- export _OPTS_CMDLINE_LONG_NA;
- export _OPTS_CMDLINE_LONG_ARG;
- ###### groffer native options
- _OPTS_GROFFER_SHORT_NA="'h' 'Q' 'v' 'V' 'X' 'Z'";
- _OPTS_GROFFER_SHORT_ARG="'T'";
- _OPTS_GROFFER_LONG_NA="'auto' \
- 'apropos' 'apropos-data' 'apropos-devel' 'apropos-progs' \
- 'debug' 'debug-all' 'debug-keep' 'debug-lm' 'debug-params' 'debug-shell' \
- 'debug-stacks' 'debug-tmpdir' 'debug-user' 'default' 'do-nothing' 'dvi' \
- 'groff' 'help' 'intermediate-output' 'html' 'man' \
- 'no-location' 'no-man' 'no-special' 'pdf' 'ps' 'rv' 'source' \
- 'text' 'text-device' \
- 'tty' 'tty-device' 'version' 'whatis' 'where' 'www' 'x' 'X'";
- _OPTS_GROFFER_LONG_ARG="\
- 'default-modes' 'device' 'dvi-viewer' 'dvi-viewer-tty' 'extension' 'fg' \
- 'fn' 'font' 'foreground' 'html-viewer' 'html-viewer-tty' 'mode' \
- 'pdf-viewer' 'pdf-viewer-tty' 'print' 'ps-viewer' 'ps-viewer-tty' 'shell' \
- 'title' 'tty-viewer' 'tty-viewer-tty' 'www-viewer' 'www-viewer-tty' \
- 'x-viewer' 'x-viewer-tty' 'X-viewer' 'X-viewer-tty'";
- ##### groffer options inhereted from groff
- _OPTS_GROFF_SHORT_NA="'a' 'b' 'c' 'C' 'e' 'E' 'g' 'G' 'i' 'l' 'N' 'p' \
- 'R' 's' 'S' 't' 'U' 'z'";
- _OPTS_GROFF_SHORT_ARG="'d' 'f' 'F' 'I' 'L' 'm' 'M' 'n' 'o' 'P' 'r' \
- 'w' 'W'";
- _OPTS_GROFF_LONG_NA="";
- _OPTS_GROFF_LONG_ARG="";
- ##### groffer options inhereted from the X Window toolkit
- _OPTS_X_SHORT_NA="";
- _OPTS_X_SHORT_ARG="";
- _OPTS_X_LONG_NA="'iconic' 'rv'";
- _OPTS_X_LONG_ARG="'background' 'bd' 'bg' 'bordercolor' 'borderwidth' \
- 'bw' 'display' 'fg' 'fn' 'font' 'foreground' 'ft' 'geometry' \
- 'resolution' 'title' 'xrm'";
- ###### groffer options inherited from man
- _OPTS_MAN_SHORT_NA="";
- _OPTS_MAN_SHORT_ARG="";
- _OPTS_MAN_LONG_NA="'all' 'ascii' 'catman' 'ditroff' \
- 'local-file' 'location' 'troff' 'update'";
- _OPTS_MAN_LONG_ARG="'locale' 'manpath' \
- 'pager' 'preprocessor' 'prompt' 'sections' 'systems' 'troff-device'";
- ###### additional options for parsing $MANOPT only
- _OPTS_MANOPT_SHORT_NA="'7' 'a' 'c' 'd' 'D' 'f' 'h' 'k' 'l' 't' 'u' \
- 'V' 'w' 'Z'";
- _OPTS_MANOPT_SHORT_ARG="'e' 'L' 'm' 'M' 'p' 'P' 'r' 'S' 'T'";
- _OPTS_MANOPT_LONG_NA="${_OPTS_MAN_LONG_NA} \
- 'apropos' 'debug' 'default' 'help' 'html' 'ignore-case' 'location-cat' \
- 'match-case' 'troff' 'update' 'version' 'whatis' 'where' 'where-cat'";
- _OPTS_MANOPT_LONG_ARG="${_OPTS_MAN_LONG_NA} \
- 'config_file' 'encoding' 'extension' 'locale'";
- ###### collections of command line options
- _OPTS_CMDLINE_SHORT_NA="${_OPTS_GROFFER_SHORT_NA} \
- ${_OPTS_GROFF_SHORT_NA} ${_OPTS_X_SHORT_NA} ${_OPTS_MAN_SHORT_NA}";
- _OPTS_CMDLINE_SHORT_ARG="${_OPTS_GROFFER_SHORT_ARG} \
- ${_OPTS_GROFF_SHORT_ARG} ${_OPTS_X_SHORT_ARG} ${_OPTS_MAN_SHORT_ARG}";
- _OPTS_CMDLINE_LONG_NA="${_OPTS_GROFFER_LONG_NA} \
- ${_OPTS_GROFF_LONG_NA} ${_OPTS_X_LONG_NA} ${_OPTS_MAN_LONG_NA}";
- _OPTS_CMDLINE_LONG_ARG="${_OPTS_GROFFER_LONG_ARG} \
- ${_OPTS_GROFF_LONG_ARG} ${_OPTS_MAN_LONG_ARG} ${_OPTS_X_LONG_ARG}";
- ########################################################################
- # read-write variables (global to this file)
- ########################################################################
- export _ALL_PARAMS; # All options and file name parameters
- export _ADDOPTS_GROFF; # Transp. options for groff (`eval').
- export _ADDOPTS_POST; # Transp. options postproc (`eval').
- export _ADDOPTS_X; # Transp. options X postproc (`eval').
- export _APROPOS_PROG; # Program to run apropos.
- export _APROPOS_SECTIONS; # Sections for different --apropos-*.
- export _DEFAULT_MODES; # Set default modes.
- export _DISPLAY_MODE; # Display mode.
- export _DISPLAY_PROG; # Viewer program to be used for display.
- export _DISPLAY_ARGS; # X resources for the viewer program.
- export _FILEARGS; # Stores filespec parameters.
- export _FILESPEC_ARG; # Stores the actual filespec parameter.
- export _FUNC_STACK; # Store debugging information.
- export _REGISTERED_TITLE; # Processed file names.
- # _HAS_* from availability tests
- export _HAS_COMPRESSION; # `yes' if gzip compression is available
- export _HAS_BZIP; # `yes' if bzip2 compression is available
- # _MAN_* finally used configuration of man searching
- export _MAN_ALL; # search all man pages per filespec
- export _MAN_ENABLE; # enable search for man pages
- export _MAN_EXT; # extension for man pages
- export _MAN_FORCE; # force file parameter to be man pages
- export _MAN_IS_SETUP; # setup man variables only once
- export _MAN_LANG; # language for man pages
- export _MAN_LANG2; # language for man pages
- export _MAN_LANG_DONE; # language dirs added to man path
- export _MAN_PATH; # search path for man pages
- export _MAN_SEC; # sections for man pages; sep. `:'
- export _MAN_SEC_DONE; # sections added to man path
- export _MAN_SYS; # system names for man pages; sep. `,'
- export _MAN_SYS; # system names added to man path
- # _MANOPT_* as parsed from $MANOPT
- export _MANOPT_ALL; # $MANOPT --all
- export _MANOPT_EXTENSION; # $MANOPT --extension
- export _MANOPT_LANG; # $MANOPT --locale
- export _MANOPT_PATH; # $MANOPT --manpath
- export _MANOPT_PAGER; # $MANOPT --pager
- export _MANOPT_SEC; # $MANOPT --sections
- export _MANOPT_SYS; # $MANOPT --systems
- # _OPT_* as parsed from groffer command line
- export _OPT_ALL; # display all suitable man pages.
- export _OPT_APROPOS; # call `apropos' program.
- export _OPT_BD; # set border color in some modes.
- export _OPT_BG; # set background color in some modes.
- export _OPT_BW; # set border width in some modes.
- export _OPT_DEFAULT_MODES; # `,'-list of modes when no mode given.
- export _OPT_DEVICE; # device option.
- export _OPT_DO_NOTHING; # do nothing in main_display().
- export _OPT_DISPLAY; # set X display.
- export _OPT_FG; # set foreground color in some modes.
- export _OPT_FN; # set font in some modes.
- export _OPT_GEOMETRY; # set size and position of viewer in X.
- export _OPT_ICONIC; # -iconic option for X viewers.
- export _OPT_LANG; # set language for man pages
- export _OPT_LOCATION; # print processed file names to stderr
- export _OPT_MODE; # values: X, tty, Q, Z, ""
- export _OPT_MANPATH; # manual setting of path for man-pages
- export _OPT_PAGER; # specify paging program for tty mode
- export _OPT_RESOLUTION; # set X resolution in dpi
- export _OPT_RV; # reverse fore- and background colors.
- export _OPT_SECTIONS; # sections for man page search
- export _OPT_SYSTEMS; # man pages of different OS's
- export _OPT_TITLE; # title for gxditview window
- export _OPT_TEXT_DEVICE; # set device for tty mode.
- export _OPT_V; # groff option -V.
- export _OPT_VIEWER_DVI; # viewer program for dvi mode
- export _OPT_VIEWER_PDF; # viewer program for pdf mode
- export _OPT_VIEWER_PS; # viewer program for ps mode
- export _OPT_VIEWER_HTML; # viewer program for html mode
- export _OPT_VIEWER_X; # viewer program for x mode
- export _OPT_WHATIS; # print the man description
- export _OPT_XRM; # specify X resource.
- export _OPT_Z; # groff option -Z.
- export _OUTPUT_FILE_NAME; # output generated, see main_set_res..()
- export _VIEWER_TERMINAL; # viewer options for terminal (--*-viewer-tty)
- # _TMP_* temporary directory and files
- export _TMP_DIR; # groffer directory for temporary files
- export _TMP_CAT; # stores concatenation of everything
- export _TMP_STDIN; # stores stdin, if any
- # these variables are preset in section `Preset' after the rudim. test
- ########################################################################
- # Preset and reset of read-write global variables
- ########################################################################
- export _START_DIR; # directory at start time of the script
- _START_DIR="$(pwd)";
- # For variables that can be reset by option `--default', see reset().
- _FILEARGS='';
- # _HAS_* from availability tests
- _HAS_COMPRESSION='';
- _HAS_BZIP='';
- # _TMP_* temporary files
- _TMP_DIR='';
- _TMP_CAT='';
- _TMP_CONF='';
- _TMP_STDIN='';
- ########################################################################
- # reset ()
- #
- # Reset the variables that can be affected by options to their default.
- #
- reset()
- {
- if test "$#" -ne 0
- then
- error "reset() does not have arguments.";
- fi;
- _ADDOPTS_GROFF='';
- _ADDOPTS_POST='';
- _ADDOPTS_X='';
- _APROPOS_PROG='';
- _APROPOS_SECTIONS='';
- _DISPLAY_ARGS='';
- _DISPLAY_MODE='';
- _DISPLAY_PROG='';
- _REGISTERED_TITLE='';
- # _MAN_* finally used configuration of man searching
- _MAN_ALL='no';
- _MAN_ENABLE='yes'; # do search for man-pages
- _MAN_EXT='';
- _MAN_FORCE='no'; # first local file, then search man page
- _MAN_IS_SETUP='no';
- _MAN_LANG='';
- _MAN_LANG2='';
- _MAN_PATH='';
- _MAN_SEC='';
- _MAN_SEC_DONE='no';
- _MAN_SYS='';
- _MAN_SYS_DONE='no';
- # _MANOPT_* as parsed from $MANOPT
- _MANOPT_ALL='no';
- _MANOPT_EXTENSION='';
- _MANOPT_LANG='';
- _MANOPT_PATH='';
- _MANOPT_PAGER='';
- _MANOPT_SEC='';
- _MANOPT_SYS='';
- # _OPT_* as parsed from groffer command line
- _OPT_ALL='no';
- _OPT_APROPOS='no';
- _OPT_BD='';
- _OPT_BG='';
- _OPT_BW='';
- _OPT_DEFAULT_MODES='';
- _OPT_DEVICE='';
- _OPT_DISPLAY='';
- _OPT_DO_NOTHING='no';
- _OPT_FG='';
- _OPT_FN='';
- _OPT_GEOMETRY='';
- _OPT_ICONIC='no';
- _OPT_LANG='';
- _OPT_LOCATION='no';
- _OPT_MODE='';
- _OPT_MANPATH='';
- _OPT_PAGER='';
- _OPT_RESOLUTION='';
- _OPT_RV='no';
- _OPT_SECTIONS='';
- _OPT_SYSTEMS='';
- _OPT_TITLE='';
- _OPT_TEXT_DEVICE='';
- _OPT_V='no';
- _OPT_VIEWER_DVI='';
- _OPT_VIEWER_PDF='';
- _OPT_VIEWER_PS='';
- _OPT_VIEWER_HTML='';
- _OPT_VIEWER_X='';
- _OPT_WHATIS='no';
- _OPT_XRM='';
- _OPT_Z='no';
- _VIEWER_TERMINAL='no';
- }
- reset;
- ########################################################################
- # Functions for error handling and debugging
- ########################################################################
- ##############
- # echo1 (<text>*)
- #
- # Output to stdout.
- #
- # Arguments : arbitrary text including `-'.
- #
- echo1()
- {
- cat <<EOF
- $@
- EOF
- }
- ##############
- # echo2 (<text>*)
- #
- # Output to stderr.
- #
- # Arguments : arbitrary text.
- #
- echo2()
- {
- cat >&2 <<EOF
- $@
- EOF
- }
- ##############
- # landmark (<text>)
- #
- # Print <text> to standard error as a debugging aid.
- #
- # Globals: $_DEBUG_LM
- #
- landmark()
- {
- if test _"${_DEBUG_LM}"_ = _yes_
- then
- echo2 "LM: $*";
- fi;
- }
- landmark "1: debugging functions";
- ##############
- # clean_up ()
- #
- # Clean up at exit.
- #
- clean_up()
- {
- cd "${_START_DIR}" >"${_NULL_DEV}" 2>&1;
- if test _${_DEBUG_KEEP_FILES}_ = _yes_
- then
- echo2 "Kept temporary directory ${_TMP_DIR}."
- else
- if test _"${_TMP_DIR}"_ != __
- then
- if test -d "${_TMP_DIR}" || test -f "${_TMP_DIR}"
- then
- rm -f -r "${_TMP_DIR}" >${_NULL_DEV} 2>&1;
- fi;
- fi;
- fi;
- }
- #############
- # diag (text>*)
- #
- # Output a diagnostic message to stderr
- #
- diag()
- {
- echo2 '>>>>>'"$*";
- }
- #############
- # error (<text>*)
- #
- # Print an error message to standard error, print the function stack,
- # exit with an error condition. The argument should contain the name
- # of the function from which it was called. This is for system errors.
- #
- error()
- {
- case "$#" in
- 1) echo2 'groffer error: '"$1"; ;;
- *) echo2 'groffer error: wrong number of arguments in error().'; ;;
- esac;
- func_stack_dump;
- if test _"${_TMP_DIR}"_ != __ && test -d "${_TMP_DIR}"
- then
- : >"${_TMP_DIR}"/,error;
- fi;
- exit "${_ERROR}";
- }
- #############
- # error_user (<text>*)
- #
- # Print an error message to standard error; exit with an error condition.
- # The error is supposed to be produce by the user. So the funtion stack
- # is omitted.
- #
- error_user()
- {
- case "$#" in
- 1)
- echo2 'groffer error: '"$1";
- ;;
- *)
- echo2 'groffer error: wrong number of arguments in error_user().';
- ;;
- esac;
- if test _"${_DEBUG_USER_WITH_STACK}"_ = _yes_
- then
- func_stack_dump;
- fi;
- if test _"${_TMP_DIR}"_ != __ && test -d "${_TMP_DIR}"
- then
- : >"${_TMP_DIR}"/,error;
- fi;
- exit "${_ERROR}";
- }
- #############
- # exit_test ()
- #
- # Test whether the former command ended with error(). Exit again.
- #
- # Globals: $_ERROR
- #
- exit_test()
- {
- if test "$?" = "${_ERROR}"
- then
- exit ${_ERROR};
- fi;
- if test _"${_TMP_DIR}"_ != __ && test -f "${_TMP_DIR}"/,error
- then
- exit ${_ERROR};
- fi;
- }
- #############
- # func_check (<func_name> <rel_op> <nr_args> "$@")
- #
- # Check number of arguments and register to _FUNC_STACK.
- #
- # Arguments: >=3
- # <func_name>: name of the calling function.
- # <rel_op>: a relational operator: = != < > <= >=
- # <nr_args>: number of arguments to be checked against <operator>
- # "$@": the arguments of the calling function.
- #
- # Variable prefix: fc
- #
- func_check()
- {
- if test "$#" -lt 3
- then
- error 'func_check() needs at least 3 arguments.';
- fi;
- fc_fname="$1";
- case "$3" in
- 1)
- fc_nargs="$3";
- fc_s='';
- ;;
- 0|[2-9])
- fc_nargs="$3";
- fc_s='s';
- ;;
- *)
- error "func_check(): third argument must be a digit.";
- ;;
- esac;
- case "$2" in
- '='|'-eq')
- fc_op='-eq';
- fc_comp='exactly';
- ;;
- '>='|'-ge')
- fc_op='-ge';
- fc_comp='at least';
- ;;
- '<='|'-le')
- fc_op='-le';
- fc_comp='at most';
- ;;
- '<'|'-lt')
- fc_op='-lt';
- fc_comp='less than';
- ;;
- '>'|'-gt')
- fc_op='-gt';
- fc_comp='more than';
- ;;
- '!='|'-ne')
- fc_op='-ne';
- fc_comp='not';
- ;;
- *)
- error \
- 'func_check(): second argument is not a relational operator.';
- ;;
- esac;
- shift;
- shift;
- shift;
- if test "$#" "${fc_op}" "${fc_nargs}"
- then
- do_nothing;
- else
- error "func_check(): \
- ${fc_fname}"'() needs '"${fc_comp} ${fc_nargs}"' argument'"${fc_s}"'.';
- fi;
- func_push "${fc_fname}";
- if test _"${_DEBUG_STACKS}"_ = _yes_
- then
- echo2 '+++ '"${fc_fname} $@";
- echo2 '>>> '"${_FUNC_STACK}";
- fi;
- eval ${_UNSET} fc_comp;
- eval ${_UNSET} fc_fname;
- eval ${_UNSET} fc_nargs;
- eval ${_UNSET} fc_op;
- eval ${_UNSET} fc_s;
- }
- #############
- # func_pop ()
- #
- # Retrieve the top element from the stack.
- #
- # The stack elements are separated by `!'; the popped element is
- # identical to the original element, except that all `!' characters
- # were removed.
- #
- # Arguments: 1
- #
- func_pop()
- {
- if test "$#" -ne 0
- then
- error 'func_pop() does not have arguments.';
- fi;
- case "${_FUNC_STACK}" in
- '')
- if test _"${_DEBUG_STACKS}"_ = _yes_
- then
- error 'func_pop(): stack is empty.';
- fi;
- ;;
- *!*)
- # split at first bang `!'.
- _FUNC_STACK="$(echo1 "${_FUNC_STACK}" | sed -e 's/^[^!]*!//')";
- exit_test;
- ;;
- *)
- _FUNC_STACK='';
- ;;
- esac;
- if test _"${_DEBUG_STACKS}"_ = _yes_
- then
- echo2 '<<< '"${_FUNC_STACK}";
- fi;
- }
- #############
- # func_push (<element>)
- #
- # Store another element to stack.
- #
- # The stack elements are separated by `!'; if <element> contains a `!'
- # it is removed first.
- #
- # Arguments: 1
- #
- # Variable prefix: fp
- #
- func_push()
- {
- if test "$#" -ne 1
- then
- error 'func_push() needs 1 argument.';
- fi;
- case "$1" in
- *'!'*)
- # remove all bangs `!'.
- fp_element="$(echo1 "$1" | sed -e 's/!//g')";
- exit_test;
- ;;
- *)
- fp_element="$1";
- ;;
- esac;
- if test _"${_FUNC_STACK}"_ = __
- then
- _FUNC_STACK="${fp_element}";
- else
- _FUNC_STACK="${fp_element}!${_FUNC_STACK}";
- fi;
- eval ${_UNSET} fp_element;
- }
- #############
- # func_stack_dump ()
- #
- # Print the content of the stack. Ignore the arguments.
- #
- func_stack_dump()
- {
- diag 'call stack: '"${_FUNC_STACK}";
- }
- ########################################################################
- # System Test
- ########################################################################
- landmark "2: system test";
- # Test the availability of the system utilities used in this script.
- ########################################################################
- # Test of function `sed'.
- #
- if test _"$(echo xTesTx \
- | sed -e 's/^.\([Tt]e*x*sTT*\).*$/\1/' \
- | sed -e 's|T|t|g')"_ != _test_
- then
- error 'Test of "sed" command failed.';
- fi;
- ########################################################################
- # Test of function `cat'.
- #
- if test _"$(echo test | cat)"_ != _test_
- then
- error 'Test of "cat" command failed.';
- fi;
- ########################################################################
- # Test for compression.
- #
- if test _"$(echo 'test' | gzip -c -d -f - 2>${_NULL_DEV})"_ = _test_
- then
- _HAS_COMPRESSION='yes';
- if echo1 'test' | bzip2 -c 2>${_NULL_DEV} | bzip2 -t 2>${_NULL_DEV} \
- && test _"$(echo 'test' | bzip2 -c 2>${_NULL_DEV} \
- | bzip2 -d -c 2>${_NULL_DEV})"_ \
- = _test_
- then
- _HAS_BZIP='yes';
- else
- _HAS_BZIP='no';
- fi;
- else
- _HAS_COMPRESSION='no';
- _HAS_BZIP='no';
- fi;
- ########################################################################
- # Definition of normal Functions in alphabetical order
- ########################################################################
- landmark "3: functions";
- ########################################################################
- # apropos_filespec ()
- #
- # Setup for the --apropos* options
- #
- apropos_filespec()
- {
- func_check apropos_filespec '=' 0 "$@";
- if obj _OPT_APROPOS is_yes
- then
- eval to_tmp_line \
- "'.SH $(echo1 "${_FILESPEC_ARG}" | sed 's/[^\\]-/\\-/g')'";
- exit_test;
- if obj _APROPOS_PROG is_empty
- then
- error 'apropos_filespec: apropos_setup() must be run first.';
- fi;
- if obj _APROPOS_SECTIONS is_empty
- then
- if obj _OPT_SECTIONS is_empty
- then
- s='^.*(.*).*$';
- else
- s='^.*(['"$(echo1 "${_OPT_SECTIONS}" | sed -e 's/://g')"']';
- fi;
- else
- s='^.*(['"${_APROPOS_SECTIONS}"']';
- fi;
- eval "${_APROPOS_PROG}" "'${_FILESPEC_ARG}'" | \
- sed -n -e '
- /^'"${_FILESPEC_ARG}"': /p
- /'"$s"'/p
- ' | \
- sort |\
- sed -e '
- s/^\(.* (..*)\) *- *\(.*\)$/\.br\n\.TP 15\n\.BR \1\n\2/
- ' >>"${_TMP_CAT}";
- fi;
- eval "${return_ok}";
- }
- ########################################################################
- # apropos_setup ()
- #
- # Setup for the --apropos* options
- #
- apropos_setup()
- {
- func_check apropos_setup '=' 0 "$@";
- if obj _OPT_APROPOS is_yes
- then
- if is_prog apropos
- then
- _APROPOS_PROG='apropos';
- elif is_prog man
- then
- if man --apropos man >${_NULL_DEV} 2>${_NULL_DEV}
- then
- _APROPOS_PROG='man --apropos';
- elif man -k man >${_NULL_DEV} 2>${_NULL_DEV}
- then
- _APROPOS_PROG='man -k';
- fi;
- fi;
- if obj _APROPOS_PROG is_empty
- then
- error 'apropos_setup: no apropos program available.';
- fi;
- to_tmp_line '.TH GROFFER APROPOS';
- fi;
- eval "${return_ok}";
- }
- ########################################################################
- # base_name (<path>)
- #
- # Get the file name part of <path>, i.e. delete everything up to last
- # `/' from the beginning of <path>. Remove final slashes, too, to get a
- # non-empty output.
- #
- # Arguments : 1
- # Output : the file name part (without slashes)
- #
- # Variable prefix: bn
- #
- base_name()
- {
- func_check base_name = 1 "$@";
- bn_name="$1";
- case "${bn_name}" in
- */)
- # delete all final slashes
- bn_name="$(echo1 "${bn_name}" | sed -e 's|//*$||')";
- exit_test;
- ;;
- esac;
- case "${bn_name}" in
- /|'')
- eval ${_UNSET} bn_name;
- eval "${return_bad}";
- ;;
- */*)
- # delete everything before and including the last slash `/'.
- echo1 "${bn_name}" | sed -e 's|^.*//*\([^/]*\)$|\1|';
- ;;
- *)
- obj bn_name echo1;
- ;;
- esac;
- eval ${_UNSET} bn_name;
- eval "${return_ok}";
- }
- ########################################################################
- # cat_z (<file>)
- #
- # Decompress if possible or just print <file> to standard output.
- #
- # gzip, bzip2, and .Z decompression is supported.
- #
- # Arguments: 1, a file name.
- # Output: the content of <file>, possibly decompressed.
- #
- if test _"${_HAS_COMPRESSION}"_ = _yes_
- then
- cat_z()
- {
- func_check cat_z = 1 "$@";
- case "$1" in
- '')
- error 'cat_z(): empty file name';
- ;;
- '-')
- error 'cat_z(): for standard input use save_stdin()';
- ;;
- esac;
- if obj _HAS_BZIP is_yes
- then
- if bzip2 -t "$1" 2>${_NULL_DEV}
- then
- bzip2 -c -d "$1" 2>${_NULL_DEV};
- eval "${return_ok}";
- fi;
- fi;
- gzip -c -d -f "$1" 2>${_NULL_DEV};
- eval "${return_ok}";
- }
- else
- cat_z()
- {
- func_check cat_z = 1 "$@";
- cat "$1";
- eval "${return_ok}";
- }
- fi;
- ########################################################################
- # clean_up ()
- #
- # Do the final cleaning up before exiting; used by the trap calls.
- #
- # defined above
- ########################################################################
- # diag (<text>*)
- #
- # Print marked message to standard error; useful for debugging.
- #
- # defined above
- ########################################################################
- landmark '4: dirname()*';
- ########################################################################
- #######################################################################
- # dirname_append (<dir> <name>)
- #
- # Append `name' to `dir' with clean handling of `/'.
- #
- # Arguments : 2
- # Output : the generated new directory name <dir>/<name>
- #
- dirname_append()
- {
- func_check dirname_append = 2 "$@";
- if is_empty "$1"
- then
- error "dir_append(): first argument is empty.";
- fi;
- if is_empty "$2"
- then
- echo1 "$1";
- else
- dirname_chop "$1"/"$2";
- fi;
- eval "${return_ok}";
- }
- ########################################################################
- # dirname_chop (<name>)
- #
- # Remove unnecessary slashes from directory name.
- #
- # Argument: 1, a directory name.
- # Output: path without double, or trailing slashes.
- #
- # Variable prefix: dc
- #
- dirname_chop()
- {
- func_check dirname_chop = 1 "$@";
- # replace all multiple slashes by a single slash `/'.
- dc_res="$(echo1 "$1" | sed -e 's|///*|/|g')";
- exit_test;
- case "${dc_res}" in
- ?*/)
- # remove trailing slash '/';
- echo1 "${dc_res}" | sed -e 's|/$||';
- ;;
- *)
- obj dc_res echo1
- ;;
- esac;
- eval ${_UNSET} dc_res;
- eval "${return_ok}";
- }
- ########################################################################
- # do_filearg (<filearg>)
- #
- # Append the file, man-page, or standard input corresponding to the
- # argument to the temporary file. If this is compressed in the gzip
- # or Z format it is decompressed. A title element is generated.
- #
- # Argument either:
- # - name of an existing file.
- # - `-' to represent standard input (several times allowed).
- # - `man:name.(section)' the man-page for `name' in `section'.
- # - `man:name.section' the man-page for `name' in `section'.
- # - `man:name' the man-page for `name' in the lowest `section'.
- # - `name.section' the man-page for `name' in `section'.
- # - `name' the man-page for `name' in the lowest `section'.
- # Globals :
- # $_TMP_STDIN, $_MAN_ENABLE, $_MAN_IS_SETUP, $_OPT_MAN
- #
- # Output : none
- # Return : $_GOOD if found, ${_BAD} otherwise.
- #
- # Variable prefix: df
- #
- do_filearg()
- {
- func_check do_filearg = 1 "$@";
- df_filespec="$1";
- # store sequence into positional parameters
- case "${df_filespec}" in
- '')
- eval ${_UNSET} df_filespec;
- eval "${return_good}";
- ;;
- '-')
- register_file '-';
- eval ${_UNSET} df_filespec;
- eval "${return_good}";
- ;;
- */*) # with directory part; so no man search
- set 'File';
- ;;
- *)
- if obj _MAN_ENABLE is_yes
- then
- if obj _MAN_FORCE is_yes
- then
- set 'Manpage' 'File';
- else
- set 'File' 'Manpage';
- fi;
- else
- set 'File';
- fi;
- ;;
- esac;
- for i
- do
- case "$i" in
- File)
- if test -f "${df_filespec}"
- then
- if test -r "${df_filespec}"
- then
- register_file "${df_filespec}";
- eval ${_UNSET} df_filespec;
- eval ${_UNSET} df_no_man;
- eval "${return_good}";
- else
- echo2 "could not read \`${df_filespec}'";
- eval ${_UNSET} df_filespec;
- eval ${_UNSET} df_no_man;
- eval "${return_bad}";
- fi;
- else
- if obj df_no_man is_not_empty
- then
- if obj _OPT_WHATIS is_yes
- then
- to_tmp_line "This is neither a file nor a man page."
- else
- echo2 "\`${df_filespec}' is neither a file nor a man page."
- fi;
- fi;
- df_no_file=yes;
- continue;
- fi;
- ;;
- Manpage) # parse filespec as man page
- if obj _MAN_IS_SETUP is_not_yes
- then
- man_setup;
- fi;
- if man_do_filespec "${df_filespec}"
- then
- eval ${_UNSET} df_filespec;
- eval ${_UNSET} df_no_file;
- eval "${return_good}";
- else
- if obj df_no_file is_not_empty
- then
- if obj _OPT_WHATIS is_yes
- then
- to_tmp_line "This is neither a file nor a man page."
- else
- echo2 "\`${df_filespec}' is neither a file nor a man page."
- fi;
- fi;
- df_no_man=yes;
- continue;
- fi;
- ;;
- esac;
- done;
- eval ${_UNSET} df_filespec;
- eval ${_UNSET} df_no_file;
- eval ${_UNSET} df_no_man;
- eval "${return_bad}";
- } # do_filearg()
- ########################################################################
- # do_nothing ()
- #
- # Dummy function.
- #
- do_nothing()
- {
- eval return "${_OK}";
- }
- ########################################################################
- # echo2 (<text>*)
- #
- # Print to standard error with final line break.
- #
- # defined above
- ########################################################################
- # error (<text>*)
- #
- # Print error message and exit with error code.
- #
- # defined above
- ########################################################################
- # exit_test ()
- #
- # Test whether the former command ended with error(). Exit again.
- #
- # defined above
- ########################################################################
- # func_check (<func_name> <rel_op> <nr_args> "$@")
- #
- # Check number of arguments and register to _FUNC_STACK.
- #
- # Arguments: >=3
- # <func_name>: name of the calling function.
- # <rel_op>: a relational operator: = != < > <= >=
- # <nr_args>: number of arguments to be checked against <operator>
- # "$@": the arguments of the calling function.
- #
- # defined above
- #########################################################################
- # func_pop ()
- #
- # Delete the top element from the function call stack.
- #
- # defined above
- ########################################################################
- # func_push (<element>)
- #
- # Store another element to function call stack.
- #
- # defined above
- ########################################################################
- # func_stack_dump ()
- #
- # Print the content of the stack.
- #
- # defined above
- ########################################################################
- # get_first_essential (<arg>*)
- #
- # Retrieve first non-empty argument.
- #
- # Return : `1' if all arguments are empty, `0' if found.
- # Output : the retrieved non-empty argument.
- #
- # Variable prefix: gfe
- #
- get_first_essential()
- {
- func_check get_first_essential '>=' 0 "$@";
- if is_equal "$#" 0
- then
- eval "${return_ok}";
- fi;
- for i
- do
- gfe_var="$i";
- if obj gfe_var is_not_empty
- then
- obj gfe_var echo1;
- eval ${_UNSET} gfe_var;
- eval "${return_ok}";
- fi;
- done;
- eval ${_UNSET} gfe_var;
- eval "${return_bad}";
- }
- ########################################################################
- landmark '5: is_*()';
- ########################################################################
- ########################################################################
- # is_dir (<name>)
- #
- # Test whether `name' is a directory.
- #
- # Arguments : 1
- # Return : `0' if arg1 is a directory, `1' otherwise.
- #
- is_dir()
- {
- func_check is_dir '=' 1 "$@";
- if test _"$1"_ != __ && test -d "$1" && test -r "$1"
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_empty (<string>)
- #
- # Test whether `string' is empty.
- #
- # Arguments : <=1
- # Return : `0' if arg1 is empty or does not exist, `1' otherwise.
- #
- is_empty()
- {
- func_check is_empty '=' 1 "$@";
- if test _"$1"_ = __
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_equal (<string1> <string2>)
- #
- # Test whether `string1' is equal to <string2>.
- #
- # Arguments : 2
- # Return : `0' both arguments are equal strings, `1' otherwise.
- #
- is_equal()
- {
- func_check is_equal '=' 2 "$@";
- if test _"$1"_ = _"$2"_
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_existing (<name>)
- #
- # Test whether `name' is an existing file or directory. Solaris 2.5 does
- # not have `test -e'.
- #
- # Arguments : 1
- # Return : `0' if arg1 exists, `1' otherwise.
- #
- is_existing()
- {
- func_check is_existing '=' 1 "$@";
- if test _"$1"_ = __
- then
- eval "${return_no}";
- fi;
- if test -f "$1" || test -d "$1" || test -c "$1"
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_file (<name>)
- #
- # Test whether `name' is a readable file.
- #
- # Arguments : 1
- # Return : `0' if arg1 is a readable file, `1' otherwise.
- #
- is_file()
- {
- func_check is_file '=' 1 "$@";
- if is_not_empty "$1" && test -f "$1" && test -r "$1"
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_non_empty_file (<file_name>)
- #
- # Test whether `file_name' is a non-empty existing file.
- #
- # Arguments : <=1
- # Return :
- # `0' if arg1 is a non-empty existing file
- # `1' otherwise
- #
- is_non_empty_file()
- {
- func_check is_non_empty_file '=' 1 "$@";
- if is_file "$1" && test -s "$1"
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_not_dir (<name>)
- #
- # Test whether `name' is not a readable directory.
- #
- # Arguments : 1
- # Return : `0' if arg1 is a directory, `1' otherwise.
- #
- is_not_dir()
- {
- func_check is_not_dir '=' 1 "$@";
- if is_dir "$1"
- then
- eval "${return_no}";
- fi;
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_empty (<string>)
- #
- # Test whether `string' is not empty.
- #
- # Arguments : <=1
- # Return : `0' if arg1 exists and is not empty, `1' otherwise.
- #
- is_not_empty()
- {
- func_check is_not_empty '=' 1 "$@";
- if is_empty "$1"
- then
- eval "${return_no}";
- fi;
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_equal (<string1> <string2>)
- #
- # Test whether `string1' differs from `string2'.
- #
- # Arguments : 2
- #
- is_not_equal()
- {
- func_check is_not_equal '=' 2 "$@";
- if is_equal "$1" "$2"
- then
- eval "${return_no}";
- fi
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_file (<filename>)
- #
- # Test whether `name' is a not readable file.
- #
- # Arguments : 1 (empty allowed)
- #
- is_not_file()
- {
- func_check is_not_file '=' 1 "$@";
- if is_file "$1"
- then
- eval "${return_no}";
- fi;
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_prog ([<name> [<arg>*]])
- #
- # Verify that arg is a not program in $PATH.
- #
- # Arguments : >=0 (empty allowed)
- # more args are ignored, this allows to specify progs with arguments
- #
- is_not_prog()
- {
- func_check is_not_prog '>=' 0 "$@";
- case "$#" in
- 0)
- eval "${return_yes}";
- ;;
- *)
- if where_is "$1" >${_NULL_DEV}
- then
- eval "${return_no}";
- fi;
- ;;
- esac
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_writable (<name>)
- #
- # Test whether `name' is a not a writable file or directory.
- #
- # Arguments : >=1 (empty allowed), more args are ignored
- #
- is_not_writable()
- {
- func_check is_not_writable '>=' 1 "$@";
- if is_writable "$1"
- then
- eval "${return_no}";
- fi;
- eval "${return_yes}";
- }
- ########################################################################
- # is_not_X ()
- #
- # Test whether not running in X Window by checking $DISPLAY
- #
- is_not_X()
- {
- func_check is_X '=' 0 "$@";
- if obj DISPLAY is_empty
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_not_yes (<string>)
- #
- # Test whether `string' is not "yes".
- #
- # Arguments : 1
- #
- is_not_yes()
- {
- func_check is_not_yes = 1 "$@";
- if is_yes "$1"
- then
- eval "${return_no}";
- fi;
- eval "${return_yes}";
- }
- ########################################################################
- # is_prog ([<name> [<arg>*]])
- #
- # Determine whether <name> is a program in $PATH
- #
- # Arguments : >=0 (empty allowed)
- # <arg>* are ignored, this allows to specify progs with arguments.
- #
- is_prog()
- {
- func_check is_prog '>=' 0 "$@";
- case "$#" in
- 0)
- eval "${return_no}";
- ;;
- *)
- if where_is "$1" >${_NULL_DEV}
- then
- eval "${return_yes}";
- fi;
- ;;
- esac
- eval "${return_no}";
- }
- ########################################################################
- # is_writable (<name>)
- #
- # Test whether `name' is a writable file or directory.
- #
- # Arguments : >=1 (empty allowed), more args are ignored
- #
- is_writable()
- {
- func_check is_writable '>=' 1 "$@";
- if test _"$1"_ = __
- then
- eval "${return_no}";
- fi;
- if test -r "$1"
- then
- if test -w "$1"
- then
- eval "${return_yes}";
- fi;
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_X ()
- #
- # Test whether running in X Window by checking $DISPLAY
- #
- is_X()
- {
- func_check is_X '=' 0 "$@";
- if obj DISPLAY is_not_empty
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # is_yes (<string>)
- #
- # Test whether `string' has value "yes".
- #
- # Return : `0' if arg1 is `yes', `1' otherwise.
- #
- is_yes()
- {
- func_check is_yes '=' 1 "$@";
- if is_equal "$1" 'yes'
- then
- eval "${return_yes}";
- fi;
- eval "${return_no}";
- }
- ########################################################################
- # landmark ()
- #
- # Print debugging information on standard error if $_DEBUG_LM is `yes'.
- #
- # Globals: $_DEBUG_LM
- #
- # Defined in section `Debugging functions'.
- ########################################################################
- # leave ([<code>])
- #
- # Clean exit without an error or with <code>.
- #
- leave()
- {
- clean_up;
- if test $# = 0
- then
- exit "${_OK}";
- else
- exit "$1";
- fi;
- }
- ########################################################################
- landmark '6: list_*()';
- ########################################################################
- #
- # `list' is an object class that represents an array or list. Its
- # data consists of space-separated single-quoted elements. So a list
- # has the form "'first' 'second' '...' 'last'". See list_append() for
- # more details on the list structure. The array elements of `list'
- # can be get by `eval set x "$list"; shift`.
- ########################################################################
- # list_append (<list> <element>...)
- #
- # Arguments: >=2
- # <list>: a variable name for a list of single-quoted elements
- # <element>: some sequence of characters.
- # Output: none, but $<list> is set to
- # if <list> is empty: "'<element>' '...'"
- # otherwise: "$list '<element>' ..."
- #
- # Variable prefix: la
- #
- list_append()
- {
- func_check list_append '>=' 2 "$@";
- la_name="$1";
- eval la_list='"${'$1'}"';
- shift;
- for s
- do
- la_s="$s";
- case "${la_s}" in
- *\'*)
- # escape each single quote by replacing each
- # "'" (squote) by "'\''" (squote bslash squote squote);
- # note that the backslash must be doubled in the following `sed'
- la_element="$(echo1 "${la_s}" | sed -e 's/'"${_SQ}"'/&\\&&/g')";
- exit_test;
- ;;
- '')
- la_element="";
- ;;
- *)
- la_element="${la_s}";
- ;;
- esac;
- if obj la_list is_empty
- then
- la_list="'${la_element}'";
- else
- la_list="${la_list} '${la_element}'";
- fi;
- done;
- eval "${la_name}"='"${la_list}"';
- eval ${_UNSET} la_element;
- eval ${_UNSET} la_list;
- eval ${_UNSET} la_name;
- eval ${_UNSET} la_s;
- eval "${return_ok}";
- }
- ########################################################################
- # list_from_cmdline (<pre_name_of_opt_lists> [<cmdline_arg>...])
- #
- # Transform command line arguments into a normalized form.
- #
- # Options, option arguments, and file parameters are identified and
- # output each as a single-quoted argument of its own. Options and
- # file parameters are separated by a '--' argument.
- #
- # Arguments: >=1
- # <pre_name>: common part of a set of 4 environment variable names:
- # $<pre_name>_SHORT_NA: list of short options without an arg.
- # $<pre_name>_SHORT_ARG: list of short options that have an arg.
- # $<pre_name>_LONG_NA: list of long options without an arg.
- # $<pre_name>_LONG_ARG: list of long options that have an arg.
- # <cmdline_arg>...: the arguments from a command line, such as "$@",
- # the content of a variable, or direct arguments.
- #
- # Output: ['-[-]opt' ['optarg']]... '--' ['filename']...
- #
- # Example:
- # list_from_cmdline PRE 'a b' 'c' '' 'long' -a f1 -bcarg --long=larg f2
- # If $PRE_SHORT_NA, $PRE_SHORT_ARG, $PRE_LONG_NA, and $PRE_LONG_ARG are
- # none-empty option lists, this will result in printing:
- # '-a' '-b' '-c' 'arg' '--long' 'larg' '--' 'f1' 'f2'
- #
- # Use this function in the following way:
- # eval set x "$(args_norm PRE_NAME "$@")";
- # shift;
- # while test "$1" != '--'; do
- # case "$1" in
- # ...
- # esac;
- # shift;
- # done;
- # shift; #skip '--'
- # # all positional parameters ("$@") left are file name parameters.
- #
- # Variable prefix: lfc
- #
- list_from_cmdline()
- {
- func_check list_from_cmdline '>=' 1 "$@";
- lfc_short_n="$(obj_data "$1"_SHORT_NA)"; # short options, no argument
- lfc_short_a="$(obj_data "$1"_SHORT_ARG)"; # short options, with argument
- lfc_long_n="$(obj_data "$1"_LONG_NA)"; # long options, no argument
- lfc_long_a="$(obj_data "$1"_LONG_ARG)"; # long options, with argument
- exit_test;
- if obj lfc_short_n is_empty
- then
- error 'list_from_cmdline(): no $'"$1"'_SHORT_NA options.';
- fi;
- if obj lfc_short_a is_empty
- then
- error 'list_from_cmdline(): no $'"$1"'_SHORT_ARG options.';
- fi;
- if obj lfc_long_n is_empty
- then
- error 'list_from_cmdline(): no $'"$1"'_LONG_NA options.';
- fi;
- if obj lfc_long_a is_empty
- then
- error 'list_from_cmdline(): no $'"$1"'_LONG_ARG options.';
- fi;
- shift;
- if is_equal "$#" 0
- then
- echo1 --
- eval ${_UNSET} lfc_fparams;
- eval ${_UNSET} lfc_short_a;
- eval ${_UNSET} lfc_short_n;
- eval ${_UNSET} lfc_long_a;
- eval ${_UNSET} lfc_long_n;
- eval ${_UNSET} lfc_result;
- eval "${return_ok}";
- fi;
- lfc_fparams='';
- lfc_result='';
- while test "$#" -ge 1…