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

Check the first commands

parent 6c856464
Pipeline #34161 passed with stage
in 47 seconds
; This file has been autogenerated from build.xml, do not edit!
((nil
(compile-command . "cd @abs_top_builddir@ && make -j 4")
(eval
. (setq company-clang-arguments
(split-string
"-I@abs_top_srcdir@ -I@abs_top_builddir@ @CFLAGS@ @CPPFLAGS@ @ASAN_CFLAGS@ -I@abs_top_srcdir@/src -I@abs_top_builddir@/src -I@abs_top_srcdir@/src/core -I@abs_top_builddir@/src/core -I@abs_top_srcdir@/src -I@abs_top_builddir@/src ")))))
......@@ -20,11 +20,14 @@ _________________
5 Let me know
6 FAQ
.. 6.1 Emacs? Are you serious?
7 Things to do [0/3]
7 Things to do [0/7]
.. 7.1 TODO Restore imputation
.. 7.2 TODO Get rid of doxygen and enable gtk-doc
.. 7.3 TODO Re-implement the tarot-status utility, with a real command line
.. 7.4 TODO Re-enable the whole program checks from the `develop' branch, with the new syntax
.. 7.5 TODO Document the command-line interface and the tarot_command api
.. 7.6 TODO Integrate the CLI in a tarot program
.. 7.7 TODO Finish the CLI
......@@ -180,7 +183,7 @@ http://gugurumbe.frama.io/tarot/tarot-devel.tar.gz
`----
7 Things to do [0/3]
7 Things to do [0/7]
====================
7.1 TODO Restore imputation
......@@ -208,3 +211,15 @@ http://gugurumbe.frama.io/tarot/tarot-devel.tar.gz
7.4 TODO Re-enable the whole program checks from the `develop' branch, with the new syntax
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7.5 TODO Document the command-line interface and the tarot_command api
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7.6 TODO Integrate the CLI in a tarot program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7.7 TODO Finish the CLI
~~~~~~~~~~~~~~~~~~~~~~~
......@@ -2,32 +2,35 @@
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org9e7d1f4">1. READ ME</a></li>
<li><a href="#org746d02f">2. About tarot</a></li>
<li><a href="#org406fa76">3. Project site</a></li>
<li><a href="#org6e317b5">4. Compile this project</a>
<li><a href="#org0aaea38">1. READ ME</a></li>
<li><a href="#org9bcd21b">2. About tarot</a></li>
<li><a href="#org4fe5e49">3. Project site</a></li>
<li><a href="#orga6f949f">4. Compile this project</a>
<ul>
<li><a href="#org934c710">4.1. Gitlab users: make a source distribution</a>
<li><a href="#org6032fd7">4.1. Gitlab users: make a source distribution</a>
<ul>
<li><a href="#org8d0aa51">4.1.1. Insane Tooling</a></li>
<li><a href="#org7fa4b46">4.1.2. The git pre-commit hook</a></li>
<li><a href="#orgc4b1571">4.1.1. Insane Tooling</a></li>
<li><a href="#org47f537b">4.1.2. The git pre-commit hook</a></li>
</ul>
</li>
<li><a href="#orgdee575a">4.2. Everyone: configure, make and install</a></li>
<li><a href="#org9c7916f">4.2. Everyone: configure, make and install</a></li>
</ul>
</li>
<li><a href="#org485abbf">5. Let me know</a></li>
<li><a href="#orgc84fd39">6. FAQ</a>
<li><a href="#org6ba5d16">5. Let me know</a></li>
<li><a href="#orgcd0d068">6. FAQ</a>
<ul>
<li><a href="#org82d3edc">6.1. Emacs? Are you serious?</a></li>
<li><a href="#org845d62a">6.1. Emacs? Are you serious?</a></li>
</ul>
</li>
<li><a href="#org9d98ab9">7. Things to do <code>[0/3]</code></a>
<li><a href="#org32e3b13">7. Things to do <code>[0/7]</code></a>
<ul>
<li><a href="#org28debc3">7.1. <span class="todo TODO">TODO</span> Restore imputation</a></li>
<li><a href="#orge05154d">7.2. <span class="todo TODO">TODO</span> Get rid of doxygen and enable gtk-doc</a></li>
<li><a href="#orgd4972bd">7.3. <span class="todo TODO">TODO</span> Re-implement the tarot-status utility, with a real command line</a></li>
<li><a href="#org022094d">7.4. <span class="todo TODO">TODO</span> Re-enable the whole program checks from the <code>develop</code> branch, with the new syntax</a></li>
<li><a href="#orgf15d987">7.1. <span class="todo TODO">TODO</span> Restore imputation</a></li>
<li><a href="#org81a4a0e">7.2. <span class="todo TODO">TODO</span> Get rid of doxygen and enable gtk-doc</a></li>
<li><a href="#org2def1ee">7.3. <span class="todo TODO">TODO</span> Re-implement the tarot-status utility, with a real command line</a></li>
<li><a href="#org10ae83c">7.4. <span class="todo TODO">TODO</span> Re-enable the whole program checks from the <code>develop</code> branch, with the new syntax</a></li>
<li><a href="#org59ce500">7.5. <span class="todo TODO">TODO</span> Document the command-line interface and the tarot<sub>command</sub> api</a></li>
<li><a href="#orgc0f810e">7.6. <span class="todo TODO">TODO</span> Integrate the CLI in a tarot program</a></li>
<li><a href="#org1fb2ee7">7.7. <span class="todo TODO">TODO</span> Finish the CLI</a></li>
</ul>
</li>
</ul>
......@@ -35,15 +38,15 @@
</div>
<a id="org9e7d1f4"></a>
<a id="org0aaea38"></a>
# READ ME
RUN THE CONFIGURE SCRIPT NOT THE BOOTSTRAP ONE. If you don't have a
configure script, see section [4.1](#org934c710).
configure script, see section [4.1](#org6032fd7).
<a id="org746d02f"></a>
<a id="org9bcd21b"></a>
# About tarot
......@@ -52,14 +55,14 @@ Of Tarot*. It aims at providing a game and an artificial
intelligence.
<a id="org406fa76"></a>
<a id="org4fe5e49"></a>
# Project site
Go to the [project site](http://gugurumbe.frama.io/tarot/usr/local/share/doc/tarot/tarot.html/api-doc/index.html).
<a id="org6e317b5"></a>
<a id="orga6f949f"></a>
# Compile this project
......@@ -71,7 +74,7 @@ some more work. Note that a source distribution is already available
my autotools!).
<a id="org934c710"></a>
<a id="org6032fd7"></a>
## Gitlab users: make a source distribution
......@@ -79,10 +82,10 @@ You need more tools in order to bootstrap the source distribution.
I am assuming you run on debian stable, if you don't then please tell
me. If you work on a platform where the extensive tooling described
in section [4.1.1](#org8d0aa51) is *not* available, or difficult to install,
in section [4.1.1](#orgc4b1571) is *not* available, or difficult to install,
then I advise you to make a *source* distribution from an easier
system or download [the latest build on the "develop" branch](http://gugurumbe.frama.io/tarot/tarot-devel.tar.gz), and then
use this distribution as discussed in section [4.2](#orgdee575a).
use this distribution as discussed in section [4.2](#org9c7916f).
If you still want to re-build the source distribution, and you are not
on a debian stable system, then be aware that the `bootstrap.sh`
......@@ -93,7 +96,7 @@ another place, then you either have to make a symlink or edit the
files.
<a id="org8d0aa51"></a>
<a id="orgc4b1571"></a>
### Insane Tooling
......@@ -115,7 +118,7 @@ It will:
- install a (severe) `git` pre-commit hook.
<a id="org7fa4b46"></a>
<a id="org47f537b"></a>
### The git pre-commit hook
......@@ -139,7 +142,7 @@ every commit on the `develop` and `master` branches to help maintain
the project.
<a id="orgdee575a"></a>
<a id="org9c7916f"></a>
## Everyone: configure, make and install
......@@ -160,7 +163,7 @@ build, or use two steps:
make -j 4
<a id="org485abbf"></a>
<a id="org6ba5d16"></a>
# Let me know
......@@ -168,12 +171,12 @@ I develop Tarot as a personal hobby. If you find it interesting, or
have bugs to submit, please let me know: `vivien@planete-kraus.eu`
<a id="orgc84fd39"></a>
<a id="orgcd0d068"></a>
# FAQ
<a id="org82d3edc"></a>
<a id="org845d62a"></a>
## Emacs? Are you serious?
......@@ -185,12 +188,12 @@ you have to have emacs installed.
checking if org-mode is installed... yes
<a id="org9d98ab9"></a>
<a id="org32e3b13"></a>
# Things to do <code>[0/3]</code>
# Things to do <code>[0/7]</code>
<a id="org28debc3"></a>
<a id="orgf15d987"></a>
## Restore imputation
......@@ -198,7 +201,7 @@ The imputation should be in an auxiliary module, and should be updated
independently of the game.
<a id="orge05154d"></a>
<a id="org81a4a0e"></a>
## Get rid of doxygen and enable gtk-doc
......@@ -206,7 +209,7 @@ We *need* gtk-doc to have the gobject introspection right. I suggest
we simply drop Doxygen, not to duplicate the API documentation.
<a id="orgd4972bd"></a>
<a id="org2def1ee"></a>
## Re-implement the tarot-status utility, with a real command line
......@@ -217,7 +220,22 @@ Don't use bison for this, because:
- it will not be possible to support readline auto-completion.
<a id="org022094d"></a>
<a id="org10ae83c"></a>
## Re-enable the whole program checks from the `develop` branch, with the new syntax
<a id="org59ce500"></a>
## Document the command-line interface and the tarot<sub>command</sub> api
<a id="orgc0f810e"></a>
## Integrate the CLI in a tarot program
<a id="org1fb2ee7"></a>
## Finish the CLI
......@@ -9,6 +9,13 @@
version-info="0:0:0">
<link name="libtarot-core" />
<link name="libtarot-command" />
<test name="check_composition" />
<test name="check_game_init" />
<test name="check_deal" />
<test name="check_do_deal" />
<test name="check_bid" />
<test name="check_parse_type" />
<test name="check_print_greeting" />
</library>
<library name="libtarot-core" directory="src/core" installed="no">
......@@ -66,11 +73,6 @@
<source name="tarot_of.c" />
<source name="tarot_private.h" />
<source name="tarot_strerror.c" potfile="yes" />
<test name="check_composition" />
<test name="check_game_init" />
<test name="check_deal" />
<test name="check_do_deal" />
<test name="check_bid" />
</library>
<library name="libtarot-command" directory="src/command" installed="no">
......@@ -91,8 +93,6 @@
<source name="_tarot_command_append_text.c" />
<source name="_tarot_command_append_number.c" />
<source name="_tarot_command_copyright.c" />
<test name="check_parse_type" />
<test name="check_print_greeting" />
</library>
<library name="libtarot-program" directory="src" installed="no">
......
......@@ -3,12 +3,15 @@
#include "tarot_command_private.h"
static void
check_one (const char *str, TarotCommandType expected, const char *expected_end)
check_one (const char *str, TarotCommandType expected,
const char *expected_end)
{
char *end;
TarotCommandType type;
int ok = 0;
type = tarot_command_parse_type (str, &end);
if (strcmp (str, expected_end) != 0)
ok = (str != (const char *) end && *end != '\0');
if (ok)
{
assert (type == expected);
}
......@@ -16,9 +19,11 @@ check_one (const char *str, TarotCommandType expected, const char *expected_end)
}
static void
check_help (const char *str, unsigned int n_expected, const TarotCommandType *expected_topics, const char *expected_end)
check_help (const char *str, unsigned int n_expected,
const TarotCommandType * expected_topics,
const char *expected_end)
{
unsigned int n_found, n_returned, n_found_2, n_returned_2, i;
size_t n_found, n_returned, n_found_2, n_returned_2, i;
TarotCommandType *buff;
char *end, *end_2;
n_returned = tarot_command_parse_as_help (str, &end, &n_found, 0, NULL);
......@@ -26,10 +31,11 @@ check_help (const char *str, unsigned int n_expected, const TarotCommandType *ex
buff = malloc (n_found * sizeof (TarotCommandType));
if (buff == NULL)
{
fprintf (stderr, _ ("Dynamic memory exhausted\n"));
fprintf (stderr, _("Dynamic memory exhausted\n"));
exit (1);
}
n_returned_2 = tarot_command_parse_as_help (str, &end_2, &n_found_2, n_found, buff);
n_returned_2 =
tarot_command_parse_as_help (str, &end_2, &n_found_2, n_found, buff);
if (strcmp (expected_end, "") != 0)
{
assert (n_returned_2 == n_returned);
......@@ -46,23 +52,25 @@ check_help (const char *str, unsigned int n_expected, const TarotCommandType *ex
}
static void
check_help_3 (const char *cmd, TarotCommandType t1, TarotCommandType t2, TarotCommandType t3, const char *end)
check_help_3 (const char *cmd, TarotCommandType t1, TarotCommandType t2,
TarotCommandType t3, const char *end)
{
TarotCommandType topics[3];
topics[1] = t1;
topics[2] = t2;
topics[3] = t3;
topics[0] = t1;
topics[1] = t2;
topics[2] = t3;
check_help (cmd, 3, topics, end);
}
static void
check_help_4 (const char *cmd, TarotCommandType t1, TarotCommandType t2, TarotCommandType t3, TarotCommandType t4, const char *end)
check_help_4 (const char *cmd, TarotCommandType t1, TarotCommandType t2,
TarotCommandType t3, TarotCommandType t4, const char *end)
{
TarotCommandType topics[4];
topics[1] = t1;
topics[2] = t2;
topics[3] = t3;
topics[4] = t4;
topics[0] = t1;
topics[1] = t2;
topics[2] = t3;
topics[3] = t4;
check_help (cmd, 4, topics, end);
}
......@@ -74,27 +82,22 @@ check ()
{
check_one ("", TAROT_COMMAND_LOL, "");
check_one ("h", TAROT_COMMAND_LOL, "");
check_one ("he", TAROT_COMMAND_LOL, "");
check_one (" he", TAROT_COMMAND_LOL, "");
check_one ("hel", TAROT_COMMAND_LOL, "");
check_one ("help", TAROT_COMMAND_LOL, "");
check_one ("halp", TAROT_COMMAND_LOL, "halp");
check_one ("help ", TAROT_COMMAND_HELP, " ");
check_one (" halp", TAROT_COMMAND_LOL, " halp");
check_one (" help ", TAROT_COMMAND_HELP, " ");
check_one ("help\n", TAROT_COMMAND_HELP, "\n");
check_help_3 ("help help license version war",
check_help_3 (" help help license version war",
TAROT_COMMAND_HELP,
TAROT_COMMAND_LICENSE,
TAROT_COMMAND_VERSION,
"");
TAROT_COMMAND_LICENSE, TAROT_COMMAND_VERSION, "");
check_help_3 ("help help license version wur",
TAROT_COMMAND_HELP,
TAROT_COMMAND_LICENSE,
TAROT_COMMAND_VERSION,
"wur");
TAROT_COMMAND_LICENSE, TAROT_COMMAND_VERSION, "wur");
check_help_4 ("help help license version warranty\n",
TAROT_COMMAND_HELP,
TAROT_COMMAND_LICENSE,
TAROT_COMMAND_VERSION,
TAROT_COMMAND_WARRANTY"\n");
TAROT_COMMAND_VERSION, TAROT_COMMAND_WARRANTY, "\n");
}
int
......
......@@ -7,33 +7,44 @@
exit (1);
static void
check_one (const char *program, const char *author, size_t n_years, const unsigned int *years, const char *expected)
check_one (const char *program, const char *author, size_t n_years,
const unsigned int *years, const char *expected)
{
size_t required;
size_t allocated;
size_t len_buffer;
const size_t len_expected = strlen (expected);
char *buffer;
required = tarot_command_gplv3p_license (program, author, n_years, years, 0, NULL);
required =
tarot_command_gplv3p_license (program, author, n_years, years, 0, NULL);
/* Check when we lack 1 byte */
allocated = required;
buffer = malloc (allocated);
if (buffer == NULL)
{
NUKE_EM_ALL;
}
required = tarot_command_gplv3p_license (program, author, n_years, years, allocated, buffer);
}
required =
tarot_command_gplv3p_license (program, author, n_years, years, allocated,
buffer);
assert (required == allocated);
assert (allocated + 1 == strlen (expected));
assert (strncmp (buffer, expected, allocated) == 0);
assert (allocated == len_expected);
assert (strncmp (buffer, expected, allocated - 1) == 0);
free (buffer);
/* Check now with the last byte */
allocated = required + 1;
buffer = malloc (allocated);
if (buffer == NULL)
{
NUKE_EM_ALL;
}
required = tarot_command_gplv3p_license (program, author, n_years, years, allocated, buffer);
}
required =
tarot_command_gplv3p_license (program, author, n_years, years, allocated,
buffer);
assert (required + 1 == allocated);
assert (allocated == strlen (expected));
assert (allocated == len_expected + 1);
len_buffer = strlen (buffer);
assert (len_buffer == len_expected);
assert (strcmp (buffer, expected) == 0);
free (buffer);
}
......@@ -41,26 +52,29 @@ check_one (const char *program, const char *author, size_t n_years, const unsign
int
main ()
{
static const unsigned int one_year[1] = {2017};
static const unsigned int two_years[2] = {2017, 2018};
static const unsigned int one_year[1] = { 2017 };
static const unsigned int two_years[2] = { 2017, 2018 };
assert (tarot_init (LOCALEDIR) == 0);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
check_one ("tarot-greeting", "Vivien Kraus", 0, NULL, _ ("\
check_one ("tarot-greeting", "Vivien Kraus", 0, NULL, _("\
tarot-greeting Copyright (C) Vivien Kraus\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type `warranty'.\n\
This is free software, and you are welcome to redistribute it\n\
under certain conditions; type `license' for details.\n"));
check_one ("tarot-greeting", "Vivien Kraus", 1, one_year, _ ("\
This program is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n"));
check_one ("tarot-greeting", "Vivien Kraus", 1, one_year, _("\
tarot-greeting Copyright (C) 2017 Vivien Kraus\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type `warranty'.\n\
This is free software, and you are welcome to redistribute it\n\
under certain conditions; type `license' for details.\n"));
check_one ("tarot-greeting", "Vivien Kraus", 2, two_years, _ ("\
This program is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n"));
check_one ("tarot-greeting", "Vivien Kraus", 2, two_years, _("\
tarot-greeting Copyright (C) 2017, 2018 Vivien Kraus\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type `warranty'.\n\
This is free software, and you are welcome to redistribute it\n\
under certain conditions; type `license' for details.\n"));
This program is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n"));
return 0;
}
......@@ -26,7 +26,7 @@ consume_digit (unsigned int *n)
#define MAX_CHARS 20
size_t
_tarot_command_append_number (unsigned int n, size_t *max_dest, char **dest)
_tarot_command_append_number (unsigned int n, size_t * max_dest, char **dest)
{
char string[MAX_CHARS] = "";
n = reverse_digits (n);
......@@ -36,6 +36,7 @@ _tarot_command_append_number (unsigned int n, size_t *max_dest, char **dest)
if (n == 0)
{
string[i + 1] = '\0';
break;
}
}
string[MAX_CHARS - 1] = '\0';
......
#include "tarot_command_private.h"
size_t
_tarot_command_append_text (const char *src, size_t *max_dest, char **dest)
_tarot_command_append_text (const char *src, size_t * max_dest, char **dest)
{
size_t src_size = strlen (src);
size_t written_size = src_size;
......
#include "tarot_command_private.h"
size_t
_tarot_command_copyright (const char *program, const char *author, size_t n_years, const unsigned int *years, size_t *max_dest, char **dest)
_tarot_command_copyright (const char *program, const char *author,
size_t n_years, const unsigned int *years,
size_t * max_dest, char **dest)
{
size_t ret = 0;
unsigned int i = 0;
......@@ -12,7 +14,7 @@ _tarot_command_copyright (const char *program, const char *author, size_t n_year
ret += _tarot_command_append_number (years[0], max_dest, dest);
for (i = 1; i < n_years; ++i)
{
ret += _tarot_command_append_text (", ", max_dest, dest);
ret += _tarot_command_append_text (", ", max_dest, dest);
ret += _tarot_command_append_number (years[i], max_dest, dest);
}
ret += _tarot_command_append_text (" ", max_dest, dest);
......
#include "tarot_command_private.h"
void
_tarot_command_skip_type (const char *cmd, char **end, TarotCommandType expected)
_tarot_command_skip_type (const char *cmd, char **end,
TarotCommandType expected)
{
TarotCommandType actual;
actual = tarot_command_parse_type (cmd, end);
assert (*end > src);
assert ((const char *) *end > cmd);
assert (actual == expected);
assert (IS_BREAK_TOKEN (**end));
while (IS_BREAK_TOKEN (**end))
{
......
......@@ -31,7 +31,8 @@ extern "C"
/**
* Enumeration of all possible commands
*/
typedef enum {
typedef enum
{
TAROT_COMMAND_HELP,
TAROT_COMMAND_VERSION,
TAROT_COMMAND_LICENSE,
......@@ -89,7 +90,9 @@ extern "C"
*
* Returns: the number of help topics.
*/
size_t tarot_command_parse_as_help (const char *cmd, char **end, size_t *n_topics, size_t max_topics, TarotCommandType *topics);
size_t tarot_command_parse_as_help (const char *cmd, char **end,
size_t * n_topics, size_t max_topics,
TarotCommandType * topics);
/**
* tarot_command_parse_as_version:
......@@ -146,7 +149,10 @@ extern "C"
* Returns: the total number of bytes (you have to add 1 for the
* final \0) required in dest to put the whole greeting.
*/
size_t tarot_command_gplv3p_greeting (const char *program_name, const char *author, size_t n_years, const unsigned int *years, size_t max_dest, char *dest);
size_t tarot_command_gplv3p_greeting (const char *program_name,
const char *author, size_t n_years,
const unsigned int *years,
size_t max_dest, char *dest);
/**
* tarot_command_gplv3p_license:
......@@ -166,7 +172,10 @@ extern "C"
* Returns: the required number of byte (minus one) to hold the
* whole license statement.
*/
size_t tarot_command_gplv3p_license (const char *program, const char *author, size_t n_years, const unsigned int *years, size_t max_dest, char *dest);
size_t tarot_command_gplv3p_license (const char *program,
const char *author, size_t n_years,
const unsigned int *years,
size_t max_dest, char *dest);
/**
* tarot_command_gplv3p_warranty:
......@@ -175,15 +184,21 @@ extern "C"
* use when you have a warranty command in a program covered by the
* GPLv3+ license.