1 #! /usr/local/bin/gawk -f
3 # fixref.awk --- fix xrefs in texinfo documents
4 # Copyright, 1991, Arnold David Robbins, arnold@skeeve.atl.ga.us
5 # Copyright, 1998, Arnold David Robbins, arnold@gnu.org
7 # FIXREF is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # FIXREF is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 # Updated: Jul 21 1992 --- change unknown
22 # Updated: Jul 18 1997 --- bug fix
24 # usage: gawk -f fixref.awk input-file > output-file
25 # or if you have #!: fixref.awk input-file > output-file
28 # 1. no more than one cross reference on a line
29 # 2. cross references may not cross a newline
33 # we make two passes over the file. To do that we artificially
34 # tweak the argument vector to do a variable assignment
37 printf("usage: %s texinfo-file\n", ARGV[0]) > "/dev/stderr"
47 heading =
"@(chapter|appendix|unnumbered|(appendix(sec|subsec|subsubsec))|section|subsection|subsubsection|unnumberedsec|heading|top)"
51 # put space between paragraphs on output
55 pass ==
1 && NF ==
0 { next }
57 # pass == 1 && /@node/ \
59 pass ==
1 && /^@node
/ \
62 n =
split($
0, lines
, "\n")
63 for (i =
1; i
<= n
; i
++) {
64 if (lines
[i
] ~
("^" heading
)) {
65 sub(heading
, "", lines
[i
])
66 sub(/^
[ \t]*/, "", lines
[i
])
68 # printf "long name is '%s'\n", lines[i]
69 } else if (lines
[i
] ~
/@node
/) {
70 sub(/@node
[ \t]*/, "", lines
[i
])
71 sub(/[ \t]*,.
*$
/, "", lines
[i
])
73 # printf "node name is '%s'\n", lines[i]
79 printf("node name for %s missing!\n", lname
) > "/dev/stderr"
81 printf("long name for %s missing!\n", name
) > "/dev/stderr"
84 printf("node `%s' contains a `:'\n", name
) > "/dev/stderr"
88 printf("name `%s' contains a `:'\n", lname
) > "/dev/stderr"
89 else if (lname ~
/,/) {
90 printf("name `%s' contains a `,'\n", lname
) > "/dev/stderr"
92 names
[name
] = lname
# added 7/18/97
97 pass ==
2 && /@
(x
|px
)?ref
{/ \
99 # split the paragraph into lines
100 # write them out one by one after fixing them
101 n =
split($
0, lines
, "\n")
102 for (i =
1; i
<= n
; i
++)
103 if (lines
[i
] ~
/@
(x
|px
)?ref
{/) {
104 res = updateref
(lines
[i
])
107 printf "%s\n", lines
[i
]
109 printf "\n" # avoid ORS
113 function updateref
(orig
, refkind
, line
)
115 line = orig
# work on a copy
117 # find the beginning of the reference
118 match(line
, "@(x|px)?ref{")
119 refkind =
substr(line
, RSTART, RLENGTH)
121 # pull out just the node name
122 sub(/.
*ref
{/, "", line
)
123 sub(/}.
*$
/, "", line
)
127 # printf("found ref to node '%s'\n", line) > "/dev/stderr"
129 # If the node name and the section name are the same
130 # we don't want to bother doing this.
132 if (!
(line in names
)) # sanity checking
133 printf("no long name for %s\n", line
) > "/dev/stderr"
134 else if (names
[line
] != line
&& names
[line
] !~
/[:,]/) {
136 newref = refkind line
", ," names
[line
] "}"
137 pat = refkind line
"[^}]*}"
139 sub(pat
, newref
, orig
)