Allow using things that were deprecated in gtk+-3.22.
[freeciv.git] / utility / capability.c
blob623ba44faa888697d84669e7c6992929a6d1feae
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include "fc_prehdrs.h"
20 #include <string.h>
22 /* utility */
23 #include "shared.h" /* TRUE, FALSE */
24 #include "support.h" /* fc_is* */
26 #include "capability.h"
28 #define GET_TOKEN(start, end) \
29 { \
30 /* skip leading whitespace */ \
31 while (fc_isspace(*start)) { \
32 start++; \
33 } \
34 /* skip to end of token */ \
35 for (end = start; *end != '\0' && !fc_isspace(*end) && *end != ','; \
36 end++) { \
37 /* nothing */ \
38 } \
41 /***************************************************************************
42 This routine returns true if the capability in cap appears
43 in the capability list in capstr. The capabilities in capstr
44 are allowed to start with a "+", but the capability in cap must not.
45 ***************************************************************************/
46 static bool fc_has_capability(const char *cap, const char *capstr,
47 const size_t cap_len)
49 const char *next;
51 fc_assert_ret_val(capstr != NULL, FALSE);
53 for (;;) {
54 GET_TOKEN(capstr, next);
56 if (*capstr == '+') {
57 capstr++;
59 if ((next-capstr == cap_len) && strncmp(cap, capstr, cap_len)==0) {
60 return TRUE;
62 if (*next == '\0') {
63 return FALSE;
66 capstr = next+1;
70 /***************************************************************************
71 Wrapper for fc_has_capability() for NULL terminated strings.
72 ***************************************************************************/
73 bool has_capability(const char *cap, const char *capstr)
75 return fc_has_capability(cap, capstr, strlen(cap));
78 /***************************************************************************
79 This routine returns true if all the mandatory capabilities in
80 us appear in them.
81 ***************************************************************************/
82 bool has_capabilities(const char *us, const char *them)
84 const char *next;
86 for (;;) {
87 GET_TOKEN(us, next);
89 if (*us == '+' && !fc_has_capability(us+1, them, next-(us+1))) {
90 return FALSE;
92 if (*next == '\0') {
93 return TRUE;
96 us = next+1;