Commit 2286a041 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Make gobject bindings

parent 4610f714
Pipeline #96120 passed with stages
in 4 minutes and 27 seconds
......@@ -50,6 +50,16 @@ AC_SEARCH_LIBS([add_history], [history], [
AX_LIB_NETTLE([yes])
PKG_CHECK_MODULES([XML], [libxml-2.0])
LIBOPTS_CHECK
AC_ARG_WITH([gobject], AS_HELP_STRING([--without-gobject], [Do not build the GObject bindings]))
WITH_GOBJECT="no"
AS_IF([test "x$with_gobject" != "xno"], [
PKG_CHECK_MODULES([GOBJECT], [gobject-2.0], [
WITH_GOBJECT="yes"
], [
AC_MSG_ERROR([GObject was not found. Please use --without-gobject.])
])
])
AM_CONDITIONAL([WITH_GOBJECT], [test "x$WITH_GOBJECT" != "xno"])
# Checks for header files.
AC_HEADER_STDBOOL
......
......@@ -21,7 +21,7 @@ bin_PROGRAMS += %reldir%/tarot
dist_man_MANS += %reldir%/tarot.6
EXTRA_DIST += %reldir%/tarot.1
LIBTAROT_VERSION_INFO=0:0:0
LIBTAROT_VERSION_INFO = 0:0:0
%canon_reldir%_libtarot_la_SOURCES =
%canon_reldir%_libtarot_la_CFLAGS = \
......@@ -42,6 +42,20 @@ LIBTAROT_VERSION_INFO=0:0:0
%reldir%/xml/libtarot-xml.la \
lib-library/libgnulibrary.la
if WITH_GOBJECT
include_HEADERS += %reldir%/tarot-gobject.h
lib_LTLIBRARIES += %reldir%/libtarot-gobject.la
%canon_reldir%_libtarot_gobject_la_SOURCES = \
%reldir%/tarot-gobject.c
%canon_reldir%_libtarot_gobject_la_CFLAGS = \
$(AM_CFLAGS) \
$(GOBJECT_CFLAGS)
%canon_reldir%_libtarot_gobject_la_LDFLAGS = \
-no-undefined -version-info $(LIBTAROT_VERSION_INFO) $(AM_LDADD) \
$(GOBJECT_LIBS)
%canon_reldir%_libtarot_gobject_la_LIBADD =
endif
%canon_reldir%_tarot_SOURCES = \
%reldir%/main.c \
%reldir%/tarot-opts.c \
......
......@@ -70,6 +70,12 @@ tarot_card_array_free (TarotCardArray * array)
card_array_free (array);
}
TarotCardArray *
tarot_card_array_dup (const TarotCardArray * array)
{
return card_array_dup (array);
}
size_t
tarot_card_array_size (const TarotCardArray * array)
{
......
......@@ -119,6 +119,7 @@ extern "C"
TarotCardArray *tarot_card_array_alloc ();
void tarot_card_array_free (TarotCardArray * array);
TarotCardArray *tarot_card_array_dup (const TarotCardArray * array);
size_t tarot_card_array_size (const TarotCardArray * array);
int tarot_card_array_resize (TarotCardArray * array, size_t new_size);
......
......@@ -56,6 +56,7 @@ extern "C"
static TarotCardArray *card_array_alloc ();
static void card_array_free (TarotCardArray * array);
static TarotCardArray *card_array_dup (const TarotCardArray * array);
static size_t card_array_size (const TarotCardArray * array);
static int card_array_resize (TarotCardArray * array, size_t new_size);
......
......@@ -148,6 +148,25 @@ card_array_free (TarotCardArray * array)
free (array);
}
static inline TarotCardArray *
card_array_dup (const TarotCardArray * array)
{
TarotCardArray *ret = card_array_alloc ();
if (ret != NULL)
{
if (card_array_resize (ret, array->n) != 0)
{
card_array_free (ret);
ret = NULL;
}
else
{
memcpy (ret->data, array->data, ret->n * sizeof (TarotCard));
}
}
return ret;
}
static inline size_t
card_array_size (const TarotCardArray * array)
{
......
......@@ -60,7 +60,7 @@ cli_free (TarotCli * cli)
static int
cli_transfer (TarotCli * cli)
{
while (tarot_parser_get_type (cli->parser) < 0
while (tarot_parser_get_command_type (cli->parser) < 0
&& tarot_lexer_get_token_type (cli->lexer) >= 0)
{
int tt;
......@@ -197,7 +197,7 @@ cli_next (TarotCli * cli)
static inline int
cli_has_command (const TarotCli * cli)
{
return tarot_parser_get_type (cli->parser) >= 0;
return tarot_parser_get_command_type (cli->parser) >= 0;
}
static inline int
......@@ -209,26 +209,30 @@ cli_is_continuation (const TarotCli * cli)
static inline int
cli_is_help (const TarotCli * cli)
{
return tarot_parser_get_type (cli->parser) == tarot_parser_type_help ();
return tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_help ();
}
static inline int
cli_is_version (const TarotCli * cli)
{
return tarot_parser_get_type (cli->parser) == tarot_parser_type_version ();
return tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_version ();
}
static inline int
cli_is_license (const TarotCli * cli)
{
return tarot_parser_get_type (cli->parser) == tarot_parser_type_license ();
return tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_license ();
}
static inline int
cli_is_error (const TarotCli * cli, char **errorstr)
{
int ok =
(tarot_parser_get_type (cli->parser) == tarot_parser_type_error ());
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_error ());
if (ok)
{
*errorstr = (char *) tarot_parser_get_error (cli->parser);
......@@ -240,7 +244,8 @@ static inline int
cli_is_status (const TarotCli * cli, int *with_imputation)
{
int ok =
(tarot_parser_get_type (cli->parser) == tarot_parser_type_status ());
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_status ());
if (ok)
{
*with_imputation = tarot_parser_get_with_imputation (cli->parser);
......@@ -251,7 +256,9 @@ cli_is_status (const TarotCli * cli, int *with_imputation)
static inline int
cli_is_load (const TarotCli * cli, char **filename)
{
int ok = (tarot_parser_get_type (cli->parser) == tarot_parser_type_load ());
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_load ());
if (ok)
{
*filename = (char *) tarot_parser_get_filename (cli->parser);
......@@ -262,7 +269,9 @@ cli_is_load (const TarotCli * cli, char **filename)
static inline int
cli_is_save (const TarotCli * cli, char **filename)
{
int ok = (tarot_parser_get_type (cli->parser) == tarot_parser_type_save ());
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_save ());
if (ok)
{
*filename = (char *) tarot_parser_get_filename (cli->parser);
......@@ -274,7 +283,8 @@ static inline int
cli_is_check (const TarotCli * cli, TarotGameEvent ** event)
{
int ok =
(tarot_parser_get_type (cli->parser) == tarot_parser_type_check ());
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_check ());
if (ok)
{
*event = (TarotGameEvent *) tarot_parser_get_event (cli->parser);
......@@ -286,7 +296,8 @@ static inline int
cli_is_event (const TarotCli * cli, TarotGameEvent ** event)
{
int ok =
(tarot_parser_get_type (cli->parser) == tarot_parser_type_event ());
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_event ());
if (ok)
{
*event = (TarotGameEvent *) tarot_parser_get_event (cli->parser);
......
......@@ -49,7 +49,7 @@ main ()
{
abort ();
}
if (tarot_parser_get_type (parser) != tarot_parser_type_help ())
if (tarot_parser_get_command_type (parser) != tarot_parser_type_help ())
{
abort ();
}
......@@ -59,7 +59,7 @@ main ()
{
abort ();
}
if (tarot_parser_get_type (parser) >= 0)
if (tarot_parser_get_command_type (parser) >= 0)
{
abort ();
}
......@@ -71,7 +71,7 @@ main ()
{
abort ();
}
if (tarot_parser_get_type (parser) != tarot_parser_type_save ())
if (tarot_parser_get_command_type (parser) != tarot_parser_type_save ())
{
abort ();
}
......@@ -79,7 +79,7 @@ main ()
{
abort ();
}
if (tarot_parser_get_type (parser) != tarot_parser_type_error ())
if (tarot_parser_get_command_type (parser) != tarot_parser_type_error ())
{
abort ();
}
......
......@@ -58,9 +58,9 @@ tarot_parser_clear (TarotParser * parser)
}
int
tarot_parser_get_type (const TarotParser * parser)
tarot_parser_get_command_type (const TarotParser * parser)
{
return parser_get_type (parser);
return parser_get_command_type (parser);
}
const char *
......
......@@ -61,10 +61,10 @@ extern "C"
int tarot_parser_push_syntax_error (TarotParser * parser,
const TarotParserTokenPosition *
position);
/* Forget the previous command. Now get_type () is different from
any command type. */
/* Forget the previous command. Now get_command_type () is
different from any command type. */
void tarot_parser_clear (TarotParser * parser);
int tarot_parser_get_type (const TarotParser * parser);
int tarot_parser_get_command_type (const TarotParser * parser);
const char *tarot_parser_get_filename (const TarotParser * parser);
const TarotGameEvent *tarot_parser_get_event (const TarotParser * parser);
void tarot_parser_get_position (const TarotParser * parser, int *fl,
......
......@@ -88,7 +88,7 @@ extern "C"
const TarotParserTokenPosition *
position);
static void parser_clear (TarotParser * parser); /* Only values, not state */
static int parser_get_type (const TarotParser * parser);
static int parser_get_command_type (const TarotParser * parser);
static const char *parser_get_filename (const TarotParser * parser);
static const TarotGameEvent *parser_get_event (const TarotParser * parser);
static void parser_get_position (const TarotParser * parser, int *fl,
......
......@@ -251,7 +251,7 @@ parser_push_syntax_error (TarotParser * parser,
}
static inline int
parser_get_type (const TarotParser * parser)
parser_get_command_type (const TarotParser * parser)
{
return parser->aux.type;
}
......
/**
* file tarot-gobject.c
*
* Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
*
* 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 <tarot-gobject.h>
G_DEFINE_BOXED_TYPE (TarotCardArray, tarot_card_array, tarot_card_array_dup, tarot_card_array_free)
G_DEFINE_BOXED_TYPE (TarotCli, tarot_cli, NULL, tarot_cli_free)
G_DEFINE_BOXED_TYPE (TarotCounter, tarot_counter, NULL, tarot_counter_free)
G_DEFINE_BOXED_TYPE (TarotGame, tarot_game, NULL, tarot_game_free)
G_DEFINE_BOXED_TYPE (TarotGameEvent, tarot_game_event, NULL, tarot_game_event_free)
G_DEFINE_BOXED_TYPE (TarotGameEventArray, tarot_game_event_array, NULL, tarot_game_event_array_free)
G_DEFINE_BOXED_TYPE (TarotLexer, tarot_lexer, NULL, tarot_lexer_free)
G_DEFINE_BOXED_TYPE (TarotParser, tarot_parser, NULL, tarot_parser_free)
G_DEFINE_BOXED_TYPE (TarotPlayerArray, tarot_player_array, NULL, tarot_player_array_free)
/**
* file tarot-gobject.h
*
* Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
*
* 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/>.
*/
#ifndef H_TAROT_GOBJECT_INCLUDED
#define H_TAROT_GOBJECT_INCLUDED
#include <tarot.h>
#include <glib-2.0/glib-object.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
GType tarot_card_array_get_type ();
GType tarot_cli_get_type ();
GType tarot_counter_get_type ();
GType tarot_game_get_type ();
GType tarot_game_event_get_type ();
GType tarot_game_event_array_get_type ();
GType tarot_lexer_get_type ();
GType tarot_parser_get_type ();
GType tarot_player_array_get_type ();
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* not H_TAROT_GOBJECT_INCLUDED */
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