Win32GUI: Gather raw_print text and display it all in single dialog
Defined strbuf_t and related routines to support dynamically sized strings. Modified strip_newline() to strip the last newline in a string instead of the first. Simplified splash window code using new strbuf_t. Prior to exiting game, re-enable getreturn and call wait_synch() in case there is buffered raw prints that must be displayed to user.
This commit is contained in:
committed by
Pasi Kallinen
parent
b02dae91a1
commit
a588541a27
@@ -61,6 +61,11 @@
|
||||
boolean friday_13th (void)
|
||||
int night (void)
|
||||
int midnight (void)
|
||||
void strbuf_init (strbuf *, const char *)
|
||||
void strbuf_append (strbuf *, const char *)
|
||||
void strbuf_reserve (strbuf *, int)
|
||||
void strbuf_empty (strbuf *)
|
||||
void strbuf_nl_to_crlf (strbuf_t *)
|
||||
=*/
|
||||
#ifdef LINT
|
||||
#define Static /* pacify lint */
|
||||
@@ -183,7 +188,7 @@ char *
|
||||
strip_newline(str)
|
||||
char *str;
|
||||
{
|
||||
char *p = index(str, '\n');
|
||||
char *p = rindex(str, '\n');
|
||||
|
||||
if (p) {
|
||||
if (p > str && *(p - 1) == '\r')
|
||||
@@ -1101,4 +1106,69 @@ midnight()
|
||||
return (getlt()->tm_hour == 0);
|
||||
}
|
||||
|
||||
/* strbuf_init() initializes strbuf state for use */
|
||||
void strbuf_init(strbuf_t * strbuf)
|
||||
{
|
||||
strbuf->str = NULL;
|
||||
strbuf->len = 0;
|
||||
}
|
||||
|
||||
/* strbuf_append() appends given str to strbuf->str */
|
||||
void strbuf_append(strbuf_t * strbuf, const char * str)
|
||||
{
|
||||
if (strbuf->str == NULL)
|
||||
strbuf_reserve(strbuf, strlen(str) + 1);
|
||||
else
|
||||
strbuf_reserve(strbuf, strlen(strbuf->str) + strlen(str) + 1);
|
||||
|
||||
strcat(strbuf->str, str);
|
||||
}
|
||||
|
||||
/* strbuf_reserve() ensure strbuf->str has storage for len characters */
|
||||
void strbuf_reserve(strbuf_t * strbuf, int len)
|
||||
{
|
||||
if (strbuf->str == NULL) {
|
||||
strbuf->str = strbuf->buf;
|
||||
strbuf->str[0] = '\0';
|
||||
strbuf->len = sizeof(strbuf->buf);
|
||||
}
|
||||
|
||||
if (len > strbuf->len) {
|
||||
char * oldbuf = strbuf->str;
|
||||
strbuf->len = len + sizeof(strbuf->buf);
|
||||
strbuf->str = (char *) alloc(strbuf->len);
|
||||
strcpy(strbuf->str, oldbuf);
|
||||
if (oldbuf != strbuf->buf) free(oldbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/* strbuf_empty() frees allocated memory and set strbuf to initial state */
|
||||
void strbuf_empty(strbuf_t * strbuf)
|
||||
{
|
||||
if (strbuf->str != strbuf->buf)
|
||||
free(strbuf->str);
|
||||
strbuf_init(strbuf);
|
||||
}
|
||||
|
||||
/* strbuf_nl_to_crlf() converts all occurences of \n to \r\n */
|
||||
void strbuf_nl_to_crlf(strbuf_t * strbuf)
|
||||
{
|
||||
if (strbuf->str) {
|
||||
int len = strlen(strbuf->str);
|
||||
int count = 0;
|
||||
char * cp = strbuf->str;
|
||||
while (*cp) if (*cp++ == '\n') count++;
|
||||
if (count) {
|
||||
strbuf_reserve(strbuf, len + count + 1);
|
||||
cp = strbuf->str + len + count;
|
||||
while (count) {
|
||||
if ((*cp-- = cp[-count]) == '\n') {
|
||||
*cp-- = '\r';
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*hacklib.c*/
|
||||
|
||||
Reference in New Issue
Block a user