コード例 #1
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_move_left (mcview_t * view, off_t columns)
{
    if (view->hex_mode)
    {
        off_t old_cursor = view->hex_cursor;
#ifdef HAVE_ASSERT_H
        assert (columns == 1);
#endif
        if (view->hexview_in_text || !view->hexedit_lownibble)
        {
            if (view->hex_cursor > 0)
                view->hex_cursor--;
        }
        if (!view->hexview_in_text)
            if (old_cursor > 0 || view->hexedit_lownibble)
                view->hexedit_lownibble = !view->hexedit_lownibble;
    }
    else
    {
        if (view->dpy_text_column >= columns)
            view->dpy_text_column -= columns;
        else
            view->dpy_text_column = 0;
    }
    mcview_movement_fixups (view, FALSE);
}
コード例 #2
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_move_right (WView * view, off_t columns)
{
    if (view->mode_flags.hex)
    {
        off_t last_byte;
        off_t old_cursor = view->hex_cursor;

        last_byte = mcview_offset_doz (mcview_get_filesize (view), 1);

        g_assert (columns == 1);

        if (view->hexview_in_text || view->hexedit_lownibble)
        {
            if (view->hex_cursor < last_byte)
                view->hex_cursor++;
        }
        if (!view->hexview_in_text)
            if (old_cursor < last_byte || !view->hexedit_lownibble)
                view->hexedit_lownibble = !view->hexedit_lownibble;
    }
    else if (!view->mode_flags.wrap)
    {
        view->dpy_text_column += columns;
    }
    mcview_movement_fixups (view, FALSE);
}
コード例 #3
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_move_down (WView * view, off_t lines)
{
    off_t last_byte;

    last_byte = mcview_get_filesize (view);

    if (view->mode_flags.hex)
    {
        off_t i, limit;

        limit = mcview_offset_doz (last_byte, (off_t) view->bytes_per_line);

        for (i = 0; i < lines && view->hex_cursor < limit; i++)
        {
            view->hex_cursor += view->bytes_per_line;
            if (lines != 1)
            {
                view->dpy_start += view->bytes_per_line;
                view->dpy_paragraph_skip_lines = 0;
                view->dpy_wrap_dirty = TRUE;
            }
        }
    }
    else
    {
        mcview_ascii_move_down (view, lines);
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #4
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_moveto_bottom (mcview_t * view)
{
    off_t filesize;

    mcview_update_filesize (view);

    if (view->growbuf_in_use)
        mcview_growbuf_read_until (view, OFFSETTYPE_MAX);

    filesize = mcview_get_filesize (view);

    if (view->hex_mode)
    {
        view->hex_cursor = mcview_offset_doz (filesize, 1);
        mcview_movement_fixups (view, TRUE);
    }
    else
    {
        const off_t datalines = view->data_area.height;

        view->dpy_start = filesize;
        mcview_move_up (view, datalines);
    }
}
コード例 #5
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_moveto_eol (WView * view)
{
    off_t bol;

    if (view->mode_flags.hex)
    {
        off_t filesize;

        bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line);
        if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE)
        {
            view->hex_cursor = bol + view->bytes_per_line - 1;
        }
        else
        {
            filesize = mcview_get_filesize (view);
            view->hex_cursor = mcview_offset_doz (filesize, 1);
        }
    }
    else
    {
        mcview_ascii_moveto_eol (view);
    }
    mcview_movement_fixups (view, FALSE);
}
コード例 #6
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_move_right (mcview_t * view, off_t columns)
{
    if (view->hex_mode)
    {
        off_t last_byte;
        off_t old_cursor = view->hex_cursor;
        last_byte = mcview_offset_doz (mcview_get_filesize (view), 1);
#ifdef HAVE_ASSERT_H
        assert (columns == 1);
#endif
        if (view->hexview_in_text || view->hexedit_lownibble)
        {
            if (view->hex_cursor < last_byte)
                view->hex_cursor++;
        }
        if (!view->hexview_in_text)
            if (old_cursor < last_byte || !view->hexedit_lownibble)
                view->hexedit_lownibble = !view->hexedit_lownibble;
    }
    else
    {
        view->dpy_text_column += columns;
    }
    mcview_movement_fixups (view, FALSE);
}
コード例 #7
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_moveto_bottom (WView * view)
{
    off_t filesize;

    mcview_update_filesize (view);

    if (view->growbuf_in_use)
        mcview_growbuf_read_all_data (view);

    filesize = mcview_get_filesize (view);

    if (view->mode_flags.hex)
    {
        view->hex_cursor = mcview_offset_doz (filesize, 1);
        mcview_movement_fixups (view, TRUE);
    }
    else
    {
        const off_t datalines = view->data_area.height;

        view->dpy_start = filesize;
        view->dpy_paragraph_skip_lines = 0;
        view->dpy_wrap_dirty = TRUE;
        mcview_move_up (view, datalines);
    }
}
コード例 #8
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_move_up (WView * view, off_t lines)
{
    if (view->mode_flags.hex)
    {
        off_t bytes = lines * view->bytes_per_line;

        if (view->hex_cursor >= bytes)
        {
            view->hex_cursor -= bytes;
            if (view->hex_cursor < view->dpy_start)
            {
                view->dpy_start = mcview_offset_doz (view->dpy_start, bytes);
                view->dpy_paragraph_skip_lines = 0;
                view->dpy_wrap_dirty = TRUE;
            }
        }
        else
        {
            view->hex_cursor %= view->bytes_per_line;
        }
    }
    else
    {
        mcview_ascii_move_up (view, lines);
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #9
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_moveto_top (mcview_t * view)
{
    view->dpy_start = 0;
    view->hex_cursor = 0;
    view->dpy_text_column = 0;
    mcview_movement_fixups (view, TRUE);
}
コード例 #10
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_moveto_eol (mcview_t * view)
{
    off_t bol;
    if (view->hex_mode)
    {
        off_t filesize;

        bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line);
        if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE)
        {
            view->hex_cursor = bol + view->bytes_per_line - 1;
        }
        else
        {
            filesize = mcview_get_filesize (view);
            view->hex_cursor = mcview_offset_doz (filesize, 1);
        }
    }
    else
    {
        off_t eol;
        bol = mcview_bol (view, view->dpy_start, 0);
        eol = mcview_eol (view, view->dpy_start, mcview_get_filesize (view));
        if (!view->utf8)
        {
            if (eol > bol)
                view->dpy_text_column = eol - bol;
        }
        else
        {
            char *str = NULL;
            switch (view->datasource)
            {
            case DS_STDIO_PIPE:
            case DS_VFS_PIPE:
                str = mcview_get_ptr_growing_buffer (view, bol);
                break;
            case DS_FILE:
                str = mcview_get_ptr_file (view, bol);
                break;
            case DS_STRING:
                str = mcview_get_ptr_string (view, bol);
                break;
            case DS_NONE:
                break;
            }
            if (str != NULL && eol > bol)
                view->dpy_text_column = g_utf8_strlen (str, eol - bol);
            else
                view->dpy_text_column = eol - bol;
        }
        view->dpy_text_column = max (0, view->dpy_text_column - view->data_area.width);
    }
    mcview_movement_fixups (view, FALSE);
}
コード例 #11
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_moveto_top (WView * view)
{
    view->dpy_start = 0;
    view->dpy_paragraph_skip_lines = 0;
    mcview_state_machine_init (&view->dpy_state_top, 0);
    view->hex_cursor = 0;
    view->dpy_text_column = 0;
    mcview_movement_fixups (view, TRUE);
}
コード例 #12
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_moveto_bol (WView * view)
{
    if (view->mode_flags.hex)
    {
        view->hex_cursor -= view->hex_cursor % view->bytes_per_line;
        view->dpy_text_column = 0;
    }
    else
    {
        mcview_ascii_moveto_bol (view);
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #13
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_moveto_offset (mcview_t * view, off_t offset)
{
    if (view->hex_mode)
    {
        view->hex_cursor = offset;
        view->dpy_start = offset - offset % view->bytes_per_line;
    }
    else
    {
        view->dpy_start = offset;
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #14
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_moveto_bol (mcview_t * view)
{
    if (view->hex_mode)
    {
        view->hex_cursor -= view->hex_cursor % view->bytes_per_line;
    }
    else if (!view->text_wrap_mode)
    {
        view->dpy_start = mcview_bol (view, view->dpy_start, 0);
    }
    view->dpy_text_column = 0;
    mcview_movement_fixups (view, TRUE);
}
コード例 #15
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_moveto_offset (WView * view, off_t offset)
{
    if (view->mode_flags.hex)
    {
        view->hex_cursor = offset;
        view->dpy_start = offset - offset % view->bytes_per_line;
        view->dpy_paragraph_skip_lines = 0;
        view->dpy_wrap_dirty = TRUE;
    }
    else
    {
        view->dpy_start = offset;
        view->dpy_paragraph_skip_lines = 0;
        view->dpy_wrap_dirty = TRUE;
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #16
0
ファイル: move.c プロジェクト: MidnightCommander/mc
void
mcview_move_left (WView * view, off_t columns)
{
    if (view->mode_flags.hex)
    {
        off_t old_cursor = view->hex_cursor;

        g_assert (columns == 1);

        if (view->hexview_in_text || !view->hexedit_lownibble)
        {
            if (view->hex_cursor > 0)
                view->hex_cursor--;
        }
        if (!view->hexview_in_text)
            if (old_cursor > 0 || view->hexedit_lownibble)
                view->hexedit_lownibble = !view->hexedit_lownibble;
    }
    else if (!view->mode_flags.wrap)
        view->dpy_text_column = mcview_offset_doz (view->dpy_text_column, columns);
    mcview_movement_fixups (view, FALSE);
}
コード例 #17
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_move_down (mcview_t * view, off_t lines)
{
    off_t last_byte;
    last_byte = mcview_get_filesize (view);
    if (view->hex_mode)
    {
        off_t i, limit;

        if (last_byte >= (off_t) view->bytes_per_line)
            limit = last_byte - view->bytes_per_line;
        else
            limit = 0;
        for (i = 0; i < lines && view->hex_cursor < limit; i++)
        {
            view->hex_cursor += view->bytes_per_line;
            if (lines != 1)
                view->dpy_start += view->bytes_per_line;
        }
    }
    else
    {
        off_t new_offset = 0;

        if (view->dpy_end - view->dpy_start > last_byte - view->dpy_end)
        {
            while (lines-- > 0)
            {
                if (view->text_wrap_mode)
                    view->dpy_end =
                        mcview_eol (view, view->dpy_end,
                                    view->dpy_end + (off_t) view->data_area.width);
                else
                    view->dpy_end = mcview_eol (view, view->dpy_end, last_byte);

                if (view->text_wrap_mode)
                    new_offset =
                        mcview_eol (view, view->dpy_start,
                                    view->dpy_start + (off_t) view->data_area.width);
                else
                    new_offset = mcview_eol (view, view->dpy_start, last_byte);
                if (new_offset < last_byte)
                    view->dpy_start = new_offset;
                if (view->dpy_end >= last_byte)
                    break;
            }
        }
        else
        {
            off_t i;
            for (i = 0; i < lines && new_offset < last_byte; i++)
            {
                if (view->text_wrap_mode)
                    new_offset =
                        mcview_eol (view, view->dpy_start,
                                    view->dpy_start + (off_t) view->data_area.width);
                else
                    new_offset = mcview_eol (view, view->dpy_start, last_byte);
                if (new_offset < last_byte)
                    view->dpy_start = new_offset;
            }
        }
    }
    mcview_movement_fixups (view, TRUE);
}
コード例 #18
0
ファイル: move.c プロジェクト: ryanlee/mc
void
mcview_move_up (mcview_t * view, off_t lines)
{
    off_t new_offset;

    if (view->hex_mode)
    {
        off_t bytes = lines * view->bytes_per_line;
        if (view->hex_cursor >= bytes)
        {
            view->hex_cursor -= bytes;
            if (view->hex_cursor < view->dpy_start)
                view->dpy_start = mcview_offset_doz (view->dpy_start, bytes);
        }
        else
        {
            view->hex_cursor %= view->bytes_per_line;
        }
    }
    else
    {
        off_t i;

        for (i = 0; i < lines; i++)
        {
            if (view->dpy_start == 0)
                break;
            if (view->text_wrap_mode)
            {
                new_offset = mcview_bol (view, view->dpy_start, view->dpy_start - (off_t) 1);
                /* check if dpy_start == BOL or not (then new_offset = dpy_start - 1,
                 * no need to check more) */
                if (new_offset == view->dpy_start)
                {
                    size_t last_row_length;

                    new_offset = mcview_bol (view, new_offset - 1, 0);
                    last_row_length = (view->dpy_start - new_offset) % view->data_area.width;
                    if (last_row_length != 0)
                    {
                        /* if dpy_start == BOL in wrapped mode, find BOL of previous line
                         * and move down all but the last rows */
                        new_offset = view->dpy_start - (off_t) last_row_length;
                    }
                }
                else
                {
                    /* if dpy_start != BOL in wrapped mode, just move one row up;
                     * no need to check if > 0 as there is at least exactly one wrap
                     * between dpy_start and BOL */
                    new_offset = view->dpy_start - (off_t) view->data_area.width;
                }
                view->dpy_start = new_offset;
            }
            else
            {
                /* if unwrapped -> current BOL equals dpy_start, just find BOL of previous line */
                new_offset = view->dpy_start - 1;
                view->dpy_start = mcview_bol (view, new_offset, 0);
            }
        }
    }
    mcview_movement_fixups (view, TRUE);
}