Commit 03670104 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Purge the XML code

parent c509fa11
......@@ -21,7 +21,6 @@
#include <tarot_private.h>
#include <tarot/cards_private.h>
#include <tarot/game_event_private.h>
#include <tarot/xml.h>
#include <tarot/game_private.h>
#include <tarot/trick_private.h>
#include <tarot/tricks_private.h>
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2017, 2018, 2019 Vivien Kraus
* Copyright (C) 2017, 2018, 2019, 2020 Vivien Kraus
*
* 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
......@@ -146,31 +146,6 @@ tarot_game_iterator_free (TarotGameIterator * iterator)
free (iterator);
}
size_t
tarot_game_save_to_xml (const TarotGame * game, size_t start, size_t max,
char *dest)
{
return game_save_to_xml (game, start, max, dest);
}
char *
tarot_game_save_to_xml_alloc (const TarotGame * game)
{
size_t n = game_save_to_xml (game, 0, 0, NULL);
char *ret = xmalloc (n + 1);
size_t n2 = game_save_to_xml (game, 0, n + 1, ret);
assert (n2 == n);
(void) n2;
assert (strlen (ret) == n);
return ret;
}
TarotGameError
tarot_game_load_from_xml (TarotGame * game, const char *input)
{
return game_load_from_xml (game, input);
}
size_t
tarot_game_n_players (const TarotGame * game)
{
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019 Vivien Kraus
* Copyright (C) 2018, 2019, 2020 Vivien Kraus
*
* 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
......@@ -39,7 +39,6 @@ extern "C"
typedef enum
{
TAROT_GAME_OK = 0,
TAROT_GAME_INVXML,
TAROT_GAME_INVEV,
TAROT_GAME_NA,
TAROT_GAME_TOOLATE
......@@ -97,24 +96,6 @@ extern "C"
void tarot_game_iterator_free (TarotGameIterator * game_iterator);
/**
* tarot_game_save_to_xml:
* @dest_out: (array length=max):
*/
size_t tarot_game_save_to_xml (const TarotGame * game, size_t start,
size_t max, char *dest_out);
/**
* tarot_game_save_to_xml_alloc: (rename-to tarot_game_save_to_xml)
*/
char *tarot_game_save_to_xml_alloc (const TarotGame * game);
/**
* tarot_game_load_from_xml:
*/
TarotGameError tarot_game_load_from_xml (TarotGame * game,
const char *input);
size_t tarot_game_n_players (const TarotGame * game);
/**
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019 Vivien Kraus
* Copyright (C) 2018, 2019, 2020 Vivien Kraus
*
* 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
......@@ -40,10 +40,6 @@ extern "C"
TarotCard call);
static void game_iterator_setup (TarotGameIterator * iterator,
const TarotGame * game);
static size_t game_save_to_xml (const TarotGame * game, size_t start,
size_t max, char *dest);
static TarotGameError game_load_from_xml (TarotGame * game,
const char *input);
static size_t game_n_players (const TarotGame * game);
static int game_with_call (const TarotGame * game);
static TarotGameError game_get_next (const TarotGame * game,
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019 Vivien Kraus
* Copyright (C) 2018, 2019, 2020 Vivien Kraus
*
* 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
......@@ -481,40 +481,6 @@ game_iterator_setup (TarotGameIterator * iterator, const TarotGame * game)
iterator->last_event.data = iterator->event_data;
}
static inline size_t
game_save_to_xml (const TarotGame * game, size_t start, size_t max,
char *dest)
{
return tarot_xml_save (game, start, max, dest);
}
static inline TarotGameError
game_load_from_xml (TarotGame * game, const char *input)
{
TarotXmlParser parser;
TarotXmlParserIterator i;
size_t ranafout;
TarotGameError ret = TAROT_GAME_OK;
const TarotGameEvent *event;
if (tarot_xml_parser_construct
(sizeof (parser), (char *) &parser, &ranafout, input) == 0)
{
return TAROT_GAME_INVXML;
}
tarot_xml_parser_iterator_construct (sizeof (i), (char *) &i, &ranafout,
&parser);
while ((event = tarot_xml_parser_iterator_next_value (&i)) != NULL)
{
if (game_add_event (game, event) != TAROT_GAME_OK)
{
ret = TAROT_GAME_INVEV;
break;
}
}
tarot_xml_parser_destruct (&parser);
return ret;
}
static inline size_t
game_n_players (const TarotGame * game)
{
......
......@@ -85,8 +85,6 @@ TAROT_BOXED_TYPE (GameIterator, game_iterator)
TAROT_BOXED_TYPE (Mcts, mcts)
TAROT_BOXED_TYPE (Perceptron, perceptron)
TAROT_BOXED_TYPE (Solo, solo)
TAROT_BOXED_TYPE (XmlParser, xml_parser)
TAROT_BOXED_TYPE (XmlParserIterator, xml_parser_iterator)
/*** END file-header ***/
/*** BEGIN file-production ***/
......
......@@ -50,8 +50,6 @@ extern "C"
GType tarot_mcts_get_type (void);
GType tarot_perceptron_get_type (void);
GType tarot_solo_get_type (void);
GType tarot_xml_parser_get_type (void);
GType tarot_xml_parser_iterator_get_type (void);
/* *INDENT-OFF* */
/*** END file-header ***/
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019 Vivien Kraus
* Copyright (C) 2018, 2019, 2020 Vivien Kraus
*
* 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
......@@ -15,7 +15,6 @@
*/
#include <config.h>
#include <tarot/xml.h>
#include <tarot/mcts_private.h>
#include "xalloc.h"
#include <string.h>
......
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# 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, version 3 of the License.
#
# 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/>.
AM_CPPFLAGS += -I $(srcdir)/%reldir% -I %reldir%
tarotinclude_HEADERS += %reldir%/tarot/xml.h
src_libtarot_libtarot_la_SOURCES += \
%reldir%/xml.c \
%reldir%/tarot/xml_private.h \
%reldir%/tarot/xml_private_impl.h
ENUM_HEADER_FILES += %reldir%/tarot/xml.h
INTROSPECTED_SOURCES += %reldir%/xml.c
check_PROGRAMS += %reldir%/check_xml
%canon_reldir%_check_xml_LDADD = src/libtarot/libtarot.la
EXTRA_DIST += %reldir%/check_xml_1.xml
$(srcdir)/%reldir%/tarot/xml_private_impl.h: src/libtarot/cards/tarot/cards_private.h
$(srcdir)/%reldir%/xml.c: src/libtarot/cards/tarot/cards_private.h
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019, 2020 Vivien Kraus
*
* 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, version 3 of the License.
*
* 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 <config.h>
#include <tarot/game_event.h>
#include <tarot/game.h>
#include <tarot/xml.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "xalloc.h"
#include <stdalign.h>
static void
unit_test (const char *xml)
{
char *rebuilt = NULL;
TarotXmlParser *parser = tarot_xml_parser_alloc (xml);
TarotXmlParserIterator *iterator;
TarotGame *game = tarot_game_alloc ();
const TarotGameEvent *event;
if (parser == NULL)
{
abort ();
}
iterator = tarot_xml_parser_iterator (parser);
if (iterator == NULL)
{
abort ();
}
while ((event = tarot_xml_parser_iterator_next_value (iterator)) != NULL)
{
if (tarot_game_add_event (game, event) != TAROT_GAME_OK)
{
abort ();
}
}
tarot_xml_parser_iterator_free (iterator);
tarot_xml_parser_free (parser);
rebuilt = tarot_game_save_to_xml_alloc (game);
if (rebuilt == NULL)
{
abort ();
}
if (strcmp (xml, rebuilt) != 0)
{
fprintf (stderr, "%s:%d: %s, size %lu\n", __FILE__, __LINE__, rebuilt, strlen (rebuilt));
abort ();
}
free (rebuilt);
tarot_game_free (game);
}
static void
push (char **buffer, size_t *available, size_t *used, char c)
{
if (*available <= *used)
{
*available *= 2;
*buffer = realloc (*buffer, *available);
if (*buffer == NULL)
{
abort ();
}
}
(*buffer)[(*used)++] = c;
}
static char *
read_all (FILE *file)
{
char *buffer = NULL;
size_t available = 1;
size_t used = 0;
int c;
buffer = malloc (1);
if (buffer == NULL)
{
abort ();
}
while ((c = fgetc (file)) != EOF)
{
push (&buffer, &available, &used, c);
}
push (&buffer, &available, &used, '\0');
return buffer;
}
int
main ()
{
const char *filename = ABS_TOP_SRCDIR "/src/libtarot/xml/check_xml_1.xml";
FILE *file = fopen (filename, "r");
char *buffer = NULL;
if (file == NULL)
{
fprintf (stderr, "'%s' is not present\n", filename);
abort ();
}
buffer = read_all (file);
fprintf (stderr, "%s:%d: Input: %lu bytes\n", __FILE__, __LINE__, strlen (buffer));
fclose (file);
unit_test (buffer);
free (buffer);
return 0;
}
<?xml version="1.0"?>
<tarot:game xmlns:tarot="http://planete-kraus.eu/tarot">
<tarot:setup n-players="5" with-call="yes"/>
<tarot:deal-all>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P6"/>
<tarot:player player="P6"/>
<tarot:player player="P6"/>
<tarot:player player="P4"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P3"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P4"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P2"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P1"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P5"/>
<tarot:player player="P2"/>
<tarot:player player="P3"/>
<tarot:player player="P5"/>
</tarot:deal-all>
<tarot:bid bid="take"/>
<tarot:bid bid="pass"/>
<tarot:bid bid="pass"/>
<tarot:bid bid="pass"/>
<tarot:bid bid="pass"/>
<tarot:decl slam="no"/>
<tarot:decl slam="no"/>
<tarot:decl slam="no"/>
<tarot:decl slam="no"/>
<tarot:decl slam="yes"/>
<tarot:call card="KC"/>
<tarot:dog>
<tarot:card card="6H"/>
<tarot:card card="7H"/>
<tarot:card card="8H"/>
</tarot:dog>
<tarot:discard>
<tarot:card card="AH"/>
<tarot:card card="2H"/>
<tarot:card card="3H"/>
</tarot:discard>
<tarot:handful/>
<tarot:card card="19T"/>
<tarot:handful/>
<tarot:card card="10T"/>
<tarot:handful/>
<tarot:card card="20T"/>
<tarot:handful/>
<tarot:card card="21T"/>
<tarot:handful/>
<tarot:card card="6C"/>
<tarot:card card="AC"/>
<tarot:card card="7C"/>
<tarot:card card="11T"/>
<tarot:card card="9T"/>
<tarot:card card="10C"/>
<tarot:card card="KH"/>
<tarot:card card="4H"/>
<tarot:card card="10D"/>
<tarot:card card="2C"/>
<tarot:card card="9H"/>
<tarot:card card="QH"/>
<tarot:card card="5H"/>
<tarot:card card="JC"/>
<tarot:card card="3C"/>
<tarot:card card="8C"/>
<tarot:card card="CH"/>
<tarot:card card="6H"/>
<tarot:card card="JD"/>
<tarot:card card="4C"/>
<tarot:card card="9C"/>
<tarot:card card="JH"/>
<tarot:card card="7H"/>
<tarot:card card="JS"/>
<tarot:card card="5C"/>
<tarot:card card="6D"/>
<tarot:card card="10H"/>
<tarot:card card="8H"/>
<tarot:card card="CC"/>
<tarot:card card="AD"/>
<tarot:card card="7D"/>
<tarot:card card="18T"/>
<tarot:card card="8T"/>
<tarot:card card="CD"/>
<tarot:card card="2D"/>
<tarot:card card="8D"/>
<tarot:card card="17T"/>
<tarot:card card="7T"/>
<tarot:card card="CS"/>
<tarot:card card="3D"/>
<tarot:card card="9D"/>
<tarot:card card="16T"/>
<tarot:card card="6T"/>
<tarot:card card="QC"/>
<tarot:card card="4D"/>
<tarot:card card="5S"/>
<tarot:card card="15T"/>
<tarot:card card="5T"/>
<tarot:card card="QD"/>
<tarot:card card="5D"/>
<tarot:card card="6S"/>
<tarot:card card="14T"/>
<tarot:card card="4T"/>
<tarot:card card="QS"/>
<tarot:card card="AS"/>
<tarot:card card="7S"/>
<tarot:card card="13T"/>
<tarot:card card="3T"/>
<tarot:card card="KD"/>
<tarot:card card="2S"/>
<tarot:card card="8S"/>
<tarot:card card="12T"/>
<tarot:card card="2T"/>
<tarot:card card="KS"/>
<tarot:card card="3S"/>
<tarot:card card="9S"/>
<tarot:card card="EXC"/>
<tarot:card card="1T"/>
<tarot:card card="KC"/>
<tarot:card card="4S"/>
<tarot:card card="10S"/>
</tarot:game>
/* tarot implements the rules of the tarot game
* Copyright (C) 2018, 2019 Vivien Kraus
*
* 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, version 3 of the License.
*
* 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_XML_INCLUDED
#define H_TAROT_XML_INCLUDED
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
struct TarotXmlParser;
typedef struct TarotXmlParser TarotXmlParser;
struct TarotGameEvent;
struct TarotGame;
struct TarotMcts;
/**
* tarot_xml_parser_construct:
* @mem_out: (array length=max_mem):
* @alignment: (out):
*/
size_t tarot_xml_parser_construct (size_t max_mem, char *mem_out,
size_t *alignment, const char *input);
void tarot_xml_parser_destruct (TarotXmlParser * parser);
/**
* tarot_xml_parser_alloc: (constructor)
*/
TarotXmlParser *tarot_xml_parser_alloc (const char *input);
TarotXmlParser *tarot_xml_parser_dup (const TarotXmlParser * source);
void tarot_xml_parser_free (TarotXmlParser * xml_parser);
struct TarotXmlParserIterator;
typedef struct TarotXmlParserIterator TarotXmlParserIterator;
/**
* tarot_xml_parser_iterator_construct:
* @mem_out: (array length=max_mem):
* @alignment: (out):
*/
size_t tarot_xml_parser_iterator_construct (size_t max_mem, char *mem_out,
size_t *alignment,
const TarotXmlParser * parser);
void tarot_xml_parser_iterator_destruct (TarotXmlParserIterator * parser);
const struct TarotGameEvent *tarot_xml_parser_iterator_next_value
(TarotXmlParserIterator * iterator);
/**
* tarot_xml_save:
* @game: (type TarotGame):
*/
size_t tarot_xml_save (const struct TarotGame *game, size_t start,
size_t max, char *dest);
TarotXmlParserIterator *tarot_xml_parser_iterator
(const TarotXmlParser * parser);
TarotXmlParserIterator *tarot_xml_parser_iterator_dup
(const TarotXmlParserIterator * source);
void tarot_xml_parser_iterator_free (TarotXmlParserIterator * xml_parser);
/**
* tarot_xml_save_mcts_tree:
* @mcts: (type TarotMcts):