summaryrefslogtreecommitdiff
path: root/docs/tutorials/linify
blob: f44747f5269217b6660c2c8bdd3804c1a736560c (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
#!/usr/local/bin/perl

while( $#ARGV > -1 ) {

	print "$ARGV[0]\n";

	$source = "$ARGV[0]";

	if( $source =~ /~$/ ) {
		$dest = "$`";
	} else {
		rename("$source","$source"."~") || die "Cannot rename ($source)";
		$dest = "$source";
		$source .= "~";
	}

	open(INPUT,"<$source") || die "Cannot open ($source)";
	open(OUTPUT,">$dest")  || die "Cannot open ($dest)";
	
	$n = 1;
	
	$prestrip = 0;
	while( <INPUT> ) {
		chomp;

		if( ! $prestrip && /^[0-9]+\.\t/ ) {
			$prestrip = 1;
			$_ = $';
		} elsif( $prestrip ) {
			if( /^[0-9]+\.\t/ ) {
				$_ = $';
			} else {
				s/^\t//;
			}
		}

		if( /^\s*$/ || /^\s*({|})\s*;?\s*$/ || /^\s*\/\//
			|| /^\s*private\s*:/ || /^\s*protected\s*:/ || /^\s*public\s*:/
			|| /^\s*}?\s*else\s*{?\s*:/
			) {
			print OUTPUT "\t$_\n";
		} else {
			print OUTPUT "$n.\t$_\n";
			++$n;
		}
	}
	
	close(INPUT);
	close(OUTPUT);

	shift(@ARGV);
}