Commit 2e0213ca authored by Vivien Kraus's avatar Vivien Kraus

Set up vala!

parent b5230c7f
Pipeline #96726 passed with stages
in 4 minutes and 53 seconds
......@@ -112,7 +112,8 @@ AM_TESTS_ENVIRONMENT += \
$(VALGRIND) --tool=memcheck \
--leak-check=full \
--error-exitcode=42 \
--suppressions=$(srcdir)/$(VALGRIND_SUPPRESSION_FILE)
--suppressions=$(srcdir)/$(VALGRIND_SUPPRESSION_FILE) \
--gen-suppressions=all
endif # HAVE_VALGRIND
TEST_EXTENSIONS = .tarot
......
......@@ -40,6 +40,7 @@ AM_MISSING_PROG([XMLLINT], [xmllint])
AM_MISSING_PROG([CONVERT], [convert])
GOBJECT_INTROSPECTION_CHECK([1.30.0])
PKG_CHECK_VAR([GLIB_MKENUMS], [glib-2.0], [glib_mkenums])
AM_PROG_VALAC
VAPIGEN_CHECK
# Checks for libraries.
......
This diff is collapsed.
......@@ -17,9 +17,8 @@
# <http://www.gnu.org/licenses/>.
lib_LTLIBRARIES += %reldir%/libtarot.la
bin_PROGRAMS += %reldir%/tarot
dist_man_MANS += %reldir%/tarot.6
EXTRA_DIST += %reldir%/tarot.1 %reldir%/tarot-gobject.h.in %reldir%/tarot-gobject.c.in
EXTRA_DIST += %reldir%/tarot.1 %reldir%/tarot-gobject.h.in %reldir%/tarot-gobject.c.in \
%reldir%/Tarot-1.0.metadata
girdir = $(datadir)/gir-1.0
typelibdir = $(datadir)/girepository-1.0
vapidir = $(datadir)/vala/vapi
......@@ -63,26 +62,42 @@ lib_LTLIBRARIES += %reldir%/libtarot-gobject.la
-no-undefined -version-info $(LIBTAROT_VERSION_INFO) $(AM_LDADD) \
$(GOBJECT_LIBS)
%canon_reldir%_libtarot_gobject_la_LIBADD =
endif
bin_PROGRAMS += %reldir%/tarot
dist_man_MANS += %reldir%/tarot.6
%canon_reldir%_tarot_SOURCES = \
%reldir%/main.c \
%reldir%/tarot-opts.c \
%reldir%/tarot-opts.h
%reldir%/tarot-opts.h \
%reldir%/application.vala \
%reldir%/tarot-1.0.vapi
%canon_reldir%_tarot_CFLAGS = \
$(AM_CFLAGS) \
$(LIBOPTS_CFLAGS)
$(LIBOPTS_CFLAGS) \
$(GOBJECT_CFLAGS) \
-w
%canon_reldir%_tarot_CXXFLAGS = \
$(AM_CXXFLAGS)
%canon_reldir%_tarot_CPPFLAGS = \
$(AM_CPPFLAGS)
$(AM_CPPFLAGS) \
-include config.h
%canon_reldir%_tarot_LDFLAGS = \
$(AM_LDADD)
%canon_reldir%_tarot_LDADD = \
%reldir%/libtarot.la \
%reldir%/libtarot-gobject.la \
lib-program/libgnulibrary.la \
$(LTLIBREADLINE) \
$(LIBOPTS_LDADD)
$(LIBOPTS_LDADD) \
$(GOBJECT_LIBS)
else # not WITH_GOBJECT
EXTRA_DIST += %reldir%/main.c \
%reldir%/tarot-opts.c \
%reldir%/tarot-opts.h \
%reldir%/application.c \
%reldir%/application.h \
%reldir%/application.vala \
%reldir%/tarot.6
endif # not WITH_GOBJECT
if HAVE_INTROSPECTION
introspection_sources = $(include_HEADERS) $(tarotinclude_HEADERS)
......@@ -128,6 +143,7 @@ endif # not HAVE_INTROSPECTION
if ENABLE_VAPIGEN
%reldir%/tarot-1.0.vapi: %reldir%/Tarot-1.0.gir
%canon_reldir%_tarot_1_0_vapi_FILES = %reldir%/Tarot-1.0.gir
%canon_reldir%_tarot_1_0_vapi_METADATADIRS = $(srcdir)
VAPIGEN_VAPIS += %reldir%/tarot-1.0.vapi
-include $(VAPIGEN_MAKEFILE)
else #not ENABLE_VAPIGEN
......
Tarot cheader_filename="tarot-gobject.h"
\ No newline at end of file
......@@ -21,6 +21,7 @@
#include <config.h>
#include <tarot/cards_private.h>
#include <stdlib.h>
#include <assert.h>
int
tarot_of (TarotNumber n, TarotSuit s, TarotCard * c)
......@@ -58,6 +59,20 @@ tarot_card_to_string (TarotCard c, size_t max, char *dest)
return card_to_string (c, max, dest);
}
char *
tarot_card_to_string_alloc (TarotCard c)
{
char *ret = malloc (4);
if (ret != NULL)
{
if (card_to_string (c, 4, ret) >= 4)
{
assert (0);
}
}
return ret;
}
TarotCardArray *
tarot_card_array_alloc ()
{
......
......@@ -89,7 +89,7 @@ extern "C"
*
* n: the number.
* s: the suit.
* c: set to the n of s.
* @c: (out): set to the n of s.
* Returns: whether there were an error.
*/
int tarot_of (TarotNumber n, TarotSuit s, TarotCard * c);
......@@ -101,8 +101,8 @@ extern "C"
* Cannot decompose the excuse.
*
* c: the card.
* n: set to the number of c.
* s: set to the suit of c.
* @n: (out): set to the number of c.
* @s: (out): set to the suit of c.
* Returns: whether there were an error.
*/
int tarot_decompose (TarotCard c, TarotNumber * n, TarotSuit * s);
......@@ -112,11 +112,22 @@ extern "C"
TarotCard tarot_card_parse (const char *text, char **end);
/**
* tarot_card_to_string: (skip):
*/
size_t tarot_card_to_string (TarotCard c, size_t max, char *dest);
/**
* tarot_card_to_string_alloc:
*/
char *tarot_card_to_string_alloc (TarotCard c);
struct TarotCardArray;
typedef struct TarotCardArray TarotCardArray;
/**
* tarot_card_array_alloc: (constructor):
*/
TarotCardArray *tarot_card_array_alloc ();
void tarot_card_array_free (TarotCardArray * array);
TarotCardArray *tarot_card_array_dup (const TarotCardArray * array);
......
......@@ -84,39 +84,63 @@ tarot_cli_is_license (const TarotCli * cli)
}
int
tarot_cli_is_error (const TarotCli * cli, char **error)
tarot_cli_is_error (const TarotCli * cli)
{
return cli_is_error (cli, error);
return cli_is_error (cli);
}
int
tarot_cli_is_status (const TarotCli * cli, int *with_imputation)
tarot_cli_is_status (const TarotCli * cli)
{
return cli_is_status (cli, with_imputation);
return cli_is_status (cli);
}
int
tarot_cli_is_load (const TarotCli * cli, char **filename)
tarot_cli_is_load (const TarotCli * cli)
{
return cli_is_load (cli, filename);
return cli_is_load (cli);
}
int
tarot_cli_is_save (const TarotCli * cli, char **filename)
tarot_cli_is_save (const TarotCli * cli)
{
return cli_is_save (cli, filename);
return cli_is_save (cli);
}
int
tarot_cli_is_check (const TarotCli * cli, TarotGameEvent ** event)
tarot_cli_is_check (const TarotCli * cli)
{
return cli_is_check (cli, event);
return cli_is_check (cli);
}
int
tarot_cli_is_event (const TarotCli * cli, TarotGameEvent ** event)
tarot_cli_is_event (const TarotCli * cli)
{
return cli_is_event (cli, event);
return cli_is_event (cli);
}
const char *
tarot_cli_get_error (const TarotCli * cli)
{
return cli_get_error (cli);
}
int
tarot_cli_get_with_imputation (const TarotCli * cli)
{
return cli_get_with_imputation (cli);
}
const char *
tarot_cli_get_filename (const TarotCli * cli)
{
return cli_get_filename (cli);
}
const TarotGameEvent *
tarot_cli_get_event (const TarotCli * cli)
{
return cli_get_event (cli);
}
#include <tarot/cli_private_impl.h>
......@@ -54,42 +54,80 @@ extern "C"
int tarot_cli_next (TarotCli * cli);
/**
* tarot_cli_has_command:
* Returns: (type boolean):
*/
int tarot_cli_has_command (const TarotCli * cli);
/**
* tarot_cli_is_continuation:
* Returns: (type boolean):
*/
int tarot_cli_is_continuation (const TarotCli * cli);
/**
* tarot_cli_is_help:
* Returns: (type boolean):
*/
int tarot_cli_is_help (const TarotCli * cli);
/**
* tarot_cli_is_version:
* Returns: (type boolean):
*/
int tarot_cli_is_version (const TarotCli * cli);
/**
* tarot_cli_is_license:
* Returns: (type boolean):
*/
int tarot_cli_is_license (const TarotCli * cli);
/**
* tarot_cli_is_error:
* errorstr: (transfer none):
* Returns: (type boolean):
*/
int tarot_cli_is_error (const TarotCli * cli);
const char *tarot_cli_get_error (const TarotCli * cli);
/**
* tarot_cli_is_status:
* Returns: (type boolean):
*/
int tarot_cli_is_status (const TarotCli * cli);
/**
* tarot_cli_get_with_imputation:
* Returns: (type boolean):
*/
int tarot_cli_is_error (const TarotCli * cli, char **errorstr);
int tarot_cli_is_status (const TarotCli * cli, int *with_imputation);
int tarot_cli_get_with_imputation (const TarotCli * cli);
/**
* tarot_cli_is_load:
* filename: (transfer none):
* Returns: (type boolean):
*/
int tarot_cli_is_load (const TarotCli * cli, char **filename);
int tarot_cli_is_load (const TarotCli * cli);
const char *tarot_cli_get_filename (const TarotCli * cli);
/**
* tarot_cli_is_save:
* filename: (transfer none):
* Returns: (type boolean):
*/
int tarot_cli_is_save (const TarotCli * cli, char **filename);
int tarot_cli_is_save (const TarotCli * cli);
/**
* tarot_cli_is_check:
* event: (transfer none):
* Returns: (type boolean):
*/
int tarot_cli_is_check (const TarotCli * cli, TarotGameEvent ** event);
int tarot_cli_is_check (const TarotCli * cli);
const TarotGameEvent *tarot_cli_get_event (const TarotCli * cli);
/**
* tarot_cli_is_event:
* event: (transfer none):
* Returns: (type boolean):
*/
int tarot_cli_is_event (const TarotCli * cli, TarotGameEvent ** event);
int tarot_cli_is_event (const TarotCli * cli);
#ifdef __cplusplus
}
......
......@@ -48,12 +48,16 @@ extern "C"
static int cli_is_help (const TarotCli * cli);
static int cli_is_version (const TarotCli * cli);
static int cli_is_license (const TarotCli * cli);
static int cli_is_error (const TarotCli * cli, char **errorstr);
static int cli_is_status (const TarotCli * cli, int *with_imputation);
static int cli_is_load (const TarotCli * cli, char **filename);
static int cli_is_save (const TarotCli * cli, char **filename);
static int cli_is_check (const TarotCli * cli, TarotGameEvent ** event);
static int cli_is_event (const TarotCli * cli, TarotGameEvent ** event);
static int cli_is_error (const TarotCli * cli);
static int cli_is_status (const TarotCli * cli);
static int cli_is_load (const TarotCli * cli);
static int cli_is_save (const TarotCli * cli);
static int cli_is_check (const TarotCli * cli);
static int cli_is_event (const TarotCli * cli);
static const char *cli_get_error (const TarotCli * cli);
static int cli_get_with_imputation (const TarotCli * cli);
static const char *cli_get_filename (const TarotCli * cli);
static const TarotGameEvent *cli_get_event (const TarotCli * cli);
#ifdef __cplusplus
}
......
......@@ -228,79 +228,79 @@ cli_is_license (const TarotCli * cli)
}
static inline int
cli_is_error (const TarotCli * cli, char **errorstr)
cli_is_error (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_error ());
if (ok)
{
*errorstr = (char *) tarot_parser_get_error (cli->parser);
}
return ok;
}
static inline int
cli_is_status (const TarotCli * cli, int *with_imputation)
cli_is_status (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_status ());
if (ok)
{
*with_imputation = tarot_parser_get_with_imputation (cli->parser);
}
return ok;
}
static inline int
cli_is_load (const TarotCli * cli, char **filename)
cli_is_load (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_load ());
if (ok)
{
*filename = (char *) tarot_parser_get_filename (cli->parser);
}
return ok;
}
static inline int
cli_is_save (const TarotCli * cli, char **filename)
cli_is_save (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_save ());
if (ok)
{
*filename = (char *) tarot_parser_get_filename (cli->parser);
}
return ok;
}
static inline int
cli_is_check (const TarotCli * cli, TarotGameEvent ** event)
cli_is_check (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_check ());
if (ok)
{
*event = (TarotGameEvent *) tarot_parser_get_event (cli->parser);
}
return ok;
}
static inline int
cli_is_event (const TarotCli * cli, TarotGameEvent ** event)
cli_is_event (const TarotCli * cli)
{
int ok =
(tarot_parser_get_command_type (cli->parser) ==
tarot_parser_type_event ());
if (ok)
{
*event = (TarotGameEvent *) tarot_parser_get_event (cli->parser);
}
return ok;
}
static inline const char *
cli_get_error (const TarotCli * cli)
{
return tarot_parser_get_error (cli->parser);
}
static inline int
cli_get_with_imputation (const TarotCli * cli)
{
return tarot_parser_get_with_imputation (cli->parser);
}
static inline const char *
cli_get_filename (const TarotCli * cli)
{
return tarot_parser_get_filename (cli->parser);
}
static inline const TarotGameEvent *
cli_get_event (const TarotCli * cli)
{
return tarot_parser_get_event (cli->parser);
}
......@@ -37,6 +37,9 @@ extern "C"
struct TarotGame;
typedef struct TarotGame TarotGame;
/**
* tarot_game_alloc: (constructor):
*/
TarotGame *tarot_game_alloc ();
/**
......@@ -61,9 +64,24 @@ extern "C"
int tarot_game_load (TarotGame * game, const TarotGameEventArray * events);
int tarot_game_load_from_xml (TarotGame * game, const char *input);
size_t tarot_game_n_players (const TarotGame * game);
/**
* tarot_game_with_call:
* Returns: (type boolean):
*/
int tarot_game_with_call (const TarotGame * game);
/**
* tarot_game_has_next:
* Returns: (type boolean):
*/
int tarot_game_has_next (const TarotGame * game);
TarotPlayer tarot_game_next (const TarotGame * game);
/**
* tarot_game_get_deal:
* @myself: (out):
*/
int tarot_game_get_deal (const TarotGame * game, TarotPlayer * myself,
TarotCardArray * array);
int tarot_game_get_deal_all (const TarotGame * game,
......@@ -71,64 +89,181 @@ extern "C"
int tarot_game_get_cards (const TarotGame * game, TarotPlayer who,
TarotCardArray * cards);
size_t tarot_game_get_n_bids (const TarotGame * game);
/**
* tarot_game_get_bid:
* @bid: (out):
*/
int tarot_game_get_bid (const TarotGame * game, TarotPlayer player,
TarotBid * bid);
/**
* tarot_game_get_taker:
* @taker: (out):
*/
int tarot_game_get_taker (const TarotGame * game, TarotPlayer * taker);
size_t tarot_game_get_n_declarations (const TarotGame * game);
/**
* tarot_game_get_declaration:
* @decl: (out) (type boolean):
*/
int tarot_game_get_declaration (const TarotGame * game, TarotPlayer player,
int *decl);
/**
* tarot_game_get_declarant:
* @declarant: (out):
*/
int tarot_game_get_declarant (const TarotGame * game,
TarotPlayer * declarant);
/**
* tarot_game_get_call:
* @card: (out):
*/
int tarot_game_get_call (const TarotGame * game, TarotCard * card);
/**
* tarot_game_get_partner:
* @partner: (out):
*/
int tarot_game_get_partner (const TarotGame * game, TarotPlayer * partner);
int tarot_game_get_dog (const TarotGame * game, TarotCardArray * cards);
int tarot_game_get_discard (const TarotGame * game, TarotCardArray * cards);
int tarot_game_get_public_discard (const TarotGame * game,
TarotCardArray * cards);
/**
* tarot_game_get_handful:
* @size: (out):
*/
int tarot_game_get_handful (const TarotGame * game, TarotPlayer p,
int *size, TarotCardArray * cards);
unsigned int tarot_game_n_tricks (const TarotGame * game);
unsigned int tarot_game_current_trick (const TarotGame * game);
/**
* tarot_game_get_lead_suit:
* @lead_suit: (out):
*/
int tarot_game_get_lead_suit (const TarotGame * game, unsigned int i_trick,
TarotSuit * lead_suit);
/**
* tarot_game_get_max_trump:
* @max_trump: (out):
*/
int tarot_game_get_max_trump (const TarotGame * game, unsigned int i_trick,
TarotNumber * max_trump);
/**
* tarot_game_get_trick_leader:
* @leader: (out):
*/
int tarot_game_get_trick_leader (const TarotGame * game,
unsigned int i_trick,
TarotPlayer * leader);
/**
* tarot_game_get_trick_taker:
* @taker: (out):
*/
int tarot_game_get_trick_taker (const TarotGame * game,
unsigned int i_trick, TarotPlayer * taker);
size_t tarot_game_trick_count_cards (const TarotGame * game,
unsigned int i_trick);
/**
* tarot_game_get_trick_card:
* @card: (out):
* @cannot_follow: (out) (type boolean):
* @cannot_overtrump: (out) (type boolean):
* @cannot_undertrump: (out) (type boolean):
*/
int tarot_game_get_trick_card (const TarotGame * game, unsigned int i_trick,
unsigned int i_card, TarotCard * card,
int *cannot_follow, int *cannot_overtrump,
int *cannot_undertrump);
/**
* tarot_game_get_trick_card_of:
* @card: (out):
* @cannot_follow: (out) (type boolean):
* @cannot_overtrump: (out) (type boolean):
* @cannot_undertrump: (out) (type boolean):
*/
int tarot_game_get_trick_card_of (const TarotGame * game,
unsigned int i_trick, TarotPlayer player,
TarotCard * card, int *cannot_follow,
int *cannot_overtrump,
int *cannot_undertrump);
/**
* tarot_game_points_in_trick:
* @halfpoints: (out):
* @oudlers: (out):
*/
int tarot_game_points_in_trick (const TarotGame * game,
unsigned int i_trick,
unsigned int *halfpoints,
unsigned int *oudlers);
int tarot_game_base_score (const TarotGame * game);
/**
* tarot_game_get_score:
* @score: (out):
*/
int tarot_game_get_score (const TarotGame * game, TarotPlayer i,
int *score);
/**
* tarot_game_hint_bid:
* @player: (out):
* @mini: (out):
*/
int tarot_game_hint_bid (const TarotGame * game, TarotPlayer * player,
TarotBid * mini);
/**
* tarot_game_hint_decl:
* @player: (out):
* @allowed: (out) (type boolean):
*/
int tarot_game_hint_decl (const TarotGame * game, TarotPlayer * player,
int *allowed);
/**
* tarot_game_hint_call:
* @player: (out):
* @mini: (out):
*/
int tarot_game_hint_call (const TarotGame * game, TarotPlayer * player,
TarotNumber * mini);
/**
* tarot_game_hint_discard:
* @player: (out):
* @n_cards: (out):
*/
int tarot_game_hint_discard (const TarotGame * game, TarotPlayer * player,
size_t * n, TarotCardArray * prio,
size_t * n_cards, TarotCardArray * prio,
TarotCardArray * additional);
/**
* tarot_game_hint_handful:
* @player: (out):
* @n_simple: (out):
* @n_double: (out):
* @n_triple: (out):
*/
int tarot_game_hint_handful (const TarotGame * game, TarotPlayer * player,
size_t * n_simple, size_t * n_double,
size_t * n_triple, TarotCardArray * prio,
TarotCardArray * additional);
/**
* tarot_game_hint_card:
* @player: (out):
*/
int tarot_game_hint_card (const TarotGame * game, TarotPlayer * player,
TarotCardArray * playable);
......
......@@ -74,7 +74,7 @@ extern "C"
/**
* tarot_game_event_set_deal_all_random:
* seed: (array length=seed_size) (element-type char):
* seed: (string length=seed_size):
*/
int tarot_game_event_set_deal_all_random (TarotGameEvent * event,
size_t n_players,
......
......@@ -47,6 +47,18 @@ tarot_player_to_string (TarotPlayer p, size_t max, char *dest)
return player_to_string (p, max, dest);
}
char *
tarot_player_to_string_alloc (TarotPlayer p)
{
size_t alloc_length = 1 + player_to_string (p, 0, NULL);
char *ret = malloc (alloc_length);
if (ret != NULL)
{
player_to_string (p, alloc_length, ret);
}
return ret;
}
TarotPlayerArray *
tarot_player_array_alloc ()
{
......
......@@ -42,8 +42,16 @@ extern "C"
*/
TarotPlayer tarot_player_parse (const char *text, char **end);
/**
* tarot_player_to_string: (skip):
*/
size_t tarot_player_to_string (TarotPlayer p, size_t max, char *dest);
/**
* tarot_player_to_string_alloc: (rename tarot_player_to_string):
*/
char *tarot_player_to_string_alloc (TarotPlayer p);
struct TarotPlayerArray;
typedef struct TarotPlayerArray TarotPlayerArray;
......
......@@ -34,6 +34,9 @@ extern "C"
struct TarotCounter;
typedef struct TarotCounter TarotCounter;
/**
* tarot_counter_alloc: (constructor):
*/
TarotCounter *tarot_counter_alloc ();
/**
......@@ -98,7 +101,7 @@ extern "C"
/**
* tarot_counter_and_game_impute:
* seed: (array length=seed_size) (element-type char):
* @seed: (array length=seed_size) (element-type char):