bump product version to 4.1.6.2
[LibreOffice.git] / solenv / bin / langwrap
blob09113e869da48efa665352030a178ad7cb3e10cc
1 #!/usr/bin/perl -w
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 # langwrap - language wrapper for building resources
22 use Getopt::Std;
24 ###### globals ######
26 $is_debug = 0;
27 $nfield = 0;
28 @LoL = ();
29 @command = ();
31 ###### main ######
33 # Version
34 print "langwrap -- Version: 1.2\n";
36 # Options
37 &check_options();
39 # parse command file
40 &parse_commandfile($opt_c);
42 # create list with command lines
43 &create_commands();
45 # finally execute commands
46 foreach $cmd (@command) {
47 if ($is_debug) {
48 print $cmd . "\n";
49 } else {
50 system($cmd);
51 $res = $? >> 8;
52 if ($res) {
53 print "langwrap: command execution failed with exitcode $res.\n";
54 exit($res);
59 exit(0);
61 ###### routines ######
63 ### parse_commandfile()
64 sub parse_commandfile {
65 my($file) = shift;
66 my(@field);
68 open(COMMAND, "<$file") or die "canĀ“t open $file";
70 while (<COMMAND>) {
71 $line = $_;
72 chomp($line);
73 if ( ($line =~ //) || ($line =~ /^\r/) || ($line =~ /^#/) ) {
74 next;
77 @field = split " ", $line;
78 push @LoL, [@field];
79 if (!$nfield) {
80 $nfield = $#field + 1;
81 } else {
82 if ( $nfield != ($#field + 1) ) {
83 print "langwrap: error in <cmdfile>: every row must ";
84 print "have the same # of columns.\n";
85 exit(3);
90 close(COMMAND);
93 ### create_command()
94 sub create_commands() {
95 my($cmd, $cmdline, $arg_string, $ntempl);
97 $cmd = shift @ARGV;
98 $arg_string = join(" ", @ARGV);
99 # just count the number of templates
100 $ntempl = ($arg_string =~ s/@\d+@/$&/eg);
101 if ( $ntempl >= $nfield ) {
102 print "lnagwrap: # of templates > # of fields in <cmdfile>.\n";
103 exit(4);
106 # create command lines
107 for $i (0..$#LoL) {
108 $cmdline = $arg_string;
109 $cmdline =~ s/@(\d+)@/$LoL[$i][$1]/eg;
110 push @command, $cmd . " " . $cmdline;
114 ### check_options()
115 sub check_options {
117 if ( !getopts('c:') ) {
118 &usage();
121 if ( !$opt_c ) {
122 &usage();
125 if ( ! -r $opt_c ) {
126 print "langwrap: $opt_c is not a readable file.\n";
127 exit(2);
130 if ( $#ARGV < 1 ) {
131 print "langwrap: empty <template_string>.\n";
132 &usage();
136 ### usage()
137 sub usage {
138 print "Usage: langwrap -c cmdfile tool <template_string>\n";
139 print "<template_string> is of form: ...\@1\@ .... \@2\@...\n";
140 print "with \@<n>\@ template #n\n";
141 exit(1);