File: gatherlinkmap.lsed

package info (click to toggle)
stx2any 1.56-2.3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 748 kB
  • sloc: sh: 312; python: 288; lisp: 137; makefile: 126; sed: 1
file content (69 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
w_doc_id(s2aimpl.gatherlink)dnl

This file is copyright (c) 2004,2005,2006 by Panu Kalliokoski
and released under the license in ../LICENSE

This is a (scary) preprocessor that gathers link data from documents.
Link abbreviation processing is two-phase: this is the first phase,
before actually processing the documents, in which we just gather enough
information for the second phase and ditch everything else.

The link data is supposed to be in blocks.  Outside blocks, all we have
to gather is labels.
{{{
/^\[[A-Za-z0-9][A-Za-z0-9]*\] /,/^$/!{
/./!d
}}}
I don't care to process more than one label per line.  If somebody uses
two explicit labels on the same line, (s)he can't have a good reason to
do so.  We read text in whole paragraphs so as to skip blocklike-looking
constructs in the middle of a paragraph.
{{{
: gulp
s#^.*\[+\([^]]*\)+\].*$#w_make_autolabel(`\1')dnl#p
s#^!!* *\(.*\)$#w_make_autolabel(`\1')dnl#p
$!{
N
/\n$/!b gulp
}
d
}
}}}

End-block processing.

{{{
/^$/{
x
s#$#`'')dnl#p
d
}
}}}

From here on, we are within a link data block.  During that, we keep the
previous line in hold space.  Empty hold space means no line.

{{{
s#'#`'w_apo`'#g
}}}

The case that we have a new datum: see whether there is a line to
finish.
{{{
/^\[\([A-Za-z0-9][A-Za-z0-9]*\)\] /{
s##define(`@w_linkdata_of_\1',`#
x
/./!d
s#$#`'')dnl#p
d
}
}}}

The case that we don't: just store the new one, dump the old one.
(Whitespace is stripped to allow indenting line continuations on the
same level as the link data marker.)
{{{
s#^[ 	]*##
x
}}}