summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@beryl-project.org>2007-04-17 16:45:11 +0200
committerDennis Kasprzyk <onestone@beryl-project.org>2007-04-17 16:45:11 +0200
commit5c5b8a8c625126ab445d3bc82260569953b80436 (patch)
tree7546ad4f0c470e6543f852a7802df30c333df97f /src
parent0320d3fb385f3350029ac7463c2444234c960e92 (diff)
downloadbcop-5c5b8a8c625126ab445d3bc82260569953b80436.tar.gz
bcop-5c5b8a8c625126ab445d3bc82260569953b80436.tar.bz2
New XSLT bcop version that uses the Compiz metadata xml format
(you can convert plugin.options files to plugin.xml files with bcopconvert.xslt)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am12
-rw-r--r--src/bcop.h224
-rwxr-xr-xsrc/bcop.in66
-rw-r--r--src/bcop.xslt1681
-rw-r--r--src/code_generator.c1380
-rw-r--r--src/schema_generator.c450
-rw-r--r--src/xml_parser.c1051
7 files changed, 1754 insertions, 3110 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3f6b028..d8dfa19 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,9 @@
-bcop_LDADD = @LIBXML2_LIBS@ @X11_LIBS@
-bcop_SOURCES = xml_parser.c code_generator.c schema_generator.c
-bcop_program = bcop
+xmldir = $(xsltdir)
+xml_files = bcop.xslt
+xml_DATA = $(xml_files)
-INCLUDES = @LIBXML2_CFLAGS@ @X11_CFLAGS@
+bin_SCRIPTS = bcop
-bin_PROGRAMS = $(bcop_program)
+DISTCLEANFILES=$(bin_SCRIPTS)
+
+EXTRA_DIST=$(bin_SCRIPTS) $(xml_files)
diff --git a/src/bcop.h b/src/bcop.h
deleted file mode 100644
index 586f435..0000000
--- a/src/bcop.h
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- *
- * Beryl/Compiz options parser
- *
- * Copyright : (C) 2007 by Dennis Kasprzyk
- * E-mail : onestone@beryl-project.org
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _BCOP_H
-#define _BCOP_H
-
-typedef enum {
- CompBindingTypeNone = 0,
- CompBindingTypeKey = 1 << 0,
- CompBindingTypeButton = 1 << 1,
- CompBindingTypeEdgeButton = 1 << 2
-} CompBindingType;
-
-#define N_BINDING_TYPES 3
-
-typedef enum {
- CompActionStateInitKey = 1 << 0,
- CompActionStateTermKey = 1 << 1,
- CompActionStateInitButton = 1 << 2,
- CompActionStateTermButton = 1 << 3,
- CompActionStateInitBell = 1 << 4,
- CompActionStateInitEdge = 1 << 5,
- CompActionStateTermEdge = 1 << 6,
- CompActionStateInitEdgeDnd = 1 << 7,
- CompActionStateTermEdgeDnd = 1 << 8,
- CompActionStateCommit = 1 << 9,
- CompActionStateCancel = 1 << 10,
- CompActionStateModifier = 1 << 11, // for things like wobbly's modifier key
-} CompActionState;
-
-#define N_ACTION_STATES 12
-
-typedef enum {
- OptionTypeInt,
- OptionTypeBool,
- OptionTypeFloat,
- OptionTypeString,
- OptionTypeStringList,
- OptionTypeEnum,
- OptionTypeSelection,
- OptionTypeColor,
- OptionTypeAction,
- OptionTypeMatch,
- OptionTypeError
-} OptionType;
-
-typedef enum {
- CodeCompiz,
- SchemaBegin, //simply ensures everything before it
- //is a code-type and everything after
- //is a schema-type
- SchemaGConf,
- GenNone
-} GenType;
-
-#define SCREEN_EDGE_LEFT 0
-#define SCREEN_EDGE_RIGHT 1
-#define SCREEN_EDGE_TOP 2
-#define SCREEN_EDGE_BOTTOM 3
-#define SCREEN_EDGE_TOPLEFT 4
-#define SCREEN_EDGE_TOPRIGHT 5
-#define SCREEN_EDGE_BOTTOMLEFT 6
-#define SCREEN_EDGE_BOTTOMRIGHT 7
-#define SCREEN_EDGE_NUM 8
-
-#undef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#undef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-typedef struct _subGroup subGroup;
-typedef struct _Group Group;
-typedef struct _Option Option;
-typedef struct _OptionValuesList OptionValuesList;
-
-
-struct _OptionValuesList
-{
- OptionValuesList* next;
- char *name;
- char *uName;
- char *fUName;
- char *value;
- int raw;
- int def;
-};
-
-typedef struct _IntOptionInfo
-{
- int min;
- int max;
- int def;
-} IntOptionInfo;
-
-typedef struct _BoolOptionInfo
-{
- int def;
-} BoolOptionInfo;
-
-typedef struct _FloatOptionInfo
-{
- float min;
- float max;
- float precision;
- float def;
-} FloatOptionInfo;
-
-typedef struct _StringOptionInfo
-{
- char *def;
-} StringOptionInfo;
-
-typedef struct _MatchOptionInfo
-{
- char *def;
-} MatchOptionInfo;
-
-typedef struct _StringListOptionInfo
-{
- OptionValuesList* begin;
- OptionValuesList* end;
-} StringListOptionInfo;
-
-typedef struct _ColorOptionInfo
-{
- int red;
- int green;
- int blue;
- int alpha;
-} ColorOptionInfo;
-
-typedef struct _BindingOptionInfo
-{
- int type;
- int state;
- char *key;
- char *mouse;
- int edge;
- int bell;
- int skey;
- int smouse;
- int sedge;
- int sbell;
-} BindingOptionInfo;
-
-
-typedef union _OptionInfo
-{
- IntOptionInfo asInt;
- FloatOptionInfo asFloat;
- BoolOptionInfo asBool;
- StringOptionInfo asString;
- BindingOptionInfo asBind;
- StringListOptionInfo asSList;
- ColorOptionInfo asColor;
- StringOptionInfo asMatch;
-} OptionInfo;
-
-struct _Option {
- Option *next;
- char *name;
- char *uName;
- char *fUName;
- char *shortDesc;
- char *longDesc;
- char *hints;
- int screen;
- int advanced;
- OptionType type;
-
- OptionInfo data;
-
- char *group;
- char *subGroup;
-
- char *temp;
-};
-
-typedef struct _Context {
- char *name;
- char *uName;
- char *fUName;
- GenType mode;
- Option *options;
-} Context;
-
-extern Context data;
-extern char* programName;
-extern char* fileName;
-extern int quiet;
-
-typedef struct _ParserState {
- int screen;
- char *group;
- char *subGroup;
-} ParserState;
-
-char * strToLower(char *str);
-char * strToUpper(char *str);
-char * strToFirstUp(char *str);
-char * strToCamel(char *str);
-
-int genCode(char *src, char *hdr);
-
-int genSchema(char *sch);
-
-#endif
diff --git a/src/bcop.in b/src/bcop.in
new file mode 100755
index 0000000..830d5d9
--- /dev/null
+++ b/src/bcop.in
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+#
+# Compiz option code generator
+#
+# Copyright : (C) 2007 by Dennis Kasprzyk
+# E-mail : onestone@beryl-project.org
+#
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+prefix=@prefix@
+xsltdir=@xsltdir@
+
+function usage()
+{
+ echo "Usage: $0 [options] <options file>"
+ echo "Options:"
+ echo " -h, --help display this help message"
+ echo " -v, --version print version information"
+ echo " --source=<file> source file name"
+ echo " --header=<file> header file name"
+ exit 1
+}
+
+srcfile=
+hdrfile=
+
+set -- `getopt -quo "hv" -l "help,version,source:,header:" -- "$@"`
+[ $# -lt 2 ] && usage
+
+while [ $# -gt 0 ]
+do
+ case "$1" in
+ -h) usage;;
+ --help) usage;;
+ -v) echo "@PACKAGE_STRING@"; exit 0;;
+ --version) echo "@PACKAGE_STRING@"; exit 0;;
+ --source) srcfile="$2"; shift;;
+ --header) hdrfile="$2"; shift;;
+ --) shift; break;;
+ -*) usage;;
+ *) break;; # terminate while loop
+ esac
+ shift
+done
+
+xmlfile="$1"
+
+if [ -e $xmlfile ]; then
+ if [ -n "$hdrfile" ]; then
+ xsltproc --stringparam "header" "true" $xsltdir/bcop.xslt $xmlfile > "$hdrfile"
+ fi
+ if [ -n "$srcfile" ]; then
+ xsltproc --stringparam "source" "true" $xsltdir/bcop.xslt $xmlfile > "$srcfile"
+ fi
+fi \ No newline at end of file
diff --git a/src/bcop.xslt b/src/bcop.xslt
new file mode 100644
index 0000000..ff95c99
--- /dev/null
+++ b/src/bcop.xslt
@@ -0,0 +1,1681 @@
+<!--
+ Compiz option code generator
+
+ Copyright : (C) 2007 by Dennis Kasprzyk
+ E-mail : onestone@beryl-project.org
+
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:output method="text"/>
+
+<!-- String conversion helper functions -->
+
+ <xsl:template name="print">
+ <xsl:param name="text"/>
+ <xsl:value-of select="translate($text,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
+ </xsl:template>
+
+ <xsl:template name="PRINT">
+ <xsl:param name="text"/>
+ <xsl:value-of select="translate($text,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
+ </xsl:template>
+
+ <xsl:template name="Print">
+ <xsl:param name="text"/>
+ <xsl:call-template name="PRINT">
+ <xsl:with-param name="text">
+ <xsl:value-of select="substring($text,1,1)"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:call-template name="print">
+ <xsl:with-param name="text">
+ <xsl:value-of select="substring($text,2)"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="PrintCamel">
+ <xsl:param name="text"/>
+ <xsl:variable name="textconv">
+ <xsl:value-of select="translate($text,' +-','___')"/>
+ </xsl:variable>
+ <xsl:if test="string-length($textconv)">
+ <xsl:if test="contains($textconv,'_')">
+ <xsl:call-template name="Print">
+ <xsl:with-param name="text">
+ <xsl:value-of select="substring-before($textconv,'_')"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="substring-after($textconv,'_')"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:if test="not(contains($textconv,'_'))">
+ <xsl:call-template name="Print">
+ <xsl:with-param name="text">
+ <xsl:value-of select="$textconv"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="saveCName">
+ <xsl:param name="text"/>
+ <xsl:variable name="textFirst">
+ <xsl:value-of select="translate(substring($text,1,1),'0123456789 +-','zottffssen___')"/>
+ </xsl:variable>
+ <xsl:value-of select="concat($textFirst,substring($text,2))"/>
+ </xsl:template>
+
+<!-- Plugin name variables -->
+
+ <xsl:variable name="pName">
+ <xsl:value-of select="/compiz/plugin[@useBcop = 'true']/@name"/>
+ </xsl:variable>
+
+ <xsl:variable name="pCName">
+ <xsl:call-template name="saveCName">
+ <xsl:with-param name="text">
+ <xsl:value-of select="$pName"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="plugin">
+ <xsl:call-template name="print">
+ <xsl:with-param name="text">
+ <xsl:value-of select="$pCName"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="Plugin">
+ <xsl:call-template name="Print">
+ <xsl:with-param name="text">
+ <xsl:value-of select="$pCName"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="PLUGIN">
+ <xsl:call-template name="PRINT">
+ <xsl:with-param name="text">
+ <xsl:value-of select="$pCName"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
+<!-- external parameters that could be passed to this document -->
+
+ <xsl:param name="header">false</xsl:param>
+ <xsl:param name="source">false</xsl:param>
+ <xsl:param name="filename"><xsl:value-of select="$plugin"/><xsl:text>_options.h</xsl:text></xsl:param>
+ <xsl:param name="metaname"><xsl:value-of select="$plugin"/></xsl:param>
+
+
+<!-- global helper functions -->
+
+ <xsl:template name="license">
+<xsl:text>/*
+ * This file is autogenerated with bcop:
+ * The Compiz option code generator
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="printOptionsEnumName">
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="screenOrDisplay"/>
+ <xsl:text>Option</xsl:text>
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="@name"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="printOptionName">
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="@name"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="screenOrDisplay">
+ <xsl:if test="ancestor::display">
+ <xsl:text>Display</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>Screen</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="baseType">
+ <xsl:if test="ancestor::display">
+ <xsl:text>CompDisplay *d</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>CompScreen *s</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+<!-- *** main block *** -->
+
+ <xsl:template match="/compiz">
+ <xsl:if test="plugin[@useBcop = 'true']">
+ <xsl:if test="$header = 'true'">
+ <xsl:call-template name="hfile"/>
+ </xsl:if>
+ <xsl:if test="$source = 'true'">
+ <xsl:call-template name="cfile"/>
+ </xsl:if>
+ </xsl:if>
+ </xsl:template>
+
+<!-- *** c source file generation *** -->
+
+ <xsl:template name="cfile">
+ <xsl:call-template name="license"/>
+ <xsl:text>#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;string.h&gt;
+
+#include &lt;compiz.h&gt;
+
+#define _</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_INTERNAL
+#include "</xsl:text>
+ <xsl:value-of select="$filename"/>
+ <xsl:text>"
+
+static int displayPrivateIndex;
+
+static CompMetadata </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata;
+
+static CompPluginVTable *</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable = NULL;
+CompPluginVTable </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable;
+
+#define GET_</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d) \
+ ((</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay *) (d)->privates[displayPrivateIndex].ptr)
+
+#define </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d) \
+ </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay *od = GET_</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY (d)
+
+#define GET_</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s, od) \
+ ((</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen *) (s)->privates[(od)->screenPrivateIndex].ptr)
+
+#define </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s) \
+ </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen *os = GET_</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN (s, GET_</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY (s->display))
+
+typedef struct _</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay
+{
+ int screenPrivateIndex;
+
+</xsl:text>
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:text> CompOption opt[</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptionNum];
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>DisplayOptionChangeNotifyProc notify[</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptionNum];
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option[@type = 'string' and ./allowed/value]">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:for-each>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option[@type = 'list' and ./allowed/value and ./type/text() = 'string']">
+ <xsl:text> unsigned int </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:text>} </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay;
+
+typedef struct _</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen
+{
+</xsl:text>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:text> CompOption opt[</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptionNum];
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>ScreenOptionChangeNotifyProc notify[</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptionNum];
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option[@type = 'string' and ./allowed/value]">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:for-each>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option[@type = 'list' and ./allowed/value and ./type/text() = 'string']">
+ <xsl:text> unsigned int </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:text>} </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen;
+
+</xsl:text>
+ <xsl:call-template name="printMetadataFallback"/>
+ <xsl:call-template name="printFunctions"/>
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:call-template name="initDisplayOptions"/>
+ <xsl:call-template name="setDisplayOptions"/>
+ <xsl:call-template name="getDisplayOptions"/>
+ </xsl:if>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:call-template name="initScreenOptions"/>
+ <xsl:call-template name="setScreenOptions"/>
+ <xsl:call-template name="getScreenOptions"/>
+ </xsl:if>
+ <xsl:call-template name="initFiniScreen"/>
+ <xsl:call-template name="initFiniDisplay"/>
+ <xsl:call-template name="initFini"/>
+ <xsl:call-template name="getVTable"/>
+ </xsl:template>
+
+<!-- helper functions -->
+
+ <xsl:template name="initPrivate">
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_</xsl:text>
+ <xsl:if test="ancestor::display">
+ <xsl:text>DISPLAY(d);
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>SCREEN(s);
+</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="privateName">
+ <xsl:if test="ancestor::display">
+ <xsl:text>od</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>os</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+<!-- print get/set functions -->
+
+ <xsl:template name="printMetadataFallback">
+ <xsl:text>char </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>StaticMetadata[] = {
+ "&lt;compiz&gt;"
+ " &lt;plugin name=\"</xsl:text>
+ <xsl:value-of select="$pName"/>
+ <xsl:text>\"&gt;"
+</xsl:text>
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:text> " &lt;display&gt;"
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:text> " &lt;option name=\"</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>\" type=\"</xsl:text>
+ <xsl:value-of select="@type"/>
+ <xsl:choose>
+ <xsl:when test="@type = 'list' and ./type/text()">
+ <xsl:text>\"&gt;"
+ " &lt;type&gt;</xsl:text>
+ <xsl:value-of select="./type/text()"/>
+ <xsl:text>&lt;/type&gt;"
+</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>\"/&gt;"
+</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text> " &lt;/display&gt;"
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:text> " &lt;screen&gt;"
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:text> " &lt;option name=\"</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>\" type=\"</xsl:text>
+ <xsl:value-of select="@type"/>
+ <xsl:choose>
+ <xsl:when test="@type = 'list' and ./type/text()">
+ <xsl:text>\"&gt;"
+ " &lt;type&gt;</xsl:text>
+ <xsl:value-of select="./type/text()"/>
+ <xsl:text>&lt;/type&gt;"
+</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>\"/&gt;"
+</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text> " &lt;/screen&gt;"
+</xsl:text>
+ </xsl:if>
+ <xsl:text> " &lt;/plugin&gt;"
+ "&lt;/compiz&gt;"
+};
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="printFunctions">
+ <xsl:for-each select="/compiz/plugin[@name=$pName]//option">
+ <xsl:choose>
+ <xsl:when test="@type='int'">
+ <xsl:text>int </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.i;
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='float'">
+ <xsl:text>float </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.f;
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='bool'">
+ <xsl:text>Bool </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.b;
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='string'">
+ <xsl:text>char * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.s;
+}
+
+</xsl:text>
+ <xsl:if test="./allowed/value">
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Index (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>;
+}
+
+</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test="@type='match'">
+ <xsl:text>CompMatch * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.match;
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='color'">
+ <xsl:text>unsigned short * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.c;
+}
+
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Red (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.c[0];
+}
+
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Green (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.c[1];
+}
+
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Blue (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.c[2];
+}
+
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Alpha (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.c[3];
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='action'">
+ <xsl:text>CompAction * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return &amp;</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.action;
+}
+
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Initiate (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, CompActionCallBackProc init)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.action.initiate = init;
+}
+
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Terminate (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, CompActionCallBackProc term)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.action.terminate = term;
+}
+
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='list'">
+ <xsl:text>CompListValue * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return &amp;</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.list;
+}
+
+</xsl:text>
+ <xsl:if test="./type[text() = 'string']/../allowed/value">
+ <xsl:text>unsigned int </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Mask (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>
+}
+
+</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Option (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> return &amp;</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>];
+}
+
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Notify (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:call-template name="screenOrDisplay"/>
+ <xsl:text>OptionChangeNotifyProc notify)
+{
+ </xsl:text>
+ <xsl:call-template name="initPrivate"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->notify[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>] = notify;
+}
+
+</xsl:text>
+ </xsl:for-each>
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:text>CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>GetDisplayOption (CompDisplay *d, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptions num)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d);
+ return &amp;od->opt[num];
+}
+
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:text>CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>GetScreenOption (CompScreen *s, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptions num)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s);
+ return &amp;os->opt[num];
+}
+
+</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+<!-- initialze option functions generation -->
+
+ <xsl:template name="initDisplayOptions">
+ <xsl:text>static void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsDisplayInitOptions (CompDisplay *d)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d);
+ CompOption *o;
+
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:call-template name="initOption"/>
+ </xsl:for-each>
+ <xsl:text>}
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="initScreenOptions">
+ <xsl:text>static void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsScreenInitOptions (CompScreen *s)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s);
+ CompOption *o;
+
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:call-template name="initOption"/>
+ </xsl:for-each>
+ <xsl:text>}
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="initOption">
+ <xsl:text> o = &amp;</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>];
+ compInit</xsl:text>
+ <xsl:call-template name="screenOrDisplay"/>
+ <xsl:text>OptionFromMetadata (</xsl:text>
+ <xsl:if test="ancestor::display">
+ <xsl:text>d</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>s</xsl:text>
+ </xsl:if>
+ <xsl:text>, &amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata, o, "</xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>");
+</xsl:text>
+ <xsl:if test="@type = 'string' and ./allowed/value">
+ <xsl:text> {
+ int i;
+ for (i = 0; i &lt; </xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Num; i++)
+ if (!strcmp (o->value.s, o->rest.s.string[i]))
+ </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> = i;
+ }
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="@type = 'list' and ./allowed/value and ./type/text() = 'string'">
+ <xsl:text> {
+ int i,j;
+ </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> = 0;
+ for (i = 0; i &lt; o->value.list.nValue; i++)
+ for (j = 0; j &lt; o->value.rest.s.nString; j++);
+ if (!strcmp (o->value.list.value[i].s, o->rest.s.string[j]))
+ </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> |= (1 &lt;&lt; j);
+ }
+</xsl:text>
+ </xsl:if>
+<xsl:text>
+
+</xsl:text>
+ </xsl:template>
+
+<!-- get option functions generation -->
+
+ <xsl:template name="getDisplayOptions">
+ <xsl:text>static CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetDisplayOptions (CompPlugin *plugin, CompDisplay *d, int *count)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d);
+ *count = </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptionNum;
+ return od->opt;
+}
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="getScreenOptions">
+ <xsl:text>static CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetScreenOptions (CompPlugin *plugin, CompScreen *s, int *count)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s);
+ *count = </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptionNum;
+ return os->opt;
+}
+
+</xsl:text>
+ </xsl:template>
+
+<!-- set option function generation -->
+
+ <xsl:template name="setDisplayOptions">
+ <xsl:text>static Bool </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsSetDisplayOption (CompPlugin *plugin, CompDisplay *d, char *name, CompOptionValue *value)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY(d);
+ CompOption *o;
+ int index;
+
+ o = compFindOption (od->opt, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptionNum, name, &amp;index);
+
+ if (!o)
+ return FALSE;
+
+ switch (index)
+ {
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:call-template name="setOption"/>
+ </xsl:for-each>
+ <xsl:text> default:
+ break;
+ }
+ return FALSE;
+}
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="setScreenOptions">
+ <xsl:text>static Bool </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsSetScreenOption (CompPlugin *plugin, CompScreen *s, char *name, CompOptionValue *value)
+{
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN(s);
+ CompOption *o;
+ int index;
+
+ o = compFindOption (os->opt, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptionNum, name, &amp;index);
+
+ if (!o)
+ return FALSE;
+
+ switch (index)
+ {
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:call-template name="setOption"/>
+ </xsl:for-each>
+ <xsl:text> default:
+ break;
+ }
+ return FALSE;
+}
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="setOption">
+ <xsl:text> case </xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>:
+ if (</xsl:text>
+ <xsl:choose>
+ <xsl:when test="@type='action'">
+ <xsl:text>setDisplayAction (d, o, value))</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>compSetOption (o, value))</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>
+ {
+</xsl:text>
+ <xsl:if test="@type = 'string' and ./allowed/value">
+ <xsl:text> int i;
+ for (i = 0; i &lt; </xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Num; i++)
+ if (!strcmp (o->value.s, o->rest.s.string[i]))
+ </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> = i;
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="@type = 'list' and ./allowed/value and ./type/text() = 'string'">
+ <xsl:text> int i,j;
+</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> = 0;
+ for (i = 0; i &lt; o->value.list.nValue; i++)
+ for (j = 0; j &lt; o->value.rest.s.nString; j++);
+ if (!strcmp (o->value.list.value[i].s, o->rest.s.string[j]))
+ </xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>-></xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> |= (1 &lt;&lt; j);
+</xsl:text>
+ </xsl:if>
+ <xsl:text> if (</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->notify[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>])
+ (*</xsl:text>
+ <xsl:call-template name="privateName"/>
+ <xsl:text>->notify[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>]) (</xsl:text>
+ <xsl:if test="ancestor::display">
+ <xsl:text>d</xsl:text>
+ </xsl:if>
+ <xsl:if test="ancestor::screen">
+ <xsl:text>s</xsl:text>
+ </xsl:if>
+ <xsl:text>, o, </xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>);
+ return TRUE;
+ }
+ break;
+</xsl:text>
+ </xsl:template>
+
+
+<!-- init/fini screen -->
+
+ <xsl:template name="initFiniScreen">
+ <xsl:text>static Bool </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInitScreen (CompPlugin *p, CompScreen *s)
+{
+ </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen *os;
+
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY (s->display);
+
+ os = calloc (1, sizeof(</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsScreen));
+ if (!os)
+ return FALSE;
+
+ s->privates[od->screenPrivateIndex].ptr = os;
+
+ </xsl:text>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsScreenInitOptions (s);
+
+</xsl:text>
+ </xsl:if>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option[@type = 'action']">
+ <xsl:text> addScreenAction (s, &amp;od->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.action);
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->initScreen)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->initScreen (p, s);
+ return TRUE;
+}
+
+static void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFiniScreen (CompPlugin *p, CompScreen *s)
+{
+ if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->finiScreen)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->finiScreen (p, s);
+
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY (s->display);
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_SCREEN (s);
+
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option[@type = 'action']">
+ <xsl:text> removeScreenAction (s, &amp;od->opt[</xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>].value.action);
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> free (os);
+}
+
+</xsl:text>
+ </xsl:template>
+
+<!-- init/fini display -->
+
+ <xsl:template name="initFiniDisplay">
+ <xsl:text>static Bool </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInitDisplay (CompPlugin *p, CompDisplay *d)
+{
+ </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay *od;
+
+ od = calloc (1, sizeof(</xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>OptionsDisplay));
+ if (!od)
+ return FALSE;
+
+ od->screenPrivateIndex = allocateScreenPrivateIndex(d);
+ if (od->screenPrivateIndex &lt; 0)
+ {
+ free(od);
+ return FALSE;
+ }
+
+ d->privates[displayPrivateIndex].ptr = od;
+
+ </xsl:text>
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsDisplayInitOptions (d);
+
+</xsl:text>
+ </xsl:if>
+ <xsl:text> if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->initDisplay)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->initDisplay (p, d);
+ return TRUE;
+}
+
+static void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFiniDisplay (CompPlugin *p, CompDisplay *d)
+{
+ if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->finiDisplay)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->finiDisplay (p, d);
+
+ </xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_DISPLAY (d);
+
+ freeScreenPrivateIndex(d, od->screenPrivateIndex);
+
+ free (od);
+}
+
+</xsl:text>
+ </xsl:template>
+
+<!-- init/fini plugin -->
+
+ <xsl:template name="initFini">
+ <xsl:text>static Bool </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInit (CompPlugin *p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex();
+ if (displayPrivateIndex &lt; 0)
+ return FALSE;
+
+ if (!compInitPluginMetadata (&amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata, "</xsl:text>
+ <xsl:value-of select="$pName"/>
+ <xsl:text>"))
+ return FALSE;
+ if (compAddMetadataFromString (&amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata, </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>StaticMetadata))
+ return FALSE;
+
+ compAddMetadataFromFile (&amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata, "</xsl:text>
+ <xsl:value-of select="$metaname"/>
+ <xsl:text>");
+ if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->init)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->init (p);
+ return TRUE;
+}
+
+static void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFini (CompPlugin *p)
+{
+ if (</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable &amp;&amp; </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->fini)
+ return </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable->fini (p);
+
+ if (displayPrivateIndex >= 0)
+ freeDisplayPrivateIndex(displayPrivateIndex);
+
+ compFiniMetadata (&amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsMetadata);
+}
+
+</xsl:text>
+ </xsl:template>
+
+<!-- vtable generation -->
+
+ <xsl:template name="getVTable">
+ <xsl:text>CompPluginVTable *getCompPluginInfo (void)
+{
+ if (!</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable)
+ {
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetCompPluginInfo ();
+ memcpy(&amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable, </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>PluginVTable, sizeof(CompPluginVTable));
+ </xsl:text>
+
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.init = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInit;
+ </xsl:text>
+
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.fini = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFini;
+ </xsl:text>
+
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.initDisplay = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInitDisplay;
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.finiDisplay = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFiniDisplay;
+ </xsl:text>
+
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.initScreen = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsInitScreen;
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.finiScreen = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsFiniScreen;
+ </xsl:text>
+
+ <xsl:if test="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.getDisplayOptions = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetDisplayOptions;
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.setDisplayOption = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsSetDisplayOption;
+ </xsl:text>
+ </xsl:if>
+ <xsl:if test="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.getScreenOptions = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetScreenOptions;
+ </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable.setScreenOption = </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsSetScreenOption;
+ </xsl:text>
+ </xsl:if>
+
+ <xsl:text>
+ }
+ return &amp;</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsVTable;
+}
+
+</xsl:text>
+ </xsl:template>
+
+
+<!-- *** header file generation *** -->
+
+ <xsl:template name="hfile">
+ <xsl:call-template name="license"/>
+ <xsl:text>#ifndef _</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_H
+#define _</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_H
+
+#ifndef _</xsl:text>
+ <xsl:value-of select="$PLUGIN"/>
+ <xsl:text>_OPTIONS_INTERNAL
+#define getCompPluginInfo </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetCompPluginInfo
+#endif
+
+CompPluginVTable *</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>OptionsGetCompPluginInfo (void);
+
+</xsl:text>
+ <xsl:call-template name="printDisplayOptionsEnum"/>
+ <xsl:call-template name="printScreenOptionsEnum"/>
+ <xsl:call-template name="printOptionEnums"/>
+ <xsl:call-template name="printOptionMasks"/>
+ <xsl:call-template name="printFunctionDefinitions"/>
+ <xsl:text>#endif
+</xsl:text>
+ </xsl:template>
+
+<!-- enums for screen/display options -->
+
+ <xsl:template name="printDisplayOptionsEnum">
+<xsl:text>typedef enum
+{
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/display//option">
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>,
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptionNum
+</xsl:text>
+<xsl:text>} </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+<xsl:text>DisplayOptions;
+
+typedef void (*</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>DisplayOptionChangeNotifyProc) (CompDisplay *display, CompOption *opt, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptions num);
+
+CompOption *</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>GetDisplayOption (CompDisplay *d, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>DisplayOptions num);
+
+</xsl:text>
+ </xsl:template>
+
+ <xsl:template name="printScreenOptionsEnum">
+<xsl:text>typedef enum
+{
+</xsl:text>
+ <xsl:for-each select="/compiz/plugin[@name=$pName]/screen//option">
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="printOptionsEnumName"/>
+ <xsl:text>,
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptionNum
+</xsl:text>
+<xsl:text>} </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+<xsl:text>ScreenOptions;
+
+typedef void (*</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>ScreenOptionChangeNotifyProc) (CompScreen *screen, CompOption *opt, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptions num);
+
+CompOption *</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>GetScreenOption (CompScreen *s, </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:text>ScreenOptions num);
+
+</xsl:text>
+ </xsl:template>
+
+<!-- generate enums/masks for restricted string options -->
+
+ <xsl:template name="printOptionEnums">
+ <xsl:for-each select="/compiz/plugin[@name=$pName]//option[@type = 'string' and ./allowed/value]">
+ <xsl:text>typedef enum
+{
+ </xsl:text>
+ <xsl:for-each select="allowed/value">
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="../../@name"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="text()"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>,
+ </xsl:text>
+ </xsl:for-each>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Num
+} </xsl:text>
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum;
+
+</xsl:text>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template name="printOptionMasks">
+ <xsl:for-each select="/compiz/plugin[@name=$pName]//option[@type = 'list' and ./allowed/value and ./type/text() = 'string']">
+ <xsl:for-each select="allowed/value">
+ <xsl:text>#define </xsl:text>
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="../../@name"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:call-template name="PrintCamel">
+ <xsl:with-param name="text">
+ <xsl:value-of select="text()"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>Mask (1 &lt;&lt; </xsl:text>
+ <xsl:number value="position()-1"/>
+ <xsl:text>)
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text>
+</xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum;
+
+</xsl:text>
+ </xsl:for-each>
+ </xsl:template>
+
+<!-- generate get/set function definitions -->
+
+ <xsl:template name="printFunctionDefinitions">
+ <xsl:for-each select="/compiz/plugin[@name=$pName]//option">
+ <xsl:choose>
+ <xsl:when test="@type='int'">
+ <xsl:text>int </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='float'">
+ <xsl:text>float </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='bool'">
+ <xsl:text>Bool </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='string'">
+ <xsl:text>char * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ <xsl:if test="./allowed/value">
+ <xsl:value-of select="$Plugin"/>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Enum </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Index (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test="@type='match'">
+ <xsl:text>CompMatch * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='color'">
+ <xsl:text>unsigned short * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Red (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Green (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Blue (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+unsigned short </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Alpha (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='action'">
+ <xsl:text>CompAction * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Initiate (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, CompActionCallBackProc init);
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Terminate (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, CompActionCallBackProc term);
+</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type='list'">
+ <xsl:text>CompListValue * </xsl:text>
+ <xsl:call-template name="printGetFunctionDef"/>
+ <xsl:text>;
+</xsl:text>
+ <xsl:if test="./type[text() = 'string']/../allowed/value">
+ <xsl:text>unsigned int </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Mask (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>CompOption * </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Option (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>);
+void </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Set</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text>Notify (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>, </xsl:text>
+ <xsl:value-of select="$plugin"/>
+ <xsl:call-template name="screenOrDisplay"/>
+ <xsl:text>OptionChangeNotifyProc notify);
+
+</xsl:text>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template name="printGetFunctionDef">
+ <xsl:value-of select="$plugin"/>
+ <xsl:text>Get</xsl:text>
+ <xsl:call-template name="printOptionName"/>
+ <xsl:text> (</xsl:text>
+ <xsl:call-template name="baseType"/>
+ <xsl:text>)</xsl:text>
+ </xsl:template>
+
+</xsl:stylesheet> \ No newline at end of file
diff --git a/src/code_generator.c b/src/code_generator.c
deleted file mode 100644
index b99023a..0000000
--- a/src/code_generator.c
+++ /dev/null
@@ -1,1380 +0,0 @@
-/*
- *
- * Beryl/Compiz options parser
- *
- * Copyright : (C) 2007 by Dennis Kasprzyk
- * E-mail : onestone@beryl-project.org
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include "../config.h"
-#endif
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <ctype.h>
-#include <math.h>
-#include <libgen.h>
-#include <X11/Xlib.h>
-
-#include "bcop.h"
-
-static char *edges[] = {
- "SCREEN_EDGE_LEFT",
- "SCREEN_EDGE_RIGHT",
- "SCREEN_EDGE_TOP",
- "SCREEN_EDGE_BOTTOM",
- "SCREEN_EDGE_TOPLEFT",
- "SCREEN_EDGE_TOPRIGHT",
- "SCREEN_EDGE_BOTTOMLEFT",
- "SCREEN_EDGE_BOTTOMRIGHT",
-};
-
-static char* actionStates[] = {
- "CompActionStateInitKey",
- "CompActionStateTermKey",
- "CompActionStateInitButton",
- "CompActionStateTermButton",
- "CompActionStateInitBell",
- "CompActionStateInitEdge",
- "CompActionStateTermEdge",
- "CompActionStateInitEdgeDnd",
- "CompActionStateTermEdgeDnd",
- "CompActionStateCommit",
- "CompActionStateCancel",
- "CompActionStateModifier"
-};
-
-static char *bindingTypes[] = {
- "CompBindingTypeKey",
- "CompBindingTypeButton",
- "CompBindingTypeEdgeButton"
-};
-
-typedef struct _StringElement
-{
- char *data;
- int size;
- int used;
-} StringElement;
-
-char *hFile = NULL;
-
-StringElement header;
-StringElement file;
-
-StringElement displayStruct;
-StringElement screenStruct;
-StringElement initScreenOpt;
-StringElement initDisplayOpt;
-StringElement setScreenOpt;
-StringElement setDisplayOpt;
-StringElement defines;
-StringElement functions;
-StringElement hdefines;
-StringElement hfunctions;
-StringElement initScreen;
-StringElement finiScreen;
-StringElement initDisplay;
-StringElement finiDisplay;
-
-
-int nOptions = 0;
-int nSOptions = 0;
-int nDOptions = 0;
-
-static void addString(StringElement *se, const char* format, ...)
-{
- char *str = NULL;
- va_list ap;
-
- va_start(ap, format);
- vasprintf(&str,format,ap);
- va_end(ap);
-
- while (strlen(str) + se->used >= se->size)
- {
- se->data = realloc(se->data, se->size + 4096);
- se->size += 4096;
- }
-
- sprintf(se->data + se->used, "%s", str);
- se->used += strlen(str);
- free(str);
-}
-
-static void initString(StringElement *se)
-{
- se->data = calloc(1,4096);
- se->size = 4096;
- se->used = 0;
- sprintf(se->data," ");
-}
-
-static void freeString(StringElement *se)
-{
- free(se->data);
- se->size = 0;
- se->used = 0;
-}
-
-static void initStrings()
-{
- initString(&header);
- initString(&file);
- initString(&displayStruct);
- initString(&screenStruct);
- initString(&initScreenOpt);
- initString(&initDisplayOpt);
- initString(&setScreenOpt);
- initString(&setDisplayOpt);
- initString(&defines);
- initString(&functions);
- initString(&hdefines);
- initString(&hfunctions);
- initString(&initScreen);
- initString(&finiScreen);
- initString(&initDisplay);
- initString(&finiDisplay);
-}
-
-struct _Modifier {
- char *name;
- char *modifier;
-} const static modifiers[] = {
- { "Shift","ShiftMask"},
- { "Control","ControlMask"},
- { "Mod1","Mod1Mask"},
- { "Mod2","Mod2Mask"},
- { "Mod3","Mod3Mask"},
- { "Mod4","Mod4Mask"},
- { "Mod5","Mod5Mask"},
- { "Alt","CompAltMask"},
- { "Meta","CompMetaMask"},
- { "Super","CompSuperMask"},
- { "Hyper","CompHyperMask"},
- { "ModeSwitch","CompModeSwitchMask"},
-};
-
-#define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
-
-static void convertBinding(char *bind, char **modret, char **value)
-{
- char *tok = strtok(bind,"+");
- int i;
- int keysym = 0;
- int button = 0;
- int num_mods = 0;
- int changed;
- StringElement mods;
- initString(&mods);
- char str[1024];
-
- while (tok)
- {
- changed = 0;
- for (i = 0; i < N_MODIFIERS && !changed; i++)
- if (!strcmp(tok,modifiers[i].name))
- {
- addString(&mods,"%s%s",(num_mods)?" | ":"",modifiers[i].modifier);
- num_mods++;
- changed = 1;
- }
- if (!changed && strncmp(tok, "Button", strlen("Button")) == 0)
- {
- int but;
- if (sscanf(tok, "Button%d", &but) == 1)
- {
- button = but;
- changed = 1;
- }
- }
- if (!changed && !keysym)
- keysym = XStringToKeysym(tok);
-
- tok = strtok(NULL,"+");
- }
-
- if (num_mods)
- {
- sprintf(str,"%s%s%s",(num_mods > 1)?"(":"",
- mods.data,(num_mods > 1)?")":"");
- *modret = strdup(str);
- }
- else
- *modret = NULL;
-
- if (button)
- {
- sprintf(str,"Button%d",button);
- *value = strdup(str);
- }
- else if (keysym)
- {
- *value = strdup(XKeysymToString(keysym));
- }
- else
- *value = NULL;
- freeString(&mods);
-}
-
-
-void addGetFunction(Option *o, const char *type, const char *nameadd,
- const char *fetch, const char *prefix)
-{
- addString(&hfunctions,"%-16s %sGet%s%s(%s);\n",type,data.name,o->fUName,nameadd,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
- addString(&functions,"%s %sGet%s%s(%s)\n",type,data.name,o->fUName,nameadd,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
- if (o->screen)
- addString(&functions,"{\n\t%s_OPTIONS_SCREEN(s);\n\treturn %sos->opt[%s]%s;\n"
- "}\n\n",data.uName,prefix,o->temp,fetch);
- else
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n\treturn %sod->opt[%s]%s;\n"
- "}\n\n",data.uName,prefix,o->temp,fetch);
-}
-
-
-void addIntOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.uName,o->uName);
- addString(&defines,"#define %s_DEFAULT %d\n",name,o->data.asInt.def);
- addString(&defines,"#define %s_MIN %d\n",name,o->data.asInt.min);
- addString(&defines,"#define %s_MAX %d\n\n",name,o->data.asInt.max);
-
- addString(out,"\to->value.i = %s_DEFAULT;\n",name);
- addString(out,"\to->rest.i.min = %s_MIN;\n",name);
- addString(out,"\to->rest.i.max = %s_MAX;\n",name);
-
- addGetFunction(o,"int","",".value.i","");
-}
-
-void addFloatOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.uName,o->uName);
- addString(&defines,"#define %s_DEFAULT %g%sf\n",name,o->data.asFloat.def,
- (o->data.asFloat.def == floor(o->data.asFloat.def))?".0":"");
- addString(&defines,"#define %s_MIN %g%sf\n",name,o->data.asFloat.min,
- (o->data.asFloat.min == floor(o->data.asFloat.min))?".0":"");
- addString(&defines,"#define %s_MAX %g%sf\n",name,o->data.asFloat.max,
- (o->data.asFloat.max == floor(o->data.asFloat.max))?".0":"");
- addString(&defines,"#define %s_PRECISION %g%sf\n\n",name,o->data.asFloat.precision,
- (o->data.asFloat.precision == floor(o->data.asFloat.precision))?".0":"");
-
- addString(out,"\to->value.f = %s_DEFAULT;\n",name);
- addString(out,"\to->rest.f.min = %s_MIN;\n",name);
- addString(out,"\to->rest.f.max = %s_MAX;\n",name);
- addString(out,"\to->rest.f.precision = %s_PRECISION;\n",name);
-
- addGetFunction(o,"float","",".value.f","");
-}
-
-void addBoolOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.uName,o->uName);
- addString(&defines,"#define %s_DEFAULT %s\n\n",name,(o->data.asBool.def)?"TRUE":"FALSE");
- addString(out,"\to->value.b = %s_DEFAULT;\n",name);
-
- addGetFunction(o,"Bool","",".value.b","");
-}
-
-void addMatchOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.uName,o->uName);
- addString(&defines,"#define %s_DEFAULT \"%s\"\n\n",name,o->data.asString.def);
-
- addString(out,"\tmatchInit (&o->value.match);\n");
- addString(out,"\tmatchAddFromString (&o->value.match, %s_DEFAULT);\n",name);
-
- addGetFunction(o,"CompMatch *","",".value.match","&");
-
- if (o->screen)
- {
- addString(&initScreen,"\tmatchUpdate (s->display, &os->opt[%s].value.match);\n",o->temp);
- addString(&finiScreen,"\tmatchFini(&os->opt[%s].value.match);\n",o->temp);
- }
- else
- {
- addString(&initDisplay,"\tmatchUpdate (d, &od->opt[%s].value.match);\n",o->temp);
- addString(&finiDisplay,"\tmatchFini(&od->opt[%s].value.match);\n",o->temp);
- }
-}
-
-void addStringOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.uName,o->uName);
- addString(&defines,"#define %s_DEFAULT \"%s\"\n\n",name,o->data.asString.def);
- addString(out,"\to->value.s = strdup(%s_DEFAULT);\n",name);
- addString(out,"\to->rest.s.string = NULL;\n");
- addString(out,"\to->rest.s.nString = 0;\n");
-
- addGetFunction(o,"char *","",".value.s","");
-}
-
-void addStringListOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
-
- OptionValuesList *l;
- int i = 0;
-
- l = o->data.asSList.begin;
- i = 0;
- while (l)
- {
- i++;
- l = l->next;
- }
-
- if (i)
- {
- addString(&defines,"static const char *%s%s[] = {\n",data.name,o->fUName);
-
- l = o->data.asSList.begin;
- while (l)
- {
- if (l->raw)
- addString(&defines,"\t%s%s\n",l->value,(l->next)?",":"");
- else
- addString(&defines,"\t\"%s\"%s\n",l->value,(l->next)?",":"");
- l = l->next;
- }
-
- addString(&defines,"};\n",data.name,o->fUName);
-
- addString(&defines,"#define N_%s_%s (sizeof(%s%s) / sizeof(%s%s[0]))\n\n",
- data.uName,o->uName,data.name,o->fUName,data.name,o->fUName);
-
- addString(out,"\to->value.list.type = CompOptionTypeString;\n");
- addString(out,"\to->value.list.nValue = N_%s_%s;\n",data.uName,o->uName);
- addString(out,"\to->value.list.value = "
- "malloc(sizeof(CompOptionValue) * N_%s_%s);\n",
- data.uName,o->uName);
-
- addString(out,"\tfor (i = 0; i < N_%s_%s; i++)\n"
- "\t\to->value.list.value[i].s = strdup(%s%s[i]);\n",
- data.uName,o->uName,data.name,o->fUName);
- }
- else
- {
- addString(out,"\to->value.list.type = CompOptionTypeString;\n");
- addString(out,"\to->value.list.nValue = 0;\n");
- addString(out,"\to->value.list.value = NULL;\n");
- }
-
- addString(out,"\to->rest.s.string = NULL;\n");
- addString(out,"\to->rest.s.nString = 0;\n");
-}
-
-
-void addEnumOption(Option *o)
-{
-
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
-
- OptionValuesList *l;
- int i = 0;
- int def = 0;
-
- addString(&hdefines,"typedef enum {\n");
-
- l = o->data.asSList.begin;
- i = 0;
-
- char *defname = NULL;
-
- while (l)
- {
- addString(&hdefines,"\t%s%s,\n",o->fUName,l->fUName);
- if (l->def || !defname)
- {
- def = i;
- defname = l->fUName;
- }
- l = l->next;
- i++;
- }
- addString(&hdefines,"\t%sNum\n",o->fUName);
- addString(&hdefines,"} %s%sEnum;\n\n",data.fUName,o->fUName);
-
- addString(&defines,"static const char *%s%s[] = {\n",data.name,o->fUName);
-
- l = o->data.asSList.begin;
- while (l)
- {
- addString(&defines,"\tN_(\"%s\")%s\n",l->value,(l->next)?",":"");
- l = l->next;
- }
-
- addString(&defines,"};\n\n",data.name,o->fUName);
-
- addString(&defines,"#define %s_%s_DEFAULT %s%s\n\n",data.uName,o->uName,o->fUName,defname);
-
- addString(out,"\to->value.s = strdup(%s%s[%s_%s_DEFAULT]);\n",
- data.name,o->fUName,data.uName,o->uName);
-
- addString(out,"\to->rest.s.string = (char **)%s%s;\n",data.name,o->fUName);
-
- addString(out,"\to->rest.s.nString = %sNum;\n",o->fUName);
-
- addGetFunction(o,"char *","AsString",".value.s","");
-
- addString((o->screen)?&screenStruct:&displayStruct,"\t%s%sEnum %s;\n",data.fUName,o->fUName,o->name);
-
- addString((o->screen)?&setScreenOpt:&setDisplayOpt,"\t\t\tint i;\n\t\t\tfor (i = 0; i < %sNum;i++)\n"
- "\t\t\t\tif (!strcmp(o->value.s, o->rest.s.string[i]))\n"
- "\t\t\t\t\t%s->%s = i;\n",o->fUName,(o->screen)?"os":"od",
- o->name);
-
- addString((o->screen)?&initScreen:&initDisplay,"\t%s->%s = %s%s;\n",(o->screen)?"os":"od",
- o->name,o->fUName,defname);
-
- char str[1024];
-
- sprintf(str,"%s%sEnum",data.fUName,o->fUName);
-
- addString(&hfunctions,"%-16s %sGet%s(%s);\n",str,data.name,o->fUName,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
- addString(&functions,"%s %sGet%s(%s)\n",str,data.name,o->fUName,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
-
- if (o->screen)
- addString(&functions,"{\n\t%s_OPTIONS_SCREEN(s);\n\treturn os->%s;\n"
- "}\n\n",data.uName,o->name);
- else
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n\treturn od->%s;\n"
- "}\n\n",data.uName,o->name);
-}
-
-
-void addSelectionOption(Option *o)
-{
-
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
-
- OptionValuesList *l;
- int i = 0;
- int def = 0;
-
- addString(&defines,"static const char *%s%s[] = {\n",data.name,o->fUName);
-
- l = o->data.asSList.begin;
- i = 0;
- while (l)
- {
- addString(&defines,"\tN_(\"%s\")%s\n",l->value,(l->next)?",":"");
- addString(&hdefines,"#define %s%sMask (1 << %d)\n",o->fUName,l->fUName,i);
- if (l->def)
- def++;
- i++;
- l = l->next;
- }
- addString(&hdefines,"\n");
-
- addString(&defines,"};\n",data.name,o->fUName);
-
- addString(&defines,"#define N_%s_%s (sizeof(%s%s) / sizeof(%s%s[0]))\n\n",
- data.uName,o->uName,data.name,o->fUName,data.name,o->fUName);
-
- if (def)
- {
- addString(&defines,"static char *%s%sDefault[] = {\n",data.name,o->fUName);
-
- int def_c = def;
- l = o->data.asSList.begin;
- while (l)
- {
- if (l->def)
- {
- def_c--;
- addString(&defines,"\tN_(\"%s\")%s\n",l->value,(def_c)?",":"");
- }
- l = l->next;
- }
-
- addString(&defines,"};\n",data.name,o->fUName);
-
- addString(&defines,"#define N_%s_%s_DEFAULT (sizeof(%s%sDefault)"
- "/ sizeof(%s%sDefault[0]))\n\n",
- data.uName,o->uName,data.name,o->fUName,data.name,o->fUName);
-
- addString(out,"\to->value.list.type = CompOptionTypeString;\n");
- addString(out,"\to->value.list.nValue = N_%s_%s_DEFAULT;\n",
- data.uName,o->uName);
- addString(out,"\to->value.list.value = "
- "malloc(sizeof(CompOptionValue) * N_%s_%s_DEFAULT);\n",
- data.uName,o->uName);
-
- addString(out,"\tfor (i = 0; i < N_%s_%s_DEFAULT; i++)\n"
- "\t\to->value.list.value[i].s = strdup(%s%sDefault[i]);\n",
- data.uName,o->uName,data.name,o->fUName);
- }
- else
- {
- addString(out,"\to->value.list.type = CompOptionTypeString;\n");
- addString(out,"\to->value.list.nValue = 0;\n");
- addString(out,"\to->value.list.value = NULL;\n");
- }
-
- addString(out,"\to->rest.s.string = (char **)%s%s;\n",data.name,o->fUName);
- addString(out,"\to->rest.s.nString = N_%s_%s;\n",data.uName,o->uName);
-
- addString((o->screen)?&screenStruct:&displayStruct,"\tunsigned int %s;\n",o->name);
-
- char obj[4];
- sprintf(obj,"%s",(o->screen)?"os":"od");
-
- addString((o->screen)?&setScreenOpt:&setDisplayOpt,
- "\t\t\tint i;\n\t\t\tint j;\n\t\t\t%s->%s = 0;\n"
- "\t\t\tfor (i = 0; i < o->value.list.nValue; i++)\n"
- "\t\t\t\tfor (j = 0; j < N_%s_%s; i++)\n"
- "\t\t\t\t\tif (!strcmp(o->value.list.value[i].s, "
- "o->rest.s.string[j]))\n\t\t\t\t\t\t%s->%s |= (1 << j);\n",
- obj,o->name,data.uName,o->uName,obj,o->name);
-
- if (!def)
- {
- addString((o->screen)?&initScreen:&initDisplay,
- "\t%s->%s = 0;\n",obj,o->name);
- }
-
- l = o->data.asSList.begin;
- i = 0;
- while (l)
- {
- if (l->def)
- {
- addString((o->screen)?&initScreen:&initDisplay,
- "\t%s->%s %s= %s%sMask;\n",obj,o->name,
- (i)?"|":" ",o->fUName,l->fUName);
- i++;
- }
- l = l->next;
- }
-
- addString(&hfunctions,"unsigned int %sGet%s(%s);\n",data.name,o->fUName,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
- addString(&functions,"unsigned int %sGet%s(%s)\n",data.name,o->fUName,
- (o->screen)?"CompScreen *s":"CompDisplay *d");
-
- if (o->screen)
- addString(&functions,"{\n\t%s_OPTIONS_SCREEN(s);\n\treturn os->%s;\n"
- "}\n\n",data.uName,o->name);
- else
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n\treturn od->%s;\n"
- "}\n\n",data.uName,o->name);
-}
-
-
-void addActionOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
-
- int i = 0;
-
- addString(out,"\to->value.action.initiate = NULL;\n");
- addString(out,"\to->value.action.terminate = NULL;\n");
-
- addString(out,"\to->value.action.bell = %s;\n",
- (o->data.asBind.sbell && o->data.asBind.bell)?"TRUE":"FALSE");
-
- if (o->data.asBind.sedge && o->data.asBind.edge)
- {
- int num_e = 0;
- for (i = 0; i < SCREEN_EDGE_NUM; i++)
- {
- if (o->data.asBind.edge & (1 << i))
- {
- addString(out,"\to->value.action.edgeMask %s= (1 << %s);\n",
- (num_e)?"|":"",edges[i]);
- num_e++;
- }
- }
- }
- else
- addString(out,"\to->value.action.edgeMask = 0;\n");
-
- if (o->data.asBind.state)
- {
- int num_s = 0;
- for (i = 0; i < N_ACTION_STATES; i++)
- {
- if (o->data.asBind.state & (1 << i))
- {
- addString(out,"\to->value.action.state %s= %s;\n",
- (num_s)?"|":"",actionStates[i]);
- num_s++;
- }
- }
- }
- else
- addString(out,"\to->value.action.state = 0;\n");
-
- if (o->data.asBind.type)
- {
- int num_t = 0;
- for (i = 0; i < N_BINDING_TYPES; i++)
- {
- if (o->data.asBind.type & (1 << i))
- {
- addString(out,"\to->value.action.type %s= %s;\n",
- (num_t)?"|":"",bindingTypes[i]);
- num_t++;
- }
- }
- }
- else
- addString(out,"\to->value.action.type = CompBindingTypeNone;\n");
-
-
- if (o->data.asBind.skey)
- {
- char *mods = NULL;
- char *key = NULL;
- convertBinding(o->data.asBind.key,&mods,&key);
- if (mods)
- {
- addString(&defines,"#define %s_%s_KEY_MODIFIERS_DEFAULT %s\n",
- data.uName,o->uName,mods);
- addString(out,"\to->value.action.key.modifiers = "
- "%s_%s_KEY_MODIFIERS_DEFAULT;\n",data.uName,o->uName);
- }
- else
- addString(out,"\to->value.action.key.modifiers = 0;\n");
-
- if (key)
- {
- addString(&defines,"#define %s_%s_KEY_DEFAULT \"%s\"\n",
- data.uName,o->uName,key);
- addString(out,"\to->value.action.key.keycode = \n"
- "\t\tXKeysymToKeycode (display,\n"
- "\n\nXStringToKeysym(%s_%s_KEY_DEFAULT));\n",
- data.uName,o->uName);
- }
- else
- {
- addString(out,"\to->value.action.key.keycode = 0;\n");
- }
- }
-
- if (o->data.asBind.smouse)
- {
- char *mods = NULL;
- char *button = NULL;
- convertBinding(o->data.asBind.mouse,&mods,&button);
- if (mods)
- {
- addString(&defines,"#define %s_%s_BUTTON_MODIFIERS_DEFAULT %s\n",
- data.uName,o->uName,mods);
- addString(out,"\to->value.action.button.modifiers = "
- "%s_%s_BUTTON_MODIFIERS_DEFAULT;\n",data.uName,o->uName);
- }
- else
- addString(out,"\to->value.action.button.modifiers = 0;\n");
-
- if (button)
- {
- addString(&defines,"#define %s_%s_BUTTON_DEFAULT %s\n",
- data.uName,o->uName,button);
- addString(out,"\to->value.action.button.button = "
- "%s_%s_BUTTON_DEFAULT;\n",data.uName,o->uName);
- }
- else
- addString(out,"\to->value.action.button.button = 0;\n");
- }
-
- addGetFunction(o,"CompAction *","",".value.action","&");
-
- addString(&hfunctions,"void %sSet%sInitiate"
- "(CompDisplay *d, CompActionCallBackProc init);\n",data.name,o->fUName);
- addString(&functions,"void %sSet%sInitiate"
- "(CompDisplay *d, CompActionCallBackProc init)\n",data.name,o->fUName);
-
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n"
- "\tod->opt[%s].value.action.initiate = init;\n"
- "}\n\n",data.uName,o->temp);
-
- addString(&hfunctions,"void %sSet%sTerminate"
- "(CompDisplay *d, CompActionCallBackProc term);\n",data.name,o->fUName);
- addString(&functions,"void %sSet%sTerminate"
- "(CompDisplay *d, CompActionCallBackProc term)\n",data.name,o->fUName);
-
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n"
- "\tod->opt[%s].value.action.terminate = term;\n"
- "}\n\n",data.uName,o->temp);
-
- addString(&initScreen,"\taddScreenAction(s, &od->opt[%s].value.action);\n",o->temp);
- addString(&finiScreen,"\tremoveScreenAction(s, &od->opt[%s].value.action);\n",o->temp);
-}
-
-void addColorOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- char name[1024];
-
- sprintf(name,"%s_%s",data.fUName,o->uName);
- addString(&defines,"#define %s_RED_DEFAULT 0x%.4x\n",name,o->data.asColor.red);
- addString(&defines,"#define %s_GREEN_DEFAULT 0x%.4x\n",name,o->data.asColor.green);
- addString(&defines,"#define %s_BLUE_DEFAULT 0x%.4x\n",name,o->data.asColor.blue);
- addString(&defines,"#define %s_ALPHA_DEFAULT 0x%.4x\n\n",name,o->data.asColor.alpha);
-
- addString(out,"\to->value.c[0] = %s_RED_DEFAULT;\n",name);
- addString(out,"\to->value.c[1] = %s_GREEN_DEFAULT;\n",name);
- addString(out,"\to->value.c[2] = %s_BLUE_DEFAULT;\n",name);
- addString(out,"\to->value.c[3] = %s_ALPHA_DEFAULT;\n",name);
-
- addGetFunction(o,"unsigned short*","",".value.c","");
- addGetFunction(o,"unsigned short","Red",".value.c[0]","");
- addGetFunction(o,"unsigned short","Green",".value.c[1]","");
- addGetFunction(o,"unsigned short","Blue",".value.c[2]","");
- addGetFunction(o,"unsigned short","Alpha",".value.c[3]","");
-}
-
-
-void addOption(Option *o)
-{
- StringElement *out = (o->screen)?&initScreenOpt:&initDisplayOpt;
- StringElement *outs = (o->screen)?&setScreenOpt:&setDisplayOpt;
-
- addString(out,"\to = &o%s->opt[%s];\n",(o->screen)?"s":"d",o->temp);
- addString(out,"\to->name = \"%s\";\n",o->name);
-
- if (o->shortDesc)
- addString(out,"\to->shortDesc = N_(\"%s\");\n",o->shortDesc);
- else
- addString(out,"\to->shortDesc = \"%s\";\n",o->name);
-
- if (o->longDesc)
- addString(out,"\to->longDesc = N_(\"%s\");\n",o->longDesc);
- else
- {
- if (o->shortDesc)
- addString(out,"\to->longDesc = N_(\"%s\");\n",o->shortDesc);
- else
- addString(out,"\to->longDesc = \"%s\";\n",o->name);
- }
-
- addString(outs,"\tcase %s:\n",o->temp);
-
- switch (o->type)
- {
- case OptionTypeInt:
- addString(outs,"\t\tif (compSetIntOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeInt;\n");
- addIntOption(o);
- break;
- case OptionTypeBool:
- addString(outs,"\t\tif (compSetBoolOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeBool;\n");
- addBoolOption(o);
- break;
- case OptionTypeFloat:
- addString(outs,"\t\tif (compSetFloatOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeFloat;\n");
- addFloatOption(o);
- break;
- case OptionTypeString:
- addString(outs,"\t\tif (compSetStringOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeString;\n");
- addStringOption(o);
- break;
- case OptionTypeStringList:
- addString(outs,"\t\tif (compSetOptionList(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeList;\n");
- addStringListOption(o);
- break;
- case OptionTypeEnum:
- addString(outs,"\t\tif (compSetStringOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeString;\n");
- addEnumOption(o);
- break;
- case OptionTypeSelection:
- addString(outs,"\t\tif (compSetOptionList(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeList;\n");
- addSelectionOption(o);
- break;
- case OptionTypeColor:
- addString(outs,"\t\tif (compSetColorOption(o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeColor;\n");
- addColorOption(o);
- break;
- case OptionTypeAction:
- addString(outs,"\t\tif (setDisplayAction(display, o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeAction;\n");
- addActionOption(o);
- break;
- case OptionTypeMatch:
- addString(outs,"\t\tif (compSetMatchOption (o, value))\n"
- "\t\t{\n");
- addString(out,"\to->type = CompOptionTypeMatch;\n");
- addMatchOption(o);
- break;
- default:
- break;
- }
-
- addString(outs,"\t\t\tif (%s->notify[%s])\n"
- "\t\t\t\t(*%s->notify[%s])(%s, o, %s);\n", (o->screen)?"os":"od",
- o->temp,(o->screen)?"os":"od",o->temp,
- (o->screen)?"screen":"display",o->temp);
-
- addString(outs,"\t\t\treturn TRUE;\n"
- "\t\t}\n"
- "\t\tbreak;\n");
-
- addGetFunction(o,"CompOption *","Option","","&");
-
- addString(&hfunctions,"void %sSet%sNotify"
- "(%s, %s%sOptionChangeNotifyProc notify);\n",
- data.name,o->fUName,(o->screen)?"CompScreen *s":"CompDisplay *d",
- data.name,(o->screen)?"Screen":"Display");
- addString(&functions,"void %sSet%sNotify"
- "(%s, %s%sOptionChangeNotifyProc notify)\n",
- data.name,o->fUName,(o->screen)?"CompScreen *s":"CompDisplay *d",
- data.name,(o->screen)?"Screen":"Display");
- if (o->screen)
- addString(&functions,"{\n\t%s_OPTIONS_SCREEN(s);\n"
- "\tos->notify[%s] = notify;\n"
- "}\n\n",data.uName,o->temp);
- else
- addString(&functions,"{\n\t%s_OPTIONS_DISPLAY(d);\n"
- "\tod->notify[%s] = notify;\n"
- "}\n\n",data.uName,o->temp);
-
- addString(out,"\n");
- addString(&hfunctions,"\n");
-}
-
-
-void addDisplayOptions()
-{
- char str[1024];
-
- addString(&displayStruct,"typedef struct _%sOptionsDisplay\n"
- "{\n",data.fUName);
- addString(&displayStruct,"\tint screenPrivateIndex;\n\n");
-
- if (nDOptions)
- {
- addString(&setDisplayOpt,"static Bool\n"
- "%sOptionsSetDisplayOption(CompPlugin * plugin, "
- "CompDisplay * display, char *name, CompOptionValue * value)\n{\n"
- "\tCompOption *o;\n\tint index;\n\n"
- "\t%s_OPTIONS_DISPLAY(display);\n\n",data.name,data.uName);
-
- addString(&initDisplay,"\t%sOptionsDisplayInitOptions"
- "(od, d->display);\n\n", data.name);
-
- addString(&initDisplayOpt,"static void %sOptionsDisplayInitOptions"
- "(%sOptionsDisplay * od, Display *display)\n{\n"
- "\tCompOption *o;\n\tint i;\n\ti = 0;\n\n",
- data.name,data.fUName);
-
- addString(&hdefines,"typedef enum\n"
- "{\n");
-
- Option *o = data.options;
- int i = 0;
- while (o)
- {
- if (!o->screen)
- {
- addString(&hdefines,"\t%sDisplayOption%s%s\n",data.fUName,o->fUName,(i == 0)?" = 0,":",");
- sprintf(str,"%sDisplayOption%s",data.fUName,o->fUName);
- o->temp = strdup(str);
- i++;
- }
- o = o->next;
- }
- addString(&hdefines,"\t%sDisplayOptionNum\n",data.fUName);
-
- addString(&hdefines,"} %sDisplayOptions;\n\n",data.fUName);
-
- addString(&hdefines,"typedef void (*%sDisplayOptionChangeNotifyProc)"
- "(CompDisplay *display, CompOption *opt, %sDisplayOptions num);\n\n",
- data.name,data.fUName);
-
- addString(&displayStruct,"\tCompOption opt[%sDisplayOptionNum];\n",data.fUName);
- addString(&displayStruct,"\tCompOption *mOpt;\n",data.fUName);
-
- addString(&displayStruct,"\t%sDisplayOptionChangeNotifyProc "
- "notify[%sDisplayOptionNum];\n",
- data.name,data.fUName);
-
- addString(&setDisplayOpt,"\to = compFindOption(od->opt, %sDisplayOptionNum, name, "
- "&index);\n\n",data.fUName);
-
- addString(&setDisplayOpt,"\tif (!o)\n\t{\n"
- "\t\tif (%sPluginVTable && %sPluginVTable->setDisplayOption)\n"
- "\t\t\treturn (*%sPluginVTable->setDisplayOption)"
- "(plugin, display, name, value);\n\t\treturn FALSE;\n\t}\n\n",
- data.name,data.name,data.name);
-
- addString(&setDisplayOpt,"\tswitch (index)\n\t{\n");
-
- o = data.options;
- while (o)
- {
- if (!o->screen)
- {
- addOption(o);
- }
- o = o->next;
- }
-
- addString(&setDisplayOpt,"\tdefault:\n\t\tbreak;\n\t}\n\treturn FALSE;\n}\n\n");
-
- addString(&initDisplayOpt,"}\n\n");
-
-
- addString(&setDisplayOpt,"static CompOption *%sOptionsGetDisplayOptions"
- "(CompPlugin *p, CompDisplay * d, int *count)\n{\n"
- "\tCompOption *pOpt = NULL;\n\tint pOptNum = 0;\n"
- "\tif (%sPluginVTable && %sPluginVTable->getDisplayOptions)\n"
- "\t\tpOpt = %sPluginVTable->getDisplayOptions(p,d,&pOptNum);\n\n"
- "\t%sOptionsDisplay *od;\n"
- "\tod = GET_%s_OPTIONS_DISPLAY(d);\n"
- "\tif (!pOptNum)\n\t{\n\t\t*count = %sDisplayOptionNum;\n"
- "\t\treturn od->opt;\n\t}\n\n"
- "\tint sOptSize = sizeof(CompOption) * %sDisplayOptionNum;\n"
- "\tint pOptSize = sizeof(CompOption) * pOptNum;\n\n"
- "\tif (!od->mOpt)\n"
- "\t\tod->mOpt = malloc(sOptSize + pOptSize);\n\n"
- "\tmemcpy(od->mOpt,od->opt,sOptSize);\n"
- "\tmemcpy(od->mOpt + %sDisplayOptionNum,pOpt,pOptSize);\n\n"
- "\t*count = %sDisplayOptionNum + pOptNum;\n"
- "\treturn od->mOpt;\n}\n\n",
- data.name,data.name,data.name,data.name,data.fUName,data.uName,
- data.fUName,data.fUName,data.fUName,data.fUName);
-
- addString(&hdefines,"CompOption * %sGetDisplayOption(CompDisplay *d,"
- " %sDisplayOptions num);\n\n",data.name, data.fUName);
-
-
- addString(&functions,"CompOption * %sGetDisplayOption(CompDisplay *d,"
- " %sDisplayOptions num)\n{\n\t%s_OPTIONS_DISPLAY(d);\n"
- "\treturn &od->opt[num];\n}\n\n",
- data.name, data.fUName, data.uName);
-
- }
-
- addString(&displayStruct,"} %sOptionsDisplay;\n\n",data.fUName);
-}
-
-void addScreenOptions()
-{
- char str[1024];
-
- addString(&screenStruct,"typedef struct _%sOptionsScreen\n"
- "{\n",data.fUName);
-
- if (nSOptions)
- {
- addString(&setScreenOpt,"static Bool\n"
- "%sOptionsSetScreenOption(CompPlugin * plugin, "
- "CompScreen * screen, char *name, CompOptionValue * value)\n{\n"
- "\tCompOption *o;\n\tint index;\n\n"
- "\t%s_OPTIONS_SCREEN(screen);\n\n",data.name,data.uName);
-
- addString(&initScreen,"\t%sOptionsScreenInitOptions(os);\n\n",data.name);
-
- addString(&initScreenOpt,"static void %sOptionsScreenInitOptions"
- "(%sOptionsScreen * os)\n{\n"
- "\tCompOption *o;\n\tint i;\n\ti = 0;\n\n",
- data.name,data.fUName);
-
- addString(&hdefines,"typedef enum\n"
- "{\n");
-
- Option *o = data.options;
- int i = 0;
- while (o)
- {
- if (o->screen)
- {
- addString(&hdefines,"\t%sScreenOption%s%s\n",data.fUName,o->fUName,(i == 0)?" = 0,":",");
- sprintf(str,"%sScreenOption%s",data.fUName,o->fUName);
- o->temp = strdup(str);
- i++;
- }
- o = o->next;
- }
- addString(&hdefines,"\t%sScreenOptionNum\n",data.fUName);
-
- addString(&hdefines,"} %sScreenOptions;\n\n",data.fUName);
-
- addString(&hdefines,"typedef void (*%sScreenOptionChangeNotifyProc)"
- "(CompScreen *screen, CompOption *opt, %sScreenOptions num);\n\n",
- data.name,data.fUName);
-
- addString(&screenStruct,"\tCompOption opt[%sScreenOptionNum];\n",data.fUName);
- addString(&screenStruct,"\tCompOption *mOpt;\n",data.fUName);
-
- addString(&screenStruct,"\t%sScreenOptionChangeNotifyProc "
- "notify[%sScreenOptionNum];\n",
- data.name,data.fUName);
-
- addString(&setScreenOpt,"\to = compFindOption(os->opt, %sScreenOptionNum, name, "
- "&index);\n\n",data.fUName);
-
- addString(&setScreenOpt,"\tif (!o)\n\t{\n"
- "\t\tif (%sPluginVTable && %sPluginVTable->setScreenOption)\n"
- "\t\t\treturn (*%sPluginVTable->setScreenOption)"
- "(plugin, screen, name, value);\n\t\treturn FALSE;\n\t}\n\n",
- data.name,data.name,data.name);
-
- addString(&setScreenOpt,"\tswitch (index)\n\t{\n");
-
- o = data.options;
- i = 0;
- while (o)
- {
- if (o->screen)
- {
- addOption(o);
- i++;
- }
- o = o->next;
- }
-
- addString(&setScreenOpt,"\tdefault:\n\t\tbreak;\n\t}\n\treturn FALSE;\n}\n\n");
-
- addString(&initScreenOpt,"}\n\n");
-
- addString(&setScreenOpt,"static CompOption *%sOptionsGetScreenOptions"
- "(CompPlugin * p, CompScreen * s, int *count)\n{\n"
- "\tCompOption *pOpt = NULL;\n\tint pOptNum = 0;\n"
- "\tif (%sPluginVTable && %sPluginVTable->getScreenOptions)\n"
- "\t\tpOpt = %sPluginVTable->getScreenOptions(p,s,&pOptNum);\n\n"
- "\t%sOptionsScreen *os;\n"
- "\tif (s)\n\t\tos = GET_%s_OPTIONS_SCREEN(s, "
- "GET_%s_OPTIONS_DISPLAY(s->display));\n"
- "\telse\n\t{\n\t\tos = calloc(1,sizeof(%sOptionsScreen));\n"
- "\t\t%sOptionsScreenInitOptions(os);\n\t}\n\n"
- "\tif (!pOptNum)\n\t{\n\t\t*count = %sScreenOptionNum;\n"
- "\t\treturn os->opt;\n\t}\n\n"
- "\tint sOptSize = sizeof(CompOption) * %sScreenOptionNum;\n"
- "\tint pOptSize = sizeof(CompOption) * pOptNum;\n\n"
- "\tif (!os->mOpt)\n"
- "\t\tos->mOpt = malloc(sOptSize + pOptSize);\n\n"
- "\tmemcpy(os->mOpt,os->opt,sOptSize);\n"
- "\tmemcpy(os->mOpt + %sScreenOptionNum,pOpt,pOptSize);\n\n"
- "\t*count = %sScreenOptionNum + pOptNum;\n"
- "\treturn os->mOpt;\n}\n\n",
- data.name,data.name,data.name,data.name,data.fUName,data.uName,data.uName,
- data.fUName,data.name,data.fUName,data.fUName,data.fUName,data.fUName);
-
- addString(&hdefines,"CompOption * %sGetScreenOption(CompScreen *d,"
- " %sScreenOptions num);\n\n",data.name, data.fUName);
-
-
- addString(&functions,"CompOption * %sGetScreenOption(CompScreen *d,"
- " %sScreenOptions num)\n{\n\t%s_OPTIONS_SCREEN(d);\n"
- "\treturn &os->opt[num];\n}\n\n",
- data.name, data.fUName, data.uName);
-
- }
-
- addString(&screenStruct,"} %sOptionsScreen;\n\n",data.fUName);
-}
-
-void finilizeCode()
-{
-
- addString(&file,"#include <stdio.h>\n#include <stdlib.h>\n"
- "#include <string.h>\n\n");
-
- addString(&file,"#include <compiz.h>\n\n");
-
- addString(&file,"#define _%s_OPTIONS_INTERNAL\n"
- "#include \"%s\"\n\n",
- data.uName,hFile);
-
- addString(&file,"static int displayPrivateIndex;\n\n");
-
- addString(&file,"static CompPluginVTable *%sPluginVTable = NULL;\n"
- "CompPluginVTable %sOptionsVTable;\n\n",data.name,data.name);
-
- addString(&file,"#define GET_%s_OPTIONS_DISPLAY(d) \\\n"
- "\t((%sOptionsDisplay *) "
- "(d)->privates[displayPrivateIndex].ptr)\n\n",data.uName,data.fUName);
-
- addString(&file,"#define %s_OPTIONS_DISPLAY(d) \\\n"
- "\t%sOptionsDisplay *od = GET_%s_OPTIONS_DISPLAY (d)\n\n",
- data.uName,data.fUName,data.uName);
-
- addString(&file,"#define GET_%s_OPTIONS_SCREEN(s, od) \\\n"
- "\t((%sOptionsScreen *) "
- "(s)->privates[(od)->screenPrivateIndex].ptr)\n\n",data.uName,data.fUName);
-
- addString(&file,"#define %s_OPTIONS_SCREEN(s) \\\n"
- "\t%sOptionsScreen *os = GET_%s_OPTIONS_SCREEN "
- "(s, GET_%s_OPTIONS_DISPLAY (s->display))\n\n",
- data.uName,data.fUName,data.uName,data.uName);
-
- addString(&file,displayStruct.data);
- addString(&file,screenStruct.data);
-
- addString(&file,defines.data);
-
- addString(&file,functions.data);
-
- addString(&file,initScreenOpt.data);
- addString(&file,initDisplayOpt.data);
-
- addString(&file,setScreenOpt.data);
- addString(&file,setDisplayOpt.data);
-
- addString(&file,"static Bool %sOptionsInitScreen"
- "(CompPlugin * p, CompScreen * s)\n{\n\t%sOptionsScreen *os;\n\n"
- "\t%s_OPTIONS_DISPLAY(s->display);\n\n"
- "\tos = calloc(1,sizeof(%sOptionsScreen));\n\tif (!os)\n"
- "\t\treturn FALSE;\n\n"
- "\ts->privates[od->screenPrivateIndex].ptr = os;\n\n",
- data.name,data.fUName,data.uName,data.fUName);
-
- addString(&file,initScreen.data);
-
- addString(&file,"\n\tif (%sPluginVTable && %sPluginVTable->initScreen)\n"
- "\t\treturn %sPluginVTable->initScreen(p,s);\n"
- "\treturn TRUE;\n}\n\n",
- data.name,data.name,data.name);
-
- addString(&file,"static void %sOptionsFiniScreen"
- "(CompPlugin * p, CompScreen * s)\n{\n"
- "\tif (%sPluginVTable && %sPluginVTable->finiScreen)\n"
- "\t\t%sPluginVTable->finiScreen(p,s);\n\n"
- "\t%s_OPTIONS_SCREEN(s);\n\t%s_OPTIONS_DISPLAY(s->display);\n\n",
- data.name,data.name,data.name,data.name,data.uName,data.uName);
-
- addString(&file,finiScreen.data);
-
- addString(&file,"\tfree(os);\n\tod = NULL;\n}\n\n");
-
- addString(&file,"static Bool %sOptionsInitDisplay"
- "(CompPlugin * p, CompDisplay * d)\n{\n\t%sOptionsDisplay *od;\n\n"
- "\tod = calloc(1,sizeof(%sOptionsDisplay));\n\tif (!od)\n"
- "\t\treturn FALSE;\n\n"
- "\tod->screenPrivateIndex = allocateScreenPrivateIndex(d);\n"
- "\tif (od->screenPrivateIndex < 0)\n\t{\n\t\tfree(od);\n"
- "\t\treturn FALSE;\n\t}\n\n"
- "\td->privates[displayPrivateIndex].ptr = od;\n\n",
- data.name,data.fUName,data.fUName);
-
- addString(&file,initDisplay.data);
-
- addString(&file,"\n\tif (%sPluginVTable && %sPluginVTable->initDisplay)\n"
- "\t\treturn %sPluginVTable->initDisplay(p,d);\n"
- "\treturn TRUE;\n}\n\n",
- data.name,data.name,data.name);
-
- addString(&file,"static void %sOptionsFiniDisplay"
- "(CompPlugin * p, CompDisplay * d)\n{\n"
- "\tif (%sPluginVTable && %sPluginVTable->finiDisplay)\n"
- "\t\t%sPluginVTable->finiDisplay(p,d);\n\n"
- "\t%s_OPTIONS_DISPLAY(d);\n\n"
- "\tfreeScreenPrivateIndex(d, od->screenPrivateIndex);\n\n",
- data.name,data.name,data.name,data.name,data.uName);
-
- addString(&file,finiDisplay.data);
-
- addString(&file,"\tfree(od);\n}\n\n");
-
- addString(&file,"static Bool %sOptionsInit(CompPlugin * p)\n{\n"
- "\tdisplayPrivateIndex = allocateDisplayPrivateIndex();\n"
- "\tif (displayPrivateIndex < 0)\n\t\treturn FALSE;\n"
- "\tif (%sPluginVTable && %sPluginVTable->init)\n"
- "\t\treturn %sPluginVTable->init(p);\n\treturn TRUE;\n}\n\n",
- data.name,data.name,data.name,data.name);
-
- addString(&file,"static void %sOptionsFini(CompPlugin * p)\n{\n"
- "\tif (%sPluginVTable && %sPluginVTable->fini)\n"
- "\t\t%sPluginVTable->fini(p);\n"
- "\tif (displayPrivateIndex >= 0)\n"
- "\t\tfreeDisplayPrivateIndex(displayPrivateIndex);\n}\n\n",
- data.name,data.name,data.name,data.name);
-
- addString(&file,"CompPluginVTable *getCompPluginInfo(void)\n{\n"
- "\tif (!%sPluginVTable)\n\t{\n"
- "\t\t%sPluginVTable = %sOptionsGetCompPluginInfo();\n"
- "\t\tmemcpy(&%sOptionsVTable,%sPluginVTable,"
- "sizeof(CompPluginVTable));\n",
- data.name,data.name,data.name,data.name,data.name);
-
- addString(&file,"\t\t%sOptionsVTable.init = %sOptionsInit;\n"
- "\t\t%sOptionsVTable.fini = %sOptionsFini;\n"
- "\t\t%sOptionsVTable.initDisplay = %sOptionsInitDisplay;\n"
- "\t\t%sOptionsVTable.finiDisplay = %sOptionsFiniDisplay;\n"
- "\t\t%sOptionsVTable.initScreen = %sOptionsInitScreen;\n"
- "\t\t%sOptionsVTable.finiScreen = %sOptionsFiniScreen;\n",
- data.name,data.name,data.name,data.name,data.name,data.name,
- data.name,data.name,data.name,data.name,data.name,data.name);
-
- if (nSOptions)
- {
- addString(&file,"\t\t%sOptionsVTable.getScreenOptions = "
- "%sOptionsGetScreenOptions;\n"
- "\t\t%sOptionsVTable.setScreenOption = "
- "%sOptionsSetScreenOption;\n",
- data.name,data.name,data.name,data.name);
- }
-
- if (nDOptions)
- {
- addString(&file,"\t\t%sOptionsVTable.getDisplayOptions = "
- "%sOptionsGetDisplayOptions;\n"
- "\t\t%sOptionsVTable.setDisplayOption = "
- "%sOptionsSetDisplayOption;\n",
- data.name,data.name,data.name,data.name);
- }
-
- addString(&file,"\t}\n\treturn &%sOptionsVTable;\n}\n",data.name);
-
- addString(&header,"#ifndef _%s_OPTIONS_H\n"
- "#define _%s_OPTIONS_H\n\n",data.uName,data.uName);
-
- addString(&header,"#ifndef _%s_OPTIONS_INTERNAL\n"
- "#define getCompPluginInfo %sOptionsGetCompPluginInfo\n"
- "#endif\n\n",data.uName,data.name);
-
- addString(&header,"CompPluginVTable *%sOptionsGetCompPluginInfo(void);\n\n"
- ,data.name);
-
- addString(&header,hdefines.data);
- addString(&header,hfunctions.data);
- addString(&header,"#endif\n\n");
-}
-
-
-static int writeFiles(char *src, char *hdr)
-{
-
- if (src)
- {
- if (!quiet) printf("Creating \"%s\"...",src);
-
- FILE *f = fopen(src,"w");
- if (!f)
- {
- if (!quiet) printf("error\n");
- fprintf(stderr,"Unable to write \"%s\"!\n",src);
- return 1;
- }
- fprintf(f,"%s",file.data);
- fclose(f);
- if (!quiet) printf("done\n");
- }
-
- if (hdr)
- {
- if (!quiet) printf("Creating \"%s\"...",hdr);
-
- FILE *f = fopen(hdr,"w");
- if (!f)
- {
- if (!quiet) printf("error\n");
- fprintf(stderr,"Unable to write \"%s\"!\n",hdr);
- return 1;
- }
- fprintf(f,"%s",header.data);
- fclose(f);
- if (!quiet) printf("done\n");
- }
- return 0;
-}
-
-void addFileHeaders()
-{
- char str[1024];
- sprintf(str,"/*\n"
- " *\n"
- " * This file is autogenerated from :\n"
- " * %s with the Beryl/Compiz optionss parser (%s)\n"
- " *\n"
- " * This program is distributed in the hope that it will be useful,\n"
- " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- " * GNU General Public License for more details.\n"
- " *\n"
- " */\n\n",
- fileName,basename(programName));
- addString(&file,str);
- addString(&header,str);
-}
-
-int genCode(char *src, char *hdr)
-{
- initStrings();
- Option *o = data.options;
- while (o)
- {
- nOptions++;
- if (o->screen)
- nSOptions++;
- else
- nDOptions++;
- o = o->next;
- }
-
- if (hdr)
- hFile = hdr;
- else
- {
- char str[1024];
- char *prefix = strtok(basename(strdup(fileName)),".");
- if (!prefix || !strlen(prefix))
- prefix = data.name;
- sprintf(str,"%s_options.h",prefix);
- hFile = strdup(str);
- }
-
- if (!quiet) printf("Generating code for %d settings...",nOptions);
-
- addFileHeaders();
- addDisplayOptions();
- addScreenOptions();
- finilizeCode();
-
- if (!quiet) printf("done\n");
-
- return writeFiles(src, hdr);
-}
diff --git a/src/schema_generator.c b/src/schema_generator.c
deleted file mode 100644
index 9209a7d..0000000
--- a/src/schema_generator.c
+++ /dev/null
@@ -1,450 +0,0 @@
-//TODO - add license header
-//some code from gconf-dump.c
-
-#ifdef HAVE_CONFIG_H
-# include "../config.h"
-#endif
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <ctype.h>
-#include <math.h>
-#include <errno.h>
-#include <libgen.h>
-#include <X11/Xlib.h>
-
-#include "bcop.h"
-
-static char *edgeName[] = {
- "Left",
- "Right",
- "Top",
- "Bottom",
- "TopLeft",
- "TopRight",
- "BottomLeft",
- "BottomRight"
-};
-
-int nEdges=sizeof(edgeName)/sizeof(edgeName[0]);
-
-enum {
- actionPartKey,
- actionPartButton,
- actionPartBell,
- actionPartEdge,
-};
-
-char * actPartInfo[][3]={
- {"key","Key","Key Binding"},
- {"button","Button","Mouse Button Binding"},
- {"bell","Bell","System Bell Binding"},
- {"edge","Edge","Screen Edge Binding"},
-};
-int nActParts=sizeof(actPartInfo)/sizeof(actPartInfo[0]);
-
-static FILE * schemaFile;
-
-//Nice little function from gconf-dump.c to pretty-print output
-//modified to append \n to each line automatically
-static void
-gconfPrintf (int level, char *format, ...)
-{
- va_list args;
-
- if (level > 0) {
- int i;
-
- for (i = 0; i < level * 2; i++)
- fprintf (schemaFile, " ");
- }
-
- va_start (args, format);
- vfprintf (schemaFile, format, args);
- va_end (args);
- fprintf(schemaFile,"\n");
-}
-
-void gconfEscapeXML(char * value)
-{
- char srcBuffer[8192];
- char destBuffer[8192];
- char tempBuffer[8192];
- char * indx;
- strcpy(srcBuffer,value);
- destBuffer[0]='\0';
- for (indx=srcBuffer;*indx;indx++)
- {
- strcpy(tempBuffer,destBuffer);
- char * rep=NULL;
- switch(*indx)
- {
- case '&':
- rep="&amp;";
- break;
- case '<':
- rep="&lt;";
- break;
- case '>':
- rep="&gt;";
- break;
- default:
- break;
- }
- if (rep)
- sprintf(destBuffer,"%s%s",tempBuffer,rep);
- else
- sprintf(destBuffer,"%s%c",tempBuffer,*indx);
- }
- strcpy(value,destBuffer);
-}
-
-void gconfWriteHeader()
-{
- gconfPrintf(0,"<!-- schema file written by bcop -->");
- gconfPrintf(0,"<gconfschemafile>");
- gconfPrintf(1,"<schemalist>");
- gconfPrintf(2,"<!-- options for %s -->",data.name);
-}
-
-void gconfWriteFooter()
-{
- gconfPrintf(1,"</schemalist>");
- gconfPrintf(0,"</gconfschemafile>");
-}
-
-//swiped from gconf-dump.c
-static char *
-gconfTypeToString (OptionType type, int actionPart)
-{
- switch (type) {
- case OptionTypeAction:
- switch(actionPart)
- {
- case actionPartBell:
- return "bool";
- case actionPartKey:
- case actionPartButton:
- return "string";
- case actionPartEdge:
- return "list";
- default:
- break;
- }
- break;
- case OptionTypeBool:
- return "bool";
- case OptionTypeString:
- case OptionTypeColor:
- case OptionTypeMatch:
- case OptionTypeEnum:
- return "string";
- case OptionTypeInt:
- return "int";
- case OptionTypeFloat:
- return "float";
- case OptionTypeSelection:
- case OptionTypeStringList:
- return "list";
- default:
- break;
- }
-
- return "unknown";
-}
-
-static char * modifiers[] = {
- "Shift",
- "Control",
- "Mod1",
- "Mod2",
- "Mod3",
- "Mod4",
- "Mod5",
- "Alt",
- "Meta",
- "Super",
- "Hyper",
- "ModeSwitch",
-};
-
-int nModifiers=sizeof(modifiers)/sizeof(modifiers[0]);
-
-char * gconfConvertModifiers(char * value, char * ret)
-{
- char tempBuffer[8192];
- char tokBuffer[8192];
- char valBuffer[8192];
- strcpy(tokBuffer,value);
- char * tok;
- ret[0]='\0';
- for (tok=strtok(tokBuffer,"+");tok;tok=strtok(NULL,"+"))
- {
- strcpy(tempBuffer,ret);
- int i;
- for (i=0;i<nModifiers;i++)
- {
- if (!strcmp(tok,modifiers[i]))
- {
- sprintf(ret,"%s<%s>",tempBuffer,tok);
- break;
- }
- }
- if (i==nModifiers)
- strcpy(valBuffer,tok);
- }
- strcpy(tempBuffer,ret);
- sprintf(ret,"%s%s",tempBuffer,valBuffer);
- return ret;
-}
-
-int gconfGetDefaultValue (Option * o, char * value, int actionPart)
-{
- OptionValuesList * l;
- int i;
- char tempBuffer[8192];
- switch (o->type)
- {
- case OptionTypeAction:
- switch(actionPart)
- {
- case actionPartKey:
- if (o->data.asBind.skey)
- sprintf(value,"%s",
- gconfConvertModifiers(
- o->data.asBind.key,
- tempBuffer));
- else
- sprintf(value,"None");
- return 1;
- case actionPartButton:
- if (o->data.asBind.smouse)
- sprintf(value,"%s",
- gconfConvertModifiers(
- o->data.asBind.mouse,
- tempBuffer));
- else
- sprintf(value,"None");
- return 1;
- case actionPartBell:
- sprintf(value,
- (o->data.asBind.sbell?
- (o->data.asBind.bell?"true":"false"):"false"));
- return 1;
- case actionPartEdge:
- if (o->data.asBind.sedge)
- {
- tempBuffer[0]='\0';
- for (i=0;i<nEdges;i++)
- {
- strcpy(value,tempBuffer);
- if (o->data.asBind.edge & 1<<i)
- {
- if (tempBuffer[0])
- sprintf(tempBuffer,"%s,%s",value,
- edgeName[i]);
- else
- sprintf(tempBuffer,"%s",edgeName[i]);
- }
- }
- sprintf(value,"[%s]",tempBuffer);
- }
- else
- sprintf(value,"[]");
- return 1;
- default:
- break;
- }
- break;
- case OptionTypeInt:
- sprintf(value,"%d",o->data.asInt.def);
- return 1;
- case OptionTypeFloat:
- sprintf(value,"%f",o->data.asFloat.def);
- return 1;
- case OptionTypeBool:
- sprintf(value,"%s",(o->data.asBool.def?"true":"false"));
- return 1;
- case OptionTypeColor:
- sprintf(value,"#%.2x%.2x%.2x%.2x",
- o->data.asColor.red>>8,
- o->data.asColor.green>>8,
- o->data.asColor.blue>>8,
- o->data.asColor.alpha>>8);
- return 1;
- case OptionTypeString:
- sprintf(value,"%s",o->data.asString.def);
- return 1;
- case OptionTypeMatch:
- sprintf(value,"%s",o->data.asMatch.def);
- return 1;
- case OptionTypeEnum:
- for(l=o->data.asSList.begin;l;l=l->next)
- {
- if (l->def)
- sprintf(value,"%s",l->value);
- return 1;
- }
- break;
- case OptionTypeStringList:
- case OptionTypeSelection:
- if (!o->data.asSList.begin)
- {
- sprintf(value,"[]");
- return 1;
- }
- tempBuffer[0]='\0';
- for (l=o->data.asSList.begin;l;l=l->next)
- {
- if (o->type==OptionTypeStringList || l->def)
- {
- strcpy(value,tempBuffer);
- if (value[0])
- sprintf(tempBuffer,"%s,%s",value,l->value);
- else
- sprintf(tempBuffer,"%s",l->value);
- }
- }
- sprintf(value,"[%s]",tempBuffer);
- return 1;
- default:
- break;
- }
- return 0;
-}
-
-int gconfGetSubInfo (Option * o, char * subInfo, int actionPart)
-{
- OptionValuesList * l;
- char tempBuffer[8192];
- switch (o->type)
- {
- case OptionTypeAction:
- sprintf(subInfo,"%s",actPartInfo[actionPart][2]);
- return 1;
- case OptionTypeInt:
- sprintf(subInfo,"%d-%d",o->data.asInt.min,o->data.asInt.max);
- return 1;
- case OptionTypeFloat:
- sprintf(subInfo,"%f-%f",o->data.asFloat.min,o->data.asFloat.max);
- return 1;
- case OptionTypeEnum:
- case OptionTypeSelection:
- if (!o->data.asSList.begin)
- return 0;
- subInfo[0]='\0';
- for (l=o->data.asSList.begin;l;l=l->next)
- {
- strcpy(tempBuffer,subInfo);
- if (subInfo[0])
- sprintf(subInfo,"%s, %s",tempBuffer,l->value);
- else
- sprintf(subInfo,"%s",l->value);
- }
- return 1;
- default:
- break;
- }
- return 0;
-}
-
-void gconfDumpToSchema(Option * o, char * pathFmt, char * subkey,
- int actionPart)
-{
- char path[1024];
- char subInfo[8192];
- char value[8192];
- sprintf(path,pathFmt,subkey,o->name);
- if (o->type == OptionTypeAction)
- {
- strcpy(subInfo,path);
- sprintf(path,"%s_%s",subInfo,actPartInfo[actionPart][0]);
- }
- gconfPrintf(2,"<schema>");
- gconfPrintf(3,"<key>/schemas%s</key>",path);
- gconfPrintf(3,"<applyto>%s</applyto>",path);
- gconfPrintf(3,"<owner>compiz</owner>");
- gconfPrintf(3,"<type>%s</type>",gconfTypeToString(o->type,actionPart));
- if (!strcmp(gconfTypeToString(o->type,actionPart),"list"))
- gconfPrintf(3,"<list_type>string</list_type>");
- if (gconfGetDefaultValue(o,value,actionPart))
- {
- gconfEscapeXML(value);
- gconfPrintf(3,"<default>%s</default>",value);
- }
- else
- gconfPrintf(3,"<!-- type not implemented yet -->");
- gconfPrintf(3,"<locale name=\"C\">");
- if (o->type == OptionTypeAction)
- gconfPrintf(4,"<short>%s %s</short>",o->shortDesc,
- actPartInfo[actionPart][1]);
- else
- gconfPrintf(4,"<short>%s</short>",o->shortDesc);
- if(gconfGetSubInfo(o,subInfo,actionPart))
- gconfPrintf(4,"<long>%s (%s)</long>",o->longDesc,subInfo);
- else
- gconfPrintf(4,"<long>%s</long>",o->longDesc);
- gconfPrintf(3,"</locale>");
- gconfPrintf(2,"</schema>");
-}
-
-void gconfWriteSchema(int is_general)
-{
- char * pluginPathFmtFmt = "/apps/compiz/plugins/%s/%%s/options/%%s";
- char pluginPathFmt[1024];
- char * generalPathFmt = "/apps/compiz/general/%s/options/%s";
- char * pathFmt;
- sprintf(pluginPathFmt,pluginPathFmtFmt,data.name);
- if (is_general)
- pathFmt = generalPathFmt;
- else
- pathFmt = pluginPathFmt;
- gconfWriteHeader();
- Option * o = data.options;
- while (o)
- {
- if (o->type==OptionTypeAction)
- {
- int i;
- for (i=0;i<nActParts;i++)
- gconfDumpToSchema(o, pathFmt,
- (o->screen?"screen0":"allscreens"),i);
- }
- else
- {
- gconfDumpToSchema(o, pathFmt,
- (o->screen?"screen0":"allscreens"),0);
- }
- o=o->next;
- }
- gconfWriteFooter();
-}
-
-int genSchema(char *sch)
-{
- int rv=0;
-
- printf("Creating \"%s\"...", sch);
- schemaFile = fopen(sch,"w");
- if (!schemaFile)
- {
- fprintf (stderr, "Could not open %s: %s\n", sch,
- strerror (errno));
- return 1;
- }
- switch (data.mode)
- {
- case SchemaGConf:
- gconfWriteSchema(0); // General not yet supported/possible
- break;
- default:
- rv=2; // unknown mode
- }
- fclose(schemaFile);
-
- printf("done.\n");
- return rv;
-}
diff --git a/src/xml_parser.c b/src/xml_parser.c
deleted file mode 100644
index d8b2b3d..0000000
--- a/src/xml_parser.c
+++ /dev/null
@@ -1,1051 +0,0 @@
-/*
- *
- * Beryl/Compiz options parser
- *
- * Copyright : (C) 2007 by Dennis Kasprzyk
- * E-mail : onestone@beryl-project.org
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include "../config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <math.h>
-#include <libgen.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include "bcop.h"
-
-Context data;
-char *programName = NULL;
-char *fileName = NULL;
-int quiet = 0;
-
-int error;
-
-static void parseElements(xmlDoc *doc, ParserState* pState, xmlNode *node);
-
-static int nameCheck(char * str)
-{
- if (!str)
- return 0;
- if (!strlen(str))
- return 0;
- int i = 0;
- for (i = 0; i < strlen(str);i++)
- if (isspace(str[i]) || !isprint(str[i]))
- return 0;
- return 1;
-}
-
-static void
-initData()
-{
- data.name = NULL;
- data.options = NULL;
- data.mode = GenNone;
-}
-
-static OptionType get_Option_type(xmlChar * type)
-{
- if (!xmlStrcmp(type, (const xmlChar *) "int"))
- return OptionTypeInt;
- if (!xmlStrcmp(type, (const xmlChar *) "bool"))
- return OptionTypeBool;
- if (!xmlStrcmp(type, (const xmlChar *) "float"))
- return OptionTypeFloat;
- if (!xmlStrcmp(type, (const xmlChar *) "string"))
- return OptionTypeString;
- if (!xmlStrcmp(type, (const xmlChar *) "stringlist"))
- return OptionTypeStringList;
- if (!xmlStrcmp(type, (const xmlChar *) "enum"))
- return OptionTypeEnum;
- if (!xmlStrcmp(type, (const xmlChar *) "selection"))
- return OptionTypeSelection;
- if (!xmlStrcmp(type, (const xmlChar *) "color"))
- return OptionTypeColor;
- if (!xmlStrcmp(type, (const xmlChar *) "action"))
- return OptionTypeAction;
- if (!xmlStrcmp(type, (const xmlChar *) "match"))
- return OptionTypeMatch;
- return OptionTypeError;
-}
-
-static void
-parseIntOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "min")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asInt.min = strtol((char *)key,NULL,0);
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "max")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asInt.max = strtol((char *)key,NULL,0);
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asInt.def = strtol((char *)key,NULL,0);
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseBoolOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asBool.def = (strcasecmp((char *)key,"true") == 0);
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseFloatOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "min")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asFloat.min = strtod((char *)key,NULL);
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "max")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asFloat.max = strtod((char *)key,NULL);
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "precision")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asFloat.precision = strtod((char *)key,NULL);
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asFloat.def = strtod((char *)key,NULL);
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseStringOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asString.def = strdup((key)?(char *)key:"");
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseMatchOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asMatch.def = strdup((key)?(char *)key:"");
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseColorOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "red")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asColor.red =
- MAX(0,MIN(0xffff,strtol((char *)key,NULL,0)));
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "green")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asColor.green =
- MAX(0,MIN(0xffff,strtol((char *)key,NULL,0)));
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "blue")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asColor.blue =
- MAX(0,MIN(0xffff,strtol((char *)key,NULL,0)));
- xmlFree(key);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "alpha")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- set->data.asColor.alpha =
- MAX(0,MIN(0xffff,strtol((char *)key,NULL,0)));
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseStringListOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "default")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if (key && strlen((char *)key))
- {
- OptionValuesList *lv = calloc(1,sizeof(OptionValuesList));
- lv->value = strdup((char *)key);
- xmlChar *raw = xmlGetProp(cur, (xmlChar *)"raw");
- if (raw && strcasecmp((char *)raw,"true") == 0)
- lv->raw = 1;
- xmlFree(raw);
- if (!set->data.asSList.begin && !set->data.asSList.end)
- {
- set->data.asSList.begin = set->data.asSList.end = lv;
- }
- else
- {
- set->data.asSList.end->next = lv;
- set->data.asSList.end = lv;
- }
- }
- xmlFree(key);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseEnumOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "value")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- xmlChar *name;
- name = xmlGetProp(cur, (xmlChar *)"name");
- if (!nameCheck((char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: wrong value name \"%s\"\n",name);
- xmlFree(name);
- xmlFree(key);
- continue;
- }
- OptionValuesList *l = set->data.asSList.begin;
- while (l && name)
- {
- if (!strcasecmp(l->name,(char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: value with same name already defined \"%s\"\n",name);
- xmlFree(name);
- xmlFree(key);
- name = NULL;
- key = NULL;
- continue;
- }
- l = l->next;
- }
- if (name && strlen((char *)name))
- {
- OptionValuesList *lv = calloc(1,sizeof(OptionValuesList));
- lv->value = (key && strlen((char *)key)) ?
- strdup((char *)key) : strdup((char *)name);
- lv->name = strToLower((char *)name);
- lv->uName = strToUpper((char *)name);
- lv->fUName = strToFirstUp((char *)name);
- xmlChar *def;
- def = xmlGetProp(cur, (xmlChar *)"default");
- if (def && strcasecmp((char *)def,"true") == 0)
- lv->def = 1;
- xmlFree(def);
- if (!set->data.asSList.begin && !set->data.asSList.end)
- {
- set->data.asSList.begin = set->data.asSList.end = lv;
- }
- else
- {
- set->data.asSList.end->next = lv;
- set->data.asSList.end = lv;
- }
- }
- xmlFree(key);
- xmlFree(name);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseSelectionOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "value")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- xmlChar *name;
- name = xmlGetProp(cur, (xmlChar *)"name");
- if (!nameCheck((char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: wrong value name \"%s\"\n",name);
- xmlFree(name);
- xmlFree(key);
- continue;
- }
- OptionValuesList *l = set->data.asSList.begin;
- while (l && name)
- {
- if (!strcasecmp(l->name,(char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: value with same name already defined \"%s\"\n",name);
- xmlFree(name);
- xmlFree(key);
- name = NULL;
- key = NULL;
- continue;
- }
- l = l->next;
- }
- if (key && strlen((char *)key) && name && strlen((char *)name))
- {
- OptionValuesList *lv = calloc(1,sizeof(OptionValuesList));
- lv->value = (key && strlen((char *)key)) ?
- strdup((char *)key) : strdup((char *)name);
- lv->name = strToLower((char *)name);
- lv->uName = strToUpper((char *)name);
- lv->fUName = strToFirstUp((char *)name);
- xmlChar *def;
- def = xmlGetProp(cur, (xmlChar *)"default");
- if (def && strcasecmp((char *)def,"true") == 0)
- lv->def = 1;
- xmlFree(def);
- if (!set->data.asSList.begin && !set->data.asSList.end)
- {
- set->data.asSList.begin = set->data.asSList.end = lv;
- }
- else
- {
- set->data.asSList.end->next = lv;
- set->data.asSList.end = lv;
- }
- }
- xmlFree(key);
- xmlFree(name);
- }
- cur = cur->next;
- }
-}
-
-static void
-parseActionOption(xmlDoc *doc, xmlNode *node, Option *set)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "key")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if (key && strlen((char *)key))
- {
- set->data.asBind.type |= CompBindingTypeKey;
- set->data.asBind.skey = 1;
- set->data.asBind.key = strdup((char *)key);
- }
- xmlFree(key);
- xmlChar *state;
- state = xmlGetProp(cur, (xmlChar *)"state");
-
- if (!state)
- {
- set->data.asBind.state |= CompActionStateInitKey;
- }
- else
- {
- char *tok = strtok((char *)state,",");
- while (tok)
- {
- if (!strcasecmp(tok,"init"))
- set->data.asBind.state |= CompActionStateInitKey;
- else if (!strcasecmp(tok,"term"))
- set->data.asBind.state |= CompActionStateTermKey;
- tok = strtok(NULL,",");
- }
- }
- xmlFree(state);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "mouse")) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if (key && strlen((char *)key))
- {
- set->data.asBind.type |= CompBindingTypeButton;
- set->data.asBind.smouse = 1;
- set->data.asBind.mouse = strdup((char *)key);
- }
- xmlFree(key);
- xmlChar *state;
- state = xmlGetProp(cur, (xmlChar *)"state");
- if (!state)
- {
- set->data.asBind.state |= CompActionStateInitButton;
- }
- else
- {
- char *tok = strtok((char *)state,",");
- while (tok)
- {
- if (!strcasecmp(tok,"init"))
- set->data.asBind.state |= CompActionStateInitButton;
- else if (!strcasecmp(tok,"term"))
- set->data.asBind.state |= CompActionStateTermButton;
- tok = strtok(NULL,",");
- }
- }
- xmlFree(state);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "edge")) {
- set->data.asBind.sedge = 1;
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- char *tok = strtok((char *)key,",");
- while (tok && key)
- {
- if (!strcasecmp(tok,"left"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_LEFT);
- else if (!strcasecmp(tok,"right"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_RIGHT);
- else if (!strcasecmp(tok,"top"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_TOP);
- else if (!strcasecmp(tok,"bottom"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_BOTTOM);
- else if (!strcasecmp(tok,"topleft"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_TOPLEFT);
- else if (!strcasecmp(tok,"topright"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_TOPRIGHT);
- else if (!strcasecmp(tok,"bottomleft"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_BOTTOMLEFT);
- else if (!strcasecmp(tok,"bottomright"))
- set->data.asBind.edge |= (1 << SCREEN_EDGE_BOTTOMRIGHT);
- tok = strtok(NULL,",");
- }
- xmlFree(key);
- xmlChar *state;
- state = xmlGetProp(cur, (xmlChar *)"state");
- if (!state)
- {
- set->data.asBind.state |= CompActionStateInitEdge;
- }
- else
- {
- char *tok = strtok((char *)state,",");
- while (tok)
- {
- if (!strcasecmp(tok,"init"))
- set->data.asBind.state |= CompActionStateInitEdge;
- else if (!strcasecmp(tok,"term"))
- set->data.asBind.state |= CompActionStateTermEdge;
- else if (!strcasecmp(tok,"initdnd"))
- set->data.asBind.state |= CompActionStateInitEdgeDnd;
- else if (!strcasecmp(tok,"termdnd"))
- set->data.asBind.state |= CompActionStateTermEdgeDnd;
- tok = strtok(NULL,",");
- }
- }
- xmlFree(state);
- } else if (!xmlStrcmp(cur->name, (const xmlChar *) "bell")) {
- set->data.asBind.sbell = 1;
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- if (key)
- set->data.asBind.bell = (strcasecmp((char *)key,"true") == 0);
- xmlFree(key);
- set->data.asBind.state |= CompActionStateInitBell;
- }
- cur = cur->next;
- }
-}
-
-
-
-static void
-parseOption(xmlDoc *doc, ParserState* pState, xmlNode *node)
-{
- xmlNode *cur = node;
- xmlChar *name;
- name = xmlGetProp(cur, (xmlChar *)"name");
- if (!name)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no Option name defined\n");
- xmlFree(name);
- return;
- }
- if (!nameCheck((char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: wrong Option name \"%s\"\n",name);
- xmlFree(name);
- return;
- }
- xmlChar *type;
- type = xmlGetProp(cur, (xmlChar *)"type");
- if (!type)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no Option type defined\n");
- xmlFree(name);
- xmlFree(type);
- return;
- }
-
- OptionType sType = get_Option_type(type);
-
- if (sType == OptionTypeError)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: wrong Option type \"%s\"\n",(char *)type);
- xmlFree(name);
- xmlFree(type);
- return;
- }
- if (sType == OptionTypeAction && pState->screen)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: action defination in screen section\n");
- xmlFree(name);
- xmlFree(type);
- return;
- }
- xmlFree(type);
-
- Option *set = data.options;
- while (set != NULL)
- {
- if (!strcmp(set->name,(char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: Option \"%s\" already defined\n",name);
- xmlFree(name);
- return;
- }
- set = set->next;
- }
-
- Option *ns = calloc(1, sizeof(Option));
- ns->name = strToLower((char *)name);
- ns->uName = strToUpper((char *)name);
- ns->fUName = strToCamel((char *)name);
- ns->type = sType;
- ns->group = (pState->group)?strdup(pState->group):NULL;
- ns->subGroup = (pState->subGroup)?strdup(pState->subGroup):NULL;
- ns->screen = pState->screen;
-
- xmlChar *adv;
- adv = xmlGetProp(cur, (xmlChar *)"name");
- if (adv && strcasecmp((char *)adv,"true") == 0)
- ns->advanced = 1;
- else
- ns->advanced = 0;
- xmlFree(adv);
-
- if (!data.options)
- {
- data.options = ns;
- }
- else
- {
- Option *s = data.options;
- while (s->next != NULL) s = s->next;
- s->next = ns;
- }
- cur = node->xmlChildrenNode;
-
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "short") && !ns->shortDesc) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- ns->shortDesc = strdup((char *)key);
- xmlFree(key);
- } else
- if (!xmlStrcmp(cur->name, (const xmlChar *) "long") && !ns->longDesc) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- ns->longDesc = strdup((char *)key);
- xmlFree(key);
- }
- if (!xmlStrcmp(cur->name, (const xmlChar *) "hints") && !ns->hints) {
- xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
- ns->hints = strdup((char *)key);
- xmlFree(key);
- }
- cur = cur->next;
- }
- xmlFree(name);
-
- switch (ns->type)
- {
- case OptionTypeInt:
- parseIntOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeBool:
- parseBoolOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeFloat:
- parseFloatOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeString:
- parseStringOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeStringList:
- parseStringListOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeEnum:
- parseEnumOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeSelection:
- parseSelectionOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeColor:
- parseColorOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeAction:
- parseActionOption(doc, node->xmlChildrenNode, ns);
- break;
- case OptionTypeMatch:
- parseMatchOption(doc, node->xmlChildrenNode, ns);
- break;
- default:
- break;
- }
-}
-
-static void
-parseSubGroup(xmlDoc *doc, ParserState* pState, xmlNode *node)
-{
- xmlNode *cur = node;
- xmlChar *name;
- name = xmlGetProp(cur, (xmlChar *)"name");
- if (!name)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no subgroup name defined\n");
- xmlFree(name);
- return;
- }
- if (pState->subGroup)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: recursive subgroup defined\n");
- xmlFree(name);
- return;
- }
-
-
- pState->subGroup = (char *)name;
- parseElements(doc, pState, node->xmlChildrenNode);
- pState->subGroup = NULL;
- xmlFree(name);
-}
-
-static void
-parseGroup(xmlDoc *doc, ParserState* pState, xmlNode *node)
-{
- xmlNode *cur = node;
- xmlChar *name;
- name = xmlGetProp(cur, (xmlChar *)"name");
- if (!name)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no group name defined\n");
- xmlFree(name);
- return;
- }
- if (pState->group)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: recursive group defined\n");
- xmlFree(name);
- return;
- }
- if (pState->subGroup)
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no group defination inside of subgroup definition allowed\n");
- xmlFree(name);
- return;
- }
-
- pState->group = (char *)name;
- parseElements(doc, pState, node->xmlChildrenNode);
- pState->group = NULL;
- xmlFree(name);
-}
-
-static void
-parseElements(xmlDoc *doc, ParserState* pState, xmlNode *node)
-{
- xmlNode *cur = node;
- while (cur != NULL)
- {
- if (!xmlStrcmp(cur->name, (const xmlChar *) "group")) {
- parseGroup(doc, pState, cur);
- } else
- if (!xmlStrcmp(cur->name, (const xmlChar *) "subgroup")) {
- parseSubGroup(doc, pState, cur);
- } else
- if (!xmlStrcmp(cur->name, (const xmlChar *) "option")) {
- parseOption(doc, pState, cur);
- }
- cur = cur->next;
- }
-
-}
-
-static void
-parseOptionFile(xmlDoc *doc)
-{
- xmlNode *root_element = NULL;
- ParserState pState;
- pState.screen = 0;
- pState.group = NULL;
- pState.subGroup = NULL;
-
- root_element = xmlDocGetRootElement(doc);
-
- if (root_element == NULL) {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: empty document\n");
- return;
- }
- if (xmlStrcmp(root_element->name, (const xmlChar *) "plugin")) {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: document of the wrong type, root node != plugin");
- return;
- }
-
- xmlChar *name;
- name = xmlGetProp(root_element, (xmlChar *)"name");
- if (!name || !strlen((char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: no plugin name defined\n");
- xmlFree(name);
- return;
- }
- if (!nameCheck((char *)name))
- {
- if (!error) printf("error\n");
- error = 1;
- fprintf(stderr,"[ERROR]: plugin name has to be a single word\n");
- xmlFree(name);
- return;
- }
- data.name = strToLower((char *)name);
- data.uName = strToUpper((char *)name);
- data.fUName = strToFirstUp((char *)name);
-
- xmlNode *pc = root_element->xmlChildrenNode;
-
- while (pc != NULL)
- {
- if (!xmlStrcmp(pc->name, (const xmlChar *)"screen"))
- {
- pState.screen = 1;
- parseElements(doc, &pState, pc->xmlChildrenNode);
- } else if (!xmlStrcmp(pc->name, (const xmlChar *)"display"))
- {
- pState.screen = 0;
- parseElements(doc, &pState, pc->xmlChildrenNode);
- }
- pc = pc->next;
- }
- xmlFree(name);
-}
-
-char * strToLower(char *str)
-{
- char *ret = strdup(str);
- int i;
- for (i = 0; i < strlen(str);i++)
- ret[i] = tolower(ret[i]);
- return ret;
-}
-
-char * strToUpper(char *str)
-{
- char *ret = strdup(str);
- int i;
- for (i = 0; i < strlen(str);i++)
- ret[i] = toupper(ret[i]);
- return ret;
-}
-
-char * strToFirstUp(char *str)
-{
- char *ret = strToLower(str);
- ret[0] = toupper(ret[0]);
- return ret;
-}
-
-char * strToCamel(char *str)
-{
- char *lowString = strToLower(str);
- char *token;
- char *buffer;
-
- buffer = malloc (sizeof(char) * (strlen(lowString) + 1));
- strcpy (buffer, "");
-
- token = strtok (lowString, "_");
- while (token)
- {
- token[0] = toupper(token[0]);
- strcat (buffer, token);
- token = strtok (NULL, "_");
- }
-
- free (lowString);
-
- return buffer;
-}
-
-static void usage(void)
-{
- printf("Usage: %9s [options] <options file>\n",programName);
- printf("Options:\n");
- printf(" -h, --help display this help message\n");
- printf(" -v, --version print version information\n");
- printf(" -c, --compiz generate compiz compatible code\n");
- printf(" -g, --gconf generate gconf schema file\n");
- printf(" -q, --quiet don't print informational messages\n");
- printf(" --source=<file> source file name\n");
- printf(" --header=<file> header file name\n");
- printf(" --schema=<file> schema file name\n");
-}
-
-#define OPT_HELP 'h'
-#define OPT_VERSION 'v'
-#define OPT_BERYL 'b'
-#define OPT_COMPIZ 'c'
-#define OPT_QUIET 'q'
-#define OPT_GCONF 'g'
-#define OPT_SOURCE 1
-#define OPT_HEADER 2
-#define OPT_SCHEMA 3
-
-int main(int argc, char **argv)
-{
- xmlDoc *doc = NULL;
- int optch;
- programName = argv[0];
- char *src = NULL;
- char *hdr = NULL;
- char *sch = NULL;
-
- char sopts[] = "hvbcqg";
- struct option lopts[] = {
- {"help", 0, 0, OPT_HELP},
- {"version", 0, 0, OPT_VERSION},
- {"compiz", 0, 0, OPT_COMPIZ},
- {"quiet", 0, &quiet, OPT_QUIET},
- {"source", 1, 0, OPT_SOURCE},
- {"header", 1, 0, OPT_HEADER},
- {"gconf", 0, 0, OPT_GCONF},
- {"schema", 1, 0, OPT_SCHEMA},
- {0, 0, 0, 0}
- };
-
- if (argc < 2)
- {
- usage();
- return 1;
- }
-
- initData();
-
- /* Process arguments */
- while ((optch = getopt_long(argc, argv, sopts, lopts, NULL)) != EOF)
- {
- switch (optch)
- {
- case OPT_HELP:
- usage();
- return 0;
- case OPT_VERSION:
- printf(PACKAGE_STRING "\n");
- return 0;
- case OPT_COMPIZ:
- if (data.mode != GenNone)
- {
- fprintf(stderr,"%s: can only generate output for one code/schema target\n",programName);
- return 1;
- }
- data.mode = CodeCompiz;
- break;
- case OPT_GCONF:
- if (data.mode != GenNone)
- {
- fprintf(stderr,"%s: can only generate output for one code/schema target\n",programName);
- return 1;
- }
- data.mode = SchemaGConf;
- break;
- case OPT_SOURCE:
- if (optarg)
- src = optarg;
-
- if (data.mode != GenNone)
- {
- fprintf(stderr,"%s: can only generate output for one code/schema target\n",programName);
- return 1;
- }
- data.mode = CodeCompiz;
- break;
- case OPT_HEADER:
- if (optarg)
- hdr = optarg;
-
- if (data.mode != GenNone)
- {
- fprintf(stderr,"%s: can only generate output for one code/schema target\n",programName);
- return 1;
- }
- data.mode = CodeCompiz;
- break;
- case OPT_SCHEMA:
- if (optarg)
- sch = optarg;
-
- if (data.mode != GenNone)
- {
- fprintf(stderr,"%s: can only generate output for one code/schema target\n",programName);
- return 1;
- }
- data.mode = SchemaGConf;
- break;
- case 0: /* Returned when auto-set stuff is in effect */
- break;
- default:
- /* Not recognised option or with missing argument.
- * getopt_long() prints an error message for us.
- */
- return 1;
-
- }
- }
-
- if (data.mode == GenNone)
- data.mode = CodeCompiz;
-
- fileName = argv[argc-1];
-
- /*
- * this initialize the library and check potential ABI mismatches
- * between the version it was compiled for and the actual shared
- * library used.
- */
- LIBXML_TEST_VERSION
-
- /*parse the file and get the DOM */
- if (!quiet) printf("Parsing XML Option file \"%s\"...",fileName);
- doc = xmlReadFile(fileName, NULL, 0);
-
- if (doc == NULL) {
- if (!quiet) printf("error\n");
- exit(1);
- }
-
- if (!quiet) printf("done\n");
-
- error = 0;
- if (!quiet) printf("Parsing XML tree...");
- parseOptionFile(doc);
- if (!quiet) printf("done\n");
-
- if (data.mode<SchemaBegin && !src && !hdr)
- {
- char str[1024];
- char *prefix = strtok(basename(strdup(fileName)),".");
- if (!prefix || !strlen(prefix))
- prefix = data.name;
- sprintf(str,"%s_options.c",prefix);
- src = strdup(str);
- sprintf(str,"%s_options.h",prefix);
- hdr = strdup(str);
- }
- else if (data.mode>SchemaBegin && !sch)
- {
- char str[1024];
- char *prefix = strtok(basename(strdup(fileName)),".");
- if (!prefix || !strlen(prefix))
- prefix = data.name;
- sprintf(str,"%s.schema",prefix);
- sch = strdup(str);
- }
-
- int rv = error;
- if (!error)
- if (data.mode < SchemaBegin)
- rv = genCode(src,hdr);
- else
- rv = genSchema(sch);
-
- /*free the document */
- xmlFreeDoc(doc);
-
- /*
- *Free the global variables that may
- *have been allocated by the parser.
- */
- xmlCleanupParser();
-
- return rv;
-}