home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / nodify.shar < prev    next >
Encoding:
Internet Message Format  |  1991-05-03  |  4.8 KB

  1. From: seindal@skinfaxe.diku.dk (Rene' Seindal)
  2. Subject: nodify -- fix @nodes in texinfo files.
  3. Date: 9 Nov 90 05:29:33 GMT
  4. Organization: Department Of Computer Science, University Of Copenhagen
  5.  
  6. (Is this the right place for a program like this?)
  7.  
  8. Here's a cute little script, nodify, which makes it a bit easier to
  9. write texinfo files.
  10.  
  11. When you write your text, insert the nodes without any forward, backward
  12. or up pointers, and when you are finished, run nodify on the file.  It
  13. scans the file for @nodes, attaches them to sectioning commands,
  14. calculates the pointers, and generates a sed-script to edit the file.
  15. This script is run to fix the texinfo file.
  16.  
  17. If forward, backward and up pointers are already present, nodify removes
  18. them, and proceeds as normal.  Nodify doesn't change the file without
  19. having to.
  20.  
  21. At a given sectioning level, nodify lets the first nodes Prev be the
  22. same as Up, and the last nodes Next be void.  I am not sure whether this
  23. is the official way, but that is how I normally do things.
  24.  
  25. There is not attempt at creating the @menus.  It could probably be done,
  26. but finding the right place to put them is hard.  I haven't bothered.
  27.  
  28. Anyway, this little script really makes makeinfo shut up when you have
  29. added a new chapter, or interchanged a few sections.
  30.  
  31. And, yes, I know, it could have been done 3*pi/e^2 lines in perl, but
  32. not by me!
  33.  
  34. Rene' Seindal (seindal@diku.dk)
  35.  
  36. ---- Cut Here and unpack ----
  37. #!/bin/sh
  38. # shar:    Shell Archiver  (v1.22)
  39. #
  40. #    Run the following text with /bin/sh to create:
  41. #      nodify
  42. #
  43. echo "x - extracting nodify (Text)"
  44. sed 's/^X//' << 'SHAR_EOF' > nodify &&
  45. X#!/bin/sh
  46. X#
  47. X# nodify -- update @node commands in texinfo files.
  48. X# Copyright (C) 1990 Rene Seindal
  49. X#
  50. X# This program is free software; you can redistribute it and/or modify
  51. X# it under the terms of the GNU General Public License as published by
  52. X# the Free Software Foundation; either version 1, or (at your option)
  53. X# any later version.
  54. X#
  55. X# This program is distributed in the hope that it will be useful,
  56. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  57. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  58. X# GNU General Public License for more details.
  59. X#
  60. X# You should have received a copy of the GNU General Public License
  61. X# along with this program; if not, write to the Free Software
  62. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  63. X
  64. Xfile="$1"
  65. Xtmp1=/tmp/nodify1-$$
  66. Xtmp2=$file.new
  67. X
  68. Xtrap "rm -f $tmp1 $tmp2; exit 1" 1 2 3 14 15
  69. X
  70. Xegrep -n '^@(node|chapter|unnumbered|appendix|section|unnumberedsec|appenndixsec|subsection|unnumberedsubsec|appendixsubsec|subsubsection|unnumberedsubsubsec|appendixsubsubsec)' $file | 
  71. Xawk -F: '
  72. X$2 ~ /^@node/ {
  73. X    line = $1;
  74. X    junk = index($2, ",");
  75. X    if (junk == 0)
  76. X        node = $2;
  77. X    else
  78. X        node = substr($2, 1, junk-1);
  79. X}
  80. X$2 ~ /^@chapter/        { print line ":" 1 ":" node }
  81. X$2 ~ /^@unnumbered/        { print line ":" 1 ":" node }
  82. X$2 ~ /^@appendix/        { print line ":" 1 ":" node }
  83. X$2 ~ /^@section/        { print line ":" 2 ":" node }
  84. X$2 ~ /^@unnumberedsec/        { print line ":" 2 ":" node }
  85. X$2 ~ /^@appenndixsec/        { print line ":" 2 ":" node }
  86. X$2 ~ /^@subsection/        { print line ":" 3 ":" node }
  87. X$2 ~ /^@unnumberedsubsec/    { print line ":" 3 ":" node }
  88. X$2 ~ /^@appendixsubsec/        { print line ":" 3 ":" node }
  89. X$2 ~ /^@subsubsection/        { print line ":" 4 ":" node }
  90. X$2 ~ /^@unnumberedsubsubsec/    { print line ":" 4 ":" node }
  91. X$2 ~ /^@appendixsubsubsec/    { print line ":" 5 ":" node }' |
  92. Xawk -F: '
  93. XBEGIN {
  94. X    level = 0;
  95. X    pnode[0] = "Top";
  96. X    pnode[1] = "Top";
  97. X}
  98. X
  99. Xlevel > $2 {
  100. X    print pline[level] "c\\\n@node " pnode[level] ", , " ppnode[level] ", " pnode[level-1]
  101. X
  102. X    ppnode[level] = pnode[level];
  103. X    ppline[level] = pline[level];
  104. X    pnode[level] = node;
  105. X    pline[level] = line;
  106. X    node = "";
  107. X    line = "";
  108. X
  109. X    level = $2;
  110. X}
  111. X
  112. Xlevel == $2 {
  113. X    node = substr($3, 7);
  114. X    line = $1;
  115. X
  116. X    if (ppnode[level] != "")
  117. X        prev = ppnode[level];
  118. X    else
  119. X        prev = pnode[level-1];
  120. X    print pline[level] "c\\\n@node " pnode[level] ", " node ", " prev ", " pnode[level-1]
  121. X
  122. X    ppnode[level] = pnode[level];
  123. X    ppline[level] = pline[level];
  124. X    pnode[level] = node;
  125. X    pline[level] = line;
  126. X    node = "";
  127. X    line = "";
  128. X
  129. X    next;
  130. X}
  131. X
  132. Xlevel < $2 {
  133. X    level = $2;
  134. X
  135. X    ppnode[level] = pnode[level];
  136. X    ppline[level] = pline[level];
  137. X    pnode[level] = substr($3, 7);
  138. X    pline[level] = $1;
  139. X    node = "";
  140. X    line = "";
  141. X
  142. X    next;
  143. X}
  144. X
  145. XEND {
  146. X    for (; level > 0; --level)
  147. X        print pline[level] "c\\\n@node " pnode[level] ", , " ppnode[level] ", " pnode[level-1]
  148. X
  149. X}' > $tmp1
  150. X
  151. Xif sed -f $tmp1 $file > $tmp2; then
  152. X    if cmp -s $file $tmp2; then
  153. X        :
  154. X    else
  155. X        rm -f $file.bak
  156. X        mv $file $file.bak
  157. X        mv $tmp2 $file
  158. X    fi
  159. Xfi
  160. X
  161. Xrm -f $tmp1 $tmp2
  162. SHAR_EOF
  163. chmod 0755 nodify || echo "restore of nodify fails"
  164. set `wc -c nodify`;Sum=$1
  165. if test "$Sum" != "2967"
  166. then echo original size 2967, current size $Sum;fi
  167. exit 0
  168.  
  169.  
  170.