summaryrefslogtreecommitdiff
path: root/development/sort_desktop_files.pl
authormickeyl <mickeyl>2003-10-29 22:07:36 (UTC)
committer mickeyl <mickeyl>2003-10-29 22:07:36 (UTC)
commitd53637f46cf217fc760d7aac58b4596843a73803 (patch) (side-by-side diff)
tree25289be556fa1ce0ba8539b7f42aeaa037bdf7fd /development/sort_desktop_files.pl
parent1af1f1d9f398d38a2bc666cd2edff5725da7a770 (diff)
downloadopie-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-xdevelopment/sort_desktop_files.pl76
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 @@
+#!/usr/bin/perl -w
+# Copyright (c) 2002,2003 by
+# Bruno Rodrigues <bruno.rodrigues@litux.org>
+# under the GNU GPL license 2.0 or newer
+# sort_desktop_files.pl,v 1.1.2.1 2003/07/01 02:22:56 davipt Exp
+# -----------------------------------------------------
+# This script reads a .desktop file and sorts its values
+# in the following format:
+# [Desktop Entry]
+# field1=val1 \
+# field2=val2 > Sorted by field name
+# ... /
+# Name=name
+# Comment=comment
+# Name[lang1]=... \
+# Comment[lang1]=... > Sorted by language name
+# Name[lang2]=... /
+
+use strict;
+use vars qw{$line %data %tr};
+
+%data = (); %tr = ();
+
+# Read first line and make sure it's "[Desktop Entry]"
+$line = <>; chop($line);
+die "E: File does not start with [Desktop Entry] ($line)\n" unless $line =~ /^\[Desktop Entry\]$/;
+
+my $end=0;
+while($line = <>) {
+ # Ignore fields without values
+ next if $line =~ /^\s*([^\s]+)\s*=\s*$/;
+
+ # Ignore empty line in the end
+ if($line =~ /^\s*$/) {
+ if($end==0) { $end=1; next;
+ } else { die "E: Empty line in middle of file\n";
+ }
+ }
+
+ # Die if line is not "field = value"
+ die "E: Error in line - not field=value ($line)\n" unless $line =~ /^\s*([^\s]+)\s*=\s*(.+?)\s*$/;
+
+ my ($key, $data) = ($1, $2);
+
+ # Grab Name[lang] and Comment[lang]
+ if($key =~ /^(Name|Comment)\[(.+)\]$/i) {
+ $tr{$2}{$1} = $data;
+ }
+ # Grab Name and Comment
+ elsif($key =~ /^(Name|Comment)$/i) {
+ $tr{"0"}{$1} = $data;
+ }
+ # Die if there is other field[x]
+ elsif($key =~ /\[|\]/) {
+ die "E: Error in line - unknown field with [] ($line)\n";
+ }
+ # Grab regular fields
+ else {
+ $data{$1} = $2;
+ }
+}
+
+
+print "[Desktop Entry]\n";
+foreach my $key (sort keys %data) {
+ print "$key=".$data{$key}."\n";
+}
+foreach my $key (sort keys %tr) {
+ my %tr2 = %{$tr{$key}};
+ foreach my $k2 (reverse sort keys %tr2) {
+ print $k2;
+ print "[$key]" unless $key eq "0";
+ print "=". $tr2{$k2}. "\n";
+ }
+}
+