home *** CD-ROM | disk | FTP | other *** search
- From: seindal@skinfaxe.diku.dk (Rene' Seindal)
- Subject: nodify -- fix @nodes in texinfo files.
- Date: 9 Nov 90 05:29:33 GMT
- Organization: Department Of Computer Science, University Of Copenhagen
-
- (Is this the right place for a program like this?)
-
- Here's a cute little script, nodify, which makes it a bit easier to
- write texinfo files.
-
- When you write your text, insert the nodes without any forward, backward
- or up pointers, and when you are finished, run nodify on the file. It
- scans the file for @nodes, attaches them to sectioning commands,
- calculates the pointers, and generates a sed-script to edit the file.
- This script is run to fix the texinfo file.
-
- If forward, backward and up pointers are already present, nodify removes
- them, and proceeds as normal. Nodify doesn't change the file without
- having to.
-
- At a given sectioning level, nodify lets the first nodes Prev be the
- same as Up, and the last nodes Next be void. I am not sure whether this
- is the official way, but that is how I normally do things.
-
- There is not attempt at creating the @menus. It could probably be done,
- but finding the right place to put them is hard. I haven't bothered.
-
- Anyway, this little script really makes makeinfo shut up when you have
- added a new chapter, or interchanged a few sections.
-
- And, yes, I know, it could have been done 3*pi/e^2 lines in perl, but
- not by me!
-
- Rene' Seindal (seindal@diku.dk)
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # shar: Shell Archiver (v1.22)
- #
- # Run the following text with /bin/sh to create:
- # nodify
- #
- echo "x - extracting nodify (Text)"
- sed 's/^X//' << 'SHAR_EOF' > nodify &&
- X#!/bin/sh
- X#
- X# nodify -- update @node commands in texinfo files.
- X# Copyright (C) 1990 Rene Seindal
- X#
- X# This program is free software; you can redistribute it and/or modify
- X# it under the terms of the GNU General Public License as published by
- X# the Free Software Foundation; either version 1, or (at your option)
- X# any later version.
- X#
- X# This program is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X# GNU General Public License for more details.
- X#
- X# You should have received a copy of the GNU General Public License
- X# along with this program; if not, write to the Free Software
- X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- Xfile="$1"
- Xtmp1=/tmp/nodify1-$$
- Xtmp2=$file.new
- X
- Xtrap "rm -f $tmp1 $tmp2; exit 1" 1 2 3 14 15
- X
- Xegrep -n '^@(node|chapter|unnumbered|appendix|section|unnumberedsec|appenndixsec|subsection|unnumberedsubsec|appendixsubsec|subsubsection|unnumberedsubsubsec|appendixsubsubsec)' $file |
- Xawk -F: '
- X$2 ~ /^@node/ {
- X line = $1;
- X junk = index($2, ",");
- X if (junk == 0)
- X node = $2;
- X else
- X node = substr($2, 1, junk-1);
- X}
- X$2 ~ /^@chapter/ { print line ":" 1 ":" node }
- X$2 ~ /^@unnumbered/ { print line ":" 1 ":" node }
- X$2 ~ /^@appendix/ { print line ":" 1 ":" node }
- X$2 ~ /^@section/ { print line ":" 2 ":" node }
- X$2 ~ /^@unnumberedsec/ { print line ":" 2 ":" node }
- X$2 ~ /^@appenndixsec/ { print line ":" 2 ":" node }
- X$2 ~ /^@subsection/ { print line ":" 3 ":" node }
- X$2 ~ /^@unnumberedsubsec/ { print line ":" 3 ":" node }
- X$2 ~ /^@appendixsubsec/ { print line ":" 3 ":" node }
- X$2 ~ /^@subsubsection/ { print line ":" 4 ":" node }
- X$2 ~ /^@unnumberedsubsubsec/ { print line ":" 4 ":" node }
- X$2 ~ /^@appendixsubsubsec/ { print line ":" 5 ":" node }' |
- Xawk -F: '
- XBEGIN {
- X level = 0;
- X pnode[0] = "Top";
- X pnode[1] = "Top";
- X}
- X
- Xlevel > $2 {
- X print pline[level] "c\\\n@node " pnode[level] ", , " ppnode[level] ", " pnode[level-1]
- X
- X ppnode[level] = pnode[level];
- X ppline[level] = pline[level];
- X pnode[level] = node;
- X pline[level] = line;
- X node = "";
- X line = "";
- X
- X level = $2;
- X}
- X
- Xlevel == $2 {
- X node = substr($3, 7);
- X line = $1;
- X
- X if (ppnode[level] != "")
- X prev = ppnode[level];
- X else
- X prev = pnode[level-1];
- X print pline[level] "c\\\n@node " pnode[level] ", " node ", " prev ", " pnode[level-1]
- X
- X ppnode[level] = pnode[level];
- X ppline[level] = pline[level];
- X pnode[level] = node;
- X pline[level] = line;
- X node = "";
- X line = "";
- X
- X next;
- X}
- X
- Xlevel < $2 {
- X level = $2;
- X
- X ppnode[level] = pnode[level];
- X ppline[level] = pline[level];
- X pnode[level] = substr($3, 7);
- X pline[level] = $1;
- X node = "";
- X line = "";
- X
- X next;
- X}
- X
- XEND {
- X for (; level > 0; --level)
- X print pline[level] "c\\\n@node " pnode[level] ", , " ppnode[level] ", " pnode[level-1]
- X
- X}' > $tmp1
- X
- Xif sed -f $tmp1 $file > $tmp2; then
- X if cmp -s $file $tmp2; then
- X :
- X else
- X rm -f $file.bak
- X mv $file $file.bak
- X mv $tmp2 $file
- X fi
- Xfi
- X
- Xrm -f $tmp1 $tmp2
- SHAR_EOF
- chmod 0755 nodify || echo "restore of nodify fails"
- set `wc -c nodify`;Sum=$1
- if test "$Sum" != "2967"
- then echo original size 2967, current size $Sum;fi
- exit 0
-
-
-