groff
[Top][All Lists]
Advanced

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

[Groff] Info files from troff source


From: Dorai Sitaram
Subject: [Groff] Info files from troff source
Date: Fri, 25 Jul 2003 09:32:08 -0400 (EDT)

Has there been any interest in getting Info files from
troff source?  It would seem quite an easy thing to do,
since you just need to automatically insert node
markers at headings, run nroff, and postprocess with a
bit of sed or awk.  Clearly nroff does all the work
already -- just the nodes need to be added.

Here's a script `troff2info' that generates a single
Info file from troff (ms) input.  Of course it can be
improved (e.g., extending to -man; split output),
but the basic idea is simple enough I think.  (I've
also placed the script in
http://www.ccs.neu.edu/~dorai/troff2info/troff2info.html.)

Gaius could probably use this prototype to add a much
better -Tinfo option without even trying.  With a
suitable -Tinfo, the technical (if not the
social) rationale for keeping the groff
documentation in Texinfo vanishes, as groff source
could generate all the output formats that Texinfo
does.

--dorai

#!/bin/sh

cat > _4info.tmac <<EOF
.rn SH ms_SH
.rn NH ms_NH
.de SH
.nf
__Info_node__
.fi
.ms_SH \\\\\$*
..
.de NH
.nf
__Info_node__
.fi
.ms_NH \\\\\$*
..
EOF

f=`echo $1|sed -e 's/\.[^.]*$//'`

groff -Tlatin1 _4info.tmac $1 > $f.info

NUMNODES=`grep -c '^__Info_node__ *$' $f.info`

if test $NUMNODES -eq 0
then exit
fi

cat $f.info |\
awk -v NUMNODES=$NUMNODES -v INFOFILENAME=$f.info \
  'BEGIN { print "";
    printf("File: %s, Node: Top, Next: 1, Up: Top\n\n",
      INFOFILENAME);
  }
  /^__Info_node__/ { print "";
    i++;
    printf("File: %s, Node: %s, Prev: %s, ",
      INFOFILENAME, i,
      (i == 1 ? "Top" : i - 1));
    if (i != NUMNODES) {
      printf("Next: %s, ", i + 1);
    }
    printf("Up: Top\n\n");
    next;
  }
  { print }' > .awktmp

mv .awktmp $f.info

reply via email to

[Prev in Thread] Current Thread [Next in Thread]