#!/usr/sbin/install-menu
#   -*- mode: shell-script; -*-
#
# Written by Joey Hess.
#
# This generates a pdmenurc file that can be preprocessed by cpp to enable
# different types of displays. For example, you can -Dx11 -Xtext to display
# only the text and x11 entries, and not the vc ones.
#
# More info: /usr/doc/menu/README, /usr/doc/pdmenu/README.Debian

# The verson of the menu package that can process this.
compat="menu-1"


#for local preferences, so that system managers can override title(),
#icon(), and maybe later more. Note that to use that in this file,
#one has to use title(), and _not_ $title etc.

!include menu.h

# menu-entry convert the packages entry co a unique name
function menu-entry($entry)= replacewith($entry,"/","_")

# return the scheme function executing directly the executable
function call($executable)="(lambda () (execute \"" $executable "\"))" 

# return the scheme function executing the executable from an xterm
function term-call($executable)="(lambda () (execute \""\
                                "xterm -T " title() " -e " \
                               esc($executable, "\"" ) "\"))"

# return the cheme function calling a new window manager
function call-wm($wman)="(lambda () (restart \"" $wman "\"))"

# return the option to specify an icon
function icon-option($icon-file)="#:left-pixmap \"" $icon-file "\"\n") 

# we need different menu entries for the "/Debian" entry

function normal-start-menu()="(define " menu-entry($section) "\n"\
                             "   (make-menu \"" title() "\"\n"\
                             "              (menu-title)\n"\
                             "              (menu-separator)\n"

function debian-start-menu()="(define " menu-entry($section) "\n"\
                             "        (apply make-menu (list-append\n"\
                             "        (list \"" title() "\"\n"\
                             "              (menu-title)\n"\
                             "              (menu-separator))\n"\
                             "              initial-menus\n"\
			     "              (list \n"

function normal-end-menu()="))\n"

function debian-end-menu()="              )\n"\
                           "              final-menus)\n"\
                           "))\n"

#every "supported" definition (and the submenutitle) start with this
#bit of code. So it's easier to define this macro:
function all() = "              (menu-item \"" title() "\"\n"\
    ifnempty(icon(),"                         " icon-option(icon()))\
    "                         #:action " 


# Filename of the pdmenurc file we will generate.
genmenu="scwm_menus"

# Where the system wide generated file is placed.
rootprefix="/etc/X11/scwm/"

# Where the user wide generated file is placed
userprefix=".scwm"

# Title of the top level menu that is made.
mainmenutitle="Debian-Menus"


# Some text to go at the top of the autogenerated file.
preoutput=";;; Automatically generated scwm file.\n;;; Do not edit\n\n"

# In what order we output the menus.
treewalk="c(m)"

# How to start a new menu in the rc file.
startmenu=ifeqelse($section,"/Debian",debian-start-menu(),normal-start-menu())

# how to end a new menu
endmenu=ifeqelse($section,"/Debian",debian-end-menu(),normal-end-menu())

# how to add a submenu to a menu.
# Notice that thanks to cpp and some #defines, the submenu is only added if 
# the submenu actually contains menu entries.

submenutitle=all() menu-entry($section) ")\n"

# The supported display types, in order of preference.
supported
  x11= all() call($command)      ")\n"
  wm = all() call-wm($command)   ")\n"
  vc=  all() call($command)      ")\n"
  text=all() term-call($command) ")\n"
endsupported
