<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

# Data of importance:
#   $attrs{$program_name}{$attribute} = $value

$argc  = $#ARGV + 1;
$quiet = 0;
if ($argc eq 1)
{
    if ($ARGV[0] eq "-q")
    {
	$quiet = 1;
    }
}

$wmconfig_dir = "/etc/X11/wmconfig";
$dt_dir = `gnome-config gnome --prefix`;
chop($dt_dir);

if ($dt_dir eq "") 
{
    print "Exiting - GNOME not found...\n";
}

$dt_dir = $dt_dir . "/share/apps";
if ($quiet ne 1)
{
    print "Installing desktop entries into directory $dt_dir\n";
}

opendir(DH, $wmconfig_dir);
@wments = readdir(DH);
closedir(DH);

# Read in /etc/X11/wmconfig entries into the %attrs hash
foreach $anent(@wments)
{
    if ($quiet ne 1)
    {
	print "Scanning wmconfig entry $anent\n";
    }
    &amp;process_wment($anent);
}

# Write out the information in %attrs hash to the .desktop entries
foreach $anent(keys %attrs)
{
    if ($quiet ne 1) 
    {
	print "Writing desktop entry $anent\n";
    }
    &amp;produce_dtent($anent);
}

sub process_wment
{
    my($fn) = @_;
    open(FH, $wmconfig_dir."/".$fn) || return;
    
    while(chomp($aline = &lt;FH&gt;))
    {
	if($aline =~ /^([^\s]+)\s+([^\s]+)\s+"?([^"]*)"?$/)
	  {
	    $ent = lc $1;
	    $attr = lc $2;
	    $val = $3;
	    if($attr eq "exec") { $val =~ s/\s*&amp;$//; }
	    $attrs{$ent}{lc $attr} = $val;
	  }
	else
	  {
	    print "Unknown line for $fn: $aline\n";
	  }
      }
    close(FH);
  }

sub produce_dtent
  {
      my($ent) = @_;
      my($thedir) = $dt_dir."/".$attrs{$ent}{"group"};
      my($thepid) = fork();
      
      if($thepid)
      {
	  waitpid($thepid,0);
      }
      else
      {
	  exec("/bin/mkdir","-p",$thedir);
      }

      open(FH, "&gt;$thedir/$ent.desktop") || return;
      printf FH "[Desktop Entry]\nName=%s\nDescription=%s\nExec=%s\n",
      $attrs{$ent}{"name"}, $attrs{$ent}{"description"},
      $attrs{$ent}{"exec"};
      if($attrs{$ent}{"icon"})
      {
	  printf FH "Icon=/usr/share/icons/%s\n",
	  $attrs{$ent}{"icon"};
      }
      elsif($attrs{$ent}{"mini-icon"})
      {
	  printf FH "Icon=/usr/share/icons/%s\n",
	  $attrs{$ent}{"mini-icon"};
      }
  }
</pre></body></html>