int show_buffer(struct session *ses) { char temp[STRING_SIZE]; int scroll_size, scroll_cnt, scroll_tmp, scroll_add, scroll_cut; if (ses != gtd->ses) { return TRUE; } scroll_size = get_scroll_size(ses); scroll_add = 0 - ses->scroll_base; scroll_tmp = 0; scroll_cnt = ses->scroll_line; scroll_cut = 0; /* Find the upper limit of the buffer shown */ while (TRUE) { if (ses->buffer[scroll_cnt] == NULL) { break; } scroll_tmp = str_hash_lines(ses->buffer[scroll_cnt]); if (scroll_add + scroll_tmp > scroll_size) { if (scroll_add == scroll_size) { scroll_cut = 0; } else { scroll_cut = scroll_tmp - (scroll_size - scroll_add); } break; } scroll_add += scroll_tmp; if (scroll_cnt == ses->scroll_max - 1) { scroll_cnt = 0; } else { scroll_cnt++; } } if (ses->buffer[scroll_cnt] == NULL) { erase_screen(ses); } if (IS_SPLIT(ses)) { save_pos(ses); goto_rowcol(ses, ses->bot_row, 1); SET_BIT(ses->flags, SES_FLAG_READMUD); } /* If the top line exists of multiple lines split it in the middle. */ if (ses->buffer[scroll_cnt] && scroll_cut) { if (scroll_add >= 0) { word_wrap_split(ses, ses->buffer[scroll_cnt], temp, scroll_tmp - scroll_cut, scroll_cut); printf("%s\n", temp); } else { word_wrap_split(ses, ses->buffer[scroll_cnt], temp, ses->scroll_base, scroll_size); goto eof; } } /* Print away */ while (TRUE) { if (scroll_cnt == 0) { scroll_cnt = ses->scroll_max - 1; } else { scroll_cnt--; } if (ses->buffer[scroll_cnt] == NULL) { break; } scroll_tmp = word_wrap(ses, ses->buffer[scroll_cnt], temp, FALSE); if (scroll_add - scroll_tmp < 0) { scroll_cut = scroll_add; break; } scroll_add -= scroll_tmp; printf("%s\n", temp); } /* If the bottom line exists of multiple lines split it in the middle */ if (scroll_tmp && ses->buffer[scroll_cnt]) { word_wrap_split(ses, ses->buffer[scroll_cnt], temp, 0, scroll_cut); } eof: if (IS_SPLIT(ses)) { restore_pos(ses); DEL_BIT(ses->flags, SES_FLAG_READMUD); } return TRUE; }
void readmud(struct session *ses) { char *line, *next_line; char linebuf[STRING_SIZE]; push_call("readmud(%p)", ses); if (gtd->mud_output_len < BUFFER_SIZE) { check_all_events(ses, SUB_ARG|SUB_SEC, 0, 1, "RECEIVED OUTPUT", gtd->mud_output_buf); } gtd->mud_output_len = 0; /* separate into lines and print away */ if (HAS_BIT(gtd->ses->flags, SES_FLAG_SPLIT)) { save_pos(gtd->ses); goto_rowcol(gtd->ses, gtd->ses->bot_row, 1); } SET_BIT(gtd->ses->flags, SES_FLAG_READMUD); for (line = gtd->mud_output_buf ; line && *line ; line = next_line) { next_line = strchr(line, '\n'); if (next_line) { *next_line = 0; next_line++; } else if (*line == 0) { break; } if (next_line == NULL && strlen(ses->more_output) < BUFFER_SIZE / 2) { if (!HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_PROMPT)) { if (gts->check_output) { strcat(ses->more_output, line); ses->check_output = utime() + gts->check_output; break; } } } if (ses->more_output[0]) { if (ses->check_output) { sprintf(linebuf, "%s%s", ses->more_output, line); ses->more_output[0] = 0; } else { strcpy(linebuf, line); } } else { strcpy(linebuf, line); } process_mud_output(ses, linebuf, next_line == NULL); } DEL_BIT(gtd->ses->flags, SES_FLAG_READMUD); if (HAS_BIT(gtd->ses->flags, SES_FLAG_SPLIT)) { restore_pos(gtd->ses); } pop_call(); return; }