void add_line_buffer(struct session *ses, char *line, int more_output) { char linebuf[STRING_SIZE]; char *pti, *pto; int lines; int sav_row, sav_col, cur_row, cur_col, top_row, bot_row; push_call("add_line_buffer(%p,%s,%d)", ses, line, more_output); if (ses->buffer == NULL || HAS_BIT(ses->flags, SES_FLAG_SCROLLSTOP)) { pop_call(); return; } sav_row = ses->sav_row; sav_col = ses->sav_col; cur_row = ses->cur_row; cur_col = ses->cur_col; top_row = ses->top_row; bot_row = ses->bot_row; if (more_output == TRUE) { if (strlen(ses->more_output) < BUFFER_SIZE / 2) { strcat(ses->more_output, line); pop_call(); return; } } strcat(ses->more_output, line); pti = pto = ses->more_output; while (*pti != 0) { while (skip_vt102_codes_non_graph(pti)) { interpret_vt102_codes(ses, pti, FALSE); pti += skip_vt102_codes_non_graph(pti); } if (*pti == 0) { break; } if (SCROLL(ses)) { *pto++ = *pti++; } else { pti++; } } *pto = 0; lines = word_wrap(ses, ses->more_output, linebuf, FALSE); ses->more_output[0] = 0; ses->buffer[ses->scroll_row] = str_hash(linebuf, lines); if (more_output == -1) { str_hash_grep(ses->buffer[ses->scroll_row], TRUE); } if (!HAS_BIT(ses->flags, SES_FLAG_LOGLEVEL)) { if (ses->logfile) { logit(ses, linebuf, ses->logfile, TRUE); } } if (gtd->chat) { chat_forward_session(ses, linebuf); } if (--ses->scroll_row < 0) { ses->scroll_row = ses->scroll_max - 1; } if (ses->buffer[ses->scroll_row]) { ses->buffer[ses->scroll_row] = str_unhash(ses->buffer[ses->scroll_row]); } ses->sav_row = sav_row; ses->sav_col = sav_col; ses->cur_row = cur_row; ses->cur_col = cur_col; ses->top_row = top_row; ses->bot_row = bot_row; pop_call(); return; }
int word_wrap(struct session *ses, char *textin, char *textout, int display) { char *pti, *pto, *lis, *los, *chi, *cho; int skip = 0, cnt = 0; push_call("word_wrap(%s,%p,%p)",ses->name, textin,textout); pti = chi = lis = textin; pto = cho = los = textout; ses->cur_col = 1; while (*pti != 0) { if (skip_vt102_codes(pti)) { if (display) { interpret_vt102_codes(ses, pti, TRUE); } for (skip = skip_vt102_codes(pti) ; skip > 0 ; skip--) { *pto++ = *pti++; } continue; } if (*pti == '\n') { *pto++ = *pti++; cnt = cnt + 1; los = pto; lis = pti; ses->cur_col = 1; continue; } if (*pti == ' ') { los = pto; lis = pti; } if (ses->cur_col > ses->cols) { cnt++; ses->cur_col = 1; if (HAS_BIT(ses->flags, SES_FLAG_WORDWRAP)) { if (pto - los > 15 || !SCROLL(ses)) { *pto++ = '\n'; los = pto; lis = pti; } else if (lis != chi) // infinite VT loop detection { pto = los; *pto++ = '\n'; pti = chi = lis; pti++; } else if (los != cho) { pto = cho = los; pto++; pti = chi = lis; pti++; } } } else { if (HAS_BIT(ses->flags, SES_FLAG_BIG5) && *pti & 128 && pti[1] != 0) { *pto++ = *pti++; *pto++ = *pti++; } else if (HAS_BIT(ses->flags, SES_FLAG_UTF8) && (*pti & 192) == 192) { *pto++ = *pti++; while ((*pti & 192) == 128) { *pto++ = *pti++; } } else { *pto++ = *pti++; } ses->cur_col++; } } *pto = 0; pop_call(); return (cnt + 1); }