File: removeMSPragma.pl

package info (click to toggle)
scorched3d 44%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 112,612 kB
  • sloc: cpp: 135,987; xml: 36,739; makefile: 4,714; sh: 3,172; ansic: 1,407; perl: 541; java: 209; python: 188; sql: 159
file content (70 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (7)
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
use strict;

my @dirs =
(
	"3dsparse",
	"common",
	"coms",
	"dialogs",
	"engine",
	"GLEXT",
	"GLW",
	"landscape",
	"landscapedef",
	"client",
	"server",
	"actions",
	"cgext",
	"scorched",
	"sprites",
	"tankai",
	"target",
	"XML",
	"ships",
	"tankgraph",
	"tank",
	"boids",
	"placement",
	"sound",
	"weapons"
);

my $dir;
foreach $dir (@dirs)
{
	opendir(IN, "../src/$dir") || die "ERROR: DIR \"$dir\"";
	my @files = grep { /\.h/ } readdir(IN);
	closedir(IN);

	my $file;
	foreach $file (@files)
	{
		open (INFILE, "../src/$dir/$file") || die "ERROR: File \"../$dir/$file\"";
		my @filelines = <INFILE>;
		close (INFILE);

		my $index = -1;
		for (my $i=0; $i<=$#filelines; $i++)
		{
			if ($filelines[$i] =~ /pragma once/)
			{
				$index = $i;
			}
		}

		if ($index != -1)
		{
			my $incline = "__INCLUDE_".$file."_INCLUDE__";
			$incline =~ s/\.//g;

			print "$dir/$file\n";

			$filelines[$index] = "#if !defined($incline)\n#define $incline\n";
			push @filelines, "\n#endif // $incline\n";

			open(OUTFILE, ">../src/$dir/$file") || die "ERROR: Out $file";
			print OUTFILE @filelines;
			close (OUTFILE);
		}
	}
}