summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--COPYING340
-rw-r--r--ChangeLog0
-rw-r--r--INSTALL236
-rw-r--r--Makefile.am5
-rw-r--r--NEWS1
-rw-r--r--README0
-rw-r--r--VERSION1
-rwxr-xr-xautogen.sh13
-rw-r--r--bcop.pc.in11
-rw-r--r--configure.ac29
-rw-r--r--examples/example.options116
-rw-r--r--pluginMakefile/Makefile165
-rw-r--r--src/Makefile.am7
-rw-r--r--src/bcop.h211
-rw-r--r--src/code_generator.c1388
-rw-r--r--src/xml_parser.c965
17 files changed, 3489 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..5689d64
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Dennis Kasprzyk <onestone@beryl-project.org> \ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..623b625
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ChangeLog
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..23e5f25
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,236 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
+Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+ It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring. (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+ The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'. You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about. Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+ You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment. Here
+is an example:
+
+ ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+ *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory. After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc. You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+ CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+ OS KERNEL-OS
+
+ See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+ If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+ If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'. However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost. In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'. For example:
+
+ ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script). Here is a another example:
+
+ /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
+configuration-related scripts to be executed by `/bin/bash'.
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+ Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`--cache-file=FILE'
+ Enable the cache: use and save the results of the tests in FILE,
+ traditionally `config.cache'. FILE defaults to `/dev/null' to
+ disable caching.
+
+`--config-cache'
+`-C'
+ Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options. Run
+`configure --help' for more details.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..1985514
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,5 @@
+## Process this file with automake to produce Makefile.in
+SUBDIRS = src
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = bcop.pc
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..94941cc
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+There is nothing here yet.
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..8303ced
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+VERSION=0.0.1
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..80ae530
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+
+autoreconf -v --install || exit 1
+cd $ORIGDIR || exit $?
+
+$srcdir/configure "$@"
+
diff --git a/bcop.pc.in b/bcop.pc.in
new file mode 100644
index 0000000..67c4b4c
--- /dev/null
+++ b/bcop.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+exec=@exec_prefix@/bin/bcop
+
+Name: bcop
+Description: Beryl/Compiz options parser
+Version: @VERSION@
+Requires: libxml-2.0 x11
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..662d4a1
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,29 @@
+AC_PREREQ(2.57)
+
+AC_INIT([bcop],esyscmd(. ./VERSION;echo -n $VERSION), [onestone@beryl-project.org])
+
+AC_DEFINE_UNQUOTED(VERSION,"$VERSION",[Version])
+
+#AC_CONFIG_AUX_DIR(config)
+
+AM_INIT_AUTOMAKE([1.9 dist-bzip2])
+AC_CONFIG_HEADER([config.h])
+AM_MAINTAINER_MODE
+
+AC_ISC_POSIX
+AC_PROG_CC
+AC_HEADER_STDC
+
+AC_C_BIGENDIAN
+
+PKG_CHECK_MODULES(LIBXML2, "libxml-2.0")
+AC_SUBST(LIBXML2_REQUIRES)
+
+PKG_CHECK_MODULES(X11, "x11")
+AC_SUBST(X11_REQUIRES)
+
+AC_OUTPUT([
+bcop.pc
+Makefile
+src/Makefile
+])
diff --git a/examples/example.options b/examples/example.options
new file mode 100644
index 0000000..fc32c91
--- /dev/null
+++ b/examples/example.options
@@ -0,0 +1,116 @@
+<plugin name="example">
+ <screen>
+ <group name="Nice options">
+ <subgroup name="First subgroup">
+ <option name="intoption" type="int">
+ <short>test int option</short>
+ <long>test int option long</long>
+ <default>5</default>
+ <min>1</min>
+ <max>10</max>
+ </option>
+ <option name="floatoption" type="float">
+ <short>test float option</short>
+ <long>test float option long</long>
+ <default>1.2</default>
+ <min>0.0</min>
+ <max>5.0</max>
+ <precision>0.1</precision>
+ </option>
+ <option name="booloption" type="bool">
+ <short>test bool option </short>
+ <long>test bool option long</long>
+ <default>true</default>
+ </option>
+ <option name="stringoption" type="string">
+ <short>test string option </short>
+ <long>test string option long</long>
+ <default>Hello world 1</default>
+ </option>
+ <option name="color" type="color">
+ <short>test color option</short>
+ <long>test color option long</long>
+ <red>0xffff</red>
+ <green>0xcf</green>
+ <blue>65535</blue>
+ <alpha>0x1f</alpha>
+ </option>
+ <option name="stringlist" type="stringlist">
+ <short>test stringlist option</short>
+ <long>test stringlist option long</long>
+ <hints>file;image;</hints>
+ <default>string1</default>
+ <default>string2</default>
+ <default raw="true">"string3"</default>
+ </option>
+ <option name="enumoption" type="enum">
+ <short>test enum option</short>
+ <long>test enum option long</long>
+ <value name="val1">Enum Value 1</value>
+ <value name="val2">Enum Value 2</value>
+ <value name="val3" default="true">Enum Value 3</value>
+ <value name="val4">Enum Value 4</value>
+ </option>
+ </subgroup>
+ <subgroup name="Second subgroup">
+ <option name="myselection" type="selection">
+ <short>test selection option</short>
+ <long>test selection option long</long>
+ <value name="val1">Value 1</value>
+ <value name="val2" default="true">Value 2</value>
+ <value name="val3">Value 3</value>
+ <value name="val4" default="true">Value 4</value>
+ </option>
+ </subgroup>
+ </group>
+ <option name="myname" type="string">
+ <short>test string option name</short>
+ <long>test string option name long</long>
+ <hint>window</hint>
+ <default>My name</default>
+ </option>
+ <subgroup name="Last subgroup">
+ <option name="size" type="int">
+ <short>test int option size</short>
+ <long>test int option size long</long>
+ <default>3</default>
+ <min>2</min>
+ <max>4</max>
+ </option>
+ </subgroup>
+ </screen>
+ <display>
+ <group name="Nice options">
+ <subgroup name="Another subgroup">
+ <option name="action1" type="action">
+ <short>test action 1</short>
+ <long>test key/mouse action long</long>
+ <key>Alt+F2</key>
+ <mouse>Button1</mouse>
+ </option>
+ </subgroup>
+ <option name="d_action2" type="action">
+ <short>test action 2</short>
+ <long>test key/mouse both without default action long</long>
+ <key></key>
+ <mouse></mouse>
+ </option>
+ <option name="float2" type="float">
+ <short>test float option 2</short>
+ <long>test float option 2 long</long>
+ <default>1.3</default>
+ <min>0.0</min>
+ <max>5.0</max>
+ <precision>0.01</precision>
+ </option>
+ </group>
+ <option name="action" type="action">
+ <short>test action 3</short>
+ <long>test all action long</long>
+ <key state="init">Control+A</key>
+ <mouse state="init">Button2</mouse>
+ <edge state="init,initdnd">topleft,topright</edge>
+ <bell>true</bell>
+ </option>
+ </display>
+</plugin> \ No newline at end of file
diff --git a/pluginMakefile/Makefile b/pluginMakefile/Makefile
new file mode 100644
index 0000000..298f693
--- /dev/null
+++ b/pluginMakefile/Makefile
@@ -0,0 +1,165 @@
+##
+#
+# Beryl/Compiz plugin Makefile
+#
+# Copyright : (C) 2006 by Dennis Kasprzyk
+# E-mail : dennis.kasprzyk@rwth-aachen.de
+#
+#
+# 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.
+#
+##
+
+## configuration
+
+#enter beryl or compiz here
+TARGET = beryl
+
+#enter plugin name here
+PLUGIN = xxx
+
+#enter dependencies here
+PKG_DEP =
+
+## end of configuration
+
+DESTDIR = $(HOME)/.$(TARGET)/plugins
+
+BUILDDIR = build
+
+CC = gcc
+LIBTOOL = libtool
+INSTALL = install
+
+BCOP = `pkg-config --variable=exec bcop`
+
+CFLAGS = -g -Wall `pkg-config --cflags $(PKG_DEP) $(TARGET) `
+LDFLAGS = `pkg-config --libs $(PKG_DEP) $(TARGET) `
+
+bcop-target := $(shell if [ -e $(PLUGIN).options ]; then echo $(PLUGIN).options; fi )
+bcop-target-src := $(shell if [ -e $(PLUGIN).options ]; then echo $(PLUGIN)_options.c; fi )
+bcop-target-hdr := $(shell if [ -e $(PLUGIN).options ]; then echo $(PLUGIN)_options.h; fi )
+bcop-opt := $(shell if [ "$(TARGET)" = "compiz" ]; then echo "--compiz"; else echo "--beryl"; fi )
+
+# find all the object files (including those from .moc.cpp files)
+
+c-objs := $(patsubst %.c,%.lo,$(shell find -name '*.c' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
+c-objs := $(filter-out $(bcop-target-src:.c=.lo),$(c-objs))
+c-objs += $(bcop-target-src:.c=.lo)
+
+# system include path parameter, -isystem doesn't work on old gcc's
+inc-path-param = $(shell if [ -z "`gcc --version | head -n 1 | grep ' 3'`" ]; then echo "-isystem"; else echo "-I"; fi)
+
+# default color settings
+color := $(shell if [ $$TERM = "dumb" ]; then echo "no"; else echo "yes"; fi)
+
+
+#
+# Do it.
+#
+
+.PHONY: $(BUILDDIR) build-dir bcop-build c-build-objs c-link-plugin
+
+all: $(BUILDDIR) build-dir bcop-build c-build-objs c-link-plugin
+
+bcop-build: $(bcop-target-hdr) $(bcop-target-src)
+
+c-build-objs: $(addprefix $(BUILDDIR)/,$(cxx-objs))
+
+c-link-plugin: $(BUILDDIR)/lib$(PLUGIN).la
+
+#
+# Create build directory
+#
+
+$(BUILDDIR) :
+ @mkdir -p $(BUILDDIR)
+
+$(DESTDIR) :
+ @mkdir -p q$(DESTDIR)
+
+#
+# BCOP'ing
+
+%_options.h: %.options
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mbcop'ing \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "bcop'ing $< -> $@"; \
+ fi
+ @$(BCOP) $(bcop-opt) --quiet --header $@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
+ fi
+
+%_options.c: %.options
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mbcop'ing \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "bcop'ing $< -> $@"; \
+ fi
+ @$(BCOP) $(bcop-opt) --quiet --source $@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
+ fi
+
+
+#
+# Compiling
+#
+
+$(BUILDDIR)/%.lo: %.c
+ @if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5mcompiling \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "compiling $< -> $@"; \
+ fi
+ @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) -c -o $@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
+ fi
+
+#
+# Linking
+#
+
+cxx-rpath-prefix := -Wl,-rpath,
+
+$(BUILDDIR)/lib$(PLUGIN).la: $(addprefix $(BUILDDIR)/,$(c-objs))
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mlinking -> \033[0;31m$@\033[0m"; \
+ else \
+ echo "linking -> $@"; \
+ fi
+ @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(addprefix $(BUILDDIR)/,$(c-objs))
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mlinking -> \033[34m$@\033[0m"; \
+ fi
+
+
+clean:
+ rm -rf $(BUILDDIR)
+ rm -f $(bcop-target-src)
+ rm -f $(bcop-target-hdr)
+
+install: $(DESTDIR) all
+ @if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5minstall \033[0;1;37m: \033[0;31m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
+ else \
+ echo "install : $(DESTDIR)/lib$(PLUGIN).so"; \
+ fi
+ @mkdir -p $(DESTDIR)
+ @$(INSTALL) $(BUILDDIR)/.libs/lib$(PLUGIN).so $(DESTDIR)/lib$(PLUGIN).so
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0minstall : \033[34m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
+ fi
+
+
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..ad78619
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,7 @@
+bcop_LDADD = @LIBXML2_LIBS@ @X11_LIBS@
+bcop_SOURCES = xml_parser.c code_generator.c
+bcop_program = bcop
+
+INCLUDES = @LIBXML2_CFLAGS@ @X11_CFLAGS@
+
+bin_PROGRAMS = $(bcop_program)
diff --git a/src/bcop.h b/src/bcop.h
new file mode 100644
index 0000000..4112069
--- /dev/null
+++ b/src/bcop.h
@@ -0,0 +1,211 @@
+/*
+ *
+ * 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,
+ OptionTypeError
+} OptionType;
+
+typedef enum {
+ CodeBeryl,
+ CodeCompiz,
+ CodeNone
+} CodeType;
+
+#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 _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;
+} 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;
+ CodeType 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);
+
+int genCode(char *src, char *hdr);
+
+#endif
diff --git a/src/code_generator.c b/src/code_generator.c
new file mode 100644
index 0000000..b1ab28c
--- /dev/null
+++ b/src/code_generator.c
@@ -0,0 +1,1388 @@
+/*
+ *
+ * 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 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);
+ if (data.mode == CodeBeryl)
+ addString(out,"\to->value.action.key.keysym = XStringToKeysym("
+ "%s_%s_KEY_DEFAULT);\n",data.uName,o->uName);
+ else
+ 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.keysym = 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);
+ }
+
+ if (data.mode == CodeBeryl)
+ {
+ if (o->hints)
+ addString(out,"\to->displayHints = \"%s\";\n",o->hints);
+ else
+ addString(out,"\to->displayHints = \"\";\n");
+
+ if (o->group)
+ addString(out,"\to->group = N_(\"%s\");\n",o->group);
+ else
+ addString(out,"\to->group = \"\";\n");
+
+ if (o->subGroup)
+ addString(out,"\to->subGroup = N_(\"%s\");\n",o->subGroup);
+ else
+ addString(out,"\to->subGroup = \"\";\n");
+ }
+
+ 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;
+ default:
+ break;
+ }
+
+ addString(outs,"\t\t\tif (%s->notify[%s])\n"
+ "\t\t\t\t(*%s->notify[%s])(o, %s);\n", (o->screen)?"os":"od",
+ o->temp,(o->screen)?"os":"od",o->temp,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(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);
+
+ if (data.mode == CodeBeryl)
+ {
+ addString(&initDisplay,"\t%sOptionsDisplayInitOptions(od);\n\n",
+ data.name);
+
+ addString(&initDisplayOpt,"static void %sOptionsDisplayInitOptions"
+ "(%sOptionsDisplay * od)\n{\n"
+ "\tCompOption *o;\n\tint i;\n\ti = 0;\n\n",
+ data.name,data.fUName);
+ }
+ else
+ {
+ 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)"
+ "(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)"
+ "(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");
+
+ if (data.mode == CodeBeryl)
+ addString(&setDisplayOpt,"static CompOption *%sOptionsGetDisplayOptions"
+ "(CompDisplay * d, int *count)\n{\n"
+ "\tCompOption *pOpt = NULL;\n\tint pOptNum = 0;\n"
+ "\tif (%sPluginVTable && %sPluginVTable->getDisplayOptions)\n"
+ "\t\tpOpt = %sPluginVTable->getDisplayOptions(d,&pOptNum);\n\n"
+ "\t%sOptionsDisplay *od;\n"
+ "\tif (d)\n\t\tod = GET_%s_OPTIONS_DISPLAY(d);\n"
+ "\telse\n\t{\n\t\tod = calloc(1,sizeof(%sOptionsDisplay));\n"
+ "\t\t%sOptionsDisplayInitOptions(od);\n\t}\n\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.name,data.fUName,data.fUName,data.fUName,data.fUName);
+ else
+ addString(&setDisplayOpt,"static CompOption *%sOptionsGetDisplayOptions"
+ "(CompDisplay * d, int *count)\n{\n"
+ "\tCompOption *pOpt = NULL;\n\tint pOptNum = 0;\n"
+ "\tif (%sPluginVTable && %sPluginVTable->getDisplayOptions)\n"
+ "\t\tpOpt = %sPluginVTable->getDisplayOptions(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(&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(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)"
+ "(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)"
+ "(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"
+ "(CompScreen * s, int *count)\n{\n"
+ "\tCompOption *pOpt = NULL;\n\tint pOptNum = 0;\n"
+ "\tif (%sPluginVTable && %sPluginVTable->getScreenOptions)\n"
+ "\t\tpOpt = %sPluginVTable->getScreenOptions(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(&screenStruct,"} %sOptionsScreen;\n\n",data.fUName);
+}
+
+void finilizeCode()
+{
+
+ addString(&file,"#include <stdio.h>\n#include <stdlib.h>\n"
+ "#include <string.h>\n\n");
+
+ if (data.mode == CodeBeryl)
+ addString(&file,"#include <beryl.h>\n\n");
+ else
+ 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/xml_parser.c b/src/xml_parser.c
new file mode 100644
index 0000000..f427b18
--- /dev/null
+++ b/src/xml_parser.c
@@ -0,0 +1,965 @@
+/*
+ *
+ * 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 = CodeNone;
+}
+
+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;
+ 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((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 (key && strlen((char *)key) && name && strlen((char *)name))
+ {
+ OptionValuesList *lv = calloc(1,sizeof(OptionValuesList));
+ lv->value = strdup((char *)key);
+ 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 = strdup((char *)key);
+ 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 = strToFirstUp((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;
+ 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;
+}
+
+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(" -b, --beryl generate beryl compatible code (default)\n");
+ printf(" -c, --compiz generate compiz compatible code\n");
+ printf(" -q, --quiet don't print informational messages\n");
+ printf(" --source=<file> source file name\n");
+ printf(" --header=<file> header 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_SOURCE 1
+#define OPT_HEADER 2
+
+int main(int argc, char **argv)
+{
+ xmlDoc *doc = NULL;
+ int optch;
+ programName = argv[0];
+ char *src = NULL;
+ char *hdr = NULL;
+
+ char sopts[] = "hvbcq";
+ struct option lopts[] = {
+ {"help", 0, 0, OPT_HELP},
+ {"version", 0, 0, OPT_VERSION},
+ {"beryl", 0, 0, OPT_BERYL},
+ {"compiz", 0, 0, OPT_COMPIZ},
+ {"quiet", 0, &quiet, OPT_QUIET},
+ {"source", 1, 0, OPT_SOURCE},
+ {"header", 1, 0, OPT_HEADER},
+ {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_BERYL:
+ if (data.mode != CodeNone)
+ {
+ fprintf(stderr,"%s: can only generate output for one composite manager\n",programName);
+ return 1;
+ }
+ data.mode = CodeBeryl;
+ break;
+ case OPT_COMPIZ:
+ if (data.mode != CodeNone)
+ {
+ fprintf(stderr,"%s: can only generate output for one composite manager\n",programName);
+ return 1;
+ }
+ data.mode = CodeCompiz;
+ break;
+ case OPT_SOURCE:
+ if (optarg)
+ src = optarg;
+ break;
+ case OPT_HEADER:
+ if (optarg)
+ hdr = optarg;
+ 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 == CodeNone)
+ data.mode = CodeBeryl;
+
+ 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 (!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);
+ }
+
+ int rv = error;
+ if (!error)
+ rv = genCode(src,hdr);
+
+ /*free the document */
+ xmlFreeDoc(doc);
+
+ /*
+ *Free the global variables that may
+ *have been allocated by the parser.
+ */
+ xmlCleanupParser();
+
+ return rv;
+}