File: convert_headers.pl

package info (click to toggle)
ossim 1.8.16-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 24,156 kB
  • ctags: 31,345
  • sloc: cpp: 324,330; ansic: 14,940; sh: 7,473; pascal: 1,072; perl: 306; makefile: 207; lex: 183; xml: 141; sql: 78; csh: 4; php: 1
file content (176 lines) | stat: -rwxr-xr-x 3,846 bytes parent folder | download
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
#!/usr/bin/perl
use File::Copy;
$Base_Dir = "";
$header_index;
#$Headers_Dir = "";
@headers;
$cpp_index;
$c_index;
@cpp;
@c;

sub process_headers
{
	if (opendir(Input_Files, $Base_Dir . $_[0]))
	{
		foreach $name (sort readdir(Input_Files))
		{ 
			if (substr($name, length($name) - 2, length($name)) eq ".h")
			{
				@headers[$header_index] = $name;
				@headers_Path[$header_index] = $Base_Dir . $_[0] .  "/" . $name;
				$header_index = $header_index + 1;
			} elsif ($name ne "." && $name ne ".." && $name[0] ne '.')
			{
				process_headers($_[0] .  "/" . $name);
			}			
		} 
		closedir(Input_Files);
	}
}

sub process_cpp
{
	if (opendir(Input_Files, $Base_Dir . $_[0]))
	{
		foreach $name (sort readdir(Input_Files))
		{ 
			if (substr($name, length($name) - 4, length($name)) eq ".cpp" or
				substr($name, length($name) - 2, length($name)) eq ".c")
			{
				@cpp[$cpp_index] = $Base_Dir . $_[0] .  "/" . $name;
				$cpp_index = $cpp_index + 1;
			} elsif ($name ne "." && $name ne ".." && $name[0] ne '.')
			{
				process_cpp($_[0] .  "/" . $name);
			}			
		} 
		closedir(Input_Files);
	}
}

sub mod_headers
{
	# open each file in $headers_path
	open(HANDLE, @headers_Path[$_[0]]);
#	$outpath = $Headers_Dir . "/" . $headers[$_[0]];
	@raw_data=<HANDLE>;
	close(HANDLE);
	open(OUTHANDLE, ">@headers_Path[$_[0]]");
	
	foreach $line (@raw_data)
	{
		# search for lines starting with "#include"
		if ($line =~ m/#include/)
		{
			chop($line);
    		# compare .h file to all values in @headaers
			for ($j=1; $j < $header_index; $j++)
			{
				$position = index($line, @headers[$j]);

		 		if ($position ge 0)
		 		{
		 			if (substr($line, $position - 1, 1) eq '/' | substr($line, $position - 1, 1) eq '"' |
		 				substr($line, $position - 1, 1) eq '<')
		 			{
						 # if found change to "ossim/@headers[i]"
						$start = index($line, '"');
						if ($start eq -1)
						{
							$start = index($line, '<');
							$end = index($line, '>', $start + 1);
						} else
						{
							$end = index($line, '"', $start + 1);
						}
						$line = substr($line, 0, $start + 1) . "ossim/" . $headers[$j] . substr($line, $end, length($line));
						goto EXIT;
					}
		 		}
		 	}
		 	EXIT:
			print OUTHANDLE $line . "\n";
		} else
		{
			print OUTHANDLE $line;
		}
	}
	close(OUTHANDLE);
}

sub mod_body
{
print @cpp[$_[0]] . "\n";
	open(HANDLE, @cpp[$_[0]]);
	@raw_data=<HANDLE>;
	close(HANDLE);
	open(OUTHANDLE, ">@cpp[$_[0]]");
	
	foreach $line (@raw_data)
	{
		# search for lines starting with "#include"
		if ($line =~ m/#include/)
		{
			chop($line);
    		# compare .h file to all values in @headaers
			for ($j=1; $j < $header_index; $j++)
			{
				$position = index($line, @headers[$j]);

		 		if ($position ge 0)
		 		{
		 			if (substr($line, $position - 1, 1) eq '/' | substr($line, $position - 1, 1) eq '"' |
		 				substr($line, $position - 1, 1) eq '<')
		 			{		 		
						# if found change to "ossim/@headers[i]"
						
						$start = index($line, '"');
						if ($start eq -1)
						{
							$start = index($line, '<');
							$end = index($line, '>', $start + 1);
						} else
						{
							$end = index($line, '"', $start + 1);
						}
						$line = substr($line, 0, $start + 1) . "ossim/" . $headers[$j] . substr($line, $end, length($line));
						goto EXIT;
					}
		 		}
		 	}
		 	EXIT:
			print OUTHANDLE $line . "\n";
		} else
		{
			print OUTHANDLE $line;
		}
	}
	close(OUTHANDLE);

}

sub move_headers
{
#	mkdir "includes", 777
#	mkdir "includes/ossim", 777
	for ($j=1; $j < $header_index; $j++)
	{
		print $headers_Path[$j] . "\n";
		move($headers_Path[$j],"includes/ossim/");
	}
}

$header_index = 1;
process_headers("src/ossim_core");
for ($i=1; $i < $header_index; $i++)
{
	mod_headers($i);
}
$cpp_index = 1;
process_cpp("src");
for ($i=1; $i < $cpp_index; $i++)
{
	mod_body($i);
}
move_headers("src/ossim_core")