-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Backport 0064-featured_text.-ch-Replace-NULL-with-nullptr.patch
Signed-off-by: Marko Lindqvist <[email protected]>
- Loading branch information
Showing
3 changed files
with
318 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
295 changes: 295 additions & 0 deletions
295
freeciv/patches/backports/0064-featured_text.-ch-Replace-NULL-with-nullptr.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,295 @@ | ||
From 2f64bb1b70965513167bcb0d29e78740712f3530 Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Mon, 2 Oct 2023 22:38:22 +0300 | ||
Subject: [PATCH 64/64] featured_text.[ch]: Replace NULL with nullptr | ||
|
||
See osdn #48793 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
common/featured_text.c | 102 +++++++++++++++++++++-------------------- | ||
common/featured_text.h | 4 +- | ||
2 files changed, 55 insertions(+), 51 deletions(-) | ||
|
||
diff --git a/common/featured_text.c b/common/featured_text.c | ||
index 9cfb819882..12cdb8cf5b 100644 | ||
--- a/common/featured_text.c | ||
+++ b/common/featured_text.c | ||
@@ -70,23 +70,23 @@ enum sequence_type { | ||
}; | ||
|
||
/* Predefined colors. */ | ||
-const struct ft_color ftc_any = FT_COLOR(NULL, NULL); | ||
- | ||
-const struct ft_color ftc_warning = FT_COLOR("#FF0000", NULL); | ||
-const struct ft_color ftc_log = FT_COLOR("#7F7F7F", NULL); | ||
-const struct ft_color ftc_server = FT_COLOR("#8B0000", NULL); | ||
-const struct ft_color ftc_client = FT_COLOR("#EF7F00", NULL); | ||
-const struct ft_color ftc_editor = FT_COLOR("#0000FF", NULL); | ||
-const struct ft_color ftc_command = FT_COLOR("#006400", NULL); | ||
- struct ft_color ftc_changed = FT_COLOR("#FF0000", NULL); | ||
+const struct ft_color ftc_any = FT_COLOR(nullptr, nullptr); | ||
+ | ||
+const struct ft_color ftc_warning = FT_COLOR("#FF0000", nullptr); | ||
+const struct ft_color ftc_log = FT_COLOR("#7F7F7F", nullptr); | ||
+const struct ft_color ftc_server = FT_COLOR("#8B0000", nullptr); | ||
+const struct ft_color ftc_client = FT_COLOR("#EF7F00", nullptr); | ||
+const struct ft_color ftc_editor = FT_COLOR("#0000FF", nullptr); | ||
+const struct ft_color ftc_command = FT_COLOR("#006400", nullptr); | ||
+ struct ft_color ftc_changed = FT_COLOR("#FF0000", nullptr); | ||
const struct ft_color ftc_server_prompt = FT_COLOR("#FF0000", "#BEBEBE"); | ||
const struct ft_color ftc_player_lost = FT_COLOR("#FFFFFF", "#000000"); | ||
const struct ft_color ftc_game_start = FT_COLOR("#00FF00", "#115511"); | ||
|
||
-const struct ft_color ftc_chat_public = FT_COLOR("#00008B", NULL); | ||
-const struct ft_color ftc_chat_ally = FT_COLOR("#551166", NULL); | ||
-const struct ft_color ftc_chat_private = FT_COLOR("#A020F0", NULL); | ||
-const struct ft_color ftc_chat_luaconsole = FT_COLOR("#006400", NULL); | ||
+const struct ft_color ftc_chat_public = FT_COLOR("#00008B", nullptr); | ||
+const struct ft_color ftc_chat_ally = FT_COLOR("#551166", nullptr); | ||
+const struct ft_color ftc_chat_private = FT_COLOR("#A020F0", nullptr); | ||
+const struct ft_color ftc_chat_luaconsole = FT_COLOR("#006400", nullptr); | ||
|
||
const struct ft_color ftc_vote_public = FT_COLOR("#FFFFFF", "#AA0000"); | ||
const struct ft_color ftc_vote_team = FT_COLOR("#FFFFFF", "#5555CC"); | ||
@@ -96,12 +96,12 @@ const struct ft_color ftc_vote_yes = FT_COLOR("#000000", "#C8FFD5"); | ||
const struct ft_color ftc_vote_no = FT_COLOR("#000000", "#FFD2D2"); | ||
const struct ft_color ftc_vote_abstain = FT_COLOR("#000000", "#E8E8E8"); | ||
|
||
-const struct ft_color ftc_luaconsole_input = FT_COLOR("#2B008B", NULL); | ||
-const struct ft_color ftc_luaconsole_error = FT_COLOR("#FF0000", NULL); | ||
-const struct ft_color ftc_luaconsole_warn = FT_COLOR("#CF2020", NULL); | ||
-const struct ft_color ftc_luaconsole_normal = FT_COLOR("#006400", NULL); | ||
-const struct ft_color ftc_luaconsole_verbose = FT_COLOR("#B8B8B8", NULL); | ||
-const struct ft_color ftc_luaconsole_debug = FT_COLOR("#B87676", NULL); | ||
+const struct ft_color ftc_luaconsole_input = FT_COLOR("#2B008B", nullptr); | ||
+const struct ft_color ftc_luaconsole_error = FT_COLOR("#FF0000", nullptr); | ||
+const struct ft_color ftc_luaconsole_warn = FT_COLOR("#CF2020", nullptr); | ||
+const struct ft_color ftc_luaconsole_normal = FT_COLOR("#006400", nullptr); | ||
+const struct ft_color ftc_luaconsole_verbose = FT_COLOR("#B8B8B8", nullptr); | ||
+const struct ft_color ftc_luaconsole_debug = FT_COLOR("#B87676", nullptr); | ||
|
||
/**********************************************************************//** | ||
Return the long name of the text tag type. | ||
@@ -123,8 +123,9 @@ static const char *text_tag_type_name(enum text_tag_type type) | ||
case TTT_LINK: | ||
return "link"; | ||
}; | ||
+ | ||
/* Don't handle the default case to be warned if a new value was added. */ | ||
- return NULL; | ||
+ return nullptr; | ||
} | ||
|
||
/**********************************************************************//** | ||
@@ -147,8 +148,9 @@ static const char *text_tag_type_short_name(enum text_tag_type type) | ||
case TTT_LINK: | ||
return "l"; | ||
}; | ||
+ | ||
/* Don't handle the default case to be warned if a new value was added. */ | ||
- return NULL; | ||
+ return nullptr; | ||
} | ||
|
||
/**********************************************************************//** | ||
@@ -164,8 +166,9 @@ static const char *text_link_type_name(enum text_link_type type) | ||
case TLT_UNIT: | ||
return "unit"; | ||
}; | ||
+ | ||
/* Don't handle the default case to be warned if a new value was added. */ | ||
- return NULL; | ||
+ return nullptr; | ||
} | ||
|
||
/**********************************************************************//** | ||
@@ -403,18 +406,18 @@ static bool text_tag_initv(struct text_tag *ptag, enum text_tag_type type, | ||
{ | ||
const struct ft_color color = va_arg(args, struct ft_color); | ||
|
||
- if ((NULL == color.foreground || '\0' == color.foreground[0]) | ||
- && (NULL == color.background || '\0' == color.background[0])) { | ||
+ if ((color.foreground == nullptr || color.foreground[0] == '\0') | ||
+ && (color.background == nullptr || color.background[0] == '\0')) { | ||
return FALSE; /* No color at all. */ | ||
} | ||
|
||
- if (NULL != color.foreground && '\0' != color.foreground[0]) { | ||
+ if (color.foreground != nullptr && color.foreground[0] != '\0') { | ||
sz_strlcpy(ptag->color.foreground, color.foreground); | ||
} else { | ||
ptag->color.foreground[0] = '\0'; | ||
} | ||
|
||
- if (NULL != color.background && '\0' != color.background[0]) { | ||
+ if (color.background != nullptr && color.background[0] != '\0') { | ||
sz_strlcpy(ptag->color.background, color.background); | ||
} else { | ||
ptag->color.background[0] = '\0'; | ||
@@ -587,11 +590,11 @@ static size_t text_tag_replace_text(const struct text_tag *ptag, | ||
{ | ||
struct city *pcity = game_city_by_number(ptag->link.id); | ||
|
||
- /* Note that if city_tile(pcity) is NULL, then it is probably an | ||
- * invisible city (see client/packhand.c). Then, we don't | ||
+ /* Note that if city_tile(pcity) is nullptr, then it is probably an | ||
+ * invisible city (see client/packhand.c). Then, we don't | ||
* use the current city name which is usually not complete, | ||
* a dumb string using the city id. */ | ||
- if (NULL != pcity && NULL != city_tile(pcity)) { | ||
+ if (pcity != nullptr && city_tile(pcity) != nullptr) { | ||
return fc_snprintf(buf, len, "%s", city_name_get(pcity)); | ||
} | ||
} | ||
@@ -619,7 +622,7 @@ static size_t text_tag_replace_text(const struct text_tag *ptag, | ||
} | ||
|
||
/**********************************************************************//** | ||
- Returns a new text_tag or NULL on error. | ||
+ Returns a new text_tag or nullptr on error. | ||
|
||
Prototype: | ||
- If tag_type is TTT_BOLD, TTT_ITALIC, TTT_STRIKE or TTT_UNDERLINE, there | ||
@@ -652,7 +655,8 @@ struct text_tag *text_tag_new(enum text_tag_type tag_type, | ||
return ptag; | ||
} else { | ||
free(ptag); | ||
- return NULL; | ||
+ | ||
+ return nullptr; | ||
} | ||
} | ||
|
||
@@ -664,8 +668,8 @@ struct text_tag *text_tag_copy(const struct text_tag *ptag) | ||
{ | ||
struct text_tag *pnew_tag; | ||
|
||
- if (!ptag) { | ||
- return NULL; | ||
+ if (ptag == nullptr) { | ||
+ return nullptr; | ||
} | ||
|
||
pnew_tag = fc_malloc(sizeof(struct text_tag)); | ||
@@ -707,36 +711,36 @@ ft_offset_t text_tag_stop_offset(const struct text_tag *ptag) | ||
} | ||
|
||
/**********************************************************************//** | ||
- Return the foreground color suggested by this text tag. This requires | ||
- the tag type to be TTT_COLOR. Returns NULL on error, "" if unset. | ||
+ Return the foreground color suggested by this text tag. This requires | ||
+ the tag type to be TTT_COLOR. Returns nullptr on error, "" if unset. | ||
**************************************************************************/ | ||
const char *text_tag_color_foreground(const struct text_tag *ptag) | ||
{ | ||
if (ptag->type != TTT_COLOR) { | ||
log_error("text_tag_color_foreground(): incompatible tag type."); | ||
- return NULL; | ||
+ return nullptr; | ||
} | ||
|
||
return ptag->color.foreground; | ||
} | ||
|
||
/**********************************************************************//** | ||
- Return the background color suggested by this text tag. This requires | ||
- the tag type to be TTT_COLOR. Returns NULL on error, "" if unset. | ||
+ Return the background color suggested by this text tag. This requires | ||
+ the tag type to be TTT_COLOR. Returns nullptr on error, "" if unset. | ||
**************************************************************************/ | ||
const char *text_tag_color_background(const struct text_tag *ptag) | ||
{ | ||
if (ptag->type != TTT_COLOR) { | ||
log_error("text_tag_color_background(): incompatible tag type."); | ||
- return NULL; | ||
+ return nullptr; | ||
} | ||
|
||
return ptag->color.background; | ||
} | ||
|
||
/**********************************************************************//** | ||
- Return the link target type suggested by this text tag. This requires | ||
- the tag type to be TTT_LINK. Returns -1 on error. | ||
+ Return the link target type suggested by this text tag. This requires | ||
+ the tag type to be TTT_LINK. Returns -1 on error. | ||
**************************************************************************/ | ||
enum text_link_type text_tag_link_type(const struct text_tag *ptag) | ||
{ | ||
@@ -750,7 +754,7 @@ enum text_link_type text_tag_link_type(const struct text_tag *ptag) | ||
|
||
/**********************************************************************//** | ||
Return the link target id suggested by this text tag (city id, | ||
- tile index or unit id). This requires the tag type to be TTT_LINK. | ||
+ tile index or unit id). This requires the tag type to be TTT_LINK. | ||
Returns -1 on error. | ||
**************************************************************************/ | ||
int text_tag_link_id(const struct text_tag *ptag) | ||
@@ -764,8 +768,8 @@ int text_tag_link_id(const struct text_tag *ptag) | ||
} | ||
|
||
/**********************************************************************//** | ||
- Extract a sequence from a string. Also, determine the type and the text | ||
- tag type of the sequence. Return 0 on error. | ||
+ Extract a sequence from a string. Also, determine the type and the text | ||
+ tag type of the sequence. Return 0 on error. | ||
**************************************************************************/ | ||
static size_t extract_sequence_text(const char *featured_text, | ||
char *buf, size_t len, | ||
@@ -780,7 +784,7 @@ static size_t extract_sequence_text(const char *featured_text, | ||
size_t name_len; | ||
int i; | ||
|
||
- if (!stop) { | ||
+ if (stop == nullptr) { | ||
return 0; /* Not valid. */ | ||
} | ||
|
||
@@ -853,7 +857,7 @@ static size_t extract_sequence_text(const char *featured_text, | ||
|
||
|
||
/**********************************************************************//** | ||
- Separate the text from the text features. 'tags' can be NULL. | ||
+ Separate the text from the text features. 'tags' can be nullptr. | ||
|
||
When 'replace_link_text' is set, the text used for the signal sequence | ||
links will be overwritten. It is used on client side to have updated | ||
@@ -905,7 +909,7 @@ size_t featured_text_to_plain_text(const char *featured_text, | ||
case ST_STOP: | ||
if (tags) { | ||
/* Set the stop offset. */ | ||
- struct text_tag *ptag = NULL; | ||
+ struct text_tag *ptag = nullptr; | ||
|
||
/* Look up on reversed order. */ | ||
text_tag_list_rev_iterate(*tags, piter) { | ||
@@ -973,8 +977,8 @@ size_t featured_text_to_plain_text(const char *featured_text, | ||
} | ||
|
||
/**********************************************************************//** | ||
- Apply a tag to a text. This text can already containing escape | ||
- sequences. Returns 0 on error. | ||
+ Apply a tag to a text. This text can already containing escape | ||
+ sequences. Returns 0 on error. | ||
|
||
Prototype: | ||
- If tag_type is TTT_BOLD, TTT_ITALIC, TTT_STRIKE or TTT_UNDERLINE, there | ||
diff --git a/common/featured_text.h b/common/featured_text.h | ||
index 2aa4b4da56..5ab6a85361 100644 | ||
--- a/common/featured_text.h | ||
+++ b/common/featured_text.h | ||
@@ -159,8 +159,8 @@ static inline struct ft_color ft_color_construct(const char *foreground, | ||
**************************************************************************/ | ||
static inline bool ft_color_requested(const struct ft_color color) | ||
{ | ||
- return ((NULL != color.foreground && '\0' != color.foreground[0]) | ||
- || (NULL != color.background && '\0' != color.background[0])); | ||
+ return ((color.foreground != nullptr && color.foreground[0] != '\0') | ||
+ || (color.background != nullptr && color.background[0] != '\0')); | ||
} | ||
|
||
/* Predefined colors. */ | ||
-- | ||
2.40.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters