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

Function add_line

win/X11/winmesg.c:391–410  ·  view source on GitHub ↗

* Add a line of text to the window. The first line in the circular list * becomes the last. So all we have to do is copy the new line over the * old one. If the line buffer is too small, then allocate a new, larger * one. */

Source from the content-addressed store, hash-verified

389 * one.
390 */
391static void
392add_line(struct mesg_info_t *mesg_info, const char *s)
393{
394 struct line_element *curr = mesg_info->head;
395 int new_line_length = strlen(s);
396
397 if (new_line_length + 1 > curr->buf_length) {
398 if (curr->line)
399 free(curr->line); /* free old line */
400
401 curr->buf_length = new_line_length + 1;
402 curr->line = (char *) alloc((unsigned) curr->buf_length);
403 }
404
405 Strcpy(curr->line, s); /* copy info */
406 curr->str_length = new_line_length; /* save string length */
407
408 mesg_info->head = mesg_info->head->next; /* move head to next line */
409 mesg_info->dirty = True; /* we have undrawn lines */
410}
411
412/*
413 * Save a position in the text buffer so we can draw a line to separate

Callers 1

append_messageFunction · 0.85

Calls 1

allocFunction · 0.50

Tested by

no test coverage detected