void scrollback_load (session *sess) { int fh; char buf[512 * 4]; char *text; time_t stamp; int lines; #ifdef WIN32 #if 0 char *cleaned_text; int cleaned_len; #endif #else char *map, *end_map; struct stat statbuf; const char *begin, *eol; #endif if (sess->text_scrollback == SET_DEFAULT) { if (!prefs.text_replay) return; } else { if (sess->text_scrollback != SET_ON) return; } if (scrollback_get_filename (sess, buf, sizeof (buf)) == NULL) return; fh = open (buf, O_RDONLY | OFLAGS); if (fh == -1) return; #ifndef WIN32 if (fstat (fh, &statbuf) < 0) return; map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fh, 0); if (map == MAP_FAILED) return; end_map = map + statbuf.st_size; lines = 0; begin = map; while (begin < end_map) { int n_bytes; eol = memchr (begin, '\n', end_map - begin); if (!eol) 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) 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) { if (prefs.text_stripcolor_replay) { text = strip_color (text + 1, -1, STRIP_COLOR); } fe_print_text (sess, text, stamp); if (prefs.text_stripcolor_replay) { g_free (text); } } lines++; } begin = eol + 1; } 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);*/ } 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) { if (prefs.text_stripcolor_replay) { text = strip_color (text + 1, -1, STRIP_COLOR); } #if 0 cleaned_text = text_replace_non_bmp (text, -1, &cleaned_len); if (cleaned_text != NULL) { if (prefs.text_stripcolor_replay) { g_free (text); } text = cleaned_text; } #endif text_replace_non_bmp2 (text); fe_print_text (sess, text, stamp); if (prefs.text_stripcolor_replay) { 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); }
void scrollback_load (session *sess) { char *buf; char *text; time_t stamp; int lines; GIOChannel *io; GError *file_error = NULL; GError *io_err = NULL; if (sess->text_scrollback == SET_DEFAULT) { if (!prefs.hex_text_replay) return; } else { if (sess->text_scrollback != SET_ON) return; } if ((buf = scrollback_get_filename (sess)) == NULL) return; io = g_io_channel_new_file (buf, "r", &file_error); g_free (buf); if (!io) return; lines = 0; while (1) { gsize n_bytes; GIOStatus io_status; io_status = g_io_channel_read_line (io, &buf, &n_bytes, NULL, &io_err); if (io_status == G_IO_STATUS_NORMAL) { char *buf_tmp; n_bytes--; buf_tmp = buf; buf = g_strndup (buf_tmp, n_bytes); g_free (buf_tmp); if (buf[0] == 'T') { if (sizeof (time_t) == 4) stamp = strtoul (buf + 2, NULL, 10); else stamp = strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */ text = strchr (buf + 3, ' '); if (text) { if (prefs.hex_text_stripcolor_replay) { text = strip_color (text + 1, -1, STRIP_COLOR); } #ifdef WIN32 #if 0 cleaned_text = text_replace_non_bmp (text, -1, &cleaned_len); if (cleaned_text != NULL) { if (prefs.hex_text_stripcolor_replay) { g_free (text); } text = cleaned_text; } #endif text_replace_non_bmp2 (text); #endif fe_print_text (sess, text, stamp); if (prefs.hex_text_stripcolor_replay) { g_free (text); } } lines++; } g_free (buf); } else break; } g_io_channel_unref (io); sess->scrollwritten = lines; if (lines) { text = ctime (&stamp); text[24] = 0; /* get rid of the \n */ buf = g_strdup_printf ("\n*\t%s %s\n\n", _("Loaded log from"), text); fe_print_text (sess, buf, 0); g_free (buf); /*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/ } }