MCPcopy Create free account
hub / github.com/NetHack/NetHack / mswin_add_text

Function mswin_add_text

outdated/sys/wince/mhtxtbuf.c:67–110  ·  view source on GitHub ↗

----------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

65}
66/*----------------------------------------------------------------*/
67void
68mswin_add_text(PNHTextBuffer pb, int attr, const char *text)
69{
70 char *p;
71 struct text_buffer_line *new_line;
72
73 /* grow buffer */
74 if (pb->n_used >= pb->n_size) {
75 pb->n_size += NHTEXT_BUFFER_INCREMENT;
76 pb->text_buffer_line = (struct text_buffer_line *) realloc(
77 pb->text_buffer_line,
78 pb->n_size * sizeof(struct text_buffer_line));
79 if (!pb->text_buffer_line)
80 panic("Memory allocation error");
81 }
82
83 /* analyze the new line of text */
84 new_line = &NHTextLine(pb, pb->n_used);
85 new_line->attr = attr;
86 new_line->beg_padding = 0;
87 new_line->text = strdup(text);
88 for (p = new_line->text; *p && isspace(*p); p++) {
89 new_line->beg_padding++;
90 }
91 if (*p) {
92 memmove(new_line->text, new_line->text + new_line->beg_padding,
93 strlen(new_line->text) - new_line->beg_padding + 1);
94 for (p = new_line->text + strlen(new_line->text);
95 p >= new_line->text && isspace(*p); p--) {
96 new_line->end_padding++;
97 *p = 0;
98 }
99
100 /* if there are 3 (or more) consecutive spaces inside the string
101 consider it formatted */
102 new_line->formatted = (strstr(new_line->text, " ") != NULL)
103 || (new_line->beg_padding > 8);
104 } else {
105 new_line->end_padding = 0;
106 new_line->text[0] = 0;
107 new_line->formatted = FALSE;
108 }
109 pb->n_used++;
110}
111/*----------------------------------------------------------------*/
112void
113mswin_set_text_wrap(PNHTextBuffer pb, BOOL wrap_text)

Callers 2

onMSNHCommandFunction · 0.85
onMSNHCommandFunction · 0.85

Calls 2

isspaceFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected