[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

es version of man



After ~30 minutes of hacking I have translated the version of man
written for rc to es. The preformance is not as good (30-40% slower,
in most cases) although there have been a few optimizations made since
the rc version. The code is ugly, but it works (I hope). Send bug
reports, etc to quanstro@stolaf.edu

#!/tmp/es
#########################################################################
# file:         man							#
#									#
# object:       display man pages					#
#									#
# Erik Quanstrom							#
# 21. M"arz 1993							#
#########################################################################
path = /bin /usr/bin /usr/ucb /usr/local/bin $path
macros = an
sections =

n=; 
fn-shiftn = {n = $n 1}

#set default values
if {~ $MANPATH ()} { manpath = /usr/man} {manpath = <>{%fsplit : $MANPATH}}
%is-interactive && ~ $PAGER () && PAGER=more -s;
~ $TCAT () && TCAT =@{ lpr -t $* }
~ $TROFF () && TROFF = @{nroff -hq -Tcrt -m^$macros $*}

#some functions
fn-usage = { 
  echo usage: $0 [-] [-t] [-M path] [-T macros [[section] name ... >[2=1]
  echo usage: $0 [-M path] -k [keyword] >[2=1]
  echo usage: $0 [-M path] -f [keyword] >[2=1]
  exit 1
}

fn-shift = @ var {
  {~ $var () && *=$*(2 ...)} || var=$var(2 ...);
}

# options 
keyprog=;keyword=

while {~ $1 -*} {
  if (
    {~ $1 -} 
      {
	 ~ $PAGER troff && throw error $0^': bad combination of flags'
	 PAGER=cat;
      }
    {~ $1 -t} 
      {
	 TROFF = @{troff -t $*}
	 PAGER = $TCAT
      }
    {~ $1 -M}
      {
         shift;	 ~ $1 () && usage;
	 MANPATH=<>{%fsplit : $1}
      }
    {~ $1 -T}
      {
	 shift;	 ~ $1 () && usage;
	 macros = $1
      }
    {~ $1 -k}
      {
	 shift; ~ $1 () && usage
	 keyword = $1;
	 break;
      }
    {~ $1 -f} 
      {
	 shift; ~ $1 () && usage
	 keyprog = $1;
	 break;
      }
    {~ $1 -*}
      {
	 echo 'bad flag `'^$1^'''' >[1=2]
	 usage
      }
  )
  shift;
}

if {! ~ $#* 1 && {~ $1 [l1-8] || ~ $1 [l1-8]?}} {
  sname=$1;
  sectionsc=$manpath/cat^<>{%fsplit '' $1};
  sectionsm=$manpath/man^<>{%fsplit '' $1};
  shift
} {
  sectionsc = $manpath^/cat*
  sectionsm = $manpath^/man*
}

if {! ~ () $keyword $keyprog} {
  dirlist=()
  for (d = $manpath)
    test -s $d^/whatis && dirlist = $dirlist $d^/whatis

  ~ $1 () && usage;

  if {! ~ $keyprog ()} {
    while {! ~ $1 ()} {
      cmd=`{echo $1 | sed 's/^.*\///g'}
      egrep -ih '^'^$cmd' ' $dirlist;
      shift;
    }
  }  {
    while {! ~ $1 ()} {
      grep -ih $1 $dirlist;
      shift;
    }
  }
  exit 0;
}

s=0; list=; tmplist=
while {!~ $1 ()} {
  troffit=
  filelist = `{echo $sectionsc^/$1^.* | tr ' ' '\12' | grep -v '*'}

  ~ $filelist () && {troffit=1
    filelist = `{echo $sectionsm^/$1^.* | tr ' ' '\12' | grep -v '*'}}


  if {~ $filelist ()} {
    if {! ~ $sname ()} {
      echo 'no entry for $1 in section `'$sname''' of the manual'>[1=2];
    } {
      echo no entry for '`'$1'''' found. >[1=2];
    }
    s=1;
  } {
    echo $filelist '(' $#filelist ')' >[1=2];
    
    if {~ $troffit 1} {
      echo -n 'Formatting'
      l=
      for (file = $filelist) {
	echo -n .
	t = /tmp/man^$pid^$#n; tmplist = $tmplist $t;
	l = $l $t;
        $TROFF $file > $t
        shiftn;
      }
      filelist = $l
      echo ' 'done.
    }
  }
  shift;
  list = $list $filelist
}

! ~ $list () && $PAGER $list

rm -f $tmplist;
exit $s;