2 eval 'exec perl -wS $0 ${1+"$@"}'
6 # This file is part of the LibreOffice project.
8 # This Source Code Form is subject to the terms of the Mozilla Public
9 # License, v. 2.0. If a copy of the MPL was not distributed with this
10 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 # This file incorporates work covered by the following license notice:
14 # Licensed to the Apache Software Foundation (ASF) under one or more
15 # contributor license agreements. See the NOTICE file distributed
16 # with this work for additional information regarding copyright
17 # ownership. The ASF licenses this file to you under the Apache
18 # License, Version 2.0 (the "License"); you may not use this file
19 # except in compliance with the License. You may obtain a copy of
20 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 # This tool is used to re-write and substitute variables
25 # into Unix .desktop, .keys files etc.
31 $productname = "LibreOffice";
32 $productfilename = "libreoffice";
37 while ($_ = $ARGV[0], /^-/) {
41 $productname = $ARGV[0];
45 $productfilename = $ARGV[0];
52 if (/^--iconprefix/) {
53 $iconprefix = $ARGV[0];
60 # Whether we can handle URLs on the command-line
67 while ($arg = shift) {
68 unless (open INFILE
,$arg) {
69 print STDOUT
"Can't open input file $arg: $!\n";
73 $srcfile = substr($arg, rindex($arg, "/") + 1);
75 unless (open OUTFILE
,"> $destdir/$prefix$srcfile") {
76 print STDOUT
"Can't open output file $destdir/$prefix$srcfile: $!\n";
81 # remove possible Windows line-ends
84 # patch all icons in ICON line with $prefix
85 if (! /Icon=document-new/ ) { # except for Icon=document-new which
86 # is a stock icon, not one of ours
87 s/Icon=/Icon=$iconprefix/;
90 # patch all occurrences of openoffice in EXEC line with
93 s/openoffice/$productfilename/;
96 # if $productfilename != "openoffice, add it to the list
98 if ( /user_level=$/ ) {
99 $_ = $_ . $productfilename;
100 } elsif ( /user_level/ ) {
101 s/$productfilename,//;
102 s/user_level=/user_level=$productfilename,/
105 # append special category if specified
106 if ( /Categories/ ) {
107 if ( length($category) > 0 ) {
112 # replace %PRODUCTNAME placeholders
113 s/%PRODUCTNAME/$productname/g;
121 print OUTFILE
"$_\n";