Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tarot
tarot
Commits
5d8dc51e
Commit
5d8dc51e
authored
Aug 04, 2018
by
Vivien Kraus
Browse files
Simplify the help command
parent
9c39d340
Pipeline
#66302
passed with stage
in 43 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.dir-locals.el.in
View file @
5d8dc51e
...
...
@@ -29,7 +29,7 @@
@libunistring_CFLAGS@
@CODE_COVERAGE_CFLAGS@
@CPPFLAGS@
@
ASAN
_CFLAGS@
@
asan
_CFLAGS@
-I@abs_top_srcdir@/src
-I@abs_top_builddir@/src
-I@abs_top_srcdir@/src/core
...
...
configure.ac
View file @
5d8dc51e
...
...
@@ -169,7 +169,7 @@ AC_COMPILE_IFELSE([
AC_MSG_RESULT([none found])
AC_MSG_ERROR([Could not find a way to recover from unused but set variable, please remove -Werror from the compiler flags])
])
NORMAL_
CFLAGS="$CFLAGS"
CFLAGS="$
NORMAL_
CFLAGS"
])
AC_SUBST([SUPPRESS_WARNING_UNUSED_BUT_SET_VARIABLE_CFLAGS], [$TESTED_FLAG])
...
...
@@ -190,7 +190,7 @@ AC_COMPILE_IFELSE([
AC_MSG_RESULT([none found])
AC_MSG_ERROR([Could not find a way to recover from unused but set variable, please remove -Werror from the compiler flags])
])
NORMAL_
CFLAGS="$CFLAGS"
CFLAGS="$
NORMAL_
CFLAGS"
])
AC_SUBST([SUPPRESS_WARNING_UNUSED_FUNCTION_CFLAGS], [$TESTED_FLAG])
...
...
src/command/check.c
View file @
5d8dc51e
...
...
@@ -42,7 +42,7 @@ main ()
TarotGameEvent
*
small
,
*
large
;
TarotCard
sample
[
6
]
=
{
77
,
10
,
20
,
30
,
40
,
0
};
TarotCard
output
[
6
]
=
{
0
};
int
error
,
wt
,
t
,
ck
;
int
error
,
ck
;
unsigned
int
i
=
0
;
size_t
nc
;
a
=
tarot_command_init
(
xmalloc
(
tarot_command_sizeof
()));
...
...
@@ -67,7 +67,7 @@ main ()
fprintf
(
stderr
,
"The small event should overflow
\n
"
);
abort
();
}
error
=
tarot_command_set_help
(
a
,
0
,
42
);
error
=
tarot_command_set_help
(
a
);
if
(
error
!=
0
)
{
fprintf
(
stderr
,
"Could not set a command.
\n
"
);
...
...
@@ -78,13 +78,7 @@ main ()
fprintf
(
stderr
,
"Could not set a command.
\n
"
);
abort
();
}
error
=
tarot_command_get_help
(
a
,
&
wt
,
&
t
);
if
(
error
!=
0
||
wt
!=
0
)
{
fprintf
(
stderr
,
"Could not get a command.
\n
"
);
abort
();
}
error
=
tarot_command_set_help
(
b
,
1
,
TAROT_COMMAND_TOPIC_DOG
);
error
=
tarot_command_set_help
(
b
);
if
(
error
!=
0
)
{
fprintf
(
stderr
,
"Could not set a command.
\n
"
);
...
...
@@ -101,12 +95,6 @@ main ()
fprintf
(
stderr
,
"Could not copy a command.
\n
"
);
abort
();
}
error
=
tarot_command_get_help
(
a
,
&
wt
,
&
t
);
if
(
error
!=
0
||
wt
==
0
||
t
!=
TAROT_COMMAND_TOPIC_DOG
)
{
fprintf
(
stderr
,
"Could not copy a command.
\n
"
);
abort
();
}
error
=
((
tarot_command_set_version
(
a
)
&&
tarot_command_get_type
(
a
)
!=
TAROT_COMMAND_VERSION
)
||
(
tarot_command_set_license
(
a
)
...
...
src/command/command.c
View file @
5d8dc51e
...
...
@@ -25,7 +25,6 @@
struct
TarotCommand
{
int
type
;
int
help_topic
;
int
check_only
;
char
event_mem
[
0
];
};
...
...
@@ -48,7 +47,6 @@ tarot_command_init (char *memory)
{
TarotCommand
*
mem
=
(
TarotCommand
*
)
memory
;
mem
->
type
=
TAROT_COMMAND_HELP
;
mem
->
help_topic
=
-
1
;
mem
->
check_only
=
0
;
tarot_game_event_init
(
mem
->
event_mem
,
78
);
return
mem
;
...
...
@@ -59,7 +57,6 @@ tarot_command_copy (TarotCommand * dest, const TarotCommand * src)
{
int
cp_error
=
0
;
dest
->
type
=
src
->
type
;
dest
->
help_topic
=
src
->
help_topic
;
dest
->
check_only
=
src
->
check_only
;
cp_error
=
tarot_game_event_copy
(
event
(
dest
),
event
(
src
));
(
void
)
cp_error
;
...
...
@@ -68,18 +65,9 @@ tarot_command_copy (TarotCommand * dest, const TarotCommand * src)
}
int
tarot_command_set_help
(
TarotCommand
*
cmd
,
int
with_topic
,
int
topic
)
tarot_command_set_help
(
TarotCommand
*
cmd
)
{
if
(
with_topic
&&
topic
<
0
)
{
return
1
;
}
cmd
->
type
=
TAROT_COMMAND_HELP
;
cmd
->
help_topic
=
-
1
;
if
(
with_topic
)
{
cmd
->
help_topic
=
topic
;
}
return
0
;
}
...
...
@@ -132,21 +120,6 @@ tarot_command_get_type (const TarotCommand * cmd)
return
cmd
->
type
;
}
int
tarot_command_get_help
(
const
TarotCommand
*
cmd
,
int
*
with_topic
,
int
*
topic
)
{
if
(
cmd
->
type
!=
TAROT_COMMAND_HELP
)
{
return
1
;
}
*
with_topic
=
(
cmd
->
help_topic
>=
0
);
if
(
cmd
->
help_topic
>=
0
)
{
*
topic
=
cmd
->
help_topic
;
}
return
0
;
}
int
tarot_command_get_event
(
const
TarotCommand
*
cmd
,
TarotGameEvent
*
dest
,
int
*
check_only
)
...
...
src/command/tarot/command.h
View file @
5d8dc51e
...
...
@@ -40,28 +40,13 @@ extern "C"
#define TAROT_COMMAND_STATUS 4
#define TAROT_COMMAND_EVENT 5
#define TAROT_COMMAND_TOPIC_HELP 0
#define TAROT_COMMAND_TOPIC_VERSION 1
#define TAROT_COMMAND_TOPIC_LICENSE 2
#define TAROT_COMMAND_TOPIC_NEW 3
#define TAROT_COMMAND_TOPIC_CHECK 4
#define TAROT_COMMAND_TOPIC_STATUS 5
#define TAROT_COMMAND_TOPIC_SETUP 6
#define TAROT_COMMAND_TOPIC_DEAL 7
#define TAROT_COMMAND_TOPIC_BID 8
#define TAROT_COMMAND_TOPIC_DECL 9
#define TAROT_COMMAND_TOPIC_DOG 10
#define TAROT_COMMAND_TOPIC_DISCARD 11
#define TAROT_COMMAND_TOPIC_HANDFUL 12
#define TAROT_COMMAND_TOPIC_PLAY 13
size_t
tarot_command_sizeof
();
TarotCommand
*
tarot_command_init
(
char
*
memory
);
int
tarot_command_copy
(
TarotCommand
*
dest
,
const
TarotCommand
*
src
);
int
tarot_command_set_help
(
TarotCommand
*
cmd
,
int
with_topic
,
int
topic
);
int
tarot_command_set_help
(
TarotCommand
*
cmd
);
int
tarot_command_set_version
(
TarotCommand
*
cmd
);
int
tarot_command_set_license
(
TarotCommand
*
cmd
);
int
tarot_command_set_new
(
TarotCommand
*
cmd
);
...
...
@@ -70,8 +55,6 @@ extern "C"
const
TarotGameEvent
*
event
,
int
check_only
);
int
tarot_command_get_type
(
const
TarotCommand
*
cmd
);
int
tarot_command_get_help
(
const
TarotCommand
*
cmd
,
int
*
with_topic
,
int
*
topic
);
int
tarot_command_get_event
(
const
TarotCommand
*
cmd
,
TarotGameEvent
*
dest
,
int
*
check_only
);
...
...
src/parser/check.c
View file @
5d8dc51e
...
...
@@ -91,28 +91,6 @@ check_arg (Argument *arg)
}
}
static
void
check_help_commands_eq
(
const
TarotCommand
*
actual
,
const
TarotCommand
*
expected
)
{
int
error
=
0
;
int
actual_with_topic
,
expected_with_topic
;
int
actual_topic
,
expected_topic
;
error
=
(
tarot_command_get_help
(
actual
,
&
actual_with_topic
,
&
actual_topic
)
||
tarot_command_get_help
(
expected
,
&
expected_with_topic
,
&
expected_topic
));
if
(
error
!=
0
)
{
fprintf
(
stderr
,
"Could not get as help.
\n
"
);
abort
();
}
if
(
actual_with_topic
!=
expected_with_topic
||
(
actual_with_topic
&&
expected_with_topic
&&
actual_topic
!=
expected_topic
))
{
fprintf
(
stderr
,
"Help command do not agree on topics.
\n
"
);
abort
();
}
}
static
void
check_setup_events_eq
(
const
TarotGameEvent
*
actual
,
const
TarotGameEvent
*
expected
)
{
...
...
@@ -347,9 +325,6 @@ check_commands_eq (const TarotCommand *actual, const TarotCommand *expected)
}
switch
(
tarot_command_get_type
(
actual
))
{
case
TAROT_COMMAND_HELP
:
check_help_commands_eq
(
actual
,
expected
);
break
;
case
TAROT_COMMAND_EVENT
:
check_event_commands_eq
(
actual
,
expected
);
break
;
...
...
@@ -477,46 +452,7 @@ test_case_help_vanilla ()
.
last_column
=
3
};
exp_command
=
tarot_command_init
(
xmalloc
(
tarot_command_sizeof
()));
if
(
tarot_command_set_help
(
exp_command
,
0
,
0
)
!=
0
)
{
abort
();
}
test_case
(
n_tokens
,
tokens
,
values
,
locations
,
expectation
,
exp_command
,
&
exp_loc
);
free
(
exp_command
);
}
static
void
test_case_help_subcommand
()
{
size_t
n_tokens
=
2
;
int
tokens
[
2
]
=
{
TAROT_TOKEN_HELP
,
TAROT_TOKEN_DOG
};
unsigned
int
values
[
2
]
=
{
0
,
0
};
TarotLexerLType
locations
[
2
]
=
{
{
.
first_line
=
42
,
.
first_column
=
8
,
.
last_line
=
44
,
.
last_column
=
3
},
{
.
first_line
=
45
,
.
first_column
=
8
,
.
last_line
=
45
,
.
last_column
=
9
}
};
int
expectation
=
0
;
TarotCommand
*
exp_command
=
NULL
;
TarotLexerLType
exp_loc
=
{
.
first_line
=
42
,
.
first_column
=
8
,
.
last_line
=
45
,
.
last_column
=
9
};
exp_command
=
tarot_command_init
(
xmalloc
(
tarot_command_sizeof
()));
if
(
tarot_command_set_help
(
exp_command
,
1
,
TAROT_COMMAND_TOPIC_DOG
)
!=
0
)
if
(
tarot_command_set_help
(
exp_command
)
!=
0
)
{
abort
();
}
...
...
@@ -764,7 +700,6 @@ main ()
{
test_case_empty
();
test_case_help_vanilla
();
test_case_help_subcommand
();
test_case_version
();
test_case_license
();
test_case_new
();
...
...
src/parser/implementation.c
View file @
5d8dc51e
...
...
@@ -44,7 +44,7 @@ struct TarotParser
static
enum
yytokentype
yylex
(
void
*
yylval
,
void
*
loc
,
TarotParser
*
parser
);
static
void
yyerror
(
void
*
yylloc_ptr
,
TarotParser
*
parser
,
const
char
*
str
);
static
TarotCommand
*
command_from_help
(
int
topic
,
TarotParser
*
parser
,
static
TarotCommand
*
command_from_help
(
TarotParser
*
parser
,
const
TarotLexerLType
*
loc
);
static
TarotCommand
*
command_from_version
(
TarotParser
*
parser
,
const
TarotLexerLType
*
loc
);
...
...
@@ -496,8 +496,7 @@ command_from_version (TarotParser * parser, const TarotLexerLType * loc)
}
static
TarotCommand
*
command_from_help
(
int
topic
,
TarotParser
*
parser
,
const
TarotLexerLType
*
loc
)
command_from_help
(
TarotParser
*
parser
,
const
TarotLexerLType
*
loc
)
{
int
error
=
0
;
char
*
mem
=
YYMALLOC
(
tarot_command_sizeof
());
...
...
@@ -508,7 +507,7 @@ command_from_help (int topic, TarotParser * parser,
parser
->
command
=
tarot_command_init
(
mem
);
if
(
parser
->
command
!=
NULL
)
{
error
=
tarot_command_set_help
(
parser
->
command
,
(
topic
>=
0
),
topic
);
error
=
tarot_command_set_help
(
parser
->
command
);
(
void
)
error
;
assert
(
error
==
0
);
}
...
...
src/parser/tarot.y
View file @
5d8dc51e
...
...
@@ -52,16 +52,15 @@
%type<int *> card_set
%type<PlayerList *> player_list
%type<TarotGameEvent *> event
%type<int> help_command
%type<TarotCommand *> command
%initial-action { @$ = parser->next_token_position; }
%%
command:
help_command
{
command:
HELP
{
@$ = @1;
$$ = command_from_help (
$1,
parser, &@$);
$$ = command_from_help (parser, &@$);
}
| VERSION {
@$ = @1;
...
...
@@ -89,68 +88,6 @@ command: help_command {
}
;
help_command: HELP {
$$ = -1;
@$ = @1;
}
| HELP HELP {
$$ = TAROT_COMMAND_TOPIC_HELP;
@$ = location_extent (@1, @2);
}
| HELP VERSION {
$$ = TAROT_COMMAND_TOPIC_VERSION;
@$ = location_extent (@1, @2);
}
| HELP LICENSE {
$$ = TAROT_COMMAND_TOPIC_LICENSE;
@$ = location_extent (@1, @2);
}
| HELP NEW {
$$ = TAROT_COMMAND_TOPIC_NEW;
@$ = location_extent (@1, @2);
}
| HELP CHECK {
$$ = TAROT_COMMAND_TOPIC_CHECK;
@$ = location_extent (@1, @2);
}
| HELP STATUS {
$$ = TAROT_COMMAND_TOPIC_STATUS;
@$ = location_extent (@1, @2);
}
| HELP SETUP {
$$ = TAROT_COMMAND_TOPIC_SETUP;
@$ = location_extent (@1, @2);
}
| HELP DEAL {
$$ = TAROT_COMMAND_TOPIC_DEAL;
@$ = location_extent (@1, @2);
}
| HELP BID {
$$ = TAROT_COMMAND_TOPIC_BID;
@$ = location_extent (@1, @2);
}
| HELP DECL {
$$ = TAROT_COMMAND_TOPIC_DECL;
@$ = location_extent (@1, @2);
}
| HELP DOG {
$$ = TAROT_COMMAND_TOPIC_DOG;
@$ = location_extent (@1, @2);
}
| HELP DISCARD {
$$ = TAROT_COMMAND_TOPIC_DISCARD;
@$ = location_extent (@1, @2);
}
| HELP HANDFUL {
$$ = TAROT_COMMAND_TOPIC_HANDFUL;
@$ = location_extent (@1, @2);
}
| HELP PLAY {
$$ = TAROT_COMMAND_TOPIC_PLAY;
@$ = location_extent (@1, @2);
}
;
card_set: %empty {
$$ = empty_card_set (parser);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment