File: deunion.pl

package info (click to toggle)
baycomusb 0.10-12.1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 6,928 kB
  • ctags: 9,413
  • sloc: ansic: 49,182; asm: 17,572; sh: 3,637; makefile: 585; pascal: 183; sed: 93; perl: 31
file content (47 lines) | stat: -rwxr-xr-x 735 bytes parent folder | download | duplicates (32)
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
#!/usr/bin/perl
#
# Ack!  gcc doesn't support unnamed unions -- we have to fake them.
#
# Expected format:
#
#struct blah
#{
#	union
#	{
#		type1 blah1;
#		type2 blah2;
#	};
#}

$lineno = 0;
$union = 0;
$ucount = 1;
while ( ($line = <STDIN>) ) {
	++$lineno;

	$line =~ s/\r//;
	if ( $line =~ /\sunion\s/ ) {
		if ( $union ) {
			die("Nested union at line $lineno -- Exiting.\n");
		}
		$union = 1;
	}
	if ( $union ) {
		if ( $line =~ /}/ ) {
			if ( $line =~ /};/ ) {
				chomp($line);
				$gnuline = $line;
				$gnuline =~ s/};/} u$ucount;/;
				$line = 
"#if defined(NONAMELESSUNION)\n$gnuline\n#else\n$line\n#endif\n";
				$ucount++;
			}
			$union = 0;
		}
	} else {
		if ( $line =~ /^}/ ) {
			$ucount = 1;
		}
	}
	print $line;
}