File: texinfo.perl

package info (click to toggle)
elisp-manual-ja 20-2.5-jp-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,996 kB
  • ctags: 239
  • sloc: lisp: 2,837; perl: 182; makefile: 45; sh: 16
file content (177 lines) | stat: -rw-r--r-- 4,874 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/local/bin/perl


if( $ARGV[0] eq '-n' ){			# ǥХåץ
    $DEBUG = 1;
    shift @ARGV;
}
( @ARGV==1 )&&( -e $ARGV[0] )||die <<'__EOF__';

NAME
     texinfo.perl -   Next,Prev,Up λ꤬礱Ƥ @node Ԥ
                      䴰 Perl script

SYNOPSIS
     texinfo.perl [-n] file

DESCRIPTION
     Next,Prev,Up λ꤬礱Ƥ @node Ԥ@menu ˤڹ¤
     ꤷ䴰 Perl script
     
     Top node ޤǤ Texinfo source file ꤷƼ¹Ԥ롣
     node ֤λȴطθФӥեν񤭴εϿϡɸ
     顼Ϥ˽Ϥ롣

     -n ץꤹȡºݤΥե񤭴ϹԤ鷺
     ̤ɸϤ˽Ϥ롣

RULE
     䴰§ϼ̤ꡣƱ̤ͥ䴰§줿硢˸
     줿ȴطͥ褹롣
       (1) Next 礱Ƥ
             a) ̤ menu Ǽ¤Ǥ node
             b) ˸Ф줿 node
       (2) Prev 礱Ƥ
             a) ̤ menu ¤Ǥ node
             b) ľ˸Ф줿 node
       (3) Up 礱Ƥ
             a) ̤ node (menu ǤȤƻȤƤ node)
             b) ߻(@xref ʤ)ˤäƻȤƤ node

KNOWN BUGS
     ߻Ȥˤ @node Ԥ䴰Ŭڤ䴰Ǥ礬¿
     ȤǤν񤭴ɬס
     file ˸줿ȡinfo ȤƤι¤ۤʤäƤ硢
     Ŭڤ䴰ԲǽǤ롣

__EOF__



push( @files,$ARGV[0] );
$current='(DIR)';
$file_prev{'Top'} = '(DIR)';
$menu_up{'Top'}   = '(DIR)';
$menu="";


# ƤΥեɤ߹߻ȴطФ
warn "Start analysis of references ...\n";
for $file ( @files ){
    unless( open( FILE,"< $file" ) ){
	warn "Can't open $file";
	next;
    }
    warn "Reading $file ...\n";
    my( @lines )=<FILE>;
    close FILE;
    for( @lines ){
	if( /^\@node[ \t]+(\S.*)$/ ){	# @node Ԥ򸡽
	    warn "  $_";
	    local( $this,$next,$prev,$up )=split(/[ \t]*,[ \t]*/,$1);
	    $file_next{$current} = $this;
	    $file_prev{$this}    = $current;
	    $current             = $this;
	    push( @node,$this );
	} elsif( /^\@menu/ ){		# @menu Ԥ򸡽
	    $menu = $current;
	} elsif( /^\@end[ \t]+menu/ ){	# menu ν򸡽
	    if( $menu_next{$current} ){
		$menu_next{$menu} = $menu_next{$current};
	    }else{
		warn "    Warning: Can't find next menu item for $current\n" if $current ne 'Top';
	    }
	    $menu = "";
	} elsif( $menu &&( /^\*[ \t]+([^:]+)::/ || /^\*[ \t]+[^:]+:[ \t]*([^\.]+)\./ )){
	    if(( $menu_up{$1} eq '' )||( $menu_up{$1} eq 'Top' )){
		warn "    menu item -> $1\n";
		$menu_next{$menu} = $1 if $menu ne $current;
		$menu_prev{$1}    = $menu;
		$menu_up{$1}      = $current;
	    }else{
		warn "    menu item -> $1 is found. But ignored.\n";
	    }
	    $menu = $1;
	} elsif( /\@(x|px|info)*ref\{([^\}]+)\}/ ){ # ߻Ȥ򸡽
	    warn "    reference -> $2 ($1ref)\n";
	    $xref{$2} = $current unless $xref{$2};
	} elsif( /^\@include[ \t]+(\S.*)$/ ){
	    warn "    include file = $1\n";
	    push( @files,$1 );
	}
    }
}
    


# ե񤭴
warn "\nStart rewriting ...\n";
for $file ( @files ){
    unless( open( FILE,"< $file" ) ){
	warn "Can't open $file";
	next;
    }
    my( @lines )=<FILE>;
    close FILE;
    if( $DEBUG==0 ){
	( -e "$file~" )&& unlink( "$file~" ) || warn "Can't unlink old backup file : $file\n";
	( link( $file,"$file~" ) & unlink( $file ) )||warn "Can't make backup file : $file\n";
	unless( open( FILE,"> $file" ) ){
	    warn "Can't open $file";
	    next;
	}
	select FILE;
	warn "Rewrite $file ...\n";
    }
    for( @lines ){
	if( /^\@node[ \t]+(\S.*)$/ ){	# @node Ԥ򸡽
	    warn "  $_";
	    local( $this,$next,$prev,$up )=split(/[ \t]*,[ \t]*/,$1);
	    unless( $up ){
		if( $menu_up{$this} ){
		    $up = $menu_up{$this};
		    warn "    Up   = \"$up\" (menu item)\n";
		}elsif( $xref{$this} ){
		    $up = $xref{$this};
		    warn "    Up   = \"$up\" (cross reference)\n";
		}else {
		    $up = 'Top';
		    warn "    Up   = \"Top\" (forced)\n";
		}
	    }
	    unless( $next ){
		if( $menu_next{$this} ){
		    $next = $menu_next{$this};
		    warn "    Next = \"$next\" (menu item)\n";
		}elsif( $file_next{$this} ){
		    $next = $file_next{$this};
		    warn "    Next = \"$next\" (file sequence)\n";
		}elsif( $up ne 'Top' ){
		    $next = 'Top';
		    warn "    Next = \"Top\" (forced)\n";
		}else{
		    warn "    Next = nil\n";
		}
	    }
	    unless( $prev ){
		if( $menu_prev{$this} ){
		    $prev = $menu_prev{$this};
		    warn "    Prev = \"$prev\" (menu item)\n";
		}elsif( $file_prev{$this} ){
		    $prev = $file_prev{$this};
		    warn "    Prev = \"$prev\" (file sequence)\n";
		}else{
		    $prev = 'Top';
		    warn "    Prev = \"Top\" (forced)\n";
		}
	    }
	    print "\@node $this, $next, $prev, $up\n";
	} else {
	    print;
	}
    }
    if( $DEBUG==0 ){
	close FILE;
	select STDOUT;
    }
}