Freeciv-3.3
Loading...
Searching...
No Matches
capability.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include "fc_prehdrs.h"
19
20#include <string.h>
21
22/* utility */
23#include "shared.h" /* TRUE, FALSE */
24#include "support.h" /* fc_is* */
25
26#include "capability.h"
27
28static bool fc_has_capability(const char *cap, const char *capstr,
29 const size_t cap_len)
30 fc__attribute((nonnull (1, 2)));
31
32#define GET_TOKEN(start, end) \
33 { \
34 /* Skip leading whitespace */ \
35 while (fc_isspace(*start)) { \
36 start++; \
37 } \
38 /* Skip to end of token */ \
39 for (end = start; *end != '\0' && !fc_isspace(*end) && *end != ','; \
40 end++) { \
41 /* Nothing */ \
42 } \
43 }
44
45/***********************************************************************/
50static bool fc_has_capability(const char *cap, const char *capstr,
51 const size_t cap_len)
52{
53 const char *next;
54
55 for (;;) {
56 GET_TOKEN(capstr, next);
57
58 if (*capstr == '+') {
59 capstr++;
60 }
61
62 fc_assert(next >= capstr);
63
64 if (((size_t)(next - capstr) == cap_len)
66 return TRUE;
67 }
68 if (*next == '\0') {
69 return FALSE;
70 }
71
72 capstr = next + 1;
73 }
74}
75
76/***********************************************************************/
79bool has_capability(const char *cap, const char *capstr)
80{
82}
83
84/***********************************************************************/
88bool has_capabilities(const char *us, const char *them)
89{
90 const char *next;
91
92 for (;;) {
93 GET_TOKEN(us, next);
94
95 if (*us == '+' && !fc_has_capability(us + 1, them, next - (us + 1))) {
96 return FALSE;
97 }
98 if (*next == '\0') {
99 return TRUE;
100 }
101
102 us = next + 1;
103 }
104}
bool has_capability(const char *cap, const char *capstr)
Definition capability.c:79
static bool fc_has_capability(const char *cap, const char *capstr, const size_t cap_len) fc__attribute((nonnull(1
Definition capability.c:50
#define GET_TOKEN(start, end)
Definition capability.c:32
bool has_capabilities(const char *us, const char *them)
Definition capability.c:88
char * incite_cost
Definition comments.c:76
#define fc_assert(condition)
Definition log.h:177
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc_strncmp(_s1_, _s2_, _len_)
Definition support.h:160