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, mimelnk, .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
68 unless (open INFILE
,$ARGV) {
69 print STDOUT
"Can't open input file $ARGV: $!\n";
73 $srcfile = substr($ARGV, rindex($ARGV, "/") + 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 occurrences of openoffice in ICON line with
86 s/Icon=/Icon=$iconprefix/;
88 # patch all occurrences of openoffice in icon_filename
90 s/icon_filename=/icon_filename=$iconprefix/;
92 # patch all occurrences of openoffice in EXEC line with
95 s/openoffice/$productfilename/;
98 # if $productfilename != "openoffice, add it to the list
100 if ( /user_level=$/ ) {
101 $_ = $_ . $productfilename;
102 } elsif ( /user_level/ ) {
103 s/$productfilename,//;
104 s/user_level=/user_level=$productfilename,/
107 # append special category if specified
108 if ( /Categories/ ) {
109 if ( length($category) > 0 ) {
114 # replace %PRODUCTNAME placeholders
115 s/%PRODUCTNAME/$productname/g;
123 print OUTFILE
"$_\n";