author | mickeyl <mickeyl> | 2003-10-29 22:07:36 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-29 22:07:36 (UTC) |
commit | d53637f46cf217fc760d7aac58b4596843a73803 (patch) (unidiff) | |
tree | 25289be556fa1ce0ba8539b7f42aeaa037bdf7fd /development/sort_desktop_files.pl | |
parent | 1af1f1d9f398d38a2bc666cd2edff5725da7a770 (diff) | |
download | opie-d53637f46cf217fc760d7aac58b4596843a73803.zip opie-d53637f46cf217fc760d7aac58b4596843a73803.tar.gz opie-d53637f46cf217fc760d7aac58b4596843a73803.tar.bz2 |
merge development/* and help/*
Diffstat (limited to 'development/sort_desktop_files.pl') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | development/sort_desktop_files.pl | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/development/sort_desktop_files.pl b/development/sort_desktop_files.pl new file mode 100755 index 0000000..e553b9e --- a/dev/null +++ b/development/sort_desktop_files.pl | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # Copyright (c) 2002,2003 by | ||
3 | # Bruno Rodrigues <bruno.rodrigues@litux.org> | ||
4 | # under the GNU GPL license 2.0 or newer | ||
5 | # sort_desktop_files.pl,v 1.1.2.1 2003/07/01 02:22:56 davipt Exp | ||
6 | # ----------------------------------------------------- | ||
7 | # This script reads a .desktop file and sorts its values | ||
8 | # in the following format: | ||
9 | # [Desktop Entry] | ||
10 | # field1=val1 \ | ||
11 | # field2=val2 > Sorted by field name | ||
12 | # ... / | ||
13 | # Name=name | ||
14 | # Comment=comment | ||
15 | # Name[lang1]=... \ | ||
16 | # Comment[lang1]=... > Sorted by language name | ||
17 | # Name[lang2]=... / | ||
18 | |||
19 | use strict; | ||
20 | use vars qw{$line %data %tr}; | ||
21 | |||
22 | %data = (); %tr = (); | ||
23 | |||
24 | # Read first line and make sure it's "[Desktop Entry]" | ||
25 | $line = <>; chop($line); | ||
26 | die "E: File does not start with [Desktop Entry] ($line)\n" unless $line =~ /^\[Desktop Entry\]$/; | ||
27 | |||
28 | my $end=0; | ||
29 | while($line = <>) { | ||
30 | # Ignore fields without values | ||
31 | next if $line =~ /^\s*([^\s]+)\s*=\s*$/; | ||
32 | |||
33 | # Ignore empty line in the end | ||
34 | if($line =~ /^\s*$/) { | ||
35 | if($end==0) { $end=1; next; | ||
36 | } else { die "E: Empty line in middle of file\n"; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | # Die if line is not "field = value" | ||
41 | die "E: Error in line - not field=value ($line)\n" unless $line =~ /^\s*([^\s]+)\s*=\s*(.+?)\s*$/; | ||
42 | |||
43 | my ($key, $data) = ($1, $2); | ||
44 | |||
45 | # Grab Name[lang] and Comment[lang] | ||
46 | if($key =~ /^(Name|Comment)\[(.+)\]$/i) { | ||
47 | $tr{$2}{$1} = $data; | ||
48 | } | ||
49 | # Grab Name and Comment | ||
50 | elsif($key =~ /^(Name|Comment)$/i) { | ||
51 | $tr{"0"}{$1} = $data; | ||
52 | } | ||
53 | # Die if there is other field[x] | ||
54 | elsif($key =~ /\[|\]/) { | ||
55 | die "E: Error in line - unknown field with [] ($line)\n"; | ||
56 | } | ||
57 | # Grab regular fields | ||
58 | else { | ||
59 | $data{$1} = $2; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | |||
64 | print "[Desktop Entry]\n"; | ||
65 | foreach my $key (sort keys %data) { | ||
66 | print "$key=".$data{$key}."\n"; | ||
67 | } | ||
68 | foreach my $key (sort keys %tr) { | ||
69 | my %tr2 = %{$tr{$key}}; | ||
70 | foreach my $k2 (reverse sort keys %tr2) { | ||
71 | print $k2; | ||
72 | print "[$key]" unless $key eq "0"; | ||
73 | print "=". $tr2{$k2}. "\n"; | ||
74 | } | ||
75 | } | ||
76 | |||