summaryrefslogtreecommitdiff
path: root/tools/linuxdoc-tools/LinuxDocTools/FixRef.pm
blob: d2549857543f9f736fc0f83206b7e1d51a3716e1 (plain)
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
70
71
72
73
74
75
76
#
#  FixRef.pm
#
#  $Id: FixRef.pm,v 1.1.1.1 2001/05/24 15:57:41 sano Exp $
#
#  Start conversion from parsed linuxdoc-sgml to html.
#        - Identify references and file count
#
#  Rules based on fixref.l
#
package LinuxDocTools::FixRef;

# Externally visible variables
$fixref = {};

# Initialize: set splitlevel before using rules
# Usage: &{$fixref->{init}}(<split level>);
	# 0 - super page mode
	# 1 - big page mode
	# 2 - small page mode
$fixref->{init} = sub {
    $splitlevel = shift;
};

# Outputs: Read after using rules
$fixref->{filenum} = 0;			# Count of files we will create
$fixref->{lrec} = {};			# label -> filenum

# Package variables
$chapter_mode = 0;	# <report> vs. <article>
$splitlevel = 0;	# See $fixref->{init} above;
			# Automatically reduced by 1 for chapter mode

# Finalize parsing
$fixref->{finish} = sub { };		# Do nothing when we're done

# Ruleset
$fixref->{rules} = {};			# Individual parsing rules
$fixref->{defaultrule} = sub { };	# If line does not match any rules

# Set the rules
# <@@ssect> - split file if necessary
$fixref->{rules}->{'^<@@ssect>.*$'} = sub { &splitfile(2); };

# <@@sect> - split file if necessary
$fixref->{rules}->{'^<@@sect>.*$'} = sub { &splitfile(1); };

# <@@chapt> - set chapter mode; reduce splitlevel if needed; split file
$fixref->{rules}->{'^<@@chapt>.*$'} = sub { 
    $splitlevel-- if (!$chapter_mode);
    $chapter_mode = 1; &splitfile(0);
};

# <@@label> - Identify label location
$fixref->{rules}->{'^<@@label>(.*)$'} = sub { 
    $fixref->{lrec}->{$1} = $fixref->{filenum};
};

#==============================
# Split the file (-split option; level in parentheses):
#  non-chapter mode: -0 -> don't split
#                    -1 -> split at sect (1)
#                    -2 -> split at sect (1) and ssect (2)
#  chapter mode: -0 -> split at chapt (0)
#                -1 -> split at chapt (0)
#                -2 -> split at chapt (0) and sect (1)
sub splitfile
{
    my ($level) = @_;
    if (($level == 0) || ($splitlevel >= $level)) {
        $fixref->{filenum}++;
    }
}

1;