#!/bin/sh --
# xhugeman - script to run myman with huge tiles in full color in a color xterm
# Copyright 1999, 2006, Benjamin Sittler <bsittler@gmail.com>
# 
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Make sure you compile and install the terminfo file from
#  /usr/X11R6/lib/X11/etc/xterm.terminfo
# (or wherever that is on your system...) so that curses understands
# that your xterm supports color.  Alternatively, you may be able to
# change termName to 'xterm-color', 'color_xterm', or something
# similar.

# Note that, on some systems, the color xterm is available as
# 'nxterm'. If this is the case on your system, change xterm
# accordingly.

# If you use a different-sized maze or tileset, you
# should probaby change the geometry and font.

xterm=xterm
geometry=145x94
ttffont="dejavu sans mono,bitstream vera sans mono,freemono"
ttfsize="6"
font="-misc-fixed-medium-r-normal--8-80-75-75-c-50-iso10646-1"
termName=xterm-256color
basename="`basename \"$0\"`"

# don't pollute the child terminal's environment
unset LINES
unset COLUMNS
if ! test -f "$TERMCAP"
    then unset TERMCAP
fi

# first, probe for myman
myman --help >/dev/null || exit $?

# second, probe for XCurses myman
if myman --help | fgrep toolkit-options > /dev/null
then
    exec \
        myman -z huge "$@" \
        -- \
        -lines "${geometry##*x}" \
        -cols "${geometry%x*}" \
        -normalFont "$font" \
        -colorBlack "#000000" \
        -colorRed "#D89345" \
        -colorGreen "#00B300" \
        -colorYellow "#FAB345" \
        -colorBlue "#0000D8" \
        -colorMagenta "#FA2093" \
        -colorCyan "#00D8D8" \
        -colorWhite "#FAB393" \
        -colorBoldBlack "#646464" \
        -colorBoldRed "#FA0000" \
        -colorBoldGreen "#93FA00" \
        -colorBoldYellow "#FAFA00" \
        -colorBoldBlue "#2020D8" \
        -colorBoldMagenta "#FAB3D8" \
        -colorBoldCyan "#00FAD8" \
        -colorBoldWhite "#D8D8D8" \
        -cursorColor "#0000DB" \
        -pointerForeColor "#FAB393" \
        -pointerBackColor "#000000" \
        -borderWidth 0
        -xrm "*waitForMap: true" \
        -xrm "*iconName: xmyman"
fi

export statusfile
statusfile="${TMPDIR:-/tmp}/${basename}$$.st"

cleanup()
{
    rm -f "${statusfile}"
}

trap cleanup 0

export arglist
arglist='-z huge'
while test $# -gt 0
do
  arglist="${arglist}"' ${arg'$#'}'
  eval export 'arg'$#
  eval 'arg'$#'="${1}"'
  shift
done

echo 1 > "${statusfile}" || exit $?

"$xterm" \
-geometry "$geometry" \
+sb \
-fn "$font" \
-bg "#000000" \
-fg "#FAB393" \
-cr "#0000DB" \
-xrm "*vt100.cjkWidth: false" \
-xrm "*vt100.faceName: $ttffont" \
-xrm "*vt100.faceSize: $ttfsize" \
-xrm "*vt100.boldFont: $font" \
-xrm "*vt100.boldMode: false" \
-xrm "*termName: $termName" \
-xrm "*iconName: xmyman" \
-xrm "*title: X MyMan" \
-xrm "*waitForMap: true" \
-xrm "*vt100.underLine: false" \
-xrm "*vt100.color0:  #000000" \
-xrm "*vt100.color1:  #D89345" \
-xrm "*vt100.color2:  #00B300" \
-xrm "*vt100.color3:  #FAB345" \
-xrm "*vt100.color4:  #0000D8" \
-xrm "*vt100.color5:  #FA2093" \
-xrm "*vt100.color6:  #00D8D8" \
-xrm "*vt100.color7:  #FAB393" \
-xrm "*vt100.color8:  #646464" \
-xrm "*vt100.color9:  #FA0000" \
-xrm "*vt100.color10: #93FA00" \
-xrm "*vt100.color11: #FAFA00" \
-xrm "*vt100.color12: #2020D8" \
-xrm "*vt100.color13: #FAB3D8" \
-xrm "*vt100.color14: #00FAD8" \
-xrm "*vt100.color15: #D8D8D8" \
-xrm "*vt100.colorBD: #FAFA00" \
-xrm "*vt100.colorUL: #2020D8" \
-xrm "*vt100.colorMode: true" \
-xrm "*vt100.colorBDMode: true" \
-xrm "*vt100.colorULMode: true" \
-xrm "*vt100.pointerColor: #FAB393" \
-xrm "*vt100.pointerColorBackground: #000000" \
-xrm "*vt100.reverseVideo: false" \
-xrm "*vt100.tekStartup: false" \
-xrm "*vt100.dynamicColors: true" \
-xrm "*vt100.internalBorder: 0" \
-xrm "*vt100.internalBorder: 0" \
-e /bin/sh -c 'myman -o '"${arglist}"'; st=$?; echo "${st}" > "${statusfile}"; echo; echo "[ press RETURN to continue ]"; stty -echo; read x; exit "${st}"'
st="${?}"
if test :"${st}" = :"0"
then
    read st < "${statusfile}"
fi
cleanup
exit "${st:-1}"
