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

Use the inline keyword instead of static + list unused functions

parent 4a0ae3f8
......@@ -13,6 +13,11 @@ dist:
- public
expire_in: 1 week
dist_ansi:
stage: dist
image: tarotbis/build:latest
script: "./ci/dist_ansi.sh"
pages:
stage: manual
script: "./ci/pages.sh"
......
......@@ -2,7 +2,7 @@
apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends texlive-base texlive-latex-base git ca-certificates texlive-fonts-recommended texlive-generic-recommended autoconf automake gettext autopoint libtool texinfo gnulib autoconf-archive make gcc flex bison gperf emacs org-mode indent check gengetopt help2man libreadline-dev libunistring-dev valgrind autogen guile-2.0 guile-2.0-dev emacs-goodies-el geiser paredit-el elpa-rainbow-delimiters ess r-base r-cran-foreign r-cran-tibble r-cran-glmnet r-cran-dplyr r-cran-magrittr r-cran-tidyr parallel
apt-get install -y --no-install-recommends texlive-base texlive-latex-base git ca-certificates texlive-fonts-recommended texlive-generic-recommended autoconf automake gettext autopoint libtool texinfo gnulib autoconf-archive make gcc flex bison gperf emacs org-mode indent check gengetopt help2man libreadline-dev libunistring-dev valgrind autogen guile-2.0 guile-2.0-dev emacs-goodies-el geiser paredit-el elpa-rainbow-delimiters ess r-base r-cran-foreign r-cran-tibble r-cran-glmnet r-cran-dplyr r-cran-magrittr r-cran-tidyr parallel nettle-dev
SOURCE_TOP=$(pwd)
CLEAN_TOP=$(cd .. && pwd)/clean
......@@ -19,7 +19,7 @@ cd $SOURCE_TOP || exit 1
rm -rf ../tarot-*.tar.gz ../tarot-*/ tarot-*.tar.gz
sh autogen.sh || exit 1
./configure \
CFLAGS="-Wall -Wextra -Werror -g -O0" \
CFLAGS="-Wall -Wextra -Werror -g -O0 $CFLAGS" \
--prefix="$SOURCE_TOP/public" \
|| (cat config.log ; exit 1) \
|| exit 1
......
#!/bin/sh
export CFLAGS="-ansi -pedantic -Wno-unused-function"
./ci/dist.sh
......@@ -48,12 +48,14 @@ AC_SEARCH_LIBS([add_history], [history], [
AC_DEFINE([HAVE_HISTORY], [0], [Whether the add_history function is available])
])
GUILE_PKG
AX_LIB_NETTLE([yes])
# Checks for header files.
AC_CHECK_HEADERS_ONCE([readline/history.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_C_INLINE
# Checks for library functions.
......
......@@ -2119,9 +2119,8 @@ For some special cases, the deal leads to a petit sec. For instance,
echo "#empty" > /tmp/empty
../pre-inst-env tarot generate \
-n 5 \
-m /tmp/empty \
-s $(echo "self-train: 1 / 37 / 5" | md5sum) \
-s 116 \
2>&1 \
|| echo "The program failed"
#+END_SRC
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2018-11-10 00:25+0100\n"
"POT-Creation-Date: 2018-11-10 17:24+0100\n"
"PO-Revision-Date: 2018-10-14 12:30+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
......@@ -18,6 +18,7 @@
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <tarot/cards_private.h>
int
......
......@@ -43,14 +43,6 @@ extern "C"
typedef char static_assertion_excuse_eq_77[(TAROT_EXCUSE == TAROT_EXC)
? 1 : -1];
#define TAROT_CARDS_UNUSED \
{ \
(void) &of; \
(void) &decompose; \
(void) &card_parse; \
(void) &card_to_string; \
}
static int of (TarotNumber n, TarotSuit s, TarotCard * c);
static int decompose (TarotCard c, TarotNumber * n, TarotSuit * s);
static TarotCard card_parse (const char *text, char **end);
......
......@@ -26,13 +26,10 @@
#include <tarot/cards_private.h>
#include <string.h>
#include <assert.h>
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
static int of (TarotNumber n, TarotSuit s, TarotCard * c)
{
static inline int
of (TarotNumber n, TarotSuit s, TarotCard * c)
{
/* *INDENT-OFF* */
[+ FOR card +][+ CASE short +][+ == "EXC" +][+ * +]
if (n == [+ number +] && s == [+ suit +])
......@@ -41,11 +38,12 @@ extern "C"
return 0;
}[+ ESAC +][+ ENDFOR card +]
/* *INDENT-ON* */
return 1;
}
return 1;
}
static int decompose (TarotCard c, TarotNumber * n, TarotSuit * s)
{
static inline int
decompose (TarotCard c, TarotNumber * n, TarotSuit * s)
{
/* *INDENT-OFF* */
[+ FOR card +][+ CASE short +][+ == "EXC" +]
if (c == [+ id +])
......@@ -59,18 +57,19 @@ extern "C"
return 0;
}[+ ESAC +][+ ENDFOR card +]
/* *INDENT-ON* */
return 1;
}
return 1;
}
static TarotCard card_parse (const char *text, char **end)
{
const char *ptr = text;
size_t len = 0;
while (*ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\r')
{
ptr++;
}
len = strlen (ptr);
static inline TarotCard
card_parse (const char *text, char **end)
{
const char *ptr = text;
size_t len = 0;
while (*ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\r')
{
ptr++;
}
len = strlen (ptr);
/* *INDENT-OFF* */
[+ FOR card +]
if (len >= strlen ("[+ short +]")
......@@ -94,15 +93,16 @@ extern "C"
}
[+ ENDFOR card +]
/* *INDENT-ON* */
if (end != NULL)
{
*end = (char *) text;
}
return (TarotCard) (-1);
}
if (end != NULL)
{
*end = (char *) text;
}
return (TarotCard) (-1);
}
static size_t card_to_string (TarotCard c, size_t max, char *dest)
{
static inline size_t
card_to_string (TarotCard c, size_t max, char *dest)
{
/* *INDENT-OFF* */
[+ FOR card +]
if (c == [+ id +])
......@@ -122,16 +122,12 @@ extern "C"
}
[+ ENDFOR card +]
/* *INDENT-ON* */
if (max != 0)
{
*dest = '\0';
}
return 0;
}
#ifdef __cplusplus
if (max != 0)
{
*dest = '\0';
}
return 0;
}
#endif /* __cplusplus */
#endif /* not H_TAROT_CARDS_PRIVATE_IMPL_INCLUDED */
......
......@@ -28,14 +28,6 @@ extern "C"
{
#endif /* __cplusplus */
#define TAROT_BID_UNUSED \
{ \
(void) &bid_discard_allowed; \
(void) &bid_discard_counted; \
(void) &bid_check; \
(void) &bid_multiplier; \
}
/**
* Check whether a discard is allowed for a given bid.
*/
......
......@@ -23,19 +23,19 @@
#include "bid_private.h"
#include <assert.h>
static int
static inline int
bid_discard_allowed (TarotBid bid)
{
return (bid < TAROT_STRAIGHT_KEEP);
}
static int
static inline int
bid_discard_counted (TarotBid bid)
{
return (bid < TAROT_DOUBLE_KEEP);
}
static int
static inline int
bid_check (TarotBid base, TarotBid newBid, int *superior)
{
*superior = 0;
......@@ -46,7 +46,7 @@ bid_check (TarotBid base, TarotBid newBid, int *superior)
return (newBid == TAROT_PASS || newBid > base);
}
static int
static inline int
bid_multiplier (TarotBid bid)
{
static const int m[5] = {
......
......@@ -25,7 +25,6 @@
static void
bids_3_generalize (TarotBids3 * bids, TarotBids * gen)
{
TAROT_BID_UNUSED;
gen->n_players = 3;
gen->n_bids = &(bids->n_bids);
gen->has_started = &(bids->has_started);
......
......@@ -48,20 +48,6 @@ extern "C"
TarotPlayer *slammer;
} TarotDecls;
#define TAROT_DECLS_UNUSED \
{ \
(void) &decls_N_generalize; \
(void) &decls_initialize; \
(void) &decls_start; \
(void) &decls_has_next; \
(void) &decls_next; \
(void) &decls_has_declarant; \
(void) &decls_declarant; \
(void) &decls_check; \
(void) &decls_add; \
(void) &decls_done; \
}
static void decls_N_generalize (TarotDeclsN * decls, size_t n_players,
TarotDecls * gen);
#define decls_3_generalize(decls, gen) decls_N_generalize (decls, 3, gen)
......
......@@ -21,7 +21,7 @@
#include <tarot/decls_private.h>
static void
static inline void
decls_N_generalize (TarotDeclsN * decls, size_t n_players, TarotDecls * gen)
{
gen->n_players = n_players;
......@@ -30,43 +30,43 @@ decls_N_generalize (TarotDeclsN * decls, size_t n_players, TarotDecls * gen)
gen->slammer = &(decls->slammer);
}
static size_t
static inline size_t
_decls_get_n_decls (const TarotDecls * decls)
{
return *(decls->n_decls);
}
static void
static inline void
_decls_set_n_decls (TarotDecls * decls, size_t n_decls)
{
*(decls->n_decls) = n_decls;
}
static int
static inline int
_decls_get_has_started (const TarotDecls * decls)
{
return *(decls->has_started);
}
static void
static inline void
_decls_set_has_started (TarotDecls * decls, int has_started)
{
*(decls->has_started) = has_started;
}
static TarotPlayer
static inline TarotPlayer
_decls_get_slammer (const TarotDecls * decls)
{
return *(decls->slammer);
}
static void
static inline void
_decls_set_slammer (TarotDecls * decls, TarotPlayer slammer)
{
*(decls->slammer) = slammer;
}
static void
static inline void
decls_initialize (TarotDecls * decls, size_t n_players)
{
decls->n_players = n_players;
......@@ -75,7 +75,7 @@ decls_initialize (TarotDecls * decls, size_t n_players)
_decls_set_slammer (decls, n_players);
}
static int
static inline int
decls_start (TarotDecls * decls)
{
int error = _decls_get_has_started (decls);
......@@ -86,20 +86,20 @@ decls_start (TarotDecls * decls)
return error;
}
static int
static inline int
decls_has_next (const TarotDecls * decls)
{
return _decls_get_has_started (decls)
&& (_decls_get_n_decls (decls) < decls->n_players);
}
static TarotPlayer
static inline TarotPlayer
decls_next (const TarotDecls * decls)
{
return _decls_get_n_decls (decls);
}
static int
static inline int
decls_has_declarant (const TarotDecls * decls)
{
return (_decls_get_has_started (decls)
......@@ -107,20 +107,20 @@ decls_has_declarant (const TarotDecls * decls)
&& _decls_get_slammer (decls) < _decls_get_n_decls (decls));
}
static TarotPlayer
static inline TarotPlayer
decls_declarant (const TarotDecls * decls)
{
return _decls_get_slammer (decls);
}
static int
static inline int
decls_check (const TarotDecls * decls, int next)
{
(void) next;
return decls_has_next (decls);
}
static int
static inline int
decls_add (TarotDecls * decls, int next)
{
int ok;
......@@ -141,7 +141,7 @@ decls_add (TarotDecls * decls, int next)
return 0;
}
static int
static inline int
decls_done (const TarotDecls * decls)
{
return (_decls_get_has_started (decls)
......
......@@ -68,35 +68,6 @@ extern "C"
TarotHand discard;
} TarotDoscard;
#define TAROT_DOSCARD_UNUSED \
{ \
(void) &doscard_3_generalize; \
(void) &doscard_4_generalize; \
(void) &doscard_5_generalize; \
(void) &doscard_initialize; \
(void) &doscard_contract; \
(void) &doscard_set_contract; \
(void) &doscard_taker; \
(void) &doscard_set_taker; \
(void) &doscard_start; \
(void) &doscard_expects_dog; \
(void) &doscard_expects_discard; \
(void) &doscard_check_dog; \
(void) &doscard_check_partial_discard; \
(void) &doscard_check_discard; \
(void) &doscard_reveal_dog; \
(void) &doscard_set_partial_discard; \
(void) &doscard_set_discard; \
(void) &doscard_infer; \
(void) &doscard_dog_known; \
(void) &doscard_discard_known; \
(void) &doscard_dog; \
(void) &doscard_discard; \
(void) &doscard_discard_public; \
(void) &doscard_points; \
(void) &doscard_oudlers; \
}
static void doscard_3_generalize (TarotDoscard3 * doscard,
TarotDoscard * gen);
static void doscard_4_generalize (TarotDoscard4 * doscard,
......
......@@ -21,7 +21,7 @@
#include <tarot/doscard_private.h>
static void
static inline void
doscard_3_generalize (TarotDoscard3 * doscard, TarotDoscard * gen)
{
gen->n_players = 3;
......@@ -34,7 +34,7 @@ doscard_3_generalize (TarotDoscard3 * doscard, TarotDoscard * gen)
hand_6_generalize (&(doscard->discard), &(gen->discard));
}
static void
static inline void
doscard_4_generalize (TarotDoscard4 * doscard, TarotDoscard * gen)
{
gen->n_players = 4;
......@@ -47,7 +47,7 @@ doscard_4_generalize (TarotDoscard4 * doscard, TarotDoscard * gen)
hand_6_generalize (&(doscard->discard), &(gen->discard));
}
static void
static inline void
doscard_5_generalize (TarotDoscard5 * doscard, TarotDoscard * gen)
{
gen->n_players = 5;
......@@ -60,67 +60,67 @@ doscard_5_generalize (TarotDoscard5 * doscard, TarotDoscard * gen)
hand_3_generalize (&(doscard->discard), &(gen->discard));
}
static int
static inline int
_doscard_get_has_started (const TarotDoscard * doscard)
{
return *(doscard->has_started);
}
static void
static inline void
_doscard_set_has_started (TarotDoscard * doscard, int value)
{
*(doscard->has_started) = value;
}
static TarotPlayer
static inline TarotPlayer
_doscard_get_taker (const TarotDoscard * doscard)
{
return *(doscard->taker);
}
static void
static inline void
_doscard_set_taker (TarotDoscard * doscard, TarotPlayer value)
{
*(doscard->taker) = value;
}
static TarotBid
static inline TarotBid
_doscard_get_contract (const TarotDoscard * doscard)
{
return *(doscard->contract);
}
static void
static inline void
_doscard_set_contract (TarotDoscard * doscard, TarotBid value)
{
*(doscard->contract) = value;
}
static int
static inline int
_doscard_get_dog_done (const TarotDoscard * doscard)
{
return *(doscard->dog_done);
}
static void
static inline void
_doscard_set_dog_done (TarotDoscard * doscard, int value)
{
*(doscard->dog_done) = value;
}
static int
static inline int
_doscard_get_discard_done (const TarotDoscard * doscard)
{
return *(doscard->discard_done);
}
static void
static inline void
_doscard_set_discard_done (TarotDoscard * doscard, int value)
{
*(doscard->discard_done) = value;
}
static void
static inline void
doscard_initialize (TarotDoscard * doscard, size_t n_players)
{
doscard->n_players = n_players;
......@@ -133,7 +133,7 @@ doscard_initialize (TarotDoscard * doscard, size_t n_players)
hand_set (&(doscard->discard), NULL, 0);
}
static int
static inline int
doscard_start (TarotDoscard * doscard)
{
int error = _doscard_get_has_started (doscard);
......@@ -148,13 +148,13 @@ doscard_start (TarotDoscard * doscard)
return error;
}
static TarotBid
static inline TarotBid
doscard_contract (const TarotDoscard * doscard)
{
return _doscard_get_contract (doscard);
}
static int
static inline int
doscard_set_contract (TarotDoscard * doscard, TarotBid contract)
{
int error = (_doscard_get_has_started (doscard));
......@@ -165,13 +165,13 @@ doscard_set_contract (TarotDoscard * doscard, TarotBid contract)
return error;
}
static TarotPlayer
static inline TarotPlayer
doscard_taker (const TarotDoscard * doscard)
{
return _doscard_get_taker (doscard);
}
static int
static inline int
doscard_set_taker (TarotDoscard * doscard, TarotPlayer taker)
{
int error = (_doscard_get_has_started (doscard));
......@@ -182,7 +182,7 @@ doscard_set_taker (TarotDoscard * doscard, TarotPlayer taker)
return error;
}
static int
static inline int
doscard_expects_dog (const TarotDoscard * doscard)
{
return (_doscard_get_has_started (doscard)
......@@ -190,7 +190,7 @@ doscard_expects_dog (const TarotDoscard * doscard)
&& !_doscard_get_dog_done (doscard));
}
static int
static inline int
doscard_expects_discard (const TarotDoscard * doscard)
{
return (_doscard_get_has_started (doscard)
......@@ -199,14 +199,14 @@ doscard_expects_discard (const TarotDoscard * doscard)
&& !_doscard_get_discard_done (doscard));
}
static int
static inline int
doscard_check_dog (const TarotDoscard * doscard, const TarotHand * dog)
{
return (doscard_expects_dog (doscard)
&& hand_size (dog) == hand_max (&(doscard->dog)));
}
static int
static inline int
doscard_all_non_oudler_trumps (const TarotHand * hand)
{
size_t i;
......@@ -221,13 +221,13 @@ doscard_all_non_oudler_trumps (const TarotHand * hand)
return 1;
}
static size_t
static inline size_t