<?xml version="1.0" standalone="yes"?>
<stylesheet version="1.0"
    	    xmlns="http://www.w3.org/1999/XSL/Transform"
    	    xmlns:y="http://www.icewm.org/2002/prefs">
<output method="text" indent="no" encoding="iso-8559-1"/>

<param name="source"/>
<param name="target"/>

<template match="/">
<choose><when test="$source">-
// DON'T EDIT THIS FILE
// Generated by prefs2cxx.xsl from <value-of select="$source"/>
<choose><when test="$target='wmaction.h'">

#ifndef __WMACTION_H
#define __WMACTION_H

#include "config.h"
#include "yaction.h"

class WMAction {
public:

<apply-templates mode="declaration" select=".//y:action-list/*"/>-

    static YAction::Id lookupAction(const char *name);

private:
    struct Symbol {
    	Symbol(YAction::Name name, YAction::Id action):
	name(name), action(action) {
	}

    	YAction::Name name;
	YAction::Id action;
    };
    
    typedef Symbol SymbolTable[];

    static const SymbolTable symtab;
};

#endif
</when><when test="$target='wmaction.cc'">

#include "wmaction.h"
#include &lt;string.h&gt;

<apply-templates mode="implementation" select=".//y:action-list/*"/>-

const WMAction::SymbolTable WMAction::symtab = {
<apply-templates mode="symboltable" select=".//y:action-list/*"/>-
};

YAction::Id WMAction::lookupAction(const char *name) {
    for (const Symbol *sym = symtab; 
    	 sym &lt; symtab + sizeof(symtab)/sizeof(*symtab); ++sym) {
    	if (!strcmp(name, sym->name)) return sym->action;
    }

    return 0;
}
</when><otherwise><message terminate="yes"><text>
You have to pass a valid value for the 'target' parameter. 
Valid targets are: 'wmaction.h', 'wmaction.cc'

Contact icewm-devel@lists.sourceforge.net for questions.
</text></message></otherwise></choose>
</when><otherwise><message terminate="yes"><text>
You have to pass the name of the source file with the 'source' parameter. 

Contact icewm-devel@lists.sourceforge.net for questions.
</text></message></otherwise></choose>
</template>

<!-- 
  create preprocessor statements 
  -->

<template match="y:if" mode="declaration">-
#if <value-of select="@test"/><text>
</text><apply-templates select="y:*" mode="declaration"/>-
#endif
</template>

<template match="y:if" mode="implementation">-
#if <value-of select="@test"/><text>
</text><apply-templates select="y:*" mode="implementation"/>-
#endif
</template>

<template match="y:if" mode="symboltable">-
#if <value-of select="@test"/><text>
</text><apply-templates select="y:*" mode="symboltable"/>-
#endif
</template>

<!--
  create actions 
  -->

<template match="y:action" mode="declaration">-
    static YAction::Id <value-of select="@name"/>;
</template>

<template match="y:action" mode="implementation">-
YAction::Id WMAction::<value-of select="@name"/>(new YAction());
</template>

<template match="y:action" mode="symboltable">-
    Symbol("<value-of select="@name"/>", <value-of select="@name"/>),
<apply-templates select="y:*" mode="symboltable"/>
</template>

<template match="y:alias" mode="symboltable">-
    Symbol("<value-of select="@name"/>", <value-of select="../@name"/>),
</template>

<!-- 
  planned as fallback template - but don't know how to pass the mode 
  -->

<!--
<template match="@*|node()" mode="declaration">
 <apply-templates select=".">
  <with-param name="mode">declaration</with-param>
 </apply-templates>
</template>
-->

</stylesheet>
