#!/usr/bin/perl -w

# converts an inc-file to a C-array

$count = 0;

print "\n//DONT EDIT THIS FILE, IT IS AUTO-GENERATED!\n\n";
print "#include <inttypes.h>\n";
print "#include <avr/pgmspace.h>\n\n";

while (<>) {
    if (/^\s*[;\#]/) {
	next;  # skip comments
    }

    if (/\s*AIRDENFACTOR:\s*/) {
		print "uint8_t AIRDENFACTOR[\] SECTION(\".airdenfactor\") = {\n    ";
    }
	if (/\s*THERMFACTOR:\s*/) {
		print "uint8_t THERMFACTOR[\] SECTION(\".thermfactor\") = {\n    ";
    }
    if (/\s*MATFACTOR:\s*/) {
		print "uint8_t MATFACTOR[\] SECTION(\".matfactor\") = {\n    ";
    }
    if (/DB\s+(\d+)T/i) {
	if ($count != 0) {
	    print ",\n    ";
	}
	printf("%d", $1);
	$count++;
    }
}

print "};\n";
