#!/usr/bin/perl -w # # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # This file incorporates work covered by the following license notice: # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed # with this work for additional information regarding copyright # ownership. The ASF licenses this file to you under the Apache # License, Version 2.0 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # # langwrap - language wrapper for building resources # use Getopt::Std; ###### globals ###### $is_debug = 0; $nfield = 0; @LoL = (); @command = (); ###### main ###### # Version print "langwrap -- Version: 1.2\n"; # Options &check_options(); # parse command file &parse_commandfile($opt_c); # create list with command lines &create_commands(); # finally execute commands foreach $cmd (@command) { if ($is_debug) { print $cmd . "\n"; } else { system($cmd); $res = $? >> 8; if ($res) { print "langwrap: command execution failed with exitcode $res.\n"; exit($res); } } } exit(0); ###### routines ###### ### parse_commandfile() sub parse_commandfile { my($file) = shift; my(@field); open(COMMAND, "<$file") or die "canīt open $file"; while () { $line = $_; chomp($line); if ( ($line =~ //) || ($line =~ /^\r/) || ($line =~ /^#/) ) { next; } @field = split " ", $line; push @LoL, [@field]; if (!$nfield) { $nfield = $#field + 1; } else { if ( $nfield != ($#field + 1) ) { print "langwrap: error in : every row must "; print "have the same # of columns.\n"; exit(3); } } } close(COMMAND); } ### create_command() sub create_commands() { my($cmd, $cmdline, $arg_string, $ntempl); $cmd = shift @ARGV; $arg_string = join(" ", @ARGV); # just count the number of templates $ntempl = ($arg_string =~ s/@\d+@/$&/eg); if ( $ntempl >= $nfield ) { print "lnagwrap: # of templates > # of fields in .\n"; exit(4); } # create command lines for $i (0..$#LoL) { $cmdline = $arg_string; $cmdline =~ s/@(\d+)@/$LoL[$i][$1]/eg; push @command, $cmd . " " . $cmdline; } } ### check_options() sub check_options { if ( !getopts('c:') ) { &usage(); } if ( !$opt_c ) { &usage(); } if ( ! -r $opt_c ) { print "langwrap: $opt_c is not a readable file.\n"; exit(2); } if ( $#ARGV < 1 ) { print "langwrap: empty .\n"; &usage(); } } ### usage() sub usage { print "Usage: langwrap -c cmdfile tool \n"; print " is of form: ...\@1\@ .... \@2\@...\n"; print "with \@\@ template #n\n"; exit(1); }