Files
loongoffice/solenv/bin/image-sort.pl
Michael Meeks 2b4fd2c89a re-base on ALv2 code. Includes:
Patches contributed by Pedro Giffuni:
    Avoid some uses of non portable #!/bin/bash in shell scripts.
    http://svn.apache.org/viewvc?view=revision&revision=1235297
    Reduce the dependencies on non standard GNU copy.
    http://svn.apache.org/viewvc?view=revision&revision=1238684
    Correct /usr/bin/env path.
    http://svn.apache.org/viewvc?view=revision&revision=1235619

    Complex Toolbar Controls Extension from the SDK
    Patches contributed by Ariel Constenla-Haile
    http://svn.apache.org/viewvc?view=revision&revision=1190390
    i118615 - make epm more verbose
    http://svn.apache.org/viewvc?view=revision&revision=1204288

    Patches contributed by Mathias Bauer (and others)
    gnumake4 work variously
    http://svn.apache.org/viewvc?view=revision&revision=1394707
    http://svn.apache.org/viewvc?view=revision&revision=1394326

    Patches contributed by Juergen Schmidt:
    jsc341: i117327: take care if no dependency node in current
    description exists, create one
    http://svn.apache.org/viewvc?view=revision&revision=1172101
    jsc341: i117327: add extra extension dependency check
    http://svn.apache.org/viewvc?view=revision&revision=1172098
    make initial branding changes
    http://svn.apache.org/viewvc?view=revision&revision=1231878

    Patches contributed by Ingo Schmidt
    native373: #i117733# no linux jre installation on 64 bit systems
    http://svn.apache.org/viewvc?view=revision&revision=1167536
    native373: ##164464# improve debian support
    http://svn.apache.org/viewvc?view=revision&revision=1167537

    Patch contribtued by Armin Le-Grand:
    Changed various aspects concerning usages of old vendor names
    http://svn.apache.org/viewvc?view=revision&revision=1293313

fix for neon webdav, remove coinmp bits, improve odk script,
cleanup & remove OS/2 conditionals, system ucpp fixes,
remove OS/2 conditionals, restore our license filenames.
2012-11-12 11:46:43 +00:00

180 lines
4.8 KiB
Perl
Executable File

#!/usr/bin/perl -w
# -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil -*-
#
# 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 .
#
my @global_list = ();
my %global_hash = ();
my $base_path;
sub read_icons($)
{
my $fname = shift;
my $fileh;
my @images;
if (! -e "$base_path/$fname") {
print "Skipping non-existent $base_path/$fname\n";
return @images;
}
open ($fileh, "$base_path/$fname") || die "Can't open $base_path/$fname: $!";
while (<$fileh>) {
m/xlink:href=\"\.uno:(\S+)\"\s+/ || next;
push @images, lc($1);
}
close ($fileh);
return @images;
}
# filter out already seen icons & do prefixing
sub read_new_icons($$)
{
my $fname = shift;
my $prefix = shift;
my @images = read_icons ($fname);
my @new_icons;
my %new_icons;
for my $icon (@images) {
my $iname = "cmd/" . $prefix . $icon . ".png";
if (!defined $global_hash{$iname} &&
!defined $new_icons{$iname}) {
push @new_icons, $iname;
$new_icons{$iname} = 1;
}
}
return @new_icons;
}
sub process_group($@)
{
my $prefix = shift;
my @uiconfigs = @_;
my %group;
my $cur_max = 1.0;
# a very noddy sorting algorithm
for my $uiconfig (@uiconfigs) {
my @images = read_new_icons ($uiconfig, $prefix);
my $prev = '';
for my $icon (@images) {
if (!defined $group{$icon}) {
if (!defined $group{$prev}) {
$group{$icon} = $cur_max;
$cur_max += 1.0;
} else {
$group{$icon} = $group{$prev} + (1.0 - 0.5 / $cur_max);
}
} # else a duplicate
}
}
for my $icon (sort { $group{$a} <=> $group{$b} } keys %group) {
push @global_list, $icon;
$global_hash{$icon} = 1;
}
}
sub process_file($$)
{
my @images = read_new_icons (shift, shift);
for my $icon (@images) {
push @global_list, $icon;
$global_hash{$icon} = 1;
}
}
sub chew_controlfile($)
{
my $fname = shift;
my $fileh;
my @list;
open ($fileh, $fname) || die "Can't open $fname: $!";
while (<$fileh>) {
/^\#/ && next;
s/[\r\n]*$//;
/^\s*$/ && next;
my $line = $_;
if ($line =~ s/^-- (\S+)\s*//) {
# control code
my $code = $1;
my $small = (lc ($line) eq 'small');
if (lc($code) eq 'group') {
if (!$small) {
process_group ("lc_", @list);
}
process_group ("sc_", @list);
} elsif (lc ($code) eq 'ordered') {
if (!$small) {
for my $file (@list) {
process_file ($file, "lc_");
}
}
for my $file (@list) {
process_file ($file, "sc_");
}
} elsif (lc ($code) eq 'literal') {
for my $file (@list) {
if (!defined $global_hash{$file}) {
push @global_list, $file;
$global_hash{$file} = 1;
}
}
} else {
die ("Unknown code '$code'");
}
@list = ();
} else {
push @list, $line;
}
}
close ($fileh);
}
if (!@ARGV) {
print "image-sort <image-sort.lst> /path/to/OOOo/source/root\n";
exit 1;
}
# where the control file lives
my $control = shift @ARGV;
# where the uiconfigs live
$base_path = shift @ARGV;
# output
if (@ARGV) {
my $outf = shift @ARGV;
open ($output, ">$outf") || die "Can't open $outf: $!";
$stdout_out = 0;
} else {
$output = STDOUT;
$stdout_out = 1;
}
chew_controlfile ($control);
for my $icon (@global_list) {
print $output $icon . "\n" if (!($icon =~ /^sc_/));
}
for my $icon (@global_list) {
print $output $icon . "\n" if ($icon =~ /^sc_/);
}
close $output if (!$stdout_out);
# dnl vim:set shiftwidth=4 softtabstop=4 expandtab: