Пример #1
0
static void line_move( int up, int n )
{
    static int lastcol;

    int ndot;
    int col = 1;
    int lim = bf_cur->num_characters() + 1;

    if( n == 0 )
        return;

    if( n < 0 )
    {
        n = -n;
        up = ! up;
    }
    if( up )
        n = -n - 1;

    if( last_proc != next_line
    && last_proc != previous_line )
    lastcol = (track_eol != 0 && dot < lim && bf_cur->char_at (dot) == '\n') ? 9999 : cur_col();

    ndot = scan_bf_for_lf( dot, n );
    while( col < lastcol && ndot < lim )
    {
        n = bf_cur->char_at( ndot );
        if( n == '\n' )
            break;
        if( n == '\t' )
            col = ((col - 1) / bf_cur->b_mode.md_tabsize + 1) * bf_cur->b_mode.md_tabsize + 1;
        else
            if( control_character( n ) )
                col += ctl_arrow != 0 ?
                        (term_deccrt != 0
                        && (n == ctl('k')
                        || n == ctl('l')
                        || n == '\r'
                        || n == '\033') ) ?
                            1
                        :
                            2
                    :
                        4;
            else
                col++;

        ndot++;
    }

    set_dot( ndot );
    dot_col = col;
    col_valid = 1;
}
Пример #2
0
int self_insert( EmacsChar_t c )
{
    int p;
    int repeat_count = arg;

    arg = 1;

    if( input_mode == 1 ) gui_input_mode_before_insert();

    if( bf_cur->b_mode.md_abbrevon && ! bf_cur->char_is( c, SYNTAX_WORD )
    && (p = dot - 1) >= bf_cur->first_character()
    && bf_cur->char_at_is( p, SYNTAX_WORD ) )
        if( abbrev_expand () != 0 )
            return 0;

    do
    {
        if( c > ' '
        && ((p = dot) > bf_cur->num_characters() || bf_cur->char_at (p) == '\n') )
            if( p > bf_cur->first_character() && cur_col() > bf_cur->b_mode.md_rightmargin )
            {
                EmacsChar_t bfc;

                if( bf_cur->b_mode.md_auto_fill_proc != 0 )
                  {
                    bf_cur->b_mode.md_auto_fill_proc->execute();
                    if( ml_value.exp_type() ==  ISINTEGER
                    && ml_value.asInt() == 0 )
                        return 0;
                }
                else
                {
                    while( (p = dot - 1) >= bf_cur->first_character())
                    {
                        bfc = bf_cur->char_at( p );
                        if( bfc == '\n' )
                        {
                            p = 0;
                            break;
                        }
                        if( !control_character( bfc ) )
                        {
                            dot_col--;
                            dot--;
                        }
                        else
                            dot_left (1);

                        if( (bfc == ' ' || bfc == '\t')
                        && cur_col() <= bf_cur->b_mode.md_rightmargin )
                            break;
                    }
                    if( p >= bf_cur->first_character() )
                    {
                        delete_white_space ();
                        arg = 1;
                        bf_cur->insert_at( dot, '\n' );
                        dot_right (1);
                        to_col (bf_cur->b_mode.md_leftmargin);
                        if( bf_cur->b_mode.md_prefixstring.isNull() )
                            bf_cur->ins_cstr( bf_cur->b_mode.md_prefixstring );
                    }
                    end_of_line ();
                }
            }
        if( bf_cur->b_mode.md_replace
        &&  bf_cur->char_at( dot ) !=  '\n'
        && c != '\n' )
        {
            bf_cur->del_frwd( dot, 1 );
            bf_cur->insert_at( dot, c );
            if( bf_cur->b_modified == 0 )
             {
                redo_modes = 1;
                cant_1line_opt = 1;
            }
            bf_cur->b_modified++;
        }
        else
            bf_cur->insert_at( dot, c );

        dot_right (1);
    }
    while( (repeat_count = repeat_count - 1) > 0 );

    return 0;
}
Пример #3
0
Tree* build_tree_from_expression(std::string str)
{
	int i = 0;
	std::stack<stack_item*> treeStack;
	int paren_depth = 0;
	int bracket_depth = 0;
	int brace_depth = 0;
	while (i < str.length())
	{
		switch (str[i])
		{
			case '\\':
			{
				i++;
				assert(i < str.length());
				if (str[i] - '0' >= 0 && str[i] - '0' <= 9)
				{
					treeStack.push(new stack_item(FUNC, str[i]));
				}
				else {
					treeStack.push(new stack_item(NODE, control_character(str[i])));
				}
				break;
			}
			case '(':
			{
				paren_depth++;
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case ')':
			{
				assert(paren_depth > 0);
				collapse_stack_strings(&treeStack);
				evaluate_stack_paren(&treeStack);
				paren_depth--;
				break;
			}
			case '[':
			{
				bracket_depth++;
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case ']':
			{
				assert(bracket_depth > 0);
				evaluate_stack_brackets(&treeStack);
				collapse_stack_strings(&treeStack);
				bracket_depth--;
				break;
			}
			case '{':
			{
				brace_depth++;
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '}':
			{
				assert(brace_depth > 0);
				evaluate_stack_braces(&treeStack);
				collapse_stack_strings(&treeStack);
				brace_depth--;
				break;
			}
			case '^':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '$':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '.':
			{
				treeStack.push(new stack_item(FUNC, '['));
				treeStack.push(new stack_item(NODE, (char)MIN_CHAR));
				treeStack.push(new stack_item(FUNC, '-'));
				treeStack.push(new stack_item(NODE, (char)MAX_CHAR));
				evaluate_stack_brackets(&treeStack);
				collapse_stack_strings(&treeStack);
				//treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '*':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '+':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '?':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '|':
			{
				treeStack.push(new stack_item(FUNC, str[i]));
				break;
			}
			case '-':
			{
				if (bracket_depth > 0)
					treeStack.push(new stack_item(FUNC, str[i]));
				else
					treeStack.push(new stack_item(NODE, str[i]));
				break;
			}
			default:
			{
				if (brace_depth > 0)
				{
					treeStack.push(new stack_item(FUNC, str[i]));
					assert(str[i] == ',' || (str[i] - '0' >= 0 && str[i] - '0' <= 9));
				}else
					treeStack.push(new stack_item(NODE, str[i]));
				break;
			}
		}
		i++;
	}
	collapse_stack_strings(&treeStack);
	evaluate_stack(&treeStack);
	return new Tree(treeStack.top()->node);
}