Esempio n. 1
0
void redraw_line() {
	static int alloc_size = 0;

	// Make sure we have enough memory for the syntax
	// highlighting
	if(line_len > alloc_size) {
		alloc_size = line_len + 256;
		syntax = realloc(syntax, alloc_size);
		memset(syntax, 127, line_len);
	}

	// TODO: flag to say no syntax check
	int i;

	for(i=0; i < line_len; i++) {
		if(i%6 == 1) {
			syntax[i] = i%7;
		}
	}

	save_pos();
	move_to(0, 0);
	show_line();
	putp(clr_eol);
	restore_pos();
}
Esempio n. 2
0
int
mm_file_io_c::truncate(int64_t pos) {
  m_cached_size = -1;

  save_pos();
  if (setFilePointer2(pos)) {
    bool result = SetEndOfFile((HANDLE)m_file);
    restore_pos();

    return result ? 0 : -1;
  }

  restore_pos();

  return -1;
}
Esempio n. 3
0
void
mm_text_io_c::detect_eol_style() {
  if (m_eol_style_detected)
    return;

  m_eol_style_detected = true;
  bool found_cr_or_nl  = false;

  save_pos();

  while (1) {
    char utf8char[9];
    size_t len = read_next_char(utf8char);
    if (0 == len)
      break;

    if ((1 == len) && ('\r' == utf8char[0])) {
      found_cr_or_nl          = true;
      m_uses_carriage_returns = true;

    } else if ((1 == len) && ('\n' == utf8char[0])) {
      found_cr_or_nl  = true;
      m_uses_newlines = true;

    } else if (found_cr_or_nl)
      break;
  }

  restore_pos();
}
Esempio n. 4
0
int64_t
mm_io_c::get_size() {
  if (-1 == m_cached_size) {
    save_pos();
    setFilePointer(0, seek_end);
    m_cached_size = getFilePointer();
    restore_pos();
  }

  return m_cached_size;
}
Esempio n. 5
0
token analyzer::get_token()
{
    refresh();
    drop_garbage();

    if( peek_char() == EOF )
        return token("END_OF_FILE","") ;

    int first_pos = comp_f_stream.tellg();
    string value = "" ;

    while( true ){
        int c = read_char();
        value.push_back(c);

        if( current_state->is_valid_transition(c) ){
            current_state = current_state->next_state(c);
            if( current_state->is_acceptance_state() ){
                last_acceptance = current_state ;
                acceptace_pos = comp_f_stream.tellg();
            }
        }
        else{//dead end
            if( last_acceptance != NULL ){
                int len = comp_f_stream.tellg()-acceptace_pos ;
                for(int i = 0 ; i < len ; ++i){
                    value.pop_back();
                }
                restore_pos();
                return token(last_acceptance->name,value);
            }
            else{//error checking
                //return fix_error(token("BAD_TOKEN",value));
                return token("BAD_TOKEN",value);
            }
        }
    }
}
Esempio n. 6
0
void redraw_line(lua_State *L) {
	static int alloc_size = 0;

	// Make sure we have enough memory for the syntax
	// highlighting
	if(line_len > alloc_size) {
		alloc_size = line_len + 256;
		syntax = realloc(syntax, alloc_size);
		memset(syntax, 127, line_len);
	}

	// Get the function onto the stack...
	lua_rawgeti(L, LUA_REGISTRYINDEX, function_index);
	lua_pushstring(L, line);
	lua_pushlightuserdata(L, (void *)syntax);
	lua_call(L, 2, 1);

	// Show the line...
	save_pos();
	move_to(0, 0);
	show_line();
	putp(clr_eol);
	restore_pos();
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
void do_one_prompt(struct session *ses, char *prompt, int row)
{
	char temp[BUFFER_SIZE];
	int original_row, len;

	if (ses != gtd->ses)
	{
		return;
	}

	original_row = row;

	if (row < 0)
	{
		row = -1 * row;
	}
	else
	{
		row = ses->rows - row;
	}

	if (row < 1 || row > ses->rows)
	{
		show_message(ses, LIST_PROMPT, "#ERROR: PROMPT ROW IS OUTSIDE THE SCREEN: {%s} {%d}.", prompt, original_row);

		return;
	}

	if (row > ses->top_row && row < ses->bot_row)
	{
		show_message(ses, LIST_PROMPT, "#ERROR: PROMPT ROW IS INSIDE THE SCROLLING REGION: {%s} {%d}.", prompt, original_row);

		return;
	}

	len = strip_vt102_strlen(ses, prompt);

	if (len == 0)
	{
		sprintf(temp, "%.*s", ses->cols + 4, "\033[0m----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
	}
	else if (len <= ses->cols)
	{
		sprintf(temp, "%s", prompt);
	}
	else
	{
		show_debug(ses, LIST_PROMPT, "#DEBUG PROMPT {%s}", prompt);

		sprintf(temp, "#PROMPT SIZE (%d) LONGER THAN ROW SIZE (%d)", len, ses->cols);
	}

	if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
	{
		save_pos(ses);
	}

	if (row == ses->rows)
	{
		gtd->input_off = len + 1;

		printf("\033[%d;1H\033[%d;1H\033[K%s%s\033[%d;%dH\0337\033[%d;1H", row, row, temp, gtd->input_buf, row, gtd->input_off + gtd->input_cur, ses->bot_row);
	}
	else
	{
		// goto row, erase to eol, print prompt, goto bot_row

		printf("\033[%d;1H\033[%d;1H\033[K%s\033[%d;1H", row, row, temp, ses->bot_row);
	}

	if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
	{
		restore_pos(ses);
	}
}
Esempio n. 9
0
File: net.c Progetto: SlySven/tintin
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;
}