diff options
author | liljencrantz <liljencrantz@gmail.com> | 2007-09-22 00:05:49 +1000 |
---|---|---|
committer | liljencrantz <liljencrantz@gmail.com> | 2007-09-22 00:05:49 +1000 |
commit | d2d397d9eb8ec9c4003d1ce45b26a7cc133e801f (patch) | |
tree | 61b8a13756c5f4978a79b5cb364f6b49d0edffea /parse_util.c | |
parent | 607e97065958640f09dbe5de103bae0fd7c350c5 (diff) |
Make up/down cursor move up or down when in multiline mode, except if already in search mode or at the top/bottom line. Since part of this is done in script-space, this involves adding some functionality to the commandline builtin.
darcs-hash:20070921140549-75c98-ba9e83f5e6fdecae5df8f83dd863794c6af9770c.gz
Diffstat (limited to 'parse_util.c')
-rw-r--r-- | parse_util.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/parse_util.c b/parse_util.c index 7a767ba0..8635bc4d 100644 --- a/parse_util.c +++ b/parse_util.c @@ -135,6 +135,97 @@ int parse_util_lineno( const wchar_t *str, int len ) return res; } + +int parse_util_get_line_from_offset( wchar_t *buff, int pos ) +{ + // return parse_util_lineno( buff, pos ); + + int i; + int count = 0; + if( pos < 0 ) + { + return -1; + } + + for( i=0; i<pos; i++ ) + { + if( !buff[i] ) + { + return -1; + } + + if( buff[i] == L'\n' ) + { + count++; + } + } + return count; +} + + +int parse_util_get_offset_from_line( wchar_t *buff, int line ) +{ + int i; + int count = 0; + + if( line < 0 ) + { + return -1; + } + + if( line == 0 ) + return 0; + + for( i=0;; i++ ) + { + if( !buff[i] ) + { + return -1; + } + + if( buff[i] == L'\n' ) + { + count++; + if( count == line ) + { + return i+1; + } + + } + } +} + +int parse_util_get_offset( wchar_t *buff, int line, int line_offset ) +{ + int off = parse_util_get_offset_from_line( buff, line ); + int off2 = parse_util_get_offset_from_line( buff, line+1 ); + int line_offset2 = line_offset; + + if( off < 0 ) + { + return -1; + } + + if( off2 < 0 ) + { + off2 = wcslen( buff ); + } + + if( line_offset2 < 0 ) + { + line_offset2 = 0; + } + + if( line_offset2 >= off2-off-1 ) + { + line_offset2 = off2-off-1; + } + + return off + line_offset2; + +} + + int parse_util_locate_cmdsubst( const wchar_t *in, wchar_t **begin, wchar_t **end, |