aboutsummaryrefslogtreecommitdiffstats
path: root/translate_menu
blob: 2fc3f88bf8153d476717ae0c35865f3d4de66f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
#---------------------------------------------------------------
# Project         : Mandrake Linux
# Module          : spec-helper
# File            : translate_menu.pl
# Version         : $Id$
# Author          : Frederic Lepied
# Created On      : Mon Jan 26 13:37:49 2004
# Purpose         : change the menu sections
#---------------------------------------------------------------

use strict;
use warnings;

my $menudir = `rpm --eval %_menudir`;
chomp($menudir);

$ENV{RPM_BUILD_ROOT} or exit(0);
! -d "$ENV{RPM_BUILD_ROOT}/$menudir/" || exit(0);

my @nested = (["Configuration", "System/Configuration"],

	   ["Applications/Monitoring", "System/Monitoring"],
	   ["Applications/Publishing", "Office/Publishing"],
	   ["Applications/File tools", "System/File Tools"],
	   ["Applications/Text tools", "System/Text Tools"],
	   ["Applications/Archiving", "System/Archiving"],
	   ["Applications", "More Applications"],

	   ["Terminals", "System/Terminals"],
	   
	   ["Documentation", "More Applications/Documentation"],
	   
           ["Office/PDA", "Office/Communications/PDA"],

	   ["Networking/IRC", "Internet/Chat"],
	   ["Networking/WWW", "Internet/Web Browsers"],
	   ["^Networking", "Internet"],
	   
	   ["Amusement", "More Applications/Games"],
	   ["Session/Windowmanagers", "System/Session/Windowmanagers"],
	   );

sub translate {
    my ($str) = @_;

    foreach my $t (@nested) {
	if ($str =~ /(.*)$t->[0](.*)/ && $str !~ /$t->[1]/) {
	    print "$str => $1$t->[1]$2\n";
	    return "$1$t->[1]$2";
	}
    }
    return $str;
}

# process each file passed on cli:

foreach my $file (glob("$ENV{RPM_BUILD_ROOT}/$menudir/*")) {
    open(my $FILE, "<$file") or die $!;
    my @lines = <$FILE>;
    close($FILE);
    open($FILE, ">$file") or die $!;
    foreach my $l (@lines) {
	chomp($l);
	if ($l =~ /(.*section=)"([^"]+)"(\s*.*)/ || $l =~ /(.*section=)([^"].+?)((\s|\\)+.*)/) {
	    my ($beg, $section, $end) = ($1, $2, $3);
            $section = translate($section);
            $l = qq($beg"$section"$end);
	}
	print $FILE "$l\n";
    }
    close($FILE);
}

# translate_menu.pl ends here