diff options
Diffstat (limited to 'src/common/text.c')
-rw-r--r-- | src/common/text.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/common/text.c b/src/common/text.c index 6b111742..9aa1bc85 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -19,13 +19,16 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> #include <ctype.h> #include <time.h> #include <sys/types.h> #include <fcntl.h> #include <sys/stat.h> + +#ifndef WIN32 +#include <unistd.h> #include <sys/mman.h> +#endif #include "xchat.h" #include <glib.h> @@ -271,9 +274,12 @@ scrollback_load (session *sess) char *text; time_t stamp; int lines; + +#ifndef WIN32 char *map, *end_map; struct stat statbuf; const char *begin, *eol; +#endif if (sess->text_scrollback == SET_DEFAULT) { @@ -293,6 +299,7 @@ scrollback_load (session *sess) if (fh == -1) return; +#ifndef WIN32 if (fstat (fh, &statbuf) < 0) return; @@ -301,7 +308,7 @@ scrollback_load (session *sess) return; end_map = map + statbuf.st_size; - + lines = 0; begin = map; while (begin < end_map) @@ -314,11 +321,11 @@ scrollback_load (session *sess) eol = end_map; n_bytes = MIN (eol - begin, sizeof (buf) - 1); - + strncpy (buf, begin, n_bytes); buf[n_bytes] = 0; - + if (buf[0] == 'T') { if (sizeof (time_t) == 4) @@ -350,6 +357,39 @@ scrollback_load (session *sess) } munmap (map, statbuf.st_size); +#else + lines = 0; + while (waitline (fh, buf, sizeof buf, FALSE) != -1) + { + if (buf[0] == 'T') + { + if (sizeof (time_t) == 4) + stamp = strtoul (buf + 2, NULL, 10); + else + stamp = strtoull (buf + 2, NULL, 10); /* just incase time_t is 64 bits */ + text = strchr (buf + 3, ' '); + if (text) + { + text = strip_color (text + 1, -1, STRIP_COLOR); + fe_print_text (sess, text, stamp); + g_free (text); + } + lines++; + } + } + + sess->scrollwritten = lines; + + if (lines) + { + text = ctime (&stamp); + text[24] = 0; /* get rid of the \n */ + snprintf (buf, sizeof (buf), "\n*\t%s %s\n\n", _("Loaded log from"), text); + fe_print_text (sess, buf, 0); + /*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/ + } +#endif + close (fh); } |