From KBase
[edit] Abstract
- PERL, make, find 를 이용하여 원하는 형태의 파일 만들기
- 요구사항
- 원래 .bmp 파일로부터 RGB565 형태로 변환하여 .c 에서 include 할 수 있는 text 파일로 만들어 주는 툴이 있음
- 위 파일을 input 으로 하여, 앞에 width, height 4바이트씩을 넣고 뒤에는 raw data 를 넣은 binary 파일 생성
[edit] makefile.pl
- 현재 폴더 이하의 tree 에 있는 .hex 파일에 대하여 Makefile 을 만듬
#!/usr/bin/perl
$find = '/usr/bin/find';
$conv_tool = './writebin.pl';
$output = <<EOM;
.PHONY: all outfiles
all : outfiles
EOM
$cmd = qq{$find . -name *.hex -print};
open(FIND, "$cmd |") or die "find: $!";
while (<FIND>) {
my ($hex) = (/^(.+?)\s*$/);
($out = $hex) =~ s/\.hex$/.out/;
$outfiles .= "$out ";
$output .= <<EOM;
$out : $hex
$conv_tool $hex
EOM
}
close(FIND);
$output .= <<EOM;
outfiles : $outfiles
clean :
rm -rf $outfiles
EOM
open(MK, "> Makefile") or die "Makefile: $!";
print MK $output;
close(MK);
[edit] writebin.pl
- hex string 으로 되어 있는 파일을 읽어 binary data 로 write 함. 앞에 width, height 도 붙임
#!/usr/bin/perl
$hex = $ARGV[0];
unless (-e $hex) {
print "File Not Found: $hex\n";
exit 1;
}
($out = $hex) =~ s/\.hex/.out/;
open(OUT, "> $out") or die "$out : $!";
while (<>) {
if (/ : (\d+) x (\d+)\s*$/) {
($width, $height) = ($1, $2);
print OUT pack('II', $width, $height);
next;
}
unless ($width && $height) {
print "Resolution not recognized\n";
exit 1;
}
@arr = split(/,/);
for $hex (@arr) {
next unless ($hex =~ /0x\w+$/);
print OUT pack('S', hex($hex));
#print "[$hex]";
#printf('%X', hex($hex));
}
#print;
#exit;
}
close(OUT);