summaryrefslogtreecommitdiff
path: root/fix-numbers.pl
blob: 217085606dec56cb2b89c45904d037f7b930bd88 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl

use strict;

sub find_footnotes {
	my @text = @_;
	my @notes = ();
	my $found = 0;
	my $l;

	for ($l = 0; $l <= $#text; $l++) {
		if ($text[$l] =~ m/^FOOTNOTES:$/) {
			$found = 1;
		}
		next unless $found;
		if ($text[$l] =~ m/^\[[0-9]+\]\s/) {
			push @notes, $l;
		}
	}
	return @notes;
};

sub find_sections {
	my @text = @_;
	my @sections = ();
	my $l;

	for ($l = 0; $l <= $#text - 1; $l++) {
		next unless (($text[$l + 1] =~ m/^=======*$/) or
			     ($text[$l + 1] =~ m/^-------*$/));

		next unless ($text[$l] =~ m/^(([0-9]+\.)+) /);

		push @sections, $l;

	}
	return @sections;
};

sub get_section {
	my ($section, @prevpath) = @_;
	my @path = split(/\./, $section);

	#Possible cases:
	if ($#path > $#prevpath) {
#		Path deeper than parent: just add .1
		my $diff = $#path - $#prevpath;
		@path = @prevpath;
		for (my $i = 0; $i < $diff; $i++) {
			push @path, 1;
		}
	} elsif ($#path == $#prevpath) {
#		Same level as parent
		@path = @prevpath;
		$path[$#path]++;
	} elsif ($#path < $#prevpath) {
#		Higher level than parent
		@path = @prevpath[0 .. $#path];
		$path[$#path]++;
	}
	my $newsection = join('.', @path) . '.';
	my $prev = join('.', @prevpath) . '.';
	return ($newsection, @path);
};

my @text = ();
while (<>) {
	push @text, $_;
}

my @footnotes = find_footnotes(@text);
my @sections = find_sections(@text);

#Set new numbers for footnotes
my %footnote_by_old_reference = ();
my $f;
for ($f = 0; $f <= $#footnotes; $f++) {
	my $l = $footnotes[$f];
	die unless ($text[$l] =~ m/^\[([0-9]+)\]\s/);
	my $footnote = $1;
	my $newfootnote = $f + 1;
	die "duplicate footnote number $footnote" if defined($footnote_by_old_reference{$footnote});
	$footnote_by_old_reference{$footnote} = $newfootnote;
}

#Find and fix references to footnotes
my $l;
for ($l = 0; $l <= $#text; $l++) {
	next unless $text[$l] =~ m/\[[0-9]+\]/; #premature optimization
	for my $old (keys(%footnote_by_old_reference)) {
		my $new = $footnote_by_old_reference{$old};
		next if $new eq $old;
		$text[$l] =~ s/\[$old\]/[XYX$new]/g;
	}
	$text[$l] =~ s/\[XYX/[/go;
}

#Set new numbers for sections
my %section_by_old_reference = ();
my $s;
my @path = ();

for ($s = 0; $s <= $#sections; $s++) {
	my $l = $sections[$s];
	die unless ($text[$l] =~ m/^(([0-9]+\.)+)/);
	my $section = $1;
	my ($newsection, @p) = get_section($section, @path);
	@path = @p;
	die "duplicate section number $section" if defined($section_by_old_reference{$section});
	$section_by_old_reference{$section} = $newsection;
}

#Find and fix references to sections
my $l;
for ($l = 0; $l <= $#text; $l++) {
	next unless $text[$l] =~ m/^(([0-9]+\.)+)/; #premature optimization
	for my $old (keys(%section_by_old_reference)) {
		my $new = $section_by_old_reference{$old};
		next if $new eq $old;
		
		my @p = split(/\./, $old);
		my $pattern = join("\\.", @p) . "\\.";
		my @s = split(/\./, $new);
		my $subst = join("XYX", @s) . "XYX";
		$text[$l] =~ s/$pattern/$subst/g;
	}
	$text[$l] =~ s/XYX/./go;
}


for my $line (@text) {
	print $line;
}


span> ctxOwner; /* last context to upload state */ int vertex_prim; int pf_enabled; /* is pageflipping allowed? */ int pf_active; int pf_current_page; /* which buffer is being displayed? */ } drm_i810_sarea_t; /* WARNING: If you change any of these defines, make sure to change the * defines in the Xserver file (xf86drmMga.h) */ /* i810 specific ioctls * The device specific ioctl range is 0x40 to 0x79. */ #define DRM_IOCTL_I810_INIT DRM_IOW( 0x40, drm_i810_init_t) #define DRM_IOCTL_I810_VERTEX DRM_IOW( 0x41, drm_i810_vertex_t) #define DRM_IOCTL_I810_CLEAR DRM_IOW( 0x42, drm_i810_clear_t) #define DRM_IOCTL_I810_FLUSH DRM_IO( 0x43) #define DRM_IOCTL_I810_GETAGE DRM_IO( 0x44) #define DRM_IOCTL_I810_GETBUF DRM_IOWR(0x45, drm_i810_dma_t) #define DRM_IOCTL_I810_SWAP DRM_IO( 0x46) #define DRM_IOCTL_I810_COPY DRM_IOW( 0x47, drm_i810_copy_t) #define DRM_IOCTL_I810_DOCOPY DRM_IO( 0x48) #define DRM_IOCTL_I810_OV0INFO DRM_IOR( 0x49, drm_i810_overlay_t) #define DRM_IOCTL_I810_FSTATUS DRM_IO ( 0x4a) #define DRM_IOCTL_I810_OV0FLIP DRM_IO ( 0x4b) #define DRM_IOCTL_I810_MC DRM_IOW( 0x4c, drm_i810_mc_t) #define DRM_IOCTL_I810_RSTATUS DRM_IO ( 0x4d ) #define DRM_IOCTL_I810_FLIP DRM_IO ( 0x4e ) typedef struct _drm_i810_clear { int clear_color; int clear_depth; int flags; } drm_i810_clear_t; /* These may be placeholders if we have more cliprects than * I810_NR_SAREA_CLIPRECTS. In that case, the client sets discard to * false, indicating that the buffer will be dispatched again with a * new set of cliprects. */ typedef struct _drm_i810_vertex { int idx; /* buffer index */ int used; /* nr bytes in use */ int discard; /* client is finished with the buffer? */ } drm_i810_vertex_t; typedef struct _drm_i810_copy_t { int idx; /* buffer index */ int used; /* nr bytes in use */ void *address; /* Address to copy from */ } drm_i810_copy_t; #define PR_TRIANGLES (0x0<<18) #define PR_TRISTRIP_0 (0x1<<18) #define PR_TRISTRIP_1 (0x2<<18) #define PR_TRIFAN (0x3<<18) #define PR_POLYGON (0x4<<18) #define PR_LINES (0x5<<18) #define PR_LINESTRIP (0x6<<18) #define PR_RECTS (0x7<<18) #define PR_MASK (0x7<<18) typedef struct drm_i810_dma { void *virtual; int request_idx; int request_size; int granted; } drm_i810_dma_t; typedef struct _drm_i810_overlay_t { unsigned int offset; /* Address of the Overlay Regs */ unsigned int physical; } drm_i810_overlay_t; typedef struct _drm_i810_mc { int idx; /* buffer index */ int used; /* nr bytes in use */ int num_blocks; /* number of GFXBlocks */ int *length; /* List of lengths for GFXBlocks (FUTURE)*/ unsigned int last_render; /* Last Render Request */ } drm_i810_mc_t; #endif /* _I810_DRM_H_ */