Commit a6d5beb8 authored by Colomban Wendling's avatar Colomban Wendling

Make the build system compile the library

parent bb2f9085
......@@ -20,8 +20,6 @@ AC_SUBST(ovccincludedir)
AC_PROG_CC
AM_PROG_VALAC([0.8])
AC_PROG_LIBTOOL
AC_CHECK_PROGS([GLIB_GENMARSHAL], [glib-genmarshal], [NONE])
AC_CHECK_PROGS([GLIB_MKENUMS], [glib-mkenums], [NONE])
# check for gtk-doc
GTK_DOC_CHECK(1.11)
......@@ -36,6 +34,8 @@ PKG_CHECK_MODULES([LIBOVCC], [glib-2.0 >= ${GLIB_REQUIRE}
libxml-2.0 >= ${LIBXML_REQUIRE}])
CFLAGS="${CFLAGS} ${LIBOVCC_CFLAGS} -Werror-implicit-function-declaration"
LIBS="${LIBS} ${LIBOVCC_LIBS}"
VALAFLAGS="--pkg glib-2.0 --pkg gio-2.0 --pkg libxml-2.0"
AC_SUBST([VALAFLAGS])
# Checks for header files.
......@@ -43,31 +43,6 @@ LIBS="${LIBS} ${LIBOVCC_LIBS}"
# Checks for library functions.
# Paranoiac (debugging) options
AC_ARG_ENABLE([paranoia],
AC_HELP_STRING([--enable-paranoia],
[enable excessively strict compiler options \
(works only with GCC and compatible) [[default=no]]]),
[enable_paranoia="$enableval"],
[enable_paranoia="no"])
AC_MSG_CHECKING([[whether to enable paranoiac compiler options]])
if test "x$enable_paranoia" = "xyes"; then
CFLAGS="$CFLAGS \
-Wall -W -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int \
-Werror-implicit-function-declaration -Wmain -Wparentheses -Wsequence-point \
-Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas \
-Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast \
-Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return \
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wmissing-noreturn -Wformat -Wmissing-format-attribute \
-Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs \
-Winline -Wlong-long -Wunreachable-code -pedantic"
AC_MSG_RESULT([[yes]])
else
AC_MSG_RESULT([[no]])
fi
AC_CONFIG_FILES([Makefile
src/Makefile
ovcc.pc
......
lib_LTLIBRARIES = libovcc.la
noinst_PROGRAMS = test
libovcc_la_CPPFLAGS = -DG_LOG_DOMAIN=\"libovcc\"
libovcc_la_SOURCES = enumtypes.c \
ovcc-marshal.c \
board.vala \
EXTRA_DIST = hack.h hack.vapi \
ovcc.h ovcc.vapi
libovcc_la_CPPFLAGS = -DG_LOG_DOMAIN=\"LibOVCC\"
libovcc_la_VALAFLAGS = $(VALAFLAGS) --library=ovcc --header=ovcc.h \
--vapidir=. --pkg=hack
libovcc_la_SOURCES = board.vala \
game.vala \
pawn.vala \
player.vala \
......@@ -13,29 +17,25 @@ libovcc_la_SOURCES = enumtypes.c \
tileobject.vala \
tileset.vala \
tilesdef.vala \
utils.vala \
xmlutils.c
utils.vala
ovccinclude_HEADERS = ovcc.h
test_LDADD = libovcc.la -lpthread
test_SOURCES = test.c
enumtypes.h: $(ovccinclude_HEADERS) enumtypes.h.template
$(AM_V_GEN) \
( cd $(srcdir) && $(GLIB_MKENUMS) --template $@.template \
$(ovccinclude_HEADERS) | \
# hack to fix glib-mkenums output \
sed 's/o_vcc_/ovcc_/g' | sed 's/O_TYPE_VCC_/OVCC_TYPE_/g' ) > $@
enumtypes.c: $(ovccinclude_HEADERS) enumtypes.c.template enumtypes.h
$(AM_V_GEN) \
( cd $(srcdir) && $(GLIB_MKENUMS) --template $@.template \
$(ovccinclude_HEADERS) | sed 's/o_vcc_/ovcc_/g' ) > $@
$(lib_LTLIBRARIES): hack-stamp
ovcc-marshal.h: ovcc-marshal.list
$(AM_V_GEN) \
$(GLIB_GENMARSHAL) $< --header --prefix=_ovcc_marshal > $@
ovcc-marshal.c: ovcc-marshal.list ovcc-marshal.h
$(AM_V_GEN) \
( echo '#include "ovcc-marshal.h"' && \
$(GLIB_GENMARSHAL) $< --body --prefix=_ovcc_marshal ) > $@
# FIXME: how to force re-generation of ovcc.h and ovcc.vapi if they got removed?
hack-stamp: ovcc.h ovcc.vapi
(f=`tempfile`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_h=ovcc.h; [ -f "$$ovcc_h" ] || ovcc_h=$(srcdir)/ovcc.h; \
cat $(srcdir)/hack.h "$$ovcc_h" > "$$f" && \
(echo "/* this file is auto-generated, do not modify it */" && \
cat "$$f") > ovcc.h)
(f=`tempfile`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_vapi=ovcc.vapi; [ -f "$$ovcc_vapi" ] || ovcc_h=$(srcdir)/ovcc.vapi; \
cat $(srcdir)/hack.vapi "$$ovcc_vapi" | sed 's/"hack.h"/"ovcc.h"/g' > "$$f" && \
(echo "/* this file is auto-generated, do not modify it */" && \
cat "$$f") > ovcc.vapi)
touch $@
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
......@@ -18,23 +18,32 @@
*
*/
#ifndef H_OVCC_OVCC
#define H_OVCC_OVCC
/*
* This file contains definitions of types derived from basic types, such as
* integers. This is needed because Vala seems to fuck this up (as of
* valac 0.11.5) and make a type half-boxed half-simple.
*
* See also hack.vapi that contains the VAPI for this file, and anything that
* can land in it (such as type methods).
*/
#include <glib.h>
#ifndef OVCC_HACK_H
#define OVCC_HACK_H
#include "board.h"
#include "pawn.h"
#include "game.h"
#include "player.h"
#include "stack.h"
#include "tile.h"
#include "tilesdef.h"
#include "tileset.h"
#include <glib.h>
G_BEGIN_DECLS
typedef guint OVCCPlayerID;
typedef guint OVCCTileID;
#define OVCC_TYPE_PLAYER_ID G_TYPE_UINT
#define OVCC_TYPE_TILE_ID G_TYPE_UINT
#define ovcc_player_id_get_type() OVCC_TYPE_PLAYER_ID
#define ovcc_tile_id_get_type() OVCC_TYPE_TILE_ID
G_END_DECLS
#endif /* guard */
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
......@@ -18,54 +18,48 @@
*
*/
#ifndef H_OVCC_XMLUTILS
#define H_OVCC_XMLUTILS
#include <glib.h>
G_BEGIN_DECLS
/**
* OVCCXmlUtilsError:
* @OVCC_XMLUTILS_ERROR_MISSING_PREFIX: There is no prefix or it is wrong
* @OVCC_XMLUTILS_ERROR_MISSING_VALUE: There is no value
* @OVCC_XMLUTILS_ERROR_INVALID_DATA: There is invalid data
* @OVCC_XMLUTILS_ERROR_OUT_RANGE: A value is out of range
* @OVCC_XMLUTILS_ERROR_FAILED: Something failed (generic case if no
* other applies)
*
* Errors of the %OVCC_XMLUTILS_ERROR domain.
*/
typedef enum
namespace OVCC
{
OVCC_XMLUTILS_ERROR_MISSING_PREFIX,
OVCC_XMLUTILS_ERROR_MISSING_VALUE,
OVCC_XMLUTILS_ERROR_INVALID_DATA,
OVCC_XMLUTILS_ERROR_OUT_RANGE,
OVCC_XMLUTILS_ERROR_FAILED
} OVCCXmlUtilsError;
/**
* OVCC_XMLUTILS_ERROR:
*
* Domain for OVCCXmlUtils errors.
*/
#define OVCC_XMLUTILS_ERROR (ovcc_xmlutils_error_quark ())
GQuark ovcc_xmlutils_error_quark (void) G_GNUC_CONST;
gulong ovcc_xmlutils_read_ulong (const gchar *num,
GError **error);
guint ovcc_xmlutils_read_uint (const gchar *num,
GError **error);
guint ovcc_xmlutils_read_id (const gchar *id,
const gchar *prefix,
GError **error);
G_END_DECLS
[SimpleType]
[CCode (cname = "OVCCPlayerID",
cheader_filename = "hack.h",
type_id = "G_TYPE_UINT",
marshaller_type_name = "UINT",
get_value_function = "g_value_get_uint",
set_value_function = "g_value_set_uint",
default_value = "0U",
type_signature = "u")]
[IntegerType (rank = 7)]
public struct PlayerID : uint
{
}
[SimpleType]
[CCode (cname = "OVCCTileID",
cheader_filename = "hack.h",
type_id = "G_TYPE_UINT",
marshaller_type_name = "UINT",
get_value_function = "g_value_get_uint",
set_value_function = "g_value_set_uint",
default_value = "0U",
type_signature = "u")]
[IntegerType (rank = 7)]
public struct TileID : uint
{
public new string to_string ()
{
return "t%u".printf (this);
}
public static TileID from_string (string str)
throws GLib.ConvertError
{
if (! str.has_prefix ("t")) {
throw new GLib.ConvertError.ILLEGAL_SEQUENCE (""""%s" is not a valid tile ID""", str);
}
return (TileID)Utils.string_to_uint ((string)((char *)str + 1));
}
}
}
#endif /* guard */
......@@ -20,8 +20,6 @@
namespace OVCC
{
public struct PlayerID : uint {}
public class Player : Object
{
private List<Pawn> _pawns = new List<Pawn> ();
......
......@@ -25,28 +25,6 @@ namespace OVCC
INVALID_TILE_ID
}
[SimpleType]
[CCode (type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
[IntegerType (rank = 7)]
/* FIXME: vala don't seem to support correctly user-defined simple types... */
public struct TileID : uint
{
public new string to_string ()
{
return "t%u".printf (this);
}
public static TileID from_string (string str)
throws ConvertError
{
if (! str.has_prefix ("t")) {
throw new ConvertError.ILLEGAL_SEQUENCE (""""%s" is not a valid tile ID""", str);
}
return (TileID)Utils.string_to_uint ((string)((char *)str + 1));
}
}
/**
* Represents a tile
*
......
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "xmlutils.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <glib.h>
/**
* SECTION: xmlutils
* @short_description: Utilities used by the XML loaders
* @include: libovcc/xmlutils.h
*
* Various functions useful for different XML loaders.
*
*/
/**
* ovcc_xmlutils_error_quark:
*
* Gets the error domain quark of OVCCXmlUtils
*
* Returns: The error domain quark of OVCCXmlUtils
*/
GQuark
ovcc_xmlutils_error_quark (void)
{
static GQuark error_quark = 0;
if (G_UNLIKELY (error_quark == 0)) {
error_quark = g_quark_from_static_string ("OVCCXmlUtilsError");
}
return error_quark;
}
/**
* ovcc_xmlutils_read_ulong:
* @num: A string
* @error: Location where store an error if any, or %NULL to ignore errors
*
* Converts a string to an unsigned long.
*
* This is a wrapper around C's standard strtoul() function, but that reports
* errors through a #GError.
* Returned errors are in the %OVCC_XMLUTILS_ERROR domain and may be:
* * %OVCC_XMLUTILS_ERROR_MISSING_VALUE if @num didn't hold any value;
* * %OVCC_XMLUTILS_ERROR_INVALID_DATA if there was unparsed data after the
* value;
* * %OVCC_XMLUTILS_ERROR_OUT_RANGE if the value was too big and truncated.
*
* Returns: The number in @num on success. On error, 0 if no value was read,
* the value-part that was read if there was invalid data and the
* highest value storable in a gulong if the value was out of bounds.
*/
gulong
ovcc_xmlutils_read_ulong (const gchar *num,
GError **error)
{
gulong value = 0;
char *endptr;
value = strtoul (num, &endptr, 0);
if (*num == 0 || num == endptr) {
g_set_error (error, OVCC_XMLUTILS_ERROR, OVCC_XMLUTILS_ERROR_MISSING_VALUE,
"'%s' contains no number", num);
} else if (*endptr != 0) {
g_set_error (error, OVCC_XMLUTILS_ERROR, OVCC_XMLUTILS_ERROR_INVALID_DATA,
"Unparsed data at end of number '%s': %s", num, endptr);
} else if (value >= ULONG_MAX && errno == ERANGE) {
g_set_error (error, OVCC_XMLUTILS_ERROR, OVCC_XMLUTILS_ERROR_OUT_RANGE,
"number '%s' is out of range (> %lu)", num, ULONG_MAX);
}
return value;
}
/**
* ovcc_xmlutils_read_uint:
* @num: A string
* @error: Location where store an error if any, or %NULL to ignore errors
*
* Converts a string to an unsigned int.
*
* See documentation of ovcc_xmlutils_read_ulong() for details.
* This function does exactly the same but returns an unsigned int (guint).
* Therefore, it reports a range error if the value cannot be stored in an
* unsigned int.
*
* <note>
* <para>
* A behaviour that may be confusing is that if the value is out of bounds
* from ovcc_xmlutils_read_ulong() point of view, the error message will
* be the one reported by ovcc_xmlutils_read_ulong() rather that the one
* that this function should set. It results by a reported range bigger
* that the one really expected by this function.
* </para>
* </note>
*
* Returns: The number in @number.
*/
guint
ovcc_xmlutils_read_uint (const gchar *num,
GError **error)
{
GError *err = NULL;
gulong v_l;
v_l = ovcc_xmlutils_read_ulong (num, &err);
if (err) {
g_propagate_error (error, err);
} else if (v_l > G_MAXUINT) {
g_set_error (error, OVCC_XMLUTILS_ERROR, OVCC_XMLUTILS_ERROR_OUT_RANGE,
"number '%s' is out of range (> %u)", num, G_MAXUINT);
}
return (guint)v_l;
}
/**
* ovcc_xmlutils_read_id:
* @id: An XML ID
* @prefix: Expected prefix of the ID
* @error: Return location for an error if any, or %NULL to ignore errors.
*
* Reads an XML ID.
*
* This function reads a string and tries to extract an ID from it.
* See documentation of ovcc_xmlutils_read_uint() for details.
*
* Returns: The read ID or 0.
*/
guint
ovcc_xmlutils_read_id (const gchar *id,
const gchar *prefix,
GError **error)
{
guint value = 0;
if (! g_str_has_prefix (id, prefix)) {
g_set_error (error, OVCC_XMLUTILS_ERROR, OVCC_XMLUTILS_ERROR_MISSING_PREFIX,
"ID '%s' does not have prefix '%s'", id, prefix);
} else {
id = &id[strlen (prefix)];
value = ovcc_xmlutils_read_uint (id, error);
}
return value;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment