2 #@ make-news-anchors.sh
3 #@ Expand *XY*# / $XY# / -XY# / `XY'# / `~XY'# / "XY"# style anchors
4 #@ so that the anchor matches the number given in ANCHORFILE.
5 #@ The number sign may be followed by space, question-mark ? or a number.
6 #@ We always expand STDIN to STDOUT, but only in the range
7 #@ ChangeLog .. ^(Appendix|git\(1\) shortlog) (or EOF, of course)
8 #@ The ANCHORFILE can be produced by
9 #@ $ < manual.mdoc mdocmx.sh |
10 #@ MDOCMX_ENABLE=1 groff -U -mdoc -dmx-anchor-dump=/tmp/anchors \
11 #@ -dmx-toc-force=tree >/dev/null
17 if [ ${#} -gt 0 ]; then
18 echo >&2 "ERROR: ${*}"
21 echo >&2 'Synopsis: make-news-anchors.sh ANCHORFILE'
25 [ ${#} -eq 1 ] || syno
26 [ -f "${1}" ] || syno
'the given anchorfile does not exist'
29 ${awk} -v anchorfile
="${1}" '
36 /^(Appendix|git\(1\) shortlog)/{
50 /(^|\(|[[:space:]]+)("[^"]+"|\*[^\*]+\*|`[^'${APO}']+'${APO}'|[-~][-\/:_.[:alnum:]]+|\$[_[:alnum:]]+)#(\?|[0-9]+)?/))
53 pre = (RSTART > 1) ? substr(s, 1, RSTART - 1) : ""
54 mat = substr(s, RSTART, RLENGTH)
55 s = substr(s, RSTART + RLENGTH)
57 # Unfortunately groups are not supported
58 if(match(mat, /^(\(|[[:space:]]+)/) != 0 && RLENGTH > 0){
59 pre = pre substr(mat, 1, RLENGTH)
60 mat = substr(mat, RSTART + RLENGTH)
63 match(mat, /#(\?|[0-9]+)?/)
64 mat = substr(mat, 1, RSTART - 1)
67 if(mat ~ /^`/){ # Cm, Ic
68 mat = substr(mat, 2, length(mat) - 2)
70 }else if(mat ~ /^\*/){ # Va
71 mat = substr(mat, 2, length(mat) - 2)
73 }else if(mat ~ /^\$/){ # Ev, Dv
74 mat = substr(mat, 2, length(mat) - 1)
76 }else if(mat ~ /^-/){ # Fl
77 mat = substr(mat, 2, length(mat) - 1)
79 }else if(mat ~ /^\"/){ # Sh, Ss. But: "catch-all"
80 mat = substr(mat, 2, length(mat) - 2)
85 # Insufficient, of course
86 gsub("\\\\", "\\e", mat)
89 while(getline < anchorfile){
91 if($2 != "Cm" && $2 != "Ic")
97 if($2 != "Ev" && $2 != "Dv")
103 if($2 == "Cm" || $2 == "Ic" ||
105 $2 == "Ev" || $2 == "Dv" ||
113 match($0, /^[[:space:]]*/)
114 $0 = substr($0, RLENGTH + 1)
118 print "WARN: ambiguous: \"" mat "\"" > "/dev/stderr"
124 print "ERROR: no anchor for \"" mat "\"" > "/dev/stderr"