Commit 11bbc8a5 authored by Vivien Kraus's avatar Vivien Kraus

Allow an output file

parent 13d958b5
......@@ -8,7 +8,7 @@ homerc = "$HOME/.config/tarot/tarot.conf";
environrc;
config-header = "config.h";
include = "int tarot_run_new_game (size_t n_players, int with_call);";
include = "int tarot_run_new_game (size_t n_players, int with_call, char **output);";
include = "int opts_main (int argc, char **argv);";
include = "int main (int argc, char **argv) { setenv (\"SYSCONFDIR\", SYSCONFDIR, 0); return opts_main (argc, argv); }";
include = "#define main opts_main";
......@@ -16,12 +16,27 @@ include = "#define main opts_main";
main = {
main-type = main;
main-text = <<- END
switch (WHICH_IDX_NEW_GAME)
{
case INDEX_OPT_NEW_GAME:
res = tarot_run_new_game (OPT_VALUE_N_PLAYERS, ENABLED_OPT (CALL_ALLOWED) && HAVE_OPT (CALL_ALLOWED));
break;
}
{
char *output = NULL;
switch (WHICH_IDX_NEW_GAME)
{
case INDEX_OPT_NEW_GAME:
res = tarot_run_new_game (OPT_VALUE_N_PLAYERS, ENABLED_OPT (CALL_ALLOWED) && HAVE_OPT (CALL_ALLOWED), &output);
break;
}
if (output != NULL)
{
if (HAVE_OPT (OUTPUT))
{
fputs (output, OPT_VALUE_OUTPUT);
}
else
{
puts (output);
}
free (output);
}
}
END;
};
......@@ -49,4 +64,14 @@ flag = {
descrip = "Allow a call in the game";
disable = no;
doc = 'When creating a game with @command{--new-game}, and there are 5 players, define whether there is a call. By default, there is no call. Even if the game has 5 players. Indeed, the default value cannot depend on the current number of players, whatever the definition of current.';
};
flag = {
name = output;
value = o;
descrip = "Output file to write";
arg-type = file;
open-file = "yes";
file-mode = "w";
doc = 'When @command{tarot-cli} generates a game, it will be saved to disk instead of printed to the standard output.';
};
\ No newline at end of file
namespace Tarot {
public static int run_new_game (size_t n_players, bool with_call) {
public static int run_new_game (size_t n_players, bool with_call, out string? output) {
var game = new Tarot.Game.alloc ();
var e = new Tarot.GameEvent.alloc ();
output = null;
if (e.set_setup (n_players, with_call) != 0) {
stderr.printf ("Dynamic memory exhausted\n");
GLib.Process.abort ();
......@@ -10,7 +11,7 @@ namespace Tarot {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
stdout.printf ("%s", game.save_to_xml ());
output = game.save_to_xml ();
return 0;
}
}
\ No newline at end of file
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