255
252
if (!find_option(sequence, "target", buf, sizeof(buf))
256
253
&& !find_option(sequence, "tgt", buf, sizeof(buf))) {
257
freelog(LOG_FEATURED_TEXT,
258
"text_tag_init_from_sequence: target link type not set.");
254
log_featured_text("text_tag_init_from_sequence(): "
255
"target link type not set.");
262
259
ptag->link.type = -1;
263
260
for (i = 0; (name = text_link_type_name(i)); i++) {
264
if (0 == mystrncasecmp(buf, name, strlen(name))) {
261
if (0 == fc_strncasecmp(buf, name, strlen(name))) {
265
262
ptag->link.type = i;
269
266
if (ptag->link.type == -1) {
270
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
271
"target link type not supported (\"%s\").", buf);
267
log_featured_text("text_tag_init_from_sequence(): "
268
"target link type not supported (\"%s\").", buf);
278
275
if (!find_option(sequence, "id", buf, sizeof(buf))) {
279
freelog(LOG_FEATURED_TEXT,
280
"text_tag_init_from_sequence: city link without id.");
276
log_featured_text("text_tag_init_from_sequence(): "
277
"city link without id.");
283
if (1 != sscanf(buf, "%d", &ptag->link.id)) {
284
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
285
"city link without valid id (\"%s\").", buf);
280
if (!str_to_int(buf, &ptag->link.id)) {
281
log_featured_text("text_tag_init_from_sequence(): "
282
"city link without valid id (\"%s\").", buf);
289
286
if (!find_option(sequence, "name", ptag->link.name,
290
287
sizeof(ptag->link.name))) {
291
288
/* Set something as name. */
292
my_snprintf(ptag->link.name, sizeof(ptag->link.name),
289
fc_snprintf(ptag->link.name, sizeof(ptag->link.name),
293
290
"CITY_ID%d", ptag->link.id);
302
299
if (!find_option(sequence, "x", buf, sizeof(buf))) {
303
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
304
"tile link without x coordinate.");
300
log_featured_text("text_tag_init_from_sequence(): "
301
"tile link without x coordinate.");
307
if (1 != sscanf(buf, "%d", &x)) {
308
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
309
"tile link without valid x coordinate (\"%s\").", buf);
304
if (!str_to_int(buf, &x)) {
305
log_featured_text("text_tag_init_from_sequence(): "
306
"tile link without valid x coordinate "
313
311
if (!find_option(sequence, "y", buf, sizeof(buf))) {
314
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
315
"tile link without y coordinate.");
312
log_featured_text("text_tag_init_from_sequence(): "
313
"tile link without y coordinate.");
318
if (1 != sscanf(buf, "%d", &y)) {
319
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
320
"tile link without valid y coordinate (\"%s\").", buf);
316
if (!str_to_int(buf, &y)) {
317
log_featured_text("text_tag_init_from_sequence(): "
318
"tile link without valid y coordinate "
324
323
ptile = map_pos_to_tile(x, y);
326
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
327
"(%d, %d) are not valid coordinates in this game.",
325
log_featured_text("text_tag_init_from_sequence(): "
326
"(%d, %d) are not valid coordinates "
327
"in this game.", x, y);
331
330
ptag->link.id = tile_index(ptile);
332
my_snprintf(ptag->link.name, sizeof(ptag->link.name),
331
fc_snprintf(ptag->link.name, sizeof(ptag->link.name),
333
332
"(%d, %d)", TILE_XY(ptile));
338
337
if (!find_option(sequence, "id", buf, sizeof(buf))) {
339
freelog(LOG_FEATURED_TEXT,
340
"text_tag_init_from_sequence: unit link without id.");
338
log_featured_text("text_tag_init_from_sequence(): "
339
"unit link without id.");
343
if (1 != sscanf(buf, "%d", &ptag->link.id)) {
344
freelog(LOG_FEATURED_TEXT, "text_tag_init_from_sequence: "
345
"unit link without valid id (\"%s\").", buf);
342
if (!str_to_int(buf, &ptag->link.id)) {
343
log_featured_text("text_tag_init_from_sequence(): "
344
"unit link without valid id (\"%s\").", buf);
349
348
if (!find_option(sequence, "name", ptag->link.name,
350
349
sizeof(ptag->link.name))) {
351
350
/* Set something as name. */
352
my_snprintf(ptag->link.name, sizeof(ptag->link.name),
351
fc_snprintf(ptag->link.name, sizeof(ptag->link.name),
353
352
"UNIT_ID%d", ptag->link.id);
470
469
case TTT_UNDERLINE:
471
return my_snprintf(buf, len, "%c%s%c", SEQ_START,
470
return fc_snprintf(buf, len, "%c%s%c", SEQ_START,
472
471
text_tag_type_short_name(ptag->type), SEQ_STOP);
475
size_t ret = my_snprintf(buf, len, "%c%s", SEQ_START,
474
size_t ret = fc_snprintf(buf, len, "%c%s", SEQ_START,
476
475
text_tag_type_short_name(ptag->type));
478
477
if (ptag->color.foreground[0] != '\0') {
479
ret += my_snprintf(buf + ret, len - ret, " fg=\"%s\"",
478
ret += fc_snprintf(buf + ret, len - ret, " fg=\"%s\"",
480
479
ptag->color.foreground);
482
481
if (ptag->color.background[0] != '\0') {
483
ret += my_snprintf(buf + ret, len - ret, " bg=\"%s\"",
482
ret += fc_snprintf(buf + ret, len - ret, " bg=\"%s\"",
484
483
ptag->color.background);
486
return ret + my_snprintf(buf + ret, len - ret, "%c", SEQ_STOP);
485
return ret + fc_snprintf(buf + ret, len - ret, "%c", SEQ_STOP);
490
size_t ret = my_snprintf(buf, len, "%c%s tgt=\"%s\"", SEQ_START,
489
size_t ret = fc_snprintf(buf, len, "%c%s tgt=\"%s\"", SEQ_START,
491
490
text_tag_type_short_name(ptag->type),
492
491
text_link_type_name(ptag->link.type));
494
493
switch (ptag->link.type) {
497
struct city *pcity = game_find_city_by_number(ptag->link.id);
496
struct city *pcity = game_city_by_number(ptag->link.id);
500
ret += my_snprintf(buf + ret, len - ret,
499
ret += fc_snprintf(buf + ret, len - ret,
501
500
" id=%d name=\"%s\"",
502
501
pcity->id, city_name(pcity));
504
ret += my_snprintf(buf + ret, len - ret,
503
ret += fc_snprintf(buf + ret, len - ret,
505
504
" id=%d", ptag->link.id);
511
510
struct tile *ptile = index_to_tile(ptag->link.id);
514
ret += my_snprintf(buf + ret, len - ret,
513
ret += fc_snprintf(buf + ret, len - ret,
515
514
" x=%d y=%d", TILE_XY(ptile));
517
ret += my_snprintf(buf + ret, len - ret,
516
ret += fc_snprintf(buf + ret, len - ret,
518
517
" id=%d", ptag->link.id);
524
struct unit *punit = game_find_unit_by_number(ptag->link.id);
523
struct unit *punit = game_unit_by_number(ptag->link.id);
527
ret += my_snprintf(buf + ret, len - ret,
526
ret += fc_snprintf(buf + ret, len - ret,
528
527
" id=%d name=\"%s\"",
529
528
punit->id, unit_rule_name(punit));
531
ret += my_snprintf(buf + ret, len - ret,
530
ret += fc_snprintf(buf + ret, len - ret,
532
531
" id=%d", ptag->link.id);
538
537
if (ptag->stop_offset == ptag->start_offset) {
539
538
/* This is a single sequence like [link ... /]. */
540
ret += my_snprintf(buf + ret, len - ret, "%c", SEQ_END);
539
ret += fc_snprintf(buf + ret, len - ret, "%c", SEQ_END);
543
return ret + my_snprintf(buf + ret, len - ret, "%c", SEQ_STOP);
542
return ret + fc_snprintf(buf + ret, len - ret, "%c", SEQ_STOP);
576
575
switch (ptag->link.type) {
579
struct city *pcity = game_find_city_by_number(ptag->link.id);
578
struct city *pcity = game_city_by_number(ptag->link.id);
581
580
/* Note that if city_tile(pcity) is NULL, then it is probably an
582
581
* invisible city (see client/packhand.c). Then, we don't
583
582
* use the current city name which is usually not complete,
584
583
* a dumb string using the city id. */
585
584
if (NULL != pcity && NULL != city_tile(pcity)) {
586
return my_snprintf(buf, len, "%s", city_name(pcity));
585
return fc_snprintf(buf, len, "%s", city_name(pcity));
604
603
if (ptag->link.type == TLT_UNIT) {
605
604
/* Attempt to translate the link name (it should be a unit type name). */
606
return my_snprintf(buf, len, "%s", _(ptag->link.name));
605
return fc_snprintf(buf, len, "%s", _(ptag->link.name));
608
return my_snprintf(buf, len, "%s", ptag->link.name);
607
return fc_snprintf(buf, len, "%s", ptag->link.name);
650
649
/**************************************************************************
650
This function returns a new pointer to a text_tag which is similar
651
to the 'ptag' argument.
652
**************************************************************************/
653
struct text_tag *text_tag_copy(const struct text_tag *ptag)
655
struct text_tag *pnew_tag;
661
pnew_tag = fc_malloc(sizeof(struct text_tag));
667
/**************************************************************************
651
668
Free a text_tag structure.
652
669
**************************************************************************/
653
670
void text_tag_destroy(struct text_tag *ptag)
739
756
/**************************************************************************
740
Clear and free all tags inside the tag list. It doesn't free the list
741
itself. It just should be used instead of text_tag_list_clear() which
742
doesn't free the tags.
743
**************************************************************************/
744
void text_tag_list_clear_all(struct text_tag_list *tags)
750
text_tag_list_iterate(tags, ptag) {
751
text_tag_destroy(ptag);
752
} text_tag_list_iterate_end;
753
text_tag_list_clear(tags);
756
/**************************************************************************
757
This function returns a new pointer to a text_tag_list which is similar
758
to the 'tags' argument.
759
**************************************************************************/
760
struct text_tag_list *text_tag_list_dup(const struct text_tag_list *tags)
762
struct text_tag_list *new_tags;
768
new_tags = text_tag_list_new();
769
text_tag_list_iterate(tags, ptag) {
770
struct text_tag *pnew_tag = fc_malloc(sizeof(struct text_tag));
773
text_tag_list_append(new_tags, pnew_tag);
774
} text_tag_list_iterate_end;
779
/**************************************************************************
780
757
Extract a sequence from a string. Also, determine the type and the text
781
758
tag type of the sequence. Return 0 on error.
782
759
**************************************************************************/
800
777
/* Check sequence type. */
801
for (read++; my_isspace(*read); read++);
778
for (read++; fc_isspace(*read); read++);
803
780
if (*read == SEQ_END) {
804
781
*seq_type = ST_STOP;
807
for (end--; my_isspace(*end); end--);
784
for (end--; fc_isspace(*end); end--);
809
786
if (*end == SEQ_END) {
810
787
*seq_type = ST_SINGLE;
812
for (end--; my_isspace(*end); end--);
789
for (end--; fc_isspace(*end); end--);
814
791
*seq_type = ST_START;
818
while (my_isspace(*read)) {
795
while (fc_isspace(*read)) {
822
799
/* Check the length of the type name. */
823
800
for (name = read; name < stop; name++) {
824
if (!my_isalpha(*name)) {
801
if (!fc_isalpha(*name)) {
869
847
**************************************************************************/
870
848
size_t featured_text_to_plain_text(const char *featured_text,
871
849
char *plain_text, size_t plain_text_len,
872
struct text_tag_list *tags)
850
struct text_tag_list **tags)
874
852
const char *read = featured_text;
875
853
char *write = plain_text;
876
854
size_t write_len = plain_text_len;
879
text_tag_list_clear_all(tags);
857
*tags = text_tag_list_new();
882
860
while (*read != '\0' && write_len > 1) {
1069
1047
static char buf[MAX_LEN_LINK];
1071
my_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1049
fc_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1072
1050
SEQ_START, text_tag_type_short_name(TTT_LINK),
1073
1051
text_link_type_name(TLT_CITY), pcity->id,
1074
1052
city_name(pcity), SEQ_END, SEQ_STOP);
1086
1064
static char buf[MAX_LEN_LINK];
1087
1065
const char *tag_name = text_tag_type_short_name(TTT_LINK);
1089
my_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1067
fc_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1090
1068
SEQ_START, tag_name, text_link_type_name(TLT_TILE),
1091
1069
TILE_XY(city_tile(pcity)), SEQ_STOP, city_name(pcity),
1092
1070
SEQ_START, SEQ_END, tag_name, SEQ_STOP);
1121
1099
/* We use the rule name of the unit, it will be translated in every
1122
1100
* local sides in the function text_tag_replace_text(). */
1123
my_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1101
fc_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" id=%d name=\"%s\" %c%c",
1124
1102
SEQ_START, text_tag_type_short_name(TTT_LINK),
1125
1103
text_link_type_name(TLT_UNIT), punit->id,
1126
1104
unit_rule_name(punit), SEQ_END, SEQ_STOP);
1138
1116
static char buf[MAX_LEN_LINK];
1139
1117
const char *tag_name = text_tag_type_short_name(TTT_LINK);
1141
my_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1119
fc_snprintf(buf, sizeof(buf), "%c%s tgt=\"%s\" x=%d y=%d%c%s%c%c%s%c",
1142
1120
SEQ_START, tag_name, text_link_type_name(TLT_TILE),
1143
1121
TILE_XY(unit_tile(punit)), SEQ_STOP,
1144
1122
unit_name_translation(punit),