36 #define MAX_LEN_STR 32
37 #define log_featured_text qDebug
39 #define text_tag_list_rev_iterate(tags, ptag) \
40 TYPED_LIST_ITERATE_REV(struct text_tag, tags, ptag)
41 #define text_tag_list_rev_iterate_end LIST_ITERATE_REV_END
176 char *buf_out,
size_t write_len)
178 size_t option_len = qstrlen(
option);
179 const char *buf_in_ptr = buf_in;
180 int len = qstrlen(buf_in);
182 while (*buf_in !=
'\0' && (buf_in - buf_in_ptr) <
len) {
183 while (QChar::isSpace(*buf_in) && *buf_in !=
'\0') {
188 buf_in += option_len;
190 while ((QChar::isSpace(*buf_in) || *buf_in ==
'=')
191 && *buf_in !=
'\0') {
194 if (*buf_in ==
'"') {
195 const char *end = strchr(++buf_in,
'"');
200 if (end - buf_in + 1 > 0) {
201 fc_strlcpy(buf_out, buf_in,
MIN(end - buf_in + 1, write_len));
207 while (QChar::isLetterOrNumber(*buf_in) && write_len > 1) {
208 *buf_out++ = *buf_in++;
233 QByteArray ba = qsequence.toLocal8Bit();
234 const char *sequence = ba.constData();
244 sizeof(ptag->
color.foreground))
246 sizeof(ptag->
color.foreground))) {
247 ptag->
color.foreground[0] =
'\0';
250 sizeof(ptag->
color.background))
252 sizeof(ptag->
color.background))) {
253 ptag->
color.background[0] =
'\0';
262 if (!
find_option(sequence,
"target", buf,
sizeof(buf))
263 && !
find_option(sequence,
"tgt", buf,
sizeof(buf))) {
265 "target link type not set.");
278 "target link type not supported (\"%s\").",
283 switch (ptag->
link.type) {
285 if (!
find_option(sequence,
"id", buf,
sizeof(buf))) {
287 "city link without id.");
292 "city link without valid id (\"%s\").",
298 sizeof(ptag->
link.name))) {
308 if (!
find_option(sequence,
"x", buf,
sizeof(buf))) {
310 "tile link without x coordinate.");
315 "tile link without valid x coordinate "
321 if (!
find_option(sequence,
"y", buf,
sizeof(buf))) {
323 "tile link without y coordinate.");
328 "tile link without valid y coordinate "
337 "(%d, %d) are not valid coordinates "
347 if (!
find_option(sequence,
"id", buf,
sizeof(buf))) {
349 "unit link without id.");
354 "unit link without valid id (\"%s\").",
360 sizeof(ptag->
link.name))) {
419 ptag->
color.foreground[0] =
'\0';
425 ptag->
color.background[0] =
'\0';
432 switch (ptag->
link.type) {
434 struct city *pcity = va_arg(args,
struct city *);
439 ptag->
link.id = pcity->
id;
444 struct tile *ptile = va_arg(args,
struct tile *);
455 struct unit *punit = va_arg(args,
struct unit *);
460 ptag->
link.id = punit->
id;
480 switch (ptag->
type) {
491 if (ptag->
color.foreground[0] !=
'\0') {
493 ptag->
color.foreground);
495 if (ptag->
color.background[0] !=
'\0') {
497 ptag->
color.background);
506 switch (ptag->
link.type) {
573 size_t len,
bool replace_link_text)
579 if (replace_link_text) {
581 switch (ptag->
link.type) {
589 if (
nullptr != pcity &&
nullptr !=
city_tile(pcity)) {
704 qCritical(
"text_tag_color_foreground(): incompatible tag type.");
705 return QStringLiteral();
708 return ptag->
color.foreground;
718 qCritical(
"text_tag_color_background(): incompatible tag type.");
719 return QStringLiteral();
722 return ptag->
color.background;
732 qCritical(
"text_tag_link_type(): incompatible tag type.");
736 return ptag->
link.type;
747 qCritical(
"text_tag_link_id(): incompatible tag type.");
751 return ptag->
link.id;
762 const char *buf_in = featured_text;
763 const char *stop = strchr(buf_in,
SEQ_STOP);
764 const char *end = stop;
775 for (buf_in++; QChar::isSpace(*buf_in); buf_in++) {
783 for (end--; QChar::isSpace(*end); end--) {
790 for (end--; QChar::isSpace(*end); end--) {
798 while (QChar::isSpace(*buf_in)) {
804 if (!QChar::isLetter(*
name)) {
808 type_len =
name - buf_in;
814 name_len = qstrlen(
name);
815 if (name_len == type_len
827 name_len = qstrlen(
name);
828 if (name_len == type_len
840 while (QChar::isSpace(*buf_in)) {
844 if (end - buf_in + 2 > 0) {
845 buf = QString(buf_in).left(
MIN(end - buf_in + 2,
len));
847 buf = QLatin1String(
"");
849 return stop - featured_text + 1;
862 char *plain_text,
size_t plain_text_len,
863 struct text_tag_list **tags,
864 bool replace_link_text)
866 const char *text_in = featured_text;
867 char *text_out = plain_text;
868 size_t text_out_len = plain_text_len;
874 while (*text_in !=
'\0' && text_out_len > 1) {
893 text_out - plain_text, buf)) {
894 text_tag_list_append(*tags, ptag);
898 qUtf8Printable(buf));
910 if (piter->type ==
type
933 qUtf8Printable(buf));
945 text_tag_list_append(*tags, ptag);
951 *text_out++ = *text_in++;
955 *text_out++ = *text_in++;
961 return plain_text_len - text_out_len;
983 size_t featured_text_len,
989 size_t len, total_len = 0;
1009 && featured_text_len > 1) {
1010 *featured_text++ = *text_source++;
1011 featured_text_len--;
1020 featured_text +=
len;
1021 featured_text_len -=
len;
1026 && featured_text_len > 1) {
1027 *featured_text++ = *text_source++;
1028 featured_text_len--;
1036 featured_text +=
len;
1037 featured_text_len -=
len;
1040 while (*text_source !=
'\0' && featured_text_len > 1) {
1041 *featured_text++ = *text_source++;
1042 featured_text_len--;
1045 *featured_text =
'\0';
1059 fc_snprintf(buf,
sizeof(buf),
"%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1077 fc_snprintf(buf,
sizeof(buf),
"%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1109 fc_snprintf(buf,
sizeof(buf),
"%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1127 fc_snprintf(buf,
sizeof(buf),
"%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1153 snprintf(buf,
sizeof(buf),
_(
"v%d %d%%"), punit->
veteran,
1224 if (firepower == 1) {
1229 _(
"FP:%d "), firepower);
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
bool is_tired_attack(int moves_left)
Returns if the attack is going to be a tired attack.
struct text_tag * text_tag_copy(const struct text_tag *ptag)
This function returns a new pointer to a text_tag which is similar to the 'ptag' argument.
static const char * text_tag_type_name(enum text_tag_type type)
Return the long name of the text tag type.
const struct ft_color ftc_chat_private
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Apply a tag to a text.
const char * unit_firepower_if_not_one(int firepower)
Get string of unit's firepower text, i.e.
const char * unit_veteran_level_and_bonus(const unit *punit)
Get a text of a unit's numerical veteran level and the bonus percentage it confers.
static const char * text_link_type_name(enum text_link_type type)
Return the name of the text tag link target type.
static bool find_option(const char *buf_in, const char *option, char *buf_out, size_t write_len)
Find inside a sequence the string associated to a particular option name.
const char * city_tile_link(const struct city *pcity)
Get a text link to a city tile (make a clickable link to a tile with the city name as text).
const struct ft_color ftc_vote_abstain
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
Return the link target type suggested by this text tag.
const struct ft_color ftc_log
const struct ft_color ftc_player_lost
size_t featured_text_to_plain_text(const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
Separate the text from the text features.
const struct ft_color ftc_luaconsole_verbose
#define text_tag_list_rev_iterate(tags, ptag)
const char * tile_link(const struct tile *ptile)
Get a text link to a tile.
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Returns a new text_tag or nullptr on error.
static bool text_tag_init_from_sequence(struct text_tag *ptag, enum text_tag_type type, ft_offset_t start_offset, QString &qsequence)
Initialize a text_tag structure from a string sequence.
const struct ft_color ftc_command
QString text_tag_color_background(const struct text_tag *ptag)
Return the background color suggested by this text tag.
const char * unit_tired_attack_string(const struct unit *punit)
Get string of unit's attack would be a tired attack or not.
QString text_tag_color_foreground(const struct text_tag *ptag)
Return the foreground color suggested by this text tag.
const char * unit_tile_link(const struct unit *punit)
Get a text link to a unit tile (make a clickable link to a tile with the unit type name as text).
ft_offset_t text_tag_stop_offset(const struct text_tag *ptag)
Return the stop offset (in bytes) of this text tag.
static bool text_tag_initv(struct text_tag *ptag, enum text_tag_type type, ft_offset_t start_offset, ft_offset_t stop_offset, va_list args)
Initialize a text_tag structure from a va_list.
const char * unit_veteran_level_string(const struct unit *punit)
Get a text of a unit's vet level.
static size_t extract_sequence_text(const char *featured_text, QString &buf, size_t len, enum sequence_type *seq_type, enum text_tag_type *type)
Extract a sequence from a string.
const struct ft_color ftc_server
const struct ft_color ftc_vote_failed
void text_tag_destroy(struct text_tag *ptag)
Free a text_tag structure.
const struct ft_color ftc_vote_yes
static size_t text_tag_start_sequence(const struct text_tag *ptag, char *buf, size_t len)
Print in a string the start sequence of the tag.
const struct ft_color ftc_luaconsole_error
const struct ft_color ftc_warning
enum text_tag_type text_tag_type(const struct text_tag *ptag)
Return the type of this text tag.
#define text_tag_list_rev_iterate_end
static const char * text_tag_type_short_name(enum text_tag_type type)
Return the name abbreviation of the text tag type.
const struct ft_color ftc_client
const struct ft_color ftc_luaconsole_normal
const struct ft_color ftc_editor
const char * unit_achieved_rank_string(const struct unit *punit)
Get string of when unit gets upgraded to new veteran level.
static size_t text_tag_replace_text(const struct text_tag *ptag, char *buf, size_t len, bool replace_link_text)
When the sequence looks like [sequence/] then we insert a string instead.
const struct ft_color ftc_any
const struct ft_color ftc_vote_no
const char * city_link(const struct city *pcity)
Get a text link to a city.
const struct ft_color ftc_vote_passed
#define log_featured_text
static size_t text_tag_stop_sequence(const struct text_tag *ptag, char *buf, size_t len)
Print in a string the stop sequence of the tag.
const struct ft_color ftc_luaconsole_warn
int text_tag_link_id(const struct text_tag *ptag)
Return the link target id suggested by this text tag (city id, tile index or unit id).
const struct ft_color ftc_chat_luaconsole
ft_offset_t text_tag_start_offset(const struct text_tag *ptag)
Return the start offset (in bytes) of this text tag.
const struct ft_color ftc_vote_team
const char * unit_link(const struct unit *punit)
Get a text link to an unit.
const struct ft_color ftc_game_start
const struct ft_color ftc_server_prompt
struct ft_color ftc_changed
const struct ft_color ftc_vote_public
const struct ft_color ftc_luaconsole_input
const struct ft_color ftc_chat_public
const struct ft_color ftc_chat_ally
#define text_tag_list_new()
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Return the tile for the given cartesian (map) position.
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Return the tile for the given index position.
static const char * name_translation_get(const struct name_translation *ptrans)
bool str_to_int(const char *str, int *pint)
Convert 'str' to it's int reprentation if possible.
The base class for options.
struct text_tag::@23::@26 link
char background[MAX_LEN_STR]
struct text_tag::@23::@25 color
char foreground[MAX_LEN_STR]
struct name_translation name
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
#define sz_strlcpy(dest, src)
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Return veteran level properties of given unit in given veterancy level.