summaryrefslogtreecommitdiffhomepage
path: root/vq/make_floor_books.pl
blob: 5c37366172f6bc513324a15076e4acb2124f26f9 (plain)
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
#!/usr/bin/perl

# quick, very dirty little script so that we can put all the
# information for building a floor book set in one spec file.

#eg:

# >floor_44
# =44c0_s 44c1_s 44c2_s
# build line_128x4_class0 0-256
# build line_128x4_0sub0  0-4

die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]);

$goflag=0;
while($line=<F>){

    print "#### $line";
    if($line=~m/^GO/){
	$goflag=1;
	next;
    }

    if($goflag==0){
	if($line=~m/\S+/ && !($line=~m/^\#/) ){
	    my $command=$line;
	    print ">>> $command";
	    die "Couldn't shell command.\n\tcommand:$command\n" 
		if syst($command);
	}
	next;
    }

    # >floor_44
    # this sets the output bookset file name
    if($line=~m/^>(\S+)\s+(\S*)/){
	# set the output name
	$globalname=$1;
	
	$command="rm -f $globalname.vqh";
	die "Couldn't remove file.\n\tcommand:$command\n" 
	    if syst($command);

	next;
    }

    #=path1 path2 path3 
    #set the search path for input files; each build line will look
    #for input files in all of the directories in the search path and
    #append them for huffbuild input
    if($line=~m/^=(.*)/){
	# set the output name
	@paths=split(' ',$1);
	next;
    }

    # build book.vqd 0-3 [noguard]
    if($line=~m/^build (.*)/){
	# build a huffman book (no mapping) 
	my($datafile,$range,$guard)=split(' ',$1);
 
	$command="rm -f $datafile.tmp";
	print "\n\n>>> $command\n";
	die "Couldn't remove temp file.\n\tcommand:$command\n" 
	    if syst($command);

	# first find all the inputs we want; they'll need to be collected into a single input file
	foreach $dir (@paths){
	    if (-e "$dir/$datafile.vqd"){
		$command="cat $dir/$datafile.vqd >> $datafile.tmp";
		print ">>> $command\n";
		die "Couldn't append training data.\n\tcommand:$command\n" 
		    if syst($command);
	    }
	}
	
	my $command="huffbuild $datafile.tmp $range $guard";
	print ">>> $command\n";
	die "Couldn't build huffbook.\n\tcommand:$command\n" 
	    if syst($command);

	$command="cat $datafile.vqh >> $globalname.vqh";
	print ">>> $command\n";
	die "Couldn't append to output book.\n\tcommand:$command\n" 
	    if syst($command);

	$command="rm $datafile.vqh";
	print ">>> $command\n";
	die "Couldn't remove temporary output file.\n\tcommand:$command\n" 
	    if syst($command);

	$command="rm -f $datafile.tmp";
	print ">>> $command\n";
	die "Couldn't remove temporary output file.\n\tcommand:$command\n" 
	    if syst($command);
	next;
    }

}

$command="rm -f temp$$.vqd";
print ">>> $command\n";
die "Couldn't remove temp files.\n\tcommand:$command\n" 
    if syst($command);

sub syst{
    system(@_)/256;
}