Feature #531 ยป 0044-Add-nonnull-attributes-for-capability.-ch-functions.patch
| utility/capability.c | ||
|---|---|---|
|
#include <string.h>
|
||
|
/* utility */
|
||
|
#include "shared.h" /* TRUE, FALSE */
|
||
|
#include "support.h" /* fc_is* */
|
||
|
#include "shared.h" /* TRUE, FALSE */
|
||
|
#include "support.h" /* fc_is* */
|
||
|
#include "capability.h"
|
||
|
static bool fc_has_capability(const char *cap, const char *capstr,
|
||
|
const size_t cap_len)
|
||
|
fc__attribute((nonnull (1, 2)));
|
||
|
#define GET_TOKEN(start, end) \
|
||
|
{ \
|
||
|
/* skip leading whitespace */ \
|
||
|
/* Skip leading whitespace */ \
|
||
|
while (fc_isspace(*start)) { \
|
||
|
start++; \
|
||
|
} \
|
||
|
/* skip to end of token */ \
|
||
|
/* Skip to end of token */ \
|
||
|
for (end = start; *end != '\0' && !fc_isspace(*end) && *end != ','; \
|
||
|
end++) { \
|
||
|
/* nothing */ \
|
||
|
/* Nothing */ \
|
||
|
} \
|
||
|
}
|
||
| ... | ... | |
|
{
|
||
|
const char *next;
|
||
|
fc_assert_ret_val(capstr != NULL, FALSE);
|
||
|
for (;;) {
|
||
|
GET_TOKEN(capstr, next);
|
||
| ... | ... | |
|
}
|
||
|
/***********************************************************************//**
|
||
|
Wrapper for fc_has_capability() for NULL terminated strings.
|
||
|
Wrapper for fc_has_capability() for nullptr terminated strings.
|
||
|
***************************************************************************/
|
||
|
bool has_capability(const char *cap, const char *capstr)
|
||
|
{
|
||
| ... | ... | |
|
for (;;) {
|
||
|
GET_TOKEN(us, next);
|
||
|
if (*us == '+' && !fc_has_capability(us+1, them, next-(us+1))) {
|
||
|
if (*us == '+' && !fc_has_capability(us + 1, them, next - (us + 1))) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
if (*next == '\0') {
|
||
|
return TRUE;
|
||
|
}
|
||
|
us = next+1;
|
||
|
us = next + 1;
|
||
|
}
|
||
|
}
|
||
| utility/capability.h | ||
|---|---|---|
|
/**********************************************************************
|
||
|
/***********************************************************************
|
||
|
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
| ... | ... | |
|
#include "support.h" /* bool type */
|
||
|
bool has_capability(const char *cap, const char *capstr);
|
||
|
bool has_capabilities(const char *us, const char *them);
|
||
|
bool has_capability(const char *cap, const char *capstr)
|
||
|
fc__attribute((nonnull (1, 2)));
|
||
|
bool has_capabilities(const char *us, const char *them)
|
||
|
fc__attribute((nonnull (1, 2)));
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif /* __cplusplus */
|
||
|
#endif /* FC__CAPABILITY_H */
|
||
|
#endif /* FC__CAPABILITY_H */
|
||