Exemple #1
0
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;
}
Exemple #2
0
int cursor_auto_tab_add(int input_now, int stop_after_first) {
  char tab[BUFFER_SIZE], buf[BUFFER_SIZE];
  int scroll_cnt, line_cnt, tab_len;
  char *arg;

  line_cnt = 0;

  scroll_cnt = gtd->ses->scroll_row;

  do {
    if (scroll_cnt == gtd->ses->scroll_max - 1) {
      scroll_cnt = 0;
    } else {
      scroll_cnt++;
    }

    if (gtd->ses->buffer[scroll_cnt] == NULL) {
      break;
    }

    if (str_hash_grep(gtd->ses->buffer[scroll_cnt], FALSE)) {
      continue;
    }

    if (line_cnt++ >= gtd->ses->auto_tab) {
      break;
    }

    strip_vt102_codes(gtd->ses->buffer[scroll_cnt], buf);

    arg = buf;

    while (*arg) {
      arg = get_arg_stop_spaces(gtd->ses, arg, tab, 0);

      if (!strncmp(tab, &gtd->input_buf[input_now], strlen(&gtd->input_buf[input_now]))) {
        tab_len = strlen(tab) - 1;

        if (tab_len > 0) {
          if (tab[tab_len] == '.' || tab[tab_len] == ',') {
            tab[tab_len] = 0;
          }
        }

        if (search_node_list(gtd->ses->list[LIST_TABCYCLE], tab)) {
          continue;
        }
        insert_node_list(gtd->ses->list[LIST_TABCYCLE], tab, "", "");

        if (stop_after_first) {
          return TRUE;
        }
      }

      if (*arg == COMMAND_SEPARATOR) {
        arg++;
      }

    }
  }
  while (scroll_cnt != gtd->ses->scroll_row);

  return FALSE;
}