Angband
Data Structures | Macros | Functions | Variables
z-textblock.c File Reference

Text output bugger (?NRM) code. More...

#include "z-color.h"
#include "z-textblock.h"
#include "z-util.h"
#include "z-virt.h"
#include "z-form.h"

Data Structures

struct  textblock
 

Macros

#define TEXTBLOCK_LEN_INITIAL   128
 Text blocks now use the internal representation of display characters, i.e. More...
 
#define TEXTBLOCK_LEN_INCR(x)   ((x) + 128)
 

Functions

textblocktextblock_new (void)
 Create a new textblock object and return it. More...
 
void textblock_free (textblock *tb)
 Free a textblock object. More...
 
void textblock_resize_if_needed (textblock *tb, size_t additional_size)
 Resize the internal textblock storage (if needed) to hold additional characters. More...
 
static void textblock_vappend_c (textblock *tb, byte attr, const char *fmt, va_list vp)
 
void textblock_append_pict (textblock *tb, byte attr, int c)
 Add a graphics tile to a text block. More...
 
void textblock_append_utf8 (textblock *tb, const char *utf8_string)
 Append a UTF-8 string to the textblock. More...
 
void textblock_append (textblock *tb, const char *fmt,...)
 Add text to a text block, formatted. More...
 
void textblock_append_c (textblock *tb, byte attr, const char *fmt,...)
 Add coloured text to a text block, formatted. More...
 
const wchar_t * textblock_text (textblock *tb)
 Return a pointer to the text inputted thus far. More...
 
const bytetextblock_attrs (textblock *tb)
 Return a pointer to the text attrs. More...
 
static void new_line (size_t **line_starts, size_t **line_lengths, size_t *n_lines, size_t *cur_line, size_t start, size_t len)
 
size_t textblock_calculate_lines (textblock *tb, size_t **line_starts, size_t **line_lengths, size_t width)
 Given a certain width, split a textblock into wrapped lines of text. More...
 
void textblock_to_file (textblock *tb, ang_file *f, int indent, int wrap_at)
 Output a textblock to file. More...
 
void text_out_to_file (byte a, const char *str)
 Write text to the given file and apply line-wrapping. More...
 
void text_out (const char *fmt,...)
 Output text to the screen or to a file depending on the selected text_out hook. More...
 
void text_out_c (byte a, const char *fmt,...)
 Output text to the screen (in color) or to a file depending on the selected hook. More...
 
static bool next_section (const char *source, size_t init, const char **text, size_t *len, const char **tag, size_t *taglen, const char **end)
 Given a "formatted" chunk of text (i.e. More...
 
void text_out_e (const char *fmt,...)
 Output text to the screen or to a file depending on the selected hook. More...
 
errr text_lines_to_file (const char *path, text_writer writer)
 Write a text file from given input. More...
 

Variables

void(* text_out_hook )(byte a, const char *str)
 

text_out()

More...
 
int text_out_wrap = 0
 Hack – Where to wrap the text when using text_out(). More...
 
int text_out_indent = 0
 Hack – Indentation for the text when using text_out(). More...
 
int text_out_pad = 0
 Hack – Padding after wrapping. More...
 
ang_filetext_out_file = NULL
 Hack - the destination file for text_out_to_file. More...
 

Detailed Description

Text output bugger (?NRM) code.

Copyright (c) 2010 Andi Sidwell Copyright (c) 2011 Peter Denison

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Macro Definition Documentation

#define TEXTBLOCK_LEN_INCR (   x)    ((x) + 128)
#define TEXTBLOCK_LEN_INITIAL   128

Text blocks now use the internal representation of display characters, i.e.

wchar_t, since they are expected to display straight to screen. Conversion from the incoming locale-encoded format is done in textblock_vappend_c().

Referenced by textblock_new(), and textblock_vappend_c().

Function Documentation

static void new_line ( size_t **  line_starts,
size_t **  line_lengths,
size_t *  n_lines,
size_t *  cur_line,
size_t  start,
size_t  len 
)
static

References mem_realloc(), and start.

Referenced by textblock_calculate_lines().

static bool next_section ( const char *  source,
size_t  init,
const char **  text,
size_t *  len,
const char **  tag,
size_t *  taglen,
const char **  end 
)
static

Given a "formatted" chunk of text (i.e.

one including tags like {red}{/}) in 'source', with starting point 'init', this finds the next section of text and any tag that goes with it, return true if it finds something to print.

If it returns true, then it also fills 'text' with a pointer to the start of the next printable section of text, and 'len' with the length of that text, and 'end' with a pointer to the start of the next section. This may differ from "text + len" because of the presence of tags. If a tag applies to the section of text, it returns a pointer to the start of that tag in 'tag' and the length in 'taglen'. Otherwise, 'tag' is filled with NULL.

See text_out_e for an example of its use.

References close, NULL, and text.

Referenced by text_out_e().

errr text_lines_to_file ( const char *  path,
text_writer  writer 
)

Write a text file from given input.

Parameters
paththe path to write to
writerthe text-writing function

References file_close(), file_delete(), file_exists(), file_move(), file_open(), FTYPE_TEXT, MODE_WRITE, NULL, safe_setuid_drop(), safe_setuid_grab(), and strnfmt().

Referenced by dump_save(), lore_save(), and pile_integrity_fail().

void text_out ( const char *  fmt,
  ... 
)

Output text to the screen or to a file depending on the selected text_out hook.

References buf, COLOUR_WHITE, text_out_hook, void(), and vstrnfmt().

Referenced by class_help(), curse_menu_browser(), race_help(), show_splashscreen(), spell_menu_browser(), spoil_artifact(), spoiler_underline(), store_display_help(), and target_display_help().

void text_out_c ( byte  a,
const char *  fmt,
  ... 
)

Output text to the screen (in color) or to a file depending on the selected hook.

References buf, text_out_hook, void(), and vstrnfmt().

Referenced by item_menu_browser(), store_display_help(), and target_display_help().

void text_out_e ( const char *  fmt,
  ... 
)

Output text to the screen or to a file depending on the selected hook.

Takes strings with "embedded formatting", such that something within {red}{/} will be printed in red.

Note that such formatting will be treated as a "breakpoint" for the printing, so if used within words may lead to part of the word being moved to the next line.

References buf, color_text_to_attr(), COLOUR_WHITE, next_section(), start, tag, text, text_out_hook, void(), and vstrnfmt().

Referenced by class_help(), ego_menu(), print_menu_instructions(), race_help(), show_splashscreen(), and skill_help().

void text_out_to_file ( byte  a,
const char *  str 
)

Write text to the given file and apply line-wrapping.

Hook function for text_out(). Make sure that text_out_file points to an open text-file.

Long lines will be wrapped at text_out_wrap, or at column 75 if that is not set; or at a newline character. Note that punctuation can sometimes be placed one column beyond the wrap limit.

You must be careful to end all file output with a newline character to "flush" the stored line position.

References buf, file_write(), file_writec(), i, my_strcpy(), text_out_indent, text_out_wrap, and void().

Referenced by spoil_artifact().

void textblock_append ( textblock tb,
const char *  fmt,
  ... 
)
void textblock_append_c ( textblock tb,
byte  attr,
const char *  fmt,
  ... 
)
void textblock_append_pict ( textblock tb,
byte  attr,
int  c 
)
void textblock_append_utf8 ( textblock tb,
const char *  utf8_string 
)

Append a UTF-8 string to the textblock.

This is needed in order for proper file writing. Normally, textblocks convert to the system's encoding when a string is appended. However, there are still some strings in the game that are imported from external files as UTF-8. Instead of requiring each port to provide another converter back to UTF-8, we'll just use the original strings as is.

Parameters
tbis the textblock we are appending to.
utf8_stringis the C string that is encoded as UTF-8.

References textblock::attrs, COLOUR_WHITE, i, textblock::strlen, textblock::text, and textblock_resize_if_needed().

Referenced by lore_append_flavor(), and spoil_mon_info().

const byte* textblock_attrs ( textblock tb)

Return a pointer to the text attrs.

References textblock::attrs.

Referenced by test_colour(), textui_textblock_place(), and textui_textblock_show().

size_t textblock_calculate_lines ( textblock tb,
size_t **  line_starts,
size_t **  line_lengths,
size_t  width 
)

Given a certain width, split a textblock into wrapped lines of text.

Trailing empty lines are trimmed.

Parameters
tbThe textblock to wrap.
line_startsOn return, an array (indexed by line number) of character indexes to the text of tb where each line begins.
line_lengthsOn return, an array (indexed by line number) of line lengths.
widthThe maximum permitted width of each line.
Returns
Number of lines in output.

References new_line(), NULL, textblock::strlen, text, textblock_text(), and width.

Referenced by edit_text(), textblock_to_file(), textui_textblock_place(), and textui_textblock_show().

void textblock_free ( textblock tb)
textblock* textblock_new ( void  )
void textblock_resize_if_needed ( textblock tb,
size_t  additional_size 
)

Resize the internal textblock storage (if needed) to hold additional characters.

Parameters
tbis the textblock we need to resize.
additional_sizeis how many characters we want to add.

References textblock::attrs, mem_realloc(), textblock::size, textblock::strlen, textblock::text, and TEXTBLOCK_LEN_INCR.

Referenced by textblock_append_pict(), textblock_append_utf8(), and textblock_vappend_c().

const wchar_t* textblock_text ( textblock tb)

Return a pointer to the text inputted thus far.

References textblock::text.

Referenced by test_append(), test_length(), textblock_calculate_lines(), textui_textblock_place(), and textui_textblock_show().

void textblock_to_file ( textblock tb,
ang_file f,
int  indent,
int  wrap_at 
)
static void textblock_vappend_c ( textblock tb,
byte  attr,
const char *  fmt,
va_list  vp 
)
static

Variable Documentation

ang_file* text_out_file = NULL

Hack - the destination file for text_out_to_file.

Referenced by spoil_artifact().

void(* text_out_hook)(byte a, const char *str)
int text_out_indent = 0
int text_out_pad = 0

Hack – Padding after wrapping.

Referenced by curse_menu_browser(), item_menu_browser(), spell_menu_browser(), and text_out_to_screen().

int text_out_wrap = 0

Hack – Where to wrap the text when using text_out().

Use the default value (for example the screen width) when 'text_out_wrap' is 0.

Referenced by curse_menu_browser(), display_player_xtra_info(), ego_menu(), item_menu_browser(), spell_menu_browser(), store_display_recalc(), text_out_to_file(), and text_out_to_screen().