void _cmsg_add_aux(byte color, cptr str, int turn, int count) { msg_ptr m; /* Repeat last message? */ if (_msg_count) { m = msg_get(0); if (strcmp(string_buffer(m->msg), str) == 0) { m->count += count; m->turn = turn; m->color = color; return; } } m = _msgs[_msg_head]; if (!m) { m = _msg_alloc(NULL); _msgs[_msg_head] = m; _msg_count++; } else { string_clear(m->msg); string_shrink(m->msg, 128); } string_append_s(m->msg, str); m->turn = turn; m->count = count; m->color = color; _msg_head = (_msg_head + 1) % _msg_max; }
void cmsg_append(byte color, cptr str) { if (!_msg_count) cmsg_add(color, str); else { msg_ptr m = msg_get(0); assert(m); /* You tunnel into the granite wall. <x17> The heroism wears off. Not: You tunnel into the granite wall. The heroism wears off. <x17> */ if (m->count > 1) { cmsg_add(color, str); return; } if (string_length(m->msg) && strlen(str) > 1) string_append_c(m->msg, ' '); if (color != m->color) string_printf(m->msg, "<color:%c>%s</color>", attr_to_attr_char(color), str); else string_append_s(m->msg, str); } }
void doc_change_html_header(doc_ptr doc, cptr header) { string_clear(doc->html_header); string_append_s(doc->html_header, header); }
void doc_change_name(doc_ptr doc, cptr name) { string_clear(doc->name); string_append_s(doc->name, name); }
static void _doc_write_html_file(doc_ptr doc, FILE *fp) { doc_pos_t pos; doc_char_ptr cell; byte old_a = _INVALID_COLOR; int bookmark_idx = 0; doc_bookmark_ptr next_bookmark = NULL; vec_ptr links = doc_get_links(doc); int link_idx = 0; doc_link_ptr next_link = NULL; if (bookmark_idx < vec_length(doc->bookmarks)) next_bookmark = vec_get(doc->bookmarks, bookmark_idx); if (link_idx < vec_length(links)) next_link = vec_get(links, link_idx); fprintf(fp, "<!DOCTYPE html>\n<html>\n"); if (string_length(doc->html_header)) fprintf(fp, "%s\n", string_buffer(doc->html_header)); fprintf(fp, "<body text=\"#ffffff\" bgcolor=\"#000000\"><pre>\n"); for (pos.y = 0; pos.y <= doc->cursor.y; pos.y++) { int cx = doc->width; pos.x = 0; if (pos.y == doc->cursor.y) cx = doc->cursor.x; cell = doc_char(doc, pos); if (next_bookmark && pos.y == next_bookmark->pos.y) { fprintf(fp, "<a name=\"%s\"></a>", string_buffer(next_bookmark->name)); bookmark_idx++; if (bookmark_idx < vec_length(doc->bookmarks)) next_bookmark = vec_get(doc->bookmarks, bookmark_idx); else next_bookmark = NULL; } for (; pos.x < cx; pos.x++) { char c = cell->c; byte a = cell->a & 0x0F; if (next_link) { if (doc_pos_compare(next_link->location.start, pos) == 0) { string_ptr s; int pos = string_last_chr(next_link->file, '.'); if (pos >= 0) { s = string_copy_sn(string_buffer(next_link->file), pos + 1); string_append_s(s, "html"); } else s = string_copy(next_link->file); fprintf(fp, "<a href=\"%s", string_buffer(s)); if (next_link->topic) fprintf(fp, "#%s", string_buffer(next_link->topic)); fprintf(fp, "\">"); string_free(s); } if (doc_pos_compare(next_link->location.stop, pos) == 0) { fprintf(fp, "</a>"); link_idx++; if (link_idx < vec_length(links)) next_link = vec_get(links, link_idx); else next_link = NULL; } } if (!c) break; if (a != old_a && c != ' ') { if (old_a != _INVALID_COLOR) fprintf(fp, "</font>"); fprintf(fp, "<font color=\"#%02x%02x%02x\">", angband_color_table[a][1], angband_color_table[a][2], angband_color_table[a][3] ); old_a = a; } switch (c) { case '&': fprintf(fp, "&"); break; case '<': fprintf(fp, "<"); break; case '>': fprintf(fp, ">"); break; default: fprintf(fp, "%c", c); break; } cell++; } fputc('\n', fp); } fprintf(fp, "</font>"); fprintf(fp, "</pre></body></html>\n"); vec_free(links); }
static _slot_info_ptr _choose(cptr verb, int options) { _slot_info_ptr result = NULL; int slot = 0; int cmd; rect_t r = _menu_rect(); string_ptr prompt = NULL; bool done = FALSE; bool exchange = FALSE; int slot1 = _INVALID_SLOT, slot2 = _INVALID_SLOT; if (REPEAT_PULL(&cmd)) { slot = A2I(cmd); if (0 <= slot && slot < _MAX_SLOTS) return &_spells[slot]; } prompt = string_alloc(); screen_save(); while (!done) { string_clear(prompt); if (exchange) { if (slot1 == _INVALID_SLOT) string_append_s(prompt, "Select the first spell:"); else string_append_s(prompt, "Select the second spell:"); } else { string_printf(prompt, "%s which spell", verb); if (options & _ALLOW_EXCHANGE) string_append_s(prompt, " [Press 'X' to Exchange]"); string_append_c(prompt, ':'); } prt(string_buffer(prompt), 0, 0); _display(r, options); cmd = inkey_special(FALSE); if (cmd == ESCAPE || cmd == 'q' || cmd == 'Q') done = TRUE; if (options & _ALLOW_EXCHANGE) { if (!exchange && (cmd == 'x' || cmd == 'X')) { exchange = TRUE; slot1 = slot2 = _INVALID_SLOT; } } if ('a' <= cmd && cmd < 'a' + _MAX_SLOTS) { slot = A2I(cmd); if (exchange) { if (slot1 == _INVALID_SLOT) slot1 = slot; else { slot2 = slot; if (slot1 != slot2) { _slot_info_t tmp = _spells[slot1]; _spells[slot1] = _spells[slot2]; _spells[slot2] = tmp; } exchange = FALSE; slot1 = slot2 = _INVALID_SLOT; } } else { if (_spells[slot].realm != REALM_NONE || (options & _ALLOW_EMPTY)) { result = &_spells[slot]; done = TRUE; } } } } if (result) { REPEAT_PUSH(I2A(slot)); } screen_load(); string_free(prompt); return result; }