merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / langwrap
blob97a50f1762ee219ae84542d7dd9886c949909e81
1 #!/usr/bin/perl -w
3 # langwrap - language wrapper for building resources
5 # $Id: langwrap,v 1.2 2008-08-18 13:10:41 vg Exp $
7 use Getopt::Std;
9 ###### globals ######
11 $is_debug = 0;
12 $nfield = 0;
13 @LoL = ();
14 @command = ();
16 ###### main ######
18 # Version
19 $idStr = ' $Revision: 1.2 $ ';
20 $idStr =~ /Revision:\s+(\S+)\s+\$/
21 ? ($langwrapRev = $1) : ($langwrapRev = "-");
23 print "langwrap -- Version: $langwrapRev\n";
25 # Options
26 &check_options();
28 # parse command file
29 &parse_commandfile($opt_c);
31 # create list with command lines
32 &create_commands();
34 # finally execute commands
35 foreach $cmd (@command) {
36 if ($is_debug) {
37 print $cmd . "\n";
38 } else {
39 system($cmd);
40 $res = $? >> 8;
41 if ($res) {
42 print "langwrap: command execution failed with exitcode $res.\n";
43 exit($res);
48 exit(0);
50 ###### routines ######
52 ### parse_commandfile()
53 sub parse_commandfile {
54 my($file) = shift;
55 my(@field);
57 open(COMMAND, "<$file") or die "canĀ“t open $file";
59 while (<COMMAND>) {
60 $line = $_;
61 chomp($line);
62 if ( ($line =~ //) || ($line =~ /^\r/) || ($line =~ /^#/) ) {
63 next;
66 @field = split " ", $line;
67 push @LoL, [@field];
68 if (!$nfield) {
69 $nfield = $#field + 1;
70 } else {
71 if ( $nfield != ($#field + 1) ) {
72 print "langwrap: error in <cmdfile>: every row must ";
73 print "have the same # of columns.\n";
74 exit(3);
79 close(COMMAND);
82 ### create_command()
83 sub create_commands() {
84 my($cmd, $cmdline, $arg_string, $ntempl);
86 $cmd = shift @ARGV;
87 $arg_string = join(" ", @ARGV);
88 # just count the number of templates
89 $ntempl = ($arg_string =~ s/@\d+@/$&/eg);
90 if ( $ntempl >= $nfield ) {
91 print "lnagwrap: # of templates > # of fields in <cmdfile>.\n";
92 exit(4);
95 # create command lines
96 for $i (0..$#LoL) {
97 $cmdline = $arg_string;
98 $cmdline =~ s/@(\d+)@/$LoL[$i][$1]/eg;
99 push @command, $cmd . " " . $cmdline;
103 ### check_options()
104 sub check_options {
106 if ( !getopts('c:') ) {
107 &usage();
110 if ( !$opt_c ) {
111 &usage();
114 if ( ! -r $opt_c ) {
115 print "langwrap: $opt_c is not a readable file.\n";
116 exit(2);
119 if ( $#ARGV < 1 ) {
120 print "langwrap: empty <template_string>.\n";
121 &usage();
125 ### usage()
126 sub usage {
127 print "Usage: langwrap -c cmdfile tool <template_string>\n";
128 print "<template_string> is of form: ...\@1\@ .... \@2\@...\n";
129 print "with \@<n>\@ template #n\n";
130 exit(1);