#!/usr/sbin/install-menu
#
# Generates AfterStep menus for all registered applications.
#

compat="menu-1"

!include menu.h

compat="menu-2"
outputencoding="ISO-8859-1";


# If file $idir/$file exists, then output "MiniPixmap" line...
function get_icon($idir, $ifile)=
        ifnempty(
          $ifile,
          ifelse(
             $idir,
             ifempty(
               parent($ifile),
               iffile(
                 $idir "/" $ifile,
                 "MiniPixmap \"" $idir "/" $ifile "\"\n"
                 )
             ),
             iffile(
               $ifile,
               "MiniPixmap \""  $ifile "\"\n"
             )
          )
        );

function my_ifelse($x, $y)=
        ifelse($x, $x, $y);


function add_pixmap_line()=
          my_ifelse(
            get_icon("", icon()),
            my_ifelse(
              get_icon("/usr/X11R6/include/X11/pixmaps", icon()),
                my_ifelse(
                  get_icon("/usr/X11R6/include/X11/bitmaps", icon()),
                  "MiniPixmap \"mini-app.xpm\"\n"
                )
             )
          );

#
# Main functions
#
function mod($var,$com)=$var " \""
          ifelse($hotkey, escfirst(title(), $hotkey, "&"), title())
          "\" exec " $com " &\n"
          add_pixmap_line();


function restart($var,$com)=$var " \""
          ifelse($hotkey, escfirst(title(), $hotkey, "&"), title())
          "\" " $com "\n"
          add_pixmap_line();

function ex($com)=mod("Exec",$com);

# We need menu >= 2.1.8-1 for $basesection
genmenu=ifelse( $command, 
                $basesection "/" tolower(replacewith(cppesc($title), "$", "-")) "_" entryindex(),
                "/"
               );


rootprefix="/var/lib/afterstep/menu";
onlyrunasroot=true;
treewalk=(M);
rootsection="/Debian";

preoutput="";

# Clean-up files we may have generated in an earlier run first.
prerun="find " prefix() " -type f -exec rm {} \\; ; find " prefix() " -type d -depth -print0 | xargs -0r rmdir --ignore-fail-on-non-empty";

# And remove any empty directories afterwards
postrun="find " prefix() " -type d -depth -print0 | xargs -0r rmdir --ignore-fail-on-non-empty";

supported;
  asmodule=     mod("Module", $command);
  fvwmmodule=   mod("Exec",   $command);
  x11fvwm=      ex($command);
  wm=           restart("Restart",$command);
  x11=          ex($command);
  text=         ex(term());
endsupported;

mainmenutitle="";
submenutitle= "";

startmenu="";
endmenu="";
