diff options
| author | Mark Purcell <msp@debian.org> | 2008-06-22 11:00:40 +1000 | 
|---|---|---|
| committer | etobi <git@e-tobi.net> | 2013-09-03 09:48:42 +0200 | 
| commit | 891c51ff368ed700dec6025eeb47ce4d96f76418 (patch) | |
| tree | 3729664829e4faa691d403274f38eb10890b533c /util/scan/section_generate.pl | |
| parent | 1c6e1f28f54ec2606c23936c1d8689f2be55a86c (diff) | |
| parent | ab959d7b4194715870128e616b8e29d4a101e488 (diff) | |
| download | linux-dvb-apps-891c51ff368ed700dec6025eeb47ce4d96f76418.tar.gz | |
Imported Debian patch 1.1.1+rev1207-1debian/1.1.1+rev1207-1
Diffstat (limited to 'util/scan/section_generate.pl')
| -rw-r--r-- | util/scan/section_generate.pl | 92 | 
1 files changed, 92 insertions, 0 deletions
| diff --git a/util/scan/section_generate.pl b/util/scan/section_generate.pl new file mode 100644 index 0000000..2080dbb --- /dev/null +++ b/util/scan/section_generate.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl -w + +use strict; + +die "no section perl file given" unless @ARGV; + +my $h = require($ARGV[0]); + +our $basename; +our $debug = $ARGV[1]; + +($basename) = $ARGV[0] =~ /([a-zA-Z0-9_\-_]+).pl/; + +local *H; +local *C; + +h_header(); +c_header(); + +foreach (sort keys %{$h}) { +	foreach my $item (@{$h->{$_}}) { +		if ($_ eq "descriptors") { +			printf H ("#define %s_ID 0x%02X\n",uc($item->{name}),$item->{id}); +		} + +		do_it  ($item->{name},$item->{elements}); +	} +} + +h_footer(); +c_footer(); + +sub type +{ +	if ($_[0] > 16) { +		return "u32"; +	} elsif ($_[0] > 8) { +		return "u16"; +	} else { +		return "u8 "; +	} +} + +sub do_it +{ +	my ($name,$val) = @_; +	print H "struct $name {\n"; + +	print C <<EOL; +struct $name read_$name(const u8 *b) +{ +	struct $name v; +EOL +	my $offs = 0; +	for (my $i = 0; $i < scalar @{$val}; $i+=2) { +		printf H ("\t\t%s %-25s :%2d;\n",type($val->[$i+1]),$val->[$i],$val->[$i+1]); + +		printf C ("\tv.%-25s = getBits(b,%3d,%2d);\n",$val->[$i],$offs,$val->[$i+1]); +		printf C ("\tfprintf(stderr,\"  %s = %%x %%d\\n\",v.%s,v.%s);\n",$val->[$i],$val->[$i],$val->[$i]) if $debug; +		$offs += $val->[$i+1]; +	} +	print H "} PACKED;\n"; +	print H "struct $name read_$name(const u8 *);\n\n"; + +	print C "\treturn v;\n}\n\n" +} + +sub h_header +{ +	open(H,">$basename.h"); +	print H "#ifndef __".uc($basename)."_H_\n"; +	print H "#define __".uc($basename)."_H_\n\n"; +	print H "#include \"section.h\"\n\n"; +} + +sub c_header +{ +	open(C,">$basename.c"); +	print C "#include \"$basename.h\"\n\n"; +} + + +sub c_footer +{ +	close(C); +} + +sub h_footer +{ +	print H "#endif\n"; +	close(H); +} | 
