Commit 66b00890 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Provide a tarot-status command

This command will print status information.  It will be most useful to
programs.
parent 7f09b730
Pipeline #160465 failed with stages
in 22 minutes and 22 seconds
......@@ -46,6 +46,7 @@
/doc/players-and-cards
/doc/players-and-cards.c
/doc/tarot-figures
/doc/tarot-status.man
/doc/tarot-tune
/doc/tarot.info
/doc/tarot.man
......@@ -109,12 +110,19 @@
/src/libtarot/test/no-slam
/src/libtarot/test/no-slam.c
/src/libtarot/xml/check_xml
/src/tarot-app/ai.c
/src/tarot-app/card_painter.c
/src/tarot-app/card_painter_default.c
/src/tarot-app/engine.c
/src/tarot-app/gui/card_view.c
/src/tarot-app/gui/widget.c
/src/tarot-app/gui/window.c
/src/tarot-app/lexer.c
/src/tarot-app/main.c
/src/tarot-app/parser.c
/src/tarot-app/parser.h
/src/tarot-app/resources.c
/src/tarot-app/server.c
/src/tarot-app/tarot
/src/tarot-app/tarot-en
/src/tarot-app/tarot-parser-stamp
......@@ -124,11 +132,4 @@
/tarot-*.*.*.tar.gz
/test-driver
/texinfo.tex
/tuneconfig.h
/src/tarot-app/ai.c
/src/tarot-app/card_painter.c
/src/tarot-app/card_painter_default.c
/src/tarot-app/gui/window.c
/src/tarot-app/gui/widget.c
/src/tarot-app/gui/card_view.c
/src/tarot-app/server.c
\ No newline at end of file
/tuneconfig.h
\ No newline at end of file
......@@ -16,8 +16,8 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
dist_man6_MANS += %reldir%/tarot.man
MAINTAINERCLEANFILES += $(srcdir)/%reldir%/tarot.man
dist_man6_MANS += %reldir%/tarot.man %reldir%/tarot-status.man
MAINTAINERCLEANFILES += $(srcdir)/%reldir%/tarot.man $(srcdir)/%reldir%/tarot-status.man
help2man_verbose = $(help2man_verbose_@AM_V@)
help2man_verbose_ = $(help2man_verbose_@AM_DEFAULT_V@)
......@@ -26,3 +26,7 @@ help2man_verbose_0 = @echo " HELP2MAN" $@;
$(srcdir)/%reldir%/tarot.man: src/tarot-app/main.vala
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot
$(help2man_verbose) ./pre-inst-env help2man tarot > $(srcdir)/%reldir%/tarot.man
$(srcdir)/%reldir%/tarot-status.man: src/tarot-app/tarot_status.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-status
$(help2man_verbose) ./pre-inst-env help2man tarot-status > $@
......@@ -9,4 +9,5 @@ src/tarot-app/gui/card_view.vala
src/tarot-app/ai.vala
src/tarot-app/card_painter.vala
src/tarot-app/card_painter_default.vala
src/tarot-app/server.vala
\ No newline at end of file
src/tarot-app/server.vala
src/tarot-app/tarot_status.c
\ No newline at end of file
......@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: tarot 0.4.2.83-ebdc-dirty\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2019-08-24 10:49+0200\n"
"PO-Revision-Date: 2019-08-24 11:00+0200\n"
"POT-Creation-Date: 2019-08-24 17:40+0200\n"
"PO-Revision-Date: 2019-08-24 17:47+0200\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
"Language: fr\n"
......@@ -26,7 +26,8 @@ msgstr ""
"ERREUR : la variable d'environnement '%s' n'est pas définie. Essayez de "
"réinstaller le programme.\n"
#: src/tarot-app/main.vala:69
#: src/tarot-app/main.vala:69 src/tarot-app/tarot_status.c:44
#, c-format
msgid "ERROR: could not initialize libtarot.\n"
msgstr "ERREUR : impossible d'initialiser libtarot.\n"
......@@ -38,13 +39,13 @@ msgstr "Affiche l'information de version et quitte"
msgid "version"
msgstr "version"
#: src/tarot-app/main.vala:100
#: src/tarot-app/main.vala:100 src/tarot-app/tarot_status.c:76
#, c-format
msgid ""
"%s (libtarot %s)\n"
"\n"
"Copyright © 2019 Vivien Kraus\n"
"This is free software; se the source for copying conditions. There is NO "
"This is free software; see the source for copying conditions. There is NO "
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
msgstr ""
"%s (libtarot %s)\n"
......@@ -1033,6 +1034,96 @@ msgstr " D"
msgid "K"
msgstr " R"
#: src/tarot-app/tarot_status.c:48
#, c-format
msgid ""
"Usage:\n"
"- tarot-status --help\n"
"- tarot-status --version\n"
"- tarot-status next < GAME\n"
"- tarot-status at-end < GAME\n"
"- tarot-status score < GAME\n"
"Please run tarot-status --help.\n"
msgstr ""
"Utilisation :\n"
"- tarot-status --aide\n"
"- tarot-status --version\n"
"- tarot-status suivant\n"
"- tarot-status fini\n"
"- tarot-status score\n"
"Veuillez exécuter tarot-status --aide.\n"
#: src/tarot-app/tarot_status.c:57
msgid "--help"
msgstr "--aide"
#: src/tarot-app/tarot_status.c:59
#, c-format
msgid ""
"Usage: tarot-status [OPTION]... ([COMMAND] < GAME)?\n"
"Print some status information of GAME. Options are:\n"
"- --help: print this message and exit\n"
"- --version: print program version and exit\n"
"\n"
"Commands:\n"
"- next: print the number of the next player. The number of a player\n"
" is the number of players that have made a bid before this player in\n"
" the bidding phase;\n"
"- at-end: exit sucessfully if the game is finished, or exit with code\n"
" 1 if the game is not finished;\n"
"- score: for a finished game, print the score, in the order of player\n"
" numbers, one line for each player.\n"
msgstr ""
"Utilisation : tarot-status [OPTION]... ([COMMANDE] < PARTIE)?\n"
"Affiche des informations sur le statut de PARTIE. Les options sont :\n"
"- --aide : affiche ce message et quitte\n"
"- --version : affiche la version du programme et quitte\n"
"\n"
"Commandes :\n"
"- suivant : affiche le numéro du joueur suivant. Le numéro de joueur\n"
" est le nombre de joueurs qui ont fait une enchère avant ce joueur\n"
" pendant la phase d'enchères ;\n"
"- fini : termine sans erreur si la partie est finie, ou termine avec\n"
" le code 1 si la partie n'est pas finie ;\n"
"- score : pour une partie terminée, affiche le score, par ordre de\n"
" numéro de joueur, une ligne pour chaque joueur.\n"
#: src/tarot-app/tarot_status.c:74
msgid "--version"
msgstr "--version"
#: src/tarot-app/tarot_status.c:84
msgid "next"
msgstr "suivant"
#: src/tarot-app/tarot_status.c:94
#, c-format
msgid "Error: all players have played in this game.\n"
msgstr "Erreur : tous les joueurs ont joué dans cette partie.\n"
#: src/tarot-app/tarot_status.c:98
msgid "at-end"
msgstr "fini"
#: src/tarot-app/tarot_status.c:107
msgid "score"
msgstr "score"
#: src/tarot-app/tarot_status.c:114
#, c-format
msgid "Error: this game is not finished yet.\n"
msgstr "ERREUR : cette partie n'est pas terminée.\n"
#: src/tarot-app/tarot_status.c:123
#, c-format
msgid "Error: unknown command '%s'.\n"
msgstr "Erreur : commande inconnue « %s ».\n"
#: src/tarot-app/tarot_status.c:138
#, c-format
msgid "Error: invalid game.\n"
msgstr "Erreur : partie invalide.\n"
#~ msgid "Hello, world!\n"
#~ msgstr "Bonjour, le monde !\n"
......@@ -1051,9 +1142,6 @@ msgstr " R"
#~ msgid "ERROR: the argument should be of the form PN=C1,C2,..., not '%s'"
#~ msgstr "Erreur : l'argument doit être de la forme PN=C1,C2,..., pas « %s »"
#~ msgid "ERROR: this game is not valid.\n"
#~ msgstr "ERREUR : cette partie n'est pas valide.\n"
#~ msgid "ERROR: could not explore with MCTS.\n"
#~ msgstr "ERREUR : impossible d'explorer avec MCTS.\n"
......@@ -1075,9 +1163,6 @@ msgstr " R"
#~ msgid "ERROR: invalid or unexpected call.\n"
#~ msgstr "ERREUR : appel invalide ou inattendu.\n"
#~ msgid "ERROR: invalid game.\n"
#~ msgstr "ERREUR : partie invalide.\n"
#~ msgid "ERROR: invalid or unexpected dog revelation.\n"
#~ msgstr "ERREUR : révélation de chien invalide ou inattendue.\n"
......
......@@ -20,3 +20,4 @@ AM_CPPFLAGS += -I $(srcdir)/%reldir% -I %reldir%
include %reldir%/tarot-cli-program.am
include %reldir%/run-with-c-locale.am
include %reldir%/tarot-status.am
......@@ -97,7 +97,7 @@ namespace Tarot {
return -1;
}
public static int run_version (string package_string) {
stdout.printf (_ ("%s (libtarot %s)\n\nCopyright © 2019 Vivien Kraus\nThis is free software; se the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
stdout.printf (_ ("%s (libtarot %s)\n\nCopyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
package_string,
Tarot.libtarot_version ());
return 0;
......
# tarot-status.am
#
# Copyright (C) 2019 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/>.
bin_PROGRAMS += %reldir%/tarot-status
%canon_reldir%_tarot_status_SOURCES = \
%reldir%/tarot_status.c \
src/gettext.h
%canon_reldir%_tarot_status_CFLAGS = \
$(AM_CFLAGS)
%canon_reldir%_tarot_status_LDADD = \
lib/libgnu.la \
src/libtarot/libtarot.la \
$(LTLIBINTL) \
$(LTLIBTHREAD) \
@INTL_MACOSX_LIBS@
/*
* tarot_status.c
*
* Copyright (C) 2019 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 <config.h>
#include <tarot.h>
#include "gettext.h"
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include "xalloc.h"
#include <assert.h>
#define _(String) gettext (String)
#define N_(String) String
static TarotGame *read_game ();
int
main (int argc, char *argv[])
{
TarotGame *game = NULL;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
if (tarot_init (LOCALEDIR) != 0)
{
fprintf (stderr, _ ("ERROR: could not initialize libtarot.\n"));
}
if (argc != 2)
{
fprintf (stderr, _ ("Usage:\n\
- tarot-status --help\n\
- tarot-status --version\n\
- tarot-status next < GAME\n\
- tarot-status at-end < GAME\n\
- tarot-status score < GAME\n\
Please run tarot-status --help.\n"));
return EXIT_FAILURE;
}
if (strcmp (argv[1], _ ("--help")) == 0)
{
printf (_ ("Usage: tarot-status [OPTION]... ([COMMAND] < GAME)?\n\
Print some status information of GAME. Options are:\n\
- --help: print this message and exit\n\
- --version: print program version and exit\n\
\n\
Commands:\n\
- next: print the number of the next player. The number of a player\n\
is the number of players that have made a bid before this player in\n\
the bidding phase;\n\
- at-end: exit sucessfully if the game is finished, or exit with code\n\
1 if the game is not finished;\n\
- score: for a finished game, print the score, in the order of player\n\
numbers, one line for each player.\n"));
return EXIT_SUCCESS;
}
if (strcmp (argv[1], _ ("--version")) == 0)
{
printf (_ ("%s (libtarot %s)\n\
\n\
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
"tarot-status",
tarot_libtarot_version ());
return EXIT_SUCCESS;
}
game = read_game ();
if (strcmp (argv[1], _ ("next")) == 0)
{
TarotPlayer next;
if (tarot_game_get_next (game, &next) == TAROT_GAME_OK)
{
printf ("%u\n", next);
return EXIT_SUCCESS;
}
else
{
fprintf (stderr, _ ("Error: all players have played in this game.\n"));
return EXIT_FAILURE;
}
}
if (strcmp (argv[1], _ ("at-end")) == 0)
{
size_t n_scores;
if (tarot_game_get_scores (game, &n_scores, 0, 0, NULL) == TAROT_GAME_OK)
{
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
if (strcmp (argv[1], _ ("score")) == 0)
{
size_t n_scores;
int i;
int *scores;
if (tarot_game_get_scores_alloc (game, &n_scores, &scores) != TAROT_GAME_OK)
{
fprintf (stderr, _ ("Error: this game is not finished yet.\n"));
return EXIT_FAILURE;
}
for (i = 0; i < n_scores; i++)
{
printf ("%d\n", scores[i]);
}
return EXIT_SUCCESS;
}
fprintf (stderr, _ ("Error: unknown command '%s'.\n"), argv[1]);
return EXIT_FAILURE;
}
static char *read_stdin (void);
static TarotGame *
read_game (void)
{
TarotGame *ret = tarot_game_alloc ();
char *input = read_stdin ();
if (tarot_game_load_from_xml (ret, input) == TAROT_GAME_OK)
{
return ret;
}
fprintf (stderr, _ ("Error: invalid game.\n"));
abort ();
}
struct buffer;
typedef struct buffer buffer;
static buffer *buffer_alloc (void);
static void buffer_push_back (buffer *b, char c);
static char *buffer_data (buffer *b); /* NOT nul-terminated */
static char *
read_stdin (void)
{
buffer *buffer = buffer_alloc ();
int c;
while ((c = getchar ()) != EOF)
{
unsigned int u = c;
buffer_push_back (buffer, (unsigned char) u);
}
buffer_push_back (buffer, '\0');
return buffer_data (buffer);
}
struct buffer
{
size_t allocated;
size_t used;
char *data;
};
static buffer *
buffer_alloc (void)
{
buffer *ret = xmalloc (sizeof (buffer));
ret->allocated = 1;
ret->used = 0;
ret->data = xmalloc (1);
return ret;
}
static void
buffer_push_back (buffer *b, char c)
{
if (b->used >= b->allocated)
{
b->allocated *= 2;
b->data = xrealloc (b->data, b->allocated);
}
assert (b->used < b->allocated);
b->data[b->used++] = c;
}
static char *
buffer_data (buffer *b)
{
return b->data;
}
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