about summary refs log tree commit diff
path: root/Functions/Misc/mere
blob: 496c67061abc9d2a22e31f3f6b241542b7bcc038 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# read a man page

setopt localoptions extendedglob

local manual="$1" col=col terminal=man magic line

# /usr/bin/col on SunOS 4 doesn't support -x.
if [[ -x /usr/5bin/col ]]; then
  col=/usr/5bin/col;
fi

# SunOS 5 has no `man' terminal.
if [[ -d /usr/share/lib/nterm &&
    ! -e /usr/share/lib/nterm/tab.$terminal ]]; then
  terminal=lp;
fi

# HP-UX has no `man' terminal.
if [[ -d /usr/share/lib/term &&
    ! -e /usr/share/lib/term/tab$terminal ]]; then
  terminal=lp;
fi

# Unixware has no `man' terminal.
if [[ -d /usr/ucblib/doctools/nterm &&
    ! -e /usr/ucblib/doctools/nterm/tab.$terminal ]]; then
  terminal=lp;
fi

# Solaris has SGML manuals.
if [[ -f /usr/lib/sgml/sgml2roff ]] && 
   [[ "$(read -er < $manual)" = "<!DOCTYPE"* ]]; then
  /usr/lib/sgml/sgml2roff $manual | {
    read -r line
    if [[ $line = ".so "* ]]; then
      # There is no cascading .so directive.
      # On Solaris 7, at least.
      /usr/lib/sgml/sgml2roff ${line#.so }
    else
      print -lr - "$line"
      cat
    fi
  }
else
  read -u0 -k 2 magic < $manual
  case $magic in
  $'\037\235') zcat $manual;;
  $'\037\213') gzip -dc $manual;;
  *) cat $manual;;
  esac
fi | (
  # cd is required to work soelim called by nroff.
  case $manual in
  */man/man*/*) cd ${manual:h:h};;
  */man/sman*/*) cd ${manual:h:h};;
  esac
  read -r line
  # The first line beginning with '\" shows preprocessors.
  # Unknown preprocessors is ignored.
  if [[ $line = "'\\\" "* ]]; then
    typeset -A filter
    filter=(
      e neqn
      g grap
      p pic
      r refer
      t tbl
      v vgrind
    )
    eval ${(j:|:)${${(s::)line#\'\\\" }//(#m)?/$filter[$MATCH]}}
  elif [[ $line = "'\\\"! "* ]]; then
    typeset -A filter
    filter=(
      eqn neqn
    )
    eval ${(j:|:)${${${${(s:|:)line#\'\\\"! }# ##}% ##}//(#m)*/$filter[$MATCH]}}
  else
    print -lr - "$line"
    cat
  fi |
  nroff -T$terminal -man | $col -x
) |
${MANPAGER:-${PAGER:-more}} -s