mark.c (screen-4.8.0) | : | mark.c (screen-4.9.0) | ||
---|---|---|---|---|
skipping to change at line 48 | skipping to change at line 48 | |||
/* | /* | |||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |||
* | * | |||
* WARNING: these routines use the global variables "fore" and | * WARNING: these routines use the global variables "fore" and | |||
* "flayer" to make things easier. | * "flayer" to make things easier. | |||
* | * | |||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |||
*/ | */ | |||
static int is_letter __P((int)); | static int is_letter __P((char)); | |||
static void nextword __P((int *, int *, int, int)); | static void nextword __P((int *, int *, int, int)); | |||
static int linestart __P((int)); | static int linestart __P((int)); | |||
static int lineend __P((int)); | static int lineend __P((int)); | |||
static int rem __P((int, int , int , int , int , char *, int)); | static int rem __P((int, int, int, int, int, char *, int)); | |||
static int eq __P((int, int )); | static int eq __P((int, int)); | |||
static int MarkScrollDownDisplay __P((int)); | static int MarkScrollDownDisplay __P((int)); | |||
static int MarkScrollUpDisplay __P((int)); | static int MarkScrollUpDisplay __P((int)); | |||
static void MarkProcess __P((char **, int *)); | static void MarkProcess __P((char **, int *)); | |||
static void MarkAbort __P((void)); | static void MarkAbort __P((void)); | |||
static void MarkRedisplayLine __P((int, int, int, int)); | static void MarkRedisplayLine __P((int, int, int, int)); | |||
static int MarkRewrite __P((int, int, int, struct mchar *, int)); | static int MarkRewrite __P((int, int, int, struct mchar *, int)); | |||
extern struct layer *flayer; | extern struct layer *flayer; | |||
extern struct display *display, *displays; | extern struct display *display, *displays; | |||
extern struct win *fore; | extern struct win *fore; | |||
extern struct mline mline_blank, mline_null; | extern struct mline mline_blank, mline_null; | |||
extern struct mchar mchar_so; | extern struct mchar mchar_so; | |||
#ifdef FONT | #ifdef FONT | |||
int pastefont = 1; | int pastefont = 1; | |||
#endif | #endif | |||
struct LayFuncs MarkLf = | struct LayFuncs MarkLf = { | |||
{ | MarkProcess, | |||
MarkProcess, | MarkAbort, | |||
MarkAbort, | MarkRedisplayLine, | |||
MarkRedisplayLine, | DefClearLine, | |||
DefClearLine, | MarkRewrite, | |||
MarkRewrite, | DefResize, | |||
DefResize, | DefRestore, | |||
DefRestore, | 0 | |||
0 | ||||
}; | }; | |||
int join_with_cr = 0; | int join_with_cr = 0; | |||
int compacthist = 0; | int compacthist = 0; | |||
unsigned char mark_key_tab[256]; /* this array must be initialised first! */ | unsigned char mark_key_tab[256]; /* this array must be initialised first! */ | |||
static struct markdata *markdata; | static struct markdata *markdata; | |||
/* | /* | |||
* VI like is_letter: 0 - whitespace | * VI like is_letter: 0 - whitespace | |||
* 1 - letter | * 1 - letter | |||
* 2 - other | * 2 - other | |||
*/ | */ | |||
static int is_letter(c) | static int | |||
char c; | is_letter(char c) | |||
{ | { | |||
if ((c >= 'a' && c <= 'z') || | if ((c >= 'a' && c <= 'z') || | |||
(c >= 'A' && c <= 'Z') || | (c >= 'A' && c <= 'Z') || | |||
(c >= '0' && c <= '9') || | (c >= '0' && c <= '9') || | |||
c == '_' || c == '.' || | c == '_' || c == '.' || | |||
c == '@' || c == ':' || | c == '@' || c == ':' || | |||
c == '%' || c == '!' || | c == '%' || c == '!' || | |||
c == '-' || c == '+') | c == '-' || c == '+') | |||
/* thus we can catch email-addresses as a word :-) */ | /* thus we can catch email-addresses as a word :-) */ | |||
return 1; | return 1; | |||
else if (c != ' ') | else if (c != ' ') | |||
return 2; | return 2; | |||
return 0; | return 0; | |||
} | } | |||
static int | static int | |||
linestart(y) | linestart(int y) | |||
int y; | ||||
{ | { | |||
register int x; | register int x; | |||
register unsigned char *i; | register unsigned char *i; | |||
for (x = markdata->left_mar, i = WIN(y)->image + x; x < fore->w_width - 1; x++ | for (x = markdata->left_mar, i = WIN(y)->image + x; x < fore->w_width - 1 | |||
) | ; x++) | |||
if (*i++ != ' ') | if (*i++ != ' ') | |||
break; | break; | |||
if (x == fore->w_width - 1) | if (x == fore->w_width - 1) | |||
x = markdata->left_mar; | x = markdata->left_mar; | |||
return x; | return x; | |||
} | } | |||
static int | static int | |||
lineend(y) | lineend(int y) | |||
int y; | ||||
{ | { | |||
register int x; | register int x; | |||
register unsigned char *i; | register unsigned char *i; | |||
for (x = markdata->right_mar, i = WIN(y)->image + x; x >= 0; x--) | for (x = markdata->right_mar, i = WIN(y)->image + x; x >= 0; x--) | |||
if (*i-- != ' ') | if (*i-- != ' ') | |||
break; | break; | |||
if (x < 0) | if (x < 0) | |||
x = markdata->left_mar; | x = markdata->left_mar; | |||
return x; | return x; | |||
} | } | |||
/* | /* | |||
* nextchar sets *xp to the num-th occurrence of the target in the line. | * nextchar sets *xp to the num-th occurrence of the target in the line. | |||
* | * | |||
* Returns -1 if the target doesn't appear num times, 0 otherwise. | * Returns -1 if the target doesn't appear num times, 0 otherwise. | |||
*/ | */ | |||
static int | static int | |||
nextchar(int *xp, int *yp, int direction, char target, int num) | nextchar(int *xp, int *yp, int direction, char target, int num) | |||
{ | { | |||
int width; /* width of the current window. */ | int width; /* width of the current window. */ | |||
int x; /* x coordinate of the current cursor position. */ | int x; /* x coordinate of the current cursor position. */ | |||
int step; /* amount to increment x (+1 or -1) */ | int step; /* amount to increment x (+1 or -1) */ | |||
int adjust; /* Final adjustment of cursor position. */ | int adjust; /* Final adjustment of cursor position. */ | |||
char *displayed_line; /* Line in which search takes place. */ | char *displayed_line; /* Line in which search takes place. */ | |||
debug("nextchar\n"); | debug("nextchar\n"); | |||
x = *xp; | x = *xp; | |||
step = 1; | step = 1; | |||
adjust = 0; | adjust = 0; | |||
width = fore->w_width; | width = fore->w_width; | |||
displayed_line = (char *)WIN(*yp) -> image; | displayed_line = (char *)WIN(*yp)->image; | |||
switch(direction) { | switch (direction) { | |||
case 't': | case 't': | |||
adjust = -1; /* fall through */ | adjust = -1; /* fall through */ | |||
case 'f': | case 'f': | |||
step = 1; | step = 1; | |||
break; | break; | |||
case 'T': | case 'T': | |||
adjust = 1; /* fall through */ | adjust = 1; /* fall through */ | |||
case 'F': | case 'F': | |||
step = -1; | step = -1; | |||
break; | break; | |||
default: | default: | |||
ASSERT(0); | ASSERT(0); | |||
} | } | |||
x += step; | x += step; | |||
debug1("ml->image = %s\n", displayed_line); | debug1("ml->image = %s\n", displayed_line); | |||
debug2("num = %d, width = %d\n",num, width); | debug2("num = %d, width = %d\n", num, width); | |||
debug2("x = %d target = %c\n", x, target ); | debug2("x = %d target = %c\n", x, target); | |||
for ( ;x>=0 && x <= width; x += step) { | for (; x >= 0 && x <= width; x += step) { | |||
if (displayed_line[x] == target) { | if (displayed_line[x] == target) { | |||
if (--num == 0) { | if (--num == 0) { | |||
*xp = x + adjust; | *xp = x + adjust; | |||
return 0; | return 0; | |||
} | } | |||
} | } | |||
} | } | |||
return -1; | return -1; | |||
} | } | |||
/* | /* | |||
* nextword calculates the cursor position of the num'th word. | * nextword calculates the cursor position of the num'th word. | |||
* If the cursor is on a word, it counts as the first. | * If the cursor is on a word, it counts as the first. | |||
* NW_BACK: search backward | * NW_BACK: search backward | |||
* NW_ENDOFWORD: find the end of the word | * NW_ENDOFWORD: find the end of the word | |||
* NW_MUSTMOVE: move at least one char | * NW_MUSTMOVE: move at least one char | |||
* NW_BIG: match WORDs not words | * NW_BIG: match WORDs not words | |||
*/ | */ | |||
#define NW_BACK (1<<0) | #define NW_BACK (1<<0) | |||
#define NW_ENDOFWORD (1<<1) | #define NW_ENDOFWORD (1<<1) | |||
#define NW_MUSTMOVE (1<<2) | #define NW_MUSTMOVE (1<<2) | |||
#define NW_BIG (1<<3) | #define NW_BIG (1<<3) | |||
static void | static void | |||
nextword(xp, yp, flags, num) | nextword(int *xp, int *yp, int flags, int num) | |||
int *xp, *yp, flags, num; | ||||
{ | { | |||
int xx = fore->w_width, yy = fore->w_histheight + fore->w_height; | int xx = fore->w_width, yy = fore->w_histheight + fore->w_height; | |||
register int sx, oq, q, x, y; | register int sx, oq, q, x, y; | |||
struct mline *ml; | struct mline *ml; | |||
x = *xp; | x = *xp; | |||
y = *yp; | y = *yp; | |||
sx = (flags & NW_BACK) ? -1 : 1; | sx = (flags & NW_BACK) ? -1 : 1; | |||
if ((flags & NW_ENDOFWORD) && (flags & NW_MUSTMOVE)) | if ((flags & NW_ENDOFWORD) && (flags & NW_MUSTMOVE)) | |||
x += sx; | x += sx; | |||
ml = WIN(y); | ml = WIN(y); | |||
for (oq = -1; ; x += sx, oq = q) | for (oq = -1;; x += sx, oq = q) { | |||
{ | if (x >= xx || x < 0) | |||
if (x >= xx || x < 0) | q = 0; | |||
q = 0; | else if (flags & NW_BIG) | |||
else if (flags & NW_BIG) | q = ml->image[x] == ' '; | |||
q = ml->image[x] == ' '; | else | |||
else | q = is_letter(ml->image[x]); | |||
q = is_letter(ml->image[x]); | ||||
if (oq >= 0 && oq != q) | if (oq >= 0 && oq != q) { | |||
{ | if (oq == 0 || !(flags & NW_ENDOFWORD)) | |||
if (oq == 0 || !(flags & NW_ENDOFWORD)) | *xp = x; | |||
*xp = x; | else | |||
else | *xp = x - sx; | |||
*xp = x-sx; | *yp = y; | |||
*yp = y; | ||||
if ((!(flags & NW_ENDOFWORD) && q) || | if ((!(flags & NW_ENDOFWORD) && q) || ((flags & NW_ENDOFW | |||
((flags & NW_ENDOFWORD) && oq)) | ORD) && oq)) { | |||
{ | if (--num <= 0) | |||
if (--num <= 0) | return; | |||
return; | } | |||
} | } | |||
} | ||||
if (x == xx) | if (x == xx) { | |||
{ | x = -1; | |||
x = -1; | if (++y >= yy) | |||
if (++y >= yy) | return; | |||
return; | ml = WIN(y); | |||
ml = WIN(y); | } else if (x < 0) { | |||
} | x = xx; | |||
else if (x < 0) | if (--y < 0) | |||
{ | return; | |||
x = xx; | ml = WIN(y); | |||
if (--y < 0) | } | |||
return; | ||||
ml = WIN(y); | ||||
} | } | |||
} | ||||
} | } | |||
/* | /* | |||
* y1, y2 are WIN coordinates | * y1, y2 are WIN coordinates | |||
* | * | |||
* redisplay: 0 - just copy | * redisplay: 0 - just copy | |||
* 1 - redisplay + copy | * 1 - redisplay + copy | |||
* 2 - count + copy, don't redisplay | * 2 - count + copy, don't redisplay | |||
*/ | */ | |||
static int | static int | |||
rem(x1, y1, x2, y2, redisplay, pt, yend) | rem(int x1, int y1, int x2, int y2, int redisplay, char *pt, int yend) | |||
int x1, y1, x2, y2, redisplay, yend; | ||||
char *pt; | ||||
{ | { | |||
int i, j, from, to, ry, c; | int i, j, from, to, ry, c; | |||
int l = 0; | int l = 0; | |||
unsigned char *im; | unsigned char *im; | |||
struct mline *ml; | struct mline *ml; | |||
#ifdef FONT | #ifdef FONT | |||
int cf, cfx, font; | int cf, cfx, font; | |||
unsigned char *fo, *fox; | unsigned char *fo, *fox; | |||
#endif | #endif | |||
markdata->second = 0; | markdata->second = 0; | |||
if (y2 < y1 || ((y2 == y1) && (x2 < x1))) | if (y2 < y1 || ((y2 == y1) && (x2 < x1))) { | |||
{ | i = y2; | |||
i = y2; | y2 = y1; | |||
y2 = y1; | y1 = i; | |||
y1 = i; | i = x2; | |||
i = x2; | x2 = x1; | |||
x2 = x1; | x1 = i; | |||
x1 = i; | } | |||
} | ry = y1 - markdata->hist_offset; | |||
ry = y1 - markdata->hist_offset; | ||||
i = y1; | ||||
i = y1; | if (redisplay != 2 && pt == 0 && ry < 0) { | |||
if (redisplay != 2 && pt == 0 && ry <0) | i -= ry; | |||
{ | ry = 0; | |||
i -= ry; | } | |||
ry = 0; | for (; i <= y2; i++, ry++) { | |||
} | if (redisplay != 2 && pt == 0 && ry > yend) | |||
for (; i <= y2; i++, ry++) | break; | |||
{ | ml = WIN(i); | |||
if (redisplay != 2 && pt == 0 && ry > yend) | from = (i == y1) ? x1 : 0; | |||
break; | ||||
ml = WIN(i); | if (from < markdata->left_mar) | |||
from = (i == y1) ? x1 : 0; | from = markdata->left_mar; | |||
if (from < markdata->left_mar) | for (to = fore->w_width, im = ml->image + to; to >= 0; to--) | |||
from = markdata->left_mar; | if (*im-- != ' ') | |||
for (to = fore->w_width, im = ml->image + to; to >= 0; to--) | break; | |||
if (*im-- != ' ') | if (i == y2 && x2 < to) | |||
break; | to = x2; | |||
if (i == y2 && x2 < to) | if (to > markdata->right_mar) | |||
to = x2; | to = markdata->right_mar; | |||
if (to > markdata->right_mar) | if (redisplay == 1 && from <= to && ry >= 0 && ry <= yend) | |||
to = markdata->right_mar; | MarkRedisplayLine(ry, from, to, 0); | |||
if (redisplay == 1 && from <= to && ry >=0 && ry <= yend) | if (redisplay != 2 && pt == 0) /* don't count/copy */ | |||
MarkRedisplayLine(ry, from, to, 0); | continue; | |||
if (redisplay != 2 && pt == 0) /* don't count/copy */ | j = from; | |||
continue; | ||||
j = from; | ||||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_right(ml, j, fore->w_encoding)) | if (dw_right(ml, j, fore->w_encoding)) | |||
j--; | j--; | |||
#endif | #endif | |||
im = ml->image + j; | im = ml->image + j; | |||
#ifdef FONT | #ifdef FONT | |||
fo = ml->font + j; | fo = ml->font + j; | |||
fox = ml->fontx + j; | fox = ml->fontx + j; | |||
font = ASCII; | font = ASCII; | |||
#endif | #endif | |||
for (; j <= to; j++) | for (; j <= to; j++) { | |||
{ | c = (unsigned char)*im++; | |||
c = (unsigned char)*im++; | ||||
#ifdef FONT | #ifdef FONT | |||
cf = (unsigned char)*fo++; | cf = (unsigned char)*fo++; | |||
cfx = (unsigned char)*fox++; | cfx = (unsigned char)*fox++; | |||
# ifdef UTF8 | # ifdef UTF8 | |||
if (fore->w_encoding == UTF8) | if (fore->w_encoding == UTF8) { | |||
{ | c |= cf << 8 | cfx << 16; | |||
c |= cf << 8 | cfx << 16; | if (c == UCS_HIDDEN) | |||
if (c == UCS_HIDDEN) | continue; | |||
continue; | c = ToUtf8_comb(pt, c); | |||
c = ToUtf8_comb(pt, c); | l += c; | |||
l += c; | if (pt) | |||
if (pt) | pt += c; | |||
pt += c; | continue; | |||
continue; | } | |||
} | ||||
# endif | # endif | |||
# ifdef DW_CHARS | # ifdef DW_CHARS | |||
if (is_dw_font(cf)) | if (is_dw_font(cf)) { | |||
{ | c = c << 8 | (unsigned char)*im++; | |||
c = c << 8 | (unsigned char)*im++; | fo++; | |||
fo++; | j++; | |||
j++; | } | |||
} | ||||
# endif | # endif | |||
if (pastefont) | if (pastefont) { | |||
{ | c = EncodeChar(pt, c | cf << 16, fore->w_encoding | |||
c = EncodeChar(pt, c | cf << 16, fore->w_encoding, &font); | , &font); | |||
l += c; | l += c; | |||
if (pt) | if (pt) | |||
pt += c; | pt += c; | |||
continue; | continue; | |||
} | } | |||
#endif /* FONT */ | #endif /* FONT */ | |||
if (pt) | if (pt) | |||
*pt++ = c; | *pt++ = c; | |||
l++; | l++; | |||
} | } | |||
#ifdef FONT | #ifdef FONT | |||
if (pastefont && font != ASCII) | if (pastefont && font != ASCII) { | |||
{ | if (pt) { | |||
if (pt) | strcpy(pt, "\033(B"); | |||
{ | pt += 3; | |||
strcpy(pt, "\033(B"); | } | |||
pt += 3; | l += 3; | |||
} | } | |||
l += 3; | ||||
} | ||||
#endif | #endif | |||
if (i != y2 && (to != fore->w_width - 1 || ml->image[to + 1] == ' ')) | if (i != y2 && (to != fore->w_width - 1 || ml->image[to + 1] == ' | |||
{ | ')) { | |||
/* | /* | |||
* this code defines, what glues lines together | * this code defines, what glues lines together | |||
*/ | */ | |||
switch (markdata->nonl) | switch (markdata->nonl) { | |||
{ | case 0: /* lines separated by newlines */ | |||
case 0: /* lines separated by newlines */ | if (pt) | |||
if (pt) | *pt++ = '\r'; | |||
*pt++ = '\r'; | l++; | |||
l++; | if (join_with_cr) { | |||
if (join_with_cr) | if (pt) | |||
{ | *pt++ = '\n'; | |||
if (pt) | l++; | |||
*pt++ = '\n'; | } | |||
l++; | break; | |||
case 1: /* nothing to separate lines */ | ||||
break; | ||||
case 2: /* lines separated by blanks */ | ||||
if (pt) | ||||
*pt++ = ' '; | ||||
l++; | ||||
break; | ||||
case 3: /* seperate by comma, for csh junkies */ | ||||
if (pt) | ||||
*pt++ = ','; | ||||
l++; | ||||
break; | ||||
} | ||||
} | } | |||
break; | ||||
case 1: /* nothing to separate lines */ | ||||
break; | ||||
case 2: /* lines separated by blanks */ | ||||
if (pt) | ||||
*pt++ = ' '; | ||||
l++; | ||||
break; | ||||
case 3: /* seperate by comma, for csh junkies */ | ||||
if (pt) | ||||
*pt++ = ','; | ||||
l++; | ||||
break; | ||||
} | ||||
} | } | |||
} | return l; | |||
return l; | ||||
} | } | |||
/* Check if two chars are identical. All digits are treated | /* Check if two chars are identical. All digits are treated | |||
* as same. Used for GetHistory() | * as same. Used for GetHistory() | |||
*/ | */ | |||
static int | static int | |||
eq(a, b) | eq(int a, int b) | |||
int a, b; | ||||
{ | { | |||
if (a == b) | if (a == b) | |||
return 1; | return 1; | |||
if (a == 0 || b == 0) | if (a == 0 || b == 0) | |||
return 1; | return 1; | |||
if (a <= '9' && a >= '0' && b <= '9' && b >= '0') | if (a <= '9' && a >= '0' && b <= '9' && b >= '0') | |||
return 1; | return 1; | |||
return 0; | return 0; | |||
} | } | |||
/**********************************************************************/ | /**********************************************************************/ | |||
int | int | |||
GetHistory() /* return value 1 if copybuffer changed */ | GetHistory() /* return value 1 if copybuffer changed */ | |||
{ | { | |||
int i = 0, q = 0, xx, yy, x, y; | int i = 0, q = 0, xx, yy, x, y; | |||
unsigned char *linep; | unsigned char *linep; | |||
struct mline *ml; | struct mline *ml; | |||
ASSERT(display && fore); | ASSERT(display && fore); | |||
x = fore->w_x; | x = fore->w_x; | |||
if (x >= fore->w_width) | if (x >= fore->w_width) | |||
x = fore->w_width - 1; | x = fore->w_width - 1; | |||
y = fore->w_y + fore->w_histheight; | y = fore->w_y + fore->w_histheight; | |||
debug2("cursor is at x=%d, y=%d\n", x, y); | debug2("cursor is at x=%d, y=%d\n", x, y); | |||
ml = WIN(y); | ml = WIN(y); | |||
for (xx = x - 1, linep = ml->image + xx; xx >= 0; xx--) | for (xx = x - 1, linep = ml->image + xx; xx >= 0; xx--) | |||
if ((q = *linep--) != ' ' ) | if ((q = *linep--) != ' ') | |||
break; | break; | |||
debug3("%c at (%d,%d)\n", q, xx, y); | debug3("%c at (%d,%d)\n", q, xx, y); | |||
for (yy = y - 1; yy >= 0; yy--) | for (yy = y - 1; yy >= 0; yy--) { | |||
{ | ml = WIN(yy); | |||
ml = WIN(yy); | linep = ml->image; | |||
linep = ml->image; | if (xx < 0 || eq(linep[xx], q)) { /* line is matchi | |||
if (xx < 0 || eq(linep[xx], q)) | ng... */ | |||
{ /* line is matching... */ | for (i = fore->w_width - 1, linep += i; i >= x; i--) | |||
for (i = fore->w_width - 1, linep += i; i >= x; i--) | if (*linep-- != ' ') | |||
if (*linep-- != ' ') | break; | |||
break; | if (i >= x) | |||
if (i >= x) | break; | |||
break; | } | |||
} | } | |||
} | if (yy < 0) | |||
if (yy < 0) | return 0; | |||
return 0; | if (D_user->u_plop.buf) | |||
if (D_user->u_plop.buf) | UserFreeCopyBuffer(D_user); | |||
UserFreeCopyBuffer(D_user); | if ((D_user->u_plop.buf = (char *)malloc((unsigned)(i - x + 2))) == | |||
if ((D_user->u_plop.buf = (char *)malloc((unsigned) (i - x + 2))) == NULL) | NULL) { | |||
{ | LMsg(0, "Not enough memory... Sorry."); | |||
LMsg(0, "Not enough memory... Sorry."); | return 0; | |||
return 0; | } | |||
} | bcopy((char *)linep - i + x + 1, D_user->u_plop.buf, i - x + 1); | |||
bcopy((char *)linep - i + x + 1, D_user->u_plop.buf, i - x + 1); | D_user->u_plop.len = i - x + 1; | |||
D_user->u_plop.len = i - x + 1; | ||||
#ifdef ENCODINGS | #ifdef ENCODINGS | |||
D_user->u_plop.enc = fore->w_encoding; | D_user->u_plop.enc = fore->w_encoding; | |||
#endif | #endif | |||
return 1; | return 1; | |||
} | } | |||
/**********************************************************************/ | /**********************************************************************/ | |||
void | void | |||
MarkRoutine() | MarkRoutine() | |||
{ | { | |||
int x, y; | int x, y; | |||
ASSERT(fore && display && D_user); | ASSERT(fore && display && D_user); | |||
debug2("MarkRoutine called: fore nr %d, display %s\n", | debug2("MarkRoutine called: fore nr %d, display %s\n", fore->w_number, D_ | |||
fore->w_number, D_usertty); | usertty); | |||
if (InitOverlayPage(sizeof(*markdata), &MarkLf, 1)) | if (InitOverlayPage(sizeof(*markdata), &MarkLf, 1)) | |||
return; | return; | |||
flayer->l_encoding = fore->w_encoding; | flayer->l_encoding = fore->w_encoding; | |||
flayer->l_mode = 1; | flayer->l_mode = 1; | |||
markdata = (struct markdata *)flayer->l_data; | markdata = (struct markdata *)flayer->l_data; | |||
markdata->md_user = D_user; /* XXX: Correct? */ | markdata->md_user = D_user; /* XXX: Correct? */ | |||
markdata->md_window = fore; | markdata->md_window = fore; | |||
markdata->second = 0; | markdata->second = 0; | |||
markdata->rep_cnt = 0; | markdata->rep_cnt = 0; | |||
markdata->append_mode = 0; | markdata->append_mode = 0; | |||
markdata->write_buffer = 0; | markdata->write_buffer = 0; | |||
markdata->nonl = 0; | markdata->nonl = 0; | |||
markdata->left_mar = 0; | markdata->left_mar = 0; | |||
markdata->right_mar = fore->w_width - 1; | markdata->right_mar = fore->w_width - 1; | |||
markdata->hist_offset = fore->w_histheight; | markdata->hist_offset = fore->w_histheight; | |||
x = fore->w_x; | x = fore->w_x; | |||
y = D2W(fore->w_y); | y = D2W(fore->w_y); | |||
if (x >= fore->w_width) | if (x >= fore->w_width) | |||
x = fore->w_width - 1; | x = fore->w_width - 1; | |||
LGotoPos(flayer, x, W2D(y)); | LGotoPos(flayer, x, W2D(y)); | |||
LMsg(0, "Copy mode - Column %d Line %d(+%d) (%d,%d)", | LMsg(0, "Copy mode - Column %d Line %d(+%d) (%d,%d)", x + 1, W2D(y + 1), | |||
x + 1, W2D(y + 1), fore->w_histheight, fore->w_width, fore->w_height); | fore->w_histheight, fore->w_width, fore->w_height); | |||
markdata->cx = markdata->x1 = x; | markdata->cx = markdata->x1 = x; | |||
markdata->cy = markdata->y1 = y; | markdata->cy = markdata->y1 = y; | |||
flayer->l_x = x; | flayer->l_x = x; | |||
flayer->l_y = W2D(y); | flayer->l_y = W2D(y); | |||
} | } | |||
static void | static void | |||
MarkProcess(inbufp,inlenp) | MarkProcess(char **inbufp, int *inlenp) | |||
char **inbufp; | ||||
int *inlenp; | ||||
{ | { | |||
char *inbuf, *pt; | char *inbuf, *pt; | |||
int inlen; | int inlen; | |||
int cx, cy, x2, y2, j, yend; | int cx, cy, x2, y2, j, yend; | |||
int newcopylen = 0, od; | int newcopylen = 0, od; | |||
int in_mark; | int in_mark; | |||
int rep_cnt; | int rep_cnt; | |||
struct acluser *md_user; | struct acluser *md_user; | |||
/* | /* | |||
char *extrap = 0, extrabuf[100]; | char *extrap = 0, extrabuf[100]; | |||
*/ | */ | |||
markdata = (struct markdata *)flayer->l_data; | markdata = (struct markdata *)flayer->l_data; | |||
fore = markdata->md_window; | fore = markdata->md_window; | |||
md_user = markdata->md_user; | md_user = markdata->md_user; | |||
if (inbufp == 0) | if (inbufp == 0) { | |||
{ | MarkAbort(); | |||
MarkAbort(); | return; | |||
return; | } | |||
} | ||||
LGotoPos(flayer, markdata->cx, W2D(markdata->cy)); | ||||
LGotoPos(flayer, markdata->cx, W2D(markdata->cy)); | inbuf = *inbufp; | |||
inbuf= *inbufp; | inlen = *inlenp; | |||
inlen= *inlenp; | pt = inbuf; | |||
pt = inbuf; | in_mark = 1; | |||
in_mark = 1; | while (in_mark && (inlen /* || extrap */)) { | |||
while (in_mark && (inlen /* || extrap */)) | unsigned char ch = (unsigned char)*pt++; | |||
{ | inlen--; | |||
unsigned char ch = (unsigned char )*pt++; | if (flayer->l_mouseevent.start) { | |||
inlen--; | int r = LayProcessMouse(flayer, ch); | |||
if (flayer->l_mouseevent.start) | if (r == -1) | |||
{ | LayProcessMouseSwitch(flayer, 0); | |||
int r = LayProcessMouse(flayer, ch); | else { | |||
if (r == -1) | if (r) | |||
LayProcessMouseSwitch(flayer, 0); | ch = 0222; | |||
else | else | |||
{ | continue; | |||
if (r) | } | |||
ch = 0222; | } | |||
else | od = mark_key_tab[(int)ch]; | |||
continue; | rep_cnt = markdata->rep_cnt; | |||
} | if (od >= '0' && od <= '9' && !markdata->f_cmd.flag) { | |||
} | if (rep_cnt < 1001 && (od != '0' || rep_cnt != 0)) { | |||
od = mark_key_tab[(int)ch]; | markdata->rep_cnt = 10 * rep_cnt + od - '0'; | |||
rep_cnt = markdata->rep_cnt; | continue; | |||
if (od >= '0' && od <= '9' && !markdata->f_cmd.flag) | ||||
{ | ||||
if (rep_cnt < 1001 && (od != '0' || rep_cnt != 0)) | ||||
{ | ||||
markdata->rep_cnt = 10 * rep_cnt + od - '0'; | ||||
continue; | ||||
/* | /* | |||
* Now what is that 1001 here? Well, we have a screen with | * Now what is that 1001 here? Well, we have a screen with | |||
* 25 * 80 = 2000 characters. Movement is at most across the full | * 25 * 80 = 2000 characters. Movement is at most across the full | |||
* screen. This we do with word by word movement, as character by | * screen. This we do with word by word movement, as character by | |||
* character movement never steps over line boundaries. The most wo rds | * character movement never steps over line boundaries. The most wo rds | |||
* we can place on the screen are 1000 single letter words. Thus 10 01 | * we can place on the screen are 1000 single letter words. Thus 10 01 | |||
* is sufficient. Users with bigger screens never write in single l etter | * is sufficient. Users with bigger screens never write in single l etter | |||
* words, as they should be more advanced. jw. | * words, as they should be more advanced. jw. | |||
* Oh, wrong. We still give even the experienced user a factor of t en. | * Oh, wrong. We still give even the experienced user a factor of t en. | |||
*/ | */ | |||
} | } | |||
} | } | |||
cx = markdata->cx; | cx = markdata->cx; | |||
cy = markdata->cy; | cy = markdata->cy; | |||
if (markdata -> f_cmd.flag) { | if (markdata->f_cmd.flag) { | |||
debug2("searching for %c:%d\n",od,rep_cnt); | debug2("searching for %c:%d\n", od, rep_cnt); | |||
markdata->f_cmd.flag = 0; | markdata->f_cmd.flag = 0; | |||
markdata->rep_cnt = 0; | markdata->rep_cnt = 0; | |||
if (isgraph (od)) { | if (isgraph(od)) { | |||
markdata->f_cmd.target = od; | markdata->f_cmd.target = od; | |||
rep_cnt = (rep_cnt) ? rep_cnt : 1; | rep_cnt = (rep_cnt) ? rep_cnt : 1; | |||
nextchar(&cx, &cy, markdata->f_cmd.direction, od, rep_cnt ); | nextchar(&cx, &cy, markdata->f_cmd.direction, od, | |||
revto(cx, cy); | rep_cnt); | |||
continue; | revto(cx, cy); | |||
} | continue; | |||
} | } | |||
} | ||||
processchar: | processchar: | |||
switch (od) | switch (od) { | |||
{ | case 'f': /* fall through */ | |||
case 'f': /* fall through */ | case 'F': /* fall through */ | |||
case 'F': /* fall through */ | case 't': /* fall through */ | |||
case 't': /* fall through */ | case 'T': /* fall through */ | |||
case 'T': /* fall through */ | ||||
/* | /* | |||
* Set f_cmd to do a search on the next key stroke. | * Set f_cmd to do a search on the next key stroke. | |||
* If we break, rep_cnt will be reset, so we | * If we break, rep_cnt will be reset, so we | |||
* continue instead. It might be cleaner to | * continue instead. It might be cleaner to | |||
* store the rep_count in f_cmd and | * store the rep_count in f_cmd and | |||
* break here so later followon code will be | * break here so later followon code will be | |||
* hit. | * hit. | |||
*/ | */ | |||
markdata->f_cmd.flag = 1; | markdata->f_cmd.flag = 1; | |||
markdata->f_cmd.direction = od; | markdata->f_cmd.direction = od; | |||
debug("entering char search\n"); | debug("entering char search\n"); | |||
continue; | continue; | |||
case ';': | case ';': | |||
case ',': | case ',': | |||
if (!markdata->f_cmd.target) | if (!markdata->f_cmd.target) | |||
break; | break; | |||
if (!rep_cnt) | if (!rep_cnt) | |||
rep_cnt = 1; | rep_cnt = 1; | |||
nextchar(&cx, &cy, | nextchar(&cx, | |||
od == ';' ? markdata->f_cmd.direction : (markdata->f_cmd.direction | &cy, | |||
^ 0x20), | od == ';' ? markdata->f_cmd.direction : (markdat | |||
markdata->f_cmd.target, rep_cnt ); | a->f_cmd.direction ^ 0x20), | |||
revto(cx, cy); | markdata->f_cmd.target, | |||
break; | rep_cnt); | |||
case 'o': | revto(cx, cy); | |||
case 'x': | break; | |||
if (!markdata->second) | case 'o': | |||
break; | case 'x': | |||
markdata->cx = markdata->x1; | if (!markdata->second) | |||
markdata->cy = markdata->y1; | break; | |||
markdata->x1 = cx; | markdata->cx = markdata->x1; | |||
markdata->y1 = cy; | markdata->cy = markdata->y1; | |||
revto(markdata->cx, markdata->cy); | markdata->x1 = cx; | |||
break; | markdata->y1 = cy; | |||
case '\014': /* CTRL-L Redisplay */ | revto(markdata->cx, markdata->cy); | |||
Redisplay(0); | break; | |||
LGotoPos(flayer, cx, W2D(cy)); | case '\014': /* CTRL-L Redisplay */ | |||
break; | Redisplay(0); | |||
case 0202: /* M-C-b */ | LGotoPos(flayer, cx, W2D(cy)); | |||
case '\010': /* CTRL-H Backspace */ | break; | |||
case 'h': | case 0202: /* M-C-b */ | |||
if (rep_cnt == 0) | case '\010': /* CTRL-H Backspace */ | |||
rep_cnt = 1; | case 'h': | |||
revto(cx - rep_cnt, cy); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case 0216: /* M-C-p */ | revto(cx - rep_cnt, cy); | |||
case '\016': /* CTRL-N */ | break; | |||
case 'j': | case 0216: /* M-C-p */ | |||
if (rep_cnt == 0) | case '\016': /* CTRL-N */ | |||
rep_cnt = 1; | case 'j': | |||
revto(cx, cy + rep_cnt); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case '+': | revto(cx, cy + rep_cnt); | |||
if (rep_cnt == 0) | break; | |||
rep_cnt = 1; | case '+': | |||
j = cy + rep_cnt; | if (rep_cnt == 0) | |||
if (j > fore->w_histheight + fore->w_height - 1) | rep_cnt = 1; | |||
j = fore->w_histheight + fore->w_height - 1; | j = cy + rep_cnt; | |||
revto(linestart(j), j); | if (j > fore->w_histheight + fore->w_height - 1) | |||
break; | j = fore->w_histheight + fore->w_height - 1; | |||
case '-': | revto(linestart(j), j); | |||
if (rep_cnt == 0) | break; | |||
rep_cnt = 1; | case '-': | |||
cy -= rep_cnt; | if (rep_cnt == 0) | |||
if (cy < 0) | rep_cnt = 1; | |||
cy = 0; | cy -= rep_cnt; | |||
revto(linestart(cy), cy); | if (cy < 0) | |||
break; | cy = 0; | |||
case '^': | revto(linestart(cy), cy); | |||
revto(linestart(cy), cy); | break; | |||
break; | case '^': | |||
case '\n': | revto(linestart(cy), cy); | |||
revto(markdata->left_mar, cy + 1); | break; | |||
break; | case '\n': | |||
case 0220: /* M-C-p */ | revto(markdata->left_mar, cy + 1); | |||
case '\020': /* CTRL-P */ | break; | |||
case 'k': | case 0220: /* M-C-p */ | |||
if (rep_cnt == 0) | case '\020': /* CTRL-P */ | |||
rep_cnt = 1; | case 'k': | |||
revto(cx, cy - rep_cnt); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case 0206: /* M-C-f */ | revto(cx, cy - rep_cnt); | |||
case 'l': | break; | |||
if (rep_cnt == 0) | case 0206: /* M-C-f */ | |||
rep_cnt = 1; | case 'l': | |||
revto(cx + rep_cnt, cy); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case '\001': /* CTRL-A from tcsh/emacs */ | revto(cx + rep_cnt, cy); | |||
case '0': | break; | |||
revto(markdata->left_mar, cy); | case '\001': /* CTRL-A from tcsh/emacs */ | |||
break; | case '0': | |||
case '\004': /* CTRL-D down half screen */ | revto(markdata->left_mar, cy); | |||
if (rep_cnt == 0) | break; | |||
rep_cnt = (fore->w_height + 1) >> 1; | case '\004': /* CTRL-D down half screen */ | |||
revto_line(cx, cy + rep_cnt, W2D(cy)); | if (rep_cnt == 0) | |||
break; | rep_cnt = (fore->w_height + 1) >> 1; | |||
case '$': | revto_line(cx, cy + rep_cnt, W2D(cy)); | |||
revto(lineend(cy), cy); | break; | |||
break; | case '$': | |||
case '\022': /* CTRL-R emacs style backwards search */ | revto(lineend(cy), cy); | |||
ISearch(-1); | break; | |||
in_mark = 0; | case '\022': /* CTRL-R emacs style backwards search */ | |||
break; | ISearch(-1); | |||
case '\023': /* CTRL-S emacs style search */ | in_mark = 0; | |||
ISearch(1); | break; | |||
in_mark = 0; | case '\023': /* CTRL-S emacs style search */ | |||
break; | ISearch(1); | |||
case '\025': /* CTRL-U up half screen */ | in_mark = 0; | |||
if (rep_cnt == 0) | break; | |||
rep_cnt = (fore->w_height + 1) >> 1; | case '\025': /* CTRL-U up half screen */ | |||
revto_line(cx, cy - rep_cnt, W2D(cy)); | if (rep_cnt == 0) | |||
break; | rep_cnt = (fore->w_height + 1) >> 1; | |||
case '\007': /* CTRL-G show cursorpos */ | revto_line(cx, cy - rep_cnt, W2D(cy)); | |||
if (markdata->left_mar == 0 && markdata->right_mar == fore->w_width - 1 | break; | |||
) | case '\007': /* CTRL-G show cursorpos */ | |||
LMsg(0, "Column %d Line %d(+%d)", cx+1, W2D(cy)+1, | if (markdata->left_mar == 0 && markdata->right_mar == for | |||
markdata->hist_offset); | e->w_width - 1) | |||
else | LMsg(0, "Column %d Line %d(+%d)", cx + 1, W2D(cy) | |||
LMsg(0, "Column %d(%d..%d) Line %d(+%d)", cx+1, | + 1, markdata->hist_offset); | |||
markdata->left_mar+1, markdata->right_mar+1, W2D(cy)+1, markdata- | else | |||
>hist_offset); | LMsg(0, "Column %d(%d..%d) Line %d(+%d)", | |||
break; | cx + 1, markdata->left_mar + 1, | |||
case '\002': /* CTRL-B back one page */ | markdata->right_mar + 1, W2D(cy) + 1, | |||
if (rep_cnt == 0) | markdata->hist_offset); | |||
rep_cnt = 1; | break; | |||
rep_cnt *= fore->w_height; | case '\002': /* CTRL-B back one page */ | |||
revto(cx, cy - rep_cnt); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case '\006': /* CTRL-F forward one page */ | rep_cnt *= fore->w_height; | |||
if (rep_cnt == 0) | revto(cx, cy - rep_cnt); | |||
rep_cnt = 1; | break; | |||
rep_cnt *= fore->w_height; | case '\006': /* CTRL-F forward one page */ | |||
revto(cx, cy + rep_cnt); | if (rep_cnt == 0) | |||
break; | rep_cnt = 1; | |||
case '\005': /* CTRL-E scroll up */ | rep_cnt *= fore->w_height; | |||
if (rep_cnt == 0) | revto(cx, cy + rep_cnt); | |||
rep_cnt = 1; | break; | |||
rep_cnt = MarkScrollUpDisplay(rep_cnt); | case '\005': /* CTRL-E scroll up */ | |||
if (cy < D2W(0)) | if (rep_cnt == 0) | |||
revto(cx, D2W(0)); | rep_cnt = 1; | |||
else | rep_cnt = MarkScrollUpDisplay(rep_cnt); | |||
LGotoPos(flayer, cx, W2D(cy)); | if (cy < D2W(0)) | |||
break; | revto(cx, D2W(0)); | |||
case '\031': /* CTRL-Y scroll down */ | else | |||
if (rep_cnt == 0) | LGotoPos(flayer, cx, W2D(cy)); | |||
rep_cnt = 1; | break; | |||
rep_cnt = MarkScrollDownDisplay(rep_cnt); | case '\031': /* CTRL-Y scroll down */ | |||
if (cy > D2W(fore->w_height-1)) | if (rep_cnt == 0) | |||
revto(cx, D2W(fore->w_height-1)); | rep_cnt = 1; | |||
else | rep_cnt = MarkScrollDownDisplay(rep_cnt); | |||
LGotoPos(flayer, cx, W2D(cy)); | if (cy > D2W(fore->w_height - 1)) | |||
break; | revto(cx, D2W(fore->w_height - 1)); | |||
case '@': | else | |||
LGotoPos(flayer, cx, W2D(cy)); | ||||
break; | ||||
case '@': | ||||
/* it may be useful to have a key that does nothing */ | /* it may be useful to have a key that does nothing */ | |||
break; | break; | |||
case '%': | case '%': | |||
/* rep_cnt is a percentage for the history buffer */ | /* rep_cnt is a percentage for the history buffer */ | |||
if (rep_cnt < 0) | if (rep_cnt < 0) | |||
rep_cnt = 0; | rep_cnt = 0; | |||
if (rep_cnt > 100) | if (rep_cnt > 100) | |||
rep_cnt = 100; | rep_cnt = 100; | |||
revto_line(markdata->left_mar, | ||||
fore->w_histheight - fore->w_scrollback_height + | revto_line(markdata->left_mar, | |||
(int)(rep_cnt * (fore->w_scrollback_height + fore->w_height) | fore->w_histheight - fore->w_scrollback_height + | |||
/ 100.0), | (int)(rep_cnt * (fore->w_scrollback_height + | |||
(fore->w_height - 1) / 2); | fore->w_height) / 100.0), (fore->w_height - 1) / 2); | |||
break; | break; | |||
case 0201: | case 0201: | |||
case 'g': | case 'g': | |||
rep_cnt = 1; | rep_cnt = 1; | |||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case 0205: | case 0205: | |||
case 'G': | case 'G': | |||
/* rep_cnt is here the WIN line number */ | /* rep_cnt is here the WIN line number */ | |||
if (rep_cnt == 0) | if (rep_cnt == 0) | |||
rep_cnt = fore->w_histheight + fore->w_height; | rep_cnt = fore->w_histheight + fore->w_height; | |||
revto_line(markdata->left_mar, --rep_cnt, (fore->w_height - 1) / 2); | revto_line(markdata->left_mar, --rep_cnt, (fore->w_height | |||
break; | - 1) / 2); | |||
case 'H': | break; | |||
revto(markdata->left_mar, D2W(0)); | case 'H': | |||
break; | revto(markdata->left_mar, D2W(0)); | |||
case 'M': | break; | |||
revto(markdata->left_mar, D2W((fore->w_height - 1) / 2)); | case 'M': | |||
break; | revto(markdata->left_mar, D2W((fore->w_height - 1) / 2)); | |||
case 'L': | break; | |||
revto(markdata->left_mar, D2W(fore->w_height - 1)); | case 'L': | |||
break; | revto(markdata->left_mar, D2W(fore->w_height - 1)); | |||
case '|': | break; | |||
revto(--rep_cnt, cy); | case '|': | |||
break; | revto(--rep_cnt, cy); | |||
case 'w': | break; | |||
if (rep_cnt == 0) | case 'w': | |||
rep_cnt = 1; | if (rep_cnt == 0) | |||
nextword(&cx, &cy, NW_MUSTMOVE, rep_cnt); | rep_cnt = 1; | |||
revto(cx, cy); | nextword(&cx, &cy, NW_MUSTMOVE, rep_cnt); | |||
break; | revto(cx, cy); | |||
case 'e': | break; | |||
case 'E': | case 'e': | |||
if (rep_cnt == 0) | case 'E': | |||
rep_cnt = 1; | if (rep_cnt == 0) | |||
nextword(&cx, &cy, NW_ENDOFWORD|NW_MUSTMOVE | (od == 'E' ? NW_BIG : 0), | rep_cnt = 1; | |||
rep_cnt); | nextword(&cx, &cy, NW_ENDOFWORD|NW_MUSTMOVE | (od == 'E' | |||
revto(cx, cy); | ? NW_BIG : 0), rep_cnt); | |||
break; | revto(cx, cy); | |||
case 'b': | break; | |||
case 'B': | case 'b': | |||
if (rep_cnt == 0) | case 'B': | |||
rep_cnt = 1; | if (rep_cnt == 0) | |||
nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD|NW_MUSTMOVE | (od == 'B' ? NW_B | rep_cnt = 1; | |||
IG : 0), rep_cnt); | nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD|NW_MUSTMOVE | (od | |||
revto(cx, cy); | == 'B' ? NW_BIG : 0), rep_cnt); | |||
break; | revto(cx, cy); | |||
case 'a': | break; | |||
markdata->append_mode = 1 - markdata->append_mode; | case 'a': | |||
debug1("append mode %d--\n", markdata->append_mode); | markdata->append_mode = 1 - markdata->append_mode; | |||
LMsg(0, (markdata->append_mode) ? ":set append" : ":set noappend"); | debug1("append mode %d--\n", markdata->append_mode); | |||
break; | LMsg(0, (markdata->append_mode) ? ":set append" : ":set n | |||
case 'v': | oappend"); | |||
case 'V': | break; | |||
case 'v': | ||||
case 'V': | ||||
/* this sets start column to column 9 for VI :set nu users */ | /* this sets start column to column 9 for VI :set nu users */ | |||
if (markdata->left_mar == 8) | if (markdata->left_mar == 8) | |||
rep_cnt = 1; | rep_cnt = 1; | |||
else | else | |||
rep_cnt = 9; | rep_cnt = 9; | |||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case 'c': | case 'c': | |||
case 'C': | case 'C': | |||
/* set start column (c) and end column (C) */ | /* set start column (c) and end column (C) */ | |||
if (markdata->second) | if (markdata->second) { | |||
{ | rem(markdata->x1, markdata->y1, cx, cy, 1, (char | |||
rem(markdata->x1, markdata->y1, cx, cy, 1, (char *)0, fore->w_heigh | *)0, fore->w_height - 1); /* Hack */ | |||
t-1); /* Hack */ | markdata->second = 1; /* rem turns off second * | |||
markdata->second = 1; /* rem turns off second */ | / | |||
} | } | |||
rep_cnt--; | rep_cnt--; | |||
if (rep_cnt < 0) | if (rep_cnt < 0) | |||
rep_cnt = cx; | rep_cnt = cx; | |||
if (od != 'C') | if (od != 'C') { | |||
{ | markdata->left_mar = rep_cnt; | |||
markdata->left_mar = rep_cnt; | if (markdata->left_mar > markdata->right_mar) | |||
if (markdata->left_mar > markdata->right_mar) | markdata->left_mar = markdata->right_mar; | |||
markdata->left_mar = markdata->right_mar; | } else { | |||
} | markdata->right_mar = rep_cnt; | |||
else | if (markdata->left_mar > markdata->right_mar) | |||
{ | markdata->right_mar = markdata->left_mar; | |||
markdata->right_mar = rep_cnt; | } | |||
if (markdata->left_mar > markdata->right_mar) | if (markdata->second) { | |||
markdata->right_mar = markdata->left_mar; | markdata->cx = markdata->x1; | |||
} | markdata->cy = markdata->y1; | |||
if (markdata->second) | revto(cx, cy); | |||
{ | } | |||
markdata->cx = markdata->x1; markdata->cy = markdata->y1; | if (od == 'v' || od == 'V') | |||
revto(cx, cy); | LMsg(0, (markdata->left_mar != 8) ? ":set nonu" : | |||
} | ":set nu"); | |||
if (od == 'v' || od == 'V') | break; | |||
LMsg(0, (markdata->left_mar != 8) ? ":set nonu" : ":set nu"); | case 'J': | |||
break; | /* how do you join lines in VI ? */ | |||
case 'J': | markdata->nonl = (markdata->nonl + 1) % 4; | |||
/* how do you join lines in VI ? */ | switch (markdata->nonl) { | |||
markdata->nonl = (markdata->nonl + 1) % 4; | case 0: | |||
switch (markdata->nonl) | if (join_with_cr) | |||
{ | LMsg(0, "Multiple lines (CR/LF)"); | |||
case 0: | else | |||
if (join_with_cr) | LMsg(0, "Multiple lines (LF)"); | |||
LMsg(0, "Multiple lines (CR/LF)"); | break; | |||
else | case 1: | |||
LMsg(0, "Multiple lines (LF)"); | LMsg(0, "Lines joined"); | |||
break; | break; | |||
case 1: | case 2: | |||
LMsg(0, "Lines joined"); | LMsg(0, "Lines joined with blanks"); | |||
break; | break; | |||
case 2: | case 3: | |||
LMsg(0, "Lines joined with blanks"); | LMsg(0, "Lines joined with comma"); | |||
break; | break; | |||
case 3: | } | |||
LMsg(0, "Lines joined with comma"); | break; | |||
break; | case '/': | |||
} | Search(1); | |||
break; | in_mark = 0; | |||
case '/': | break; | |||
Search(1); | case '?': | |||
in_mark = 0; | Search(-1); | |||
break; | in_mark = 0; | |||
case '?': | break; | |||
Search(-1); | case 'n': | |||
in_mark = 0; | Search(0); | |||
break; | break; | |||
case 'n': | case 'N': | |||
Search(0); | markdata->isdir = -markdata->isdir; | |||
break; | Search(0); | |||
case 'N': | markdata->isdir = -markdata->isdir; | |||
markdata->isdir = -markdata->isdir; | break; | |||
Search(0); | case 'y': | |||
markdata->isdir = -markdata->isdir; | case 'Y': | |||
break; | if (markdata->second == 0) { | |||
case 'y': | revto(linestart(cy), cy); | |||
case 'Y': | markdata->second++; | |||
if (markdata->second == 0) | cx = markdata->x1 = markdata->cx; | |||
{ | cy = markdata->y1 = markdata->cy; | |||
revto(linestart(cy), cy); | } | |||
markdata->second++; | if (--rep_cnt > 0) | |||
cx = markdata->x1 = markdata->cx; | revto(cx, cy + rep_cnt); | |||
cy = markdata->y1 = markdata->cy; | revto(lineend(markdata->cy), markdata->cy); | |||
} | if (od == 'y') | |||
if (--rep_cnt > 0) | break; | |||
revto(cx, cy + rep_cnt); | ||||
revto(lineend(markdata->cy), markdata->cy); | ||||
if (od == 'y') | ||||
break; | ||||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case 'W': | case 'W': | |||
if (od == 'W') | if (od == 'W') { | |||
{ | if (rep_cnt == 0) | |||
if (rep_cnt == 0) | rep_cnt = 1; | |||
rep_cnt = 1; | if (!markdata->second) { | |||
if (!markdata->second) | nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD, | |||
{ | 1); | |||
nextword(&cx, &cy, NW_BACK|NW_ENDOFWORD, 1); | revto(cx, cy); | |||
revto(cx, cy); | markdata->second++; | |||
markdata->second++; | cx = markdata->x1 = markdata->cx; | |||
cx = markdata->x1 = markdata->cx; | cy = markdata->y1 = markdata->cy; | |||
cy = markdata->y1 = markdata->cy; | } | |||
} | nextword(&cx, &cy, NW_ENDOFWORD, rep_cnt); | |||
nextword(&cx, &cy, NW_ENDOFWORD, rep_cnt); | revto(cx, cy); | |||
revto(cx, cy); | } | |||
} | cx = markdata->cx; | |||
cx = markdata->cx; | cy = markdata->cy; | |||
cy = markdata->cy; | ||||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case 'A': | case 'A': | |||
if (od == 'A') | if (od == 'A') | |||
markdata->append_mode = 1; | markdata->append_mode = 1; | |||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case '>': | case '>': | |||
if (od == '>') | if (od == '>') | |||
markdata->write_buffer = 1; | markdata->write_buffer = 1; | |||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | |||
case ' ': | case ' ': | |||
case '\r': | case '\r': | |||
if (!markdata->second) | if (!markdata->second) { | |||
{ | markdata->second++; | |||
markdata->second++; | markdata->x1 = cx; | |||
markdata->x1 = cx; | markdata->y1 = cy; | |||
markdata->y1 = cy; | revto(cx, cy); | |||
revto(cx, cy); | LMsg(0, "First mark set - Column %d Line %d", cx | |||
LMsg(0, "First mark set - Column %d Line %d", cx+1, W2D(cy)+1); | + 1, W2D(cy) + 1); | |||
break; | break; | |||
} | } else { | |||
else | int append_mode = markdata->append_mode; | |||
{ | int write_buffer = markdata->write_buffer; | |||
int append_mode = markdata->append_mode; | ||||
int write_buffer = markdata->write_buffer; | x2 = cx; | |||
y2 = cy; | ||||
x2 = cx; | newcopylen = rem(markdata->x1, markdata->y1, x2, | |||
y2 = cy; | y2, 2, (char *)0, 0); /* count */ | |||
newcopylen = rem(markdata->x1, markdata->y1, x2, y2, 2, (char *)0, | if (md_user->u_plop.buf && !append_mode) | |||
0); /* count */ | UserFreeCopyBuffer(md_user); | |||
if (md_user->u_plop.buf && !append_mode) | yend = fore->w_height - 1; | |||
UserFreeCopyBuffer(md_user); | if (fore->w_histheight - markdata->hist_offset < | |||
yend = fore->w_height - 1; | fore->w_height) { | |||
if (fore->w_histheight - markdata->hist_offset < fore->w_height) | markdata->second = 0; | |||
{ | yend -= MarkScrollUpDisplay(fore->w_histh | |||
markdata->second = 0; | eight - markdata->hist_offset); | |||
yend -= MarkScrollUpDisplay(fore->w_histheight - markdata->hist | } | |||
_offset); | if (newcopylen > 0) { | |||
} | ||||
if (newcopylen > 0) | ||||
{ | ||||
/* the +3 below is for : cr + lf + \0 */ | /* the +3 below is for : cr + lf + \0 */ | |||
if (md_user->u_plop.buf) | if (md_user->u_plop.buf) | |||
md_user->u_plop.buf = realloc(md_user->u_plop.buf, | md_user->u_plop.buf = realloc(md_ | |||
(unsigned) (md_user->u_plop.len + newcopylen + 3)); | user->u_plop.buf, (unsigned)(md_user->u_plop.len + newcopylen + 3)); | |||
else | else { | |||
{ | md_user->u_plop.len = 0; | |||
md_user->u_plop.len = 0; | md_user->u_plop.buf = malloc((uns | |||
md_user->u_plop.buf = malloc((unsigned) (newcopylen + 3)); | igned)(newcopylen + 3)); | |||
} | } | |||
if (!md_user->u_plop.buf) | if (!md_user->u_plop.buf) { | |||
{ | MarkAbort(); | |||
MarkAbort(); | in_mark = 0; | |||
in_mark = 0; | LMsg(0, "Not enough memory... Sor | |||
LMsg(0, "Not enough memory... Sorry."); | ry."); | |||
md_user->u_plop.len = 0; | md_user->u_plop.len = 0; | |||
md_user->u_plop.buf = 0; | md_user->u_plop.buf = 0; | |||
break; | break; | |||
} | } | |||
if (append_mode) | if (append_mode) { | |||
{ | switch (markdata->nonl) { | |||
switch (markdata->nonl) | ||||
{ | ||||
/* | /* | |||
* this code defines, what glues lines together | * this code defines, what glues lines together | |||
*/ | */ | |||
case 0: | case 0: | |||
if (join_with_cr) | if (join_with_cr) { | |||
{ | md_user->u_plop.b | |||
md_user->u_plop.buf[md_user->u_plop.len] = '\r'; | uf[md_user->u_plop.len] = '\r'; | |||
md_user->u_plop.len++; | md_user->u_plop.l | |||
} | en++; | |||
md_user->u_plop.buf[md_user->u_plop.len] = '\n'; | } | |||
md_user->u_plop.len++; | md_user->u_plop.buf[md_us | |||
break; | er->u_plop.len] = '\n'; | |||
case 1: | md_user->u_plop.len++; | |||
break; | break; | |||
case 2: | case 1: | |||
md_user->u_plop.buf[md_user->u_plop.len] = ' '; | break; | |||
md_user->u_plop.len++; | case 2: | |||
break; | md_user->u_plop.buf[md_us | |||
case 3: | er->u_plop.len] = ' '; | |||
md_user->u_plop.buf[md_user->u_plop.len] = ','; | md_user->u_plop.len++; | |||
md_user->u_plop.len++; | break; | |||
break; | case 3: | |||
} | md_user->u_plop.buf[md_us | |||
} | er->u_plop.len] = ','; | |||
md_user->u_plop.len += rem(markdata->x1, markdata->y1, x2, y2, | md_user->u_plop.len++; | |||
markdata->hist_offset == fore->w_histheight, | break; | |||
md_user->u_plop.buf + md_user->u_plop.len, yend); | } | |||
} | ||||
md_user->u_plop.len += rem(markdata->x1, | ||||
markdata->y1, | ||||
x2, | ||||
y2, | ||||
markdata->hist | ||||
_offset == fore->w_histheight, | ||||
md_user->u_plo | ||||
p.buf + md_user->u_plop.len, | ||||
yend); | ||||
#ifdef ENCODINGS | #ifdef ENCODINGS | |||
md_user->u_plop.enc = fore->w_encoding; | md_user->u_plop.enc = fore->w_encoding; | |||
#endif | #endif | |||
} | } | |||
if (markdata->hist_offset != fore->w_histheight) | if (markdata->hist_offset != fore->w_histheight) | |||
{ | { | |||
LAY_CALL_UP(LRefreshAll(flayer, 0)); | LAY_CALL_UP(LRefreshAll(flayer, 0)); | |||
} | } | |||
ExitOverlayPage(); | ExitOverlayPage(); | |||
WindowChanged(fore, 'P'); | WindowChanged(fore, 'P'); | |||
if (append_mode) | ||||
LMsg(0, "Appended %d characters to buffer", | if (append_mode) | |||
newcopylen); | LMsg(0, "Appended %d characters to buffer | |||
else | ", newcopylen); | |||
LMsg(0, "Copied %d characters into buffer", md_user->u_plop.len); | else | |||
if (write_buffer) | LMsg(0, "Copied %d characters into buffer | |||
WriteFile(md_user, (char *)0, DUMP_EXCHANGE); | ", md_user->u_plop.len); | |||
in_mark = 0; | ||||
break; | if (write_buffer) | |||
} | WriteFile(md_user, (char *)0, DUMP_EXCHAN | |||
GE); | ||||
case 0222: | in_mark = 0; | |||
if (flayer->l_mouseevent.start) | break; | |||
{ | } | |||
int button = flayer->l_mouseevent.buffer[0]; | ||||
if (button == 'a') | ||||
{ | ||||
/* Scroll down */ | ||||
od = 'j'; | ||||
} | ||||
else if (button == '`') | ||||
{ | ||||
/* Scroll up */ | ||||
od = 'k'; | ||||
} | ||||
else if (button == ' ') | ||||
{ | ||||
/* Left click */ | ||||
cx = flayer->l_mouseevent.buffer[1]; | ||||
cy = D2W(flayer->l_mouseevent.buffer[2]); | ||||
revto(cx, cy); | ||||
od = ' '; | ||||
} | ||||
else | ||||
od = 0; | ||||
LayProcessMouseSwitch(flayer, 0); | ||||
if (od) | ||||
goto processchar; | ||||
} | ||||
else | ||||
LayProcessMouseSwitch(flayer, 1); | ||||
break; | ||||
default: | case 0222: | |||
MarkAbort(); | if (flayer->l_mouseevent.start) { | |||
LMsg(0, "Copy mode aborted"); | int button = flayer->l_mouseevent.buffer[0]; | |||
in_mark = 0; | if (button == 'a') { | |||
break; | /* Scroll down */ | |||
} | od = 'j'; | |||
if (in_mark) /* markdata may be freed */ | } else if (button == '`') { | |||
markdata->rep_cnt = 0; | /* Scroll up */ | |||
} | od = 'k'; | |||
if (in_mark) | } else if (button == ' ') { | |||
{ | /* Left click */ | |||
flayer->l_x = markdata->cx; | cx = flayer->l_mouseevent.buffer[1]; | |||
flayer->l_y = W2D(markdata->cy); | cy = D2W(flayer->l_mouseevent.buffer[2]); | |||
} | revto(cx, cy); | |||
*inbufp = pt; | od = ' '; | |||
*inlenp = inlen; | } else | |||
od = 0; | ||||
LayProcessMouseSwitch(flayer, 0); | ||||
if (od) | ||||
goto processchar; | ||||
} else | ||||
LayProcessMouseSwitch(flayer, 1); | ||||
break; | ||||
default: | ||||
MarkAbort(); | ||||
LMsg(0, "Copy mode aborted"); | ||||
in_mark = 0; | ||||
break; | ||||
} | ||||
if (in_mark) /* markdata may be freed */ | ||||
markdata->rep_cnt = 0; | ||||
} | ||||
if (in_mark) { | ||||
flayer->l_x = markdata->cx; | ||||
flayer->l_y = W2D(markdata->cy); | ||||
} | ||||
*inbufp = pt; | ||||
*inlenp = inlen; | ||||
} | } | |||
void revto(tx, ty) | void | |||
int tx, ty; | revto(int tx, int ty) | |||
{ | { | |||
revto_line(tx, ty, -1); | revto_line(tx, ty, -1); | |||
} | } | |||
/* tx, ty: WINDOW, line: DISPLAY */ | /* tx, ty: WINDOW, line: DISPLAY */ | |||
void revto_line(tx, ty, line) | void | |||
int tx, ty, line; | revto_line(int tx, int ty, int line) | |||
{ | { | |||
int fx, fy; | int fx, fy; | |||
int x, y, t, revst, reven, qq, ff, tt, st, en, ce = 0; | int x, y, t, revst, reven, qq, ff, tt, st, en, ce = 0; | |||
int ystart = 0, yend = fore->w_height-1; | int ystart = 0, yend = fore->w_height - 1; | |||
int i, ry; | int i, ry; | |||
unsigned char *wi; | unsigned char *wi; | |||
struct mline *ml; | struct mline *ml; | |||
struct mchar mc; | struct mchar mc; | |||
if (tx < 0) | if (tx < 0) | |||
tx = 0; | tx = 0; | |||
else if (tx > fore->w_width - 1) | else if (tx > fore->w_width - 1) | |||
tx = fore->w_width -1; | tx = fore->w_width - 1; | |||
if (ty < fore->w_histheight - fore->w_scrollback_height) | if (ty < fore->w_histheight - fore->w_scrollback_height) | |||
ty = fore->w_histheight - fore->w_scrollback_height; | ty = fore->w_histheight - fore->w_scrollback_height; | |||
else if (ty > fore->w_histheight + fore->w_height - 1) | else if (ty > fore->w_histheight + fore->w_height - 1) | |||
ty = fore->w_histheight + fore->w_height - 1; | ty = fore->w_histheight + fore->w_height - 1; | |||
fx = markdata->cx; fy = markdata->cy; | fx = markdata->cx; | |||
fy = markdata->cy; | ||||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
/* don't just move inside of a kanji, the user wants to see something */ | /* don't just move inside of a kanji, the user wants to see something */ | |||
ml = WIN(ty); | ml = WIN(ty); | |||
if (ty == fy && fx + 1 == tx && dw_right(ml, tx, fore->w_encoding) && tx < D_w | if (ty == fy && fx + 1 == tx && dw_right(ml, tx, fore->w_encoding) && tx | |||
idth - 1) | < D_width - 1) | |||
tx++; | tx++; | |||
if (ty == fy && fx - 1 == tx && dw_right(ml, fx, fore->w_encoding) && tx) | if (ty == fy && fx - 1 == tx && dw_right(ml, fx, fore->w_encoding) && tx) | |||
tx--; | tx--; | |||
#endif | #endif | |||
markdata->cx = tx; markdata->cy = ty; | markdata->cx = tx; | |||
markdata->cy = ty; | ||||
/* | /* | |||
* if we go to a position that is currently offscreen | * if we go to a position that is currently offscreen | |||
* then scroll the screen | * then scroll the screen | |||
*/ | */ | |||
i = 0; | i = 0; | |||
if (line >= 0 && line < fore->w_height) | ||||
i = W2D(ty) - line; | if (line >= 0 && line < fore->w_height) | |||
else if (ty < markdata->hist_offset) | i = W2D(ty) - line; | |||
i = ty - markdata->hist_offset; | else if (ty < markdata->hist_offset) | |||
else if (ty > markdata->hist_offset + (fore->w_height - 1)) | i = ty - markdata->hist_offset; | |||
i = ty - markdata->hist_offset - (fore->w_height - 1); | else if (ty > markdata->hist_offset + (fore->w_height - 1)) | |||
if (i > 0) | i = ty - markdata->hist_offset - (fore->w_height - 1); | |||
yend -= MarkScrollUpDisplay(i); | ||||
else if (i < 0) | if (i > 0) | |||
ystart += MarkScrollDownDisplay(-i); | yend -= MarkScrollUpDisplay(i); | |||
else if (i < 0) | ||||
if (markdata->second == 0) | ystart += MarkScrollDownDisplay(-i); | |||
{ | ||||
flayer->l_x = tx; | if (markdata->second == 0) { | |||
flayer->l_y = W2D(ty); | flayer->l_x = tx; | |||
LGotoPos(flayer, tx, W2D(ty)); | flayer->l_y = W2D(ty); | |||
return; | LGotoPos(flayer, tx, W2D(ty)); | |||
} | return; | |||
} | ||||
qq = markdata->x1 + markdata->y1 * fore->w_width; | ||||
ff = fx + fy * fore->w_width; /* "from" offset in WIN coords */ | qq = markdata->x1 + markdata->y1 * fore->w_width; | |||
tt = tx + ty * fore->w_width; /* "to" offset in WIN coords*/ | ff = fx + fy * fore->w_width; /* "from" offset in WIN coords */ | |||
tt = tx + ty * fore->w_width; /* "to" offset in WIN coords*/ | ||||
if (ff > tt) | ||||
{ | if (ff > tt) { | |||
st = tt; en = ff; | st = tt; | |||
x = tx; y = ty; | en = ff; | |||
} | x = tx; | |||
else | y = ty; | |||
{ | } else { | |||
st = ff; en = tt; | st = ff; | |||
x = fx; y = fy; | en = tt; | |||
} | x = fx; | |||
if (st > qq) | y = fy; | |||
{ | } | |||
st++; | ||||
x++; | if (st > qq) { | |||
} | st++; | |||
if (en < qq) | x++; | |||
en--; | ||||
if (tt > qq) | ||||
{ | ||||
revst = qq; reven = tt; | ||||
} | ||||
else | ||||
{ | ||||
revst = tt; reven = qq; | ||||
} | ||||
ry = y - markdata->hist_offset; | ||||
if (ry < ystart) | ||||
{ | ||||
y += (ystart - ry); | ||||
x = 0; | ||||
st = y * fore->w_width; | ||||
ry = ystart; | ||||
} | ||||
ml = WIN(y); | ||||
for (t = st; t <= en; t++, x++) | ||||
{ | ||||
if (x >= fore->w_width) | ||||
{ | ||||
x = 0; | ||||
y++, ry++; | ||||
ml = WIN(y); | ||||
} | ||||
if (ry > yend) | ||||
break; | ||||
if (t == st || x == 0) | ||||
{ | ||||
wi = ml->image + fore->w_width; | ||||
for (ce = fore->w_width; ce >= 0; ce--, wi--) | ||||
if (*wi != ' ') | ||||
break; | ||||
} | } | |||
if (x <= ce && x >= markdata->left_mar && x <= markdata->right_mar) | ||||
{ | if (en < qq) | |||
en--; | ||||
if (tt > qq) { | ||||
revst = qq; | ||||
reven = tt; | ||||
} else { | ||||
revst = tt; | ||||
reven = qq; | ||||
} | ||||
ry = y - markdata->hist_offset; | ||||
if (ry < ystart) { | ||||
y += (ystart - ry); | ||||
x = 0; | ||||
st = y * fore->w_width; | ||||
ry = ystart; | ||||
} | ||||
ml = WIN(y); | ||||
for (t = st; t <= en; t++, x++) { | ||||
if (x >= fore->w_width) { | ||||
x = 0; | ||||
y++, ry++; | ||||
ml = WIN(y); | ||||
} | ||||
if (ry > yend) | ||||
break; | ||||
if (t == st || x == 0) { | ||||
wi = ml->image + fore->w_width; | ||||
for (ce = fore->w_width; ce >= 0; ce--, wi--) | ||||
if (*wi != ' ') | ||||
break; | ||||
} | ||||
if (x <= ce && x >= markdata->left_mar && x <= markdata->right_ma | ||||
r) { | ||||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_right(ml, x, fore->w_encoding)) | if (dw_right(ml, x, fore->w_encoding)) { | |||
{ | if (t == revst) | |||
if (t == revst) | revst--; | |||
revst--; | t--; | |||
t--; | x--; | |||
x--; | } | |||
} | ||||
#endif | #endif | |||
if (t >= revst && t <= reven) | if (t >= revst && t <= reven) { | |||
{ | mc = mchar_so; | |||
mc = mchar_so; | ||||
#ifdef FONT | #ifdef FONT | |||
if (pastefont) | if (pastefont) { | |||
{ | mc.font = ml->font[x]; | |||
mc.font = ml->font[x]; | mc.fontx = ml->fontx[x]; | |||
mc.fontx = ml->fontx[x]; | } | |||
} | ||||
#endif | #endif | |||
mc.image = ml->image[x]; | mc.image = ml->image[x]; | |||
} | } else | |||
else | copy_mline2mchar(&mc, ml, x); | |||
copy_mline2mchar(&mc, ml, x); | ||||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_left(ml, x, fore->w_encoding)) | if (dw_left(ml, x, fore->w_encoding)) { | |||
{ | mc.mbcs = ml->image[x + 1]; | |||
mc.mbcs = ml->image[x + 1]; | LPutChar(flayer, &mc, x, W2D(y)); | |||
LPutChar(flayer, &mc, x, W2D(y)); | t++; | |||
t++; | } | |||
} | ||||
#endif | #endif | |||
LPutChar(flayer, &mc, x, W2D(y)); | LPutChar(flayer, &mc, x, W2D(y)); | |||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_left(ml, x, fore->w_encoding)) | if (dw_left(ml, x, fore->w_encoding)) | |||
x++; | x++; | |||
#endif | #endif | |||
} | ||||
} | } | |||
} | flayer->l_x = tx; | |||
flayer->l_x = tx; | flayer->l_y = W2D(ty); | |||
flayer->l_y = W2D(ty); | LGotoPos(flayer, tx, W2D(ty)); | |||
LGotoPos(flayer, tx, W2D(ty)); | ||||
} | } | |||
static void | static void | |||
MarkAbort() | MarkAbort() | |||
{ | { | |||
int yend, redisp; | int yend, redisp; | |||
debug("MarkAbort\n"); | debug("MarkAbort\n"); | |||
markdata = (struct markdata *)flayer->l_data; | markdata = (struct markdata *)flayer->l_data; | |||
fore = markdata->md_window; | fore = markdata->md_window; | |||
yend = fore->w_height - 1; | yend = fore->w_height - 1; | |||
redisp = markdata->second; | redisp = markdata->second; | |||
if (fore->w_histheight - markdata->hist_offset < fore->w_height) | if (fore->w_histheight - markdata->hist_offset < fore->w_height) { | |||
{ | markdata->second = 0; | |||
markdata->second = 0; | yend -= MarkScrollUpDisplay(fore->w_histheight - markdata->hist_o | |||
yend -= MarkScrollUpDisplay(fore->w_histheight - markdata->hist_offset); | ffset); | |||
} | } | |||
if (markdata->hist_offset != fore->w_histheight) | if (markdata->hist_offset != fore->w_histheight) { | |||
{ | LAY_CALL_UP(LRefreshAll(flayer, 0)); | |||
LAY_CALL_UP(LRefreshAll(flayer, 0)); | } else { | |||
} | rem(markdata->x1, markdata->y1, markdata->cx, markdata->cy, redis | |||
else | p, (char *)0, yend); | |||
{ | } | |||
rem(markdata->x1, markdata->y1, markdata->cx, markdata->cy, redisp, (char | ExitOverlayPage(); | |||
*)0, yend); | WindowChanged(fore, 'P'); | |||
} | ||||
ExitOverlayPage(); | ||||
WindowChanged(fore, 'P'); | ||||
} | } | |||
static void | static void | |||
MarkRedisplayLine(y, xs, xe, isblank) | MarkRedisplayLine(int y, int xs, int xe, int isblank) /* NOTE: y is in DISPLAY c | |||
int y; /* NOTE: y is in DISPLAY coords system! */ | oords system! */ | |||
int xs, xe; | ||||
int isblank; | ||||
{ | { | |||
int wy, x, i, rm; | int wy, x, i, rm; | |||
int sta, sto, cp; /* NOTE: these 3 are in WINDOW coords system */ | int sta, sto, cp; /* NOTE: these 3 are in | |||
unsigned char *wi; | WINDOW coords system */ | |||
struct mline *ml; | unsigned char *wi; | |||
struct mchar mchar_marked; | struct mline *ml; | |||
struct mchar mchar_marked; | ||||
if (y < 0) /* No special full page handling */ | ||||
return; | if (y < 0) /* No special full page handling */ | |||
return; | ||||
markdata = (struct markdata *)flayer->l_data; | ||||
fore = markdata->md_window; | markdata = (struct markdata *)flayer->l_data; | |||
fore = markdata->md_window; | ||||
mchar_marked = mchar_so; | ||||
mchar_marked = mchar_so; | ||||
wy = D2W(y); | ||||
ml = WIN(wy); | wy = D2W(y); | |||
ml = WIN(wy); | ||||
if (markdata->second == 0) | ||||
{ | if (markdata->second == 0) { | |||
if (dw_right(ml, xs, fore->w_encoding) && xs > 0) | if (dw_right(ml, xs, fore->w_encoding) && xs > 0) | |||
xs--; | xs--; | |||
if (dw_left(ml, xe, fore->w_encoding) && xe < fore->w_width - 1) | if (dw_left(ml, xe, fore->w_encoding) && xe < fore->w_width - 1) | |||
xe++; | xe++; | |||
if (xs == 0 && y > 0 && wy > 0 && WIN(wy - 1)->image[flayer->l_width] == 0 | if (xs == 0 && y > 0 && wy > 0 && WIN(wy - 1)->image[flayer->l_wi | |||
) | dth] == 0) | |||
LCDisplayLineWrap(flayer, ml, y, xs, xe, isblank); | LCDisplayLineWrap(flayer, ml, y, xs, xe, isblank); | |||
else | else | |||
LCDisplayLine(flayer, ml, y, xs, xe, isblank); | LCDisplayLine(flayer, ml, y, xs, xe, isblank); | |||
return; | return; | |||
} | } | |||
sta = markdata->y1 * fore->w_width + markdata->x1; | sta = markdata->y1 * fore->w_width + markdata->x1; | |||
sto = markdata->cy * fore->w_width + markdata->cx; | sto = markdata->cy * fore->w_width + markdata->cx; | |||
if (sta > sto) | if (sta > sto) { | |||
{ | i = sta; | |||
i=sta; sta=sto; sto=i; | sta = sto; | |||
} | sto = i; | |||
cp = wy * fore->w_width + xs; | } | |||
cp = wy * fore->w_width + xs; | ||||
rm = markdata->right_mar; | ||||
for (x = fore->w_width, wi = ml->image + fore->w_width; x >= 0; x--, wi--) | rm = markdata->right_mar; | |||
if (*wi != ' ') | for (x = fore->w_width, wi = ml->image + fore->w_width; x >= 0; x--, wi-- | |||
break; | ) | |||
if (x < rm) | if (*wi != ' ') | |||
rm = x; | break; | |||
if (x < rm) | ||||
for (x = xs; x <= xe; x++, cp++) | rm = x; | |||
if (cp >= sta && x >= markdata->left_mar) | ||||
break; | for (x = xs; x <= xe; x++, cp++) | |||
if (cp >= sta && x >= markdata->left_mar) | ||||
break; | ||||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_right(ml, x, fore->w_encoding)) | if (dw_right(ml, x, fore->w_encoding)) | |||
x--; | x--; | |||
#endif | #endif | |||
if (x > xs) | if (x > xs) | |||
LCDisplayLine(flayer, ml, y, xs, x - 1, isblank); | LCDisplayLine(flayer, ml, y, xs, x - 1, isblank); | |||
for (; x <= xe; x++, cp++) | for (; x <= xe; x++, cp++) { | |||
{ | if (cp > sto || x > rm) | |||
if (cp > sto || x > rm) | break; | |||
break; | ||||
#ifdef FONT | #ifdef FONT | |||
if (pastefont) | if (pastefont) { | |||
{ | mchar_marked.font = ml->font[x]; | |||
mchar_marked.font = ml->font[x]; | mchar_marked.fontx = ml->fontx[x]; | |||
mchar_marked.fontx = ml->fontx[x]; | } | |||
} | ||||
#endif | #endif | |||
mchar_marked.image = ml->image[x]; | mchar_marked.image = ml->image[x]; | |||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
mchar_marked.mbcs = 0; | mchar_marked.mbcs = 0; | |||
if (dw_left(ml, x, fore->w_encoding)) | if (dw_left(ml, x, fore->w_encoding)) { | |||
{ | mchar_marked.mbcs = ml->image[x + 1]; | |||
mchar_marked.mbcs = ml->image[x + 1]; | cp++; | |||
cp++; | } | |||
} | ||||
#endif | #endif | |||
LPutChar(flayer, &mchar_marked, x, y); | LPutChar(flayer, &mchar_marked, x, y); | |||
#ifdef DW_CHARS | #ifdef DW_CHARS | |||
if (dw_left(ml, x, fore->w_encoding)) | if (dw_left(ml, x, fore->w_encoding)) | |||
x++; | x++; | |||
#endif | #endif | |||
} | } | |||
if (x <= xe) | if (x <= xe) | |||
LCDisplayLine(flayer, ml, y, x, xe, isblank); | LCDisplayLine(flayer, ml, y, x, xe, isblank); | |||
} | } | |||
/* | /* | |||
* This ugly routine is to speed up GotoPos() | * This ugly routine is to speed up GotoPos() | |||
*/ | */ | |||
static int | static int | |||
MarkRewrite(ry, xs, xe, rend, doit) | MarkRewrite(int ry, int xs, int xe, struct mchar *rend, int doit) | |||
int ry, xs, xe, doit; | ||||
struct mchar *rend; | ||||
{ | { | |||
int dx, x, y, st, en, t, rm; | int dx, x, y, st, en, t, rm; | |||
unsigned char *i; | unsigned char *i; | |||
struct mline *ml; | struct mline *ml; | |||
struct mchar mchar_marked; | struct mchar mchar_marked; | |||
mchar_marked = mchar_so; | mchar_marked = mchar_so; | |||
debug3("MarkRewrite %d, %d-%d\n", ry, xs, xe); | debug3("MarkRewrite %d, %d-%d\n", ry, xs, xe); | |||
markdata = (struct markdata *)flayer->l_data; | markdata = (struct markdata *)flayer->l_data; | |||
fore = markdata->md_window; | fore = markdata->md_window; | |||
y = D2W(ry); | y = D2W(ry); | |||
ml = WIN(y); | ml = WIN(y); | |||
#ifdef UTF8 | #ifdef UTF8 | |||
if (fore->w_encoding && fore->w_encoding != UTF8 && D_encoding == UTF8 && Cont | if (fore->w_encoding && fore->w_encoding != UTF8 && D_encoding == UTF8 && | |||
ainsSpecialDeffont(ml, xs, xe, fore->w_encoding)) | ContainsSpecialDeffont(ml, xs, xe, fore->w_encoding)) | |||
return EXPENSIVE; | return EXPENSIVE; | |||
#endif | #endif | |||
dx = xe - xs + 1; | dx = xe - xs + 1; | |||
if (doit) | if (doit) { | |||
{ | i = ml->image + xs; | |||
i = ml->image + xs; | while (dx--) | |||
while (dx--) | PUTCHAR(*i++); | |||
PUTCHAR(*i++); | return 0; | |||
return 0; | } | |||
} | ||||
if (markdata->second == 0) | ||||
if (markdata->second == 0) | st = en = -1; | |||
st = en = -1; | else { | |||
else | st = markdata->y1 * fore->w_width + markdata->x1; | |||
{ | en = markdata->cy * fore->w_width + markdata->cx; | |||
st = markdata->y1 * fore->w_width + markdata->x1; | if (st > en) { | |||
en = markdata->cy * fore->w_width + markdata->cx; | t = st; | |||
if (st > en) | st = en; | |||
{ | en = t; | |||
t = st; st = en; en = t; | } | |||
} | } | |||
} | t = y * fore->w_width + xs; | |||
t = y * fore->w_width + xs; | for (rm = fore->w_width, i = ml->image + fore->w_width; rm >= 0; rm--) | |||
for (rm = fore->w_width, i = ml->image + fore->w_width; rm >= 0; rm--) | if (*i-- != ' ') | |||
if (*i-- != ' ') | break; | |||
break; | if (rm > markdata->right_mar) | |||
if (rm > markdata->right_mar) | rm = markdata->right_mar; | |||
rm = markdata->right_mar; | x = xs; | |||
x = xs; | while (dx--) { | |||
while (dx--) | if (t >= st && t <= en && x >= markdata->left_mar && x <= rm) { | |||
{ | ||||
if (t >= st && t <= en && x >= markdata->left_mar && x <= rm) | ||||
{ | ||||
#ifdef FONT | #ifdef FONT | |||
if (pastefont) | if (pastefont) { | |||
{ | mchar_marked.font = ml->font[x]; | |||
mchar_marked.font = ml->font[x]; | mchar_marked.fontx = ml->fontx[x]; | |||
mchar_marked.fontx = ml->fontx[x]; | } | |||
} | ||||
#endif | #endif | |||
rend->image = mchar_marked.image; | rend->image = mchar_marked.image; | |||
if (!cmp_mchar(rend, &mchar_marked)) | if (!cmp_mchar(rend, &mchar_marked)) | |||
return EXPENSIVE; | return EXPENSIVE; | |||
} | } else { | |||
else | rend->image = ml->image[x]; | |||
{ | if (!cmp_mchar_mline(rend, ml, x)) | |||
rend->image = ml->image[x]; | return EXPENSIVE; | |||
if (!cmp_mchar_mline(rend, ml, x)) | } | |||
return EXPENSIVE; | x++; | |||
} | } | |||
x++; | return xe - xs + 1; | |||
} | ||||
return xe - xs + 1; | ||||
} | } | |||
/* | /* | |||
* scroll the screen contents up/down. | * scroll the screen contents up/down. | |||
*/ | */ | |||
static int MarkScrollUpDisplay(n) | static int | |||
int n; | MarkScrollUpDisplay(int n) | |||
{ | { | |||
int i; | int i; | |||
debug1("MarkScrollUpDisplay(%d)\n", n); | debug1("MarkScrollUpDisplay(%d)\n", n); | |||
if (n <= 0) | if (n <= 0) | |||
return 0; | return 0; | |||
if (n > fore->w_histheight - markdata->hist_offset) | if (n > fore->w_histheight - markdata->hist_offset) | |||
n = fore->w_histheight - markdata->hist_offset; | n = fore->w_histheight - markdata->hist_offset; | |||
markdata->hist_offset += n; | ||||
i = (n < flayer->l_height) ? n : (flayer->l_height); | markdata->hist_offset += n; | |||
LScrollV(flayer, i, 0, flayer->l_height - 1, 0); | i = (n < flayer->l_height) ? n : (flayer->l_height); | |||
while (i-- > 0) | LScrollV(flayer, i, 0, flayer->l_height - 1, 0); | |||
MarkRedisplayLine(flayer->l_height - i - 1, 0, flayer->l_width - 1, 1); | while (i-- > 0) | |||
return n; | MarkRedisplayLine(flayer->l_height - i - 1, 0, flayer->l_width - | |||
1, 1); | ||||
return n; | ||||
} | } | |||
static int | static int | |||
MarkScrollDownDisplay(n) | MarkScrollDownDisplay(int n) | |||
int n; | ||||
{ | { | |||
int i; | int i; | |||
debug1("MarkScrollDownDisplay(%d)\n", n); | debug1("MarkScrollDownDisplay(%d)\n", n); | |||
if (n <= 0) | if (n <= 0) | |||
return 0; | return 0; | |||
if (n > markdata->hist_offset) | if (n > markdata->hist_offset) | |||
n = markdata->hist_offset; | n = markdata->hist_offset; | |||
markdata->hist_offset -= n; | markdata->hist_offset -= n; | |||
i = (n < flayer->l_height) ? n : (flayer->l_height); | i = (n < flayer->l_height) ? n : (flayer->l_height); | |||
LScrollV(flayer, -i, 0, fore->w_height - 1, 0); | LScrollV(flayer, -i, 0, fore->w_height - 1, 0); | |||
while (i-- > 0) | while (i-- > 0) | |||
MarkRedisplayLine(i, 0, flayer->l_width - 1, 1); | MarkRedisplayLine(i, 0, flayer->l_width - 1, 1); | |||
return n; | return n; | |||
} | } | |||
void | void | |||
MakePaster(pa, buf, len, bufiscopy) | MakePaster(struct paster *pa, char *buf, int len, int bufiscopy) | |||
struct paster *pa; | ||||
char *buf; | ||||
int len; | ||||
int bufiscopy; | ||||
{ | { | |||
FreePaster(pa); | FreePaster(pa); | |||
pa->pa_pasteptr = buf; | pa->pa_pasteptr = buf; | |||
pa->pa_pastelen = len; | pa->pa_pastelen = len; | |||
if (bufiscopy) | if (bufiscopy) | |||
pa->pa_pastebuf = buf; | pa->pa_pastebuf = buf; | |||
pa->pa_pastelayer = flayer; | pa->pa_pastelayer = flayer; | |||
DoProcess(Layer2Window(flayer), &pa->pa_pasteptr, &pa->pa_pastelen, pa); | DoProcess(Layer2Window(flayer), &pa->pa_pasteptr, &pa->pa_pastelen, pa); | |||
} | } | |||
void | void | |||
FreePaster(pa) | FreePaster(struct paster *pa) | |||
struct paster *pa; | ||||
{ | { | |||
if (pa->pa_pastebuf) | if (pa->pa_pastebuf) | |||
free(pa->pa_pastebuf); | free(pa->pa_pastebuf); | |||
pa->pa_pastebuf = 0; | pa->pa_pastebuf = 0; | |||
pa->pa_pasteptr = 0; | pa->pa_pasteptr = 0; | |||
pa->pa_pastelen = 0; | pa->pa_pastelen = 0; | |||
pa->pa_pastelayer = 0; | pa->pa_pastelayer = 0; | |||
evdeq(&pa->pa_slowev); | evdeq(&pa->pa_slowev); | |||
} | } | |||
#endif /* COPY_PASTE */ | #endif /* COPY_PASTE */ | |||
End of changes. 115 change blocks. | ||||
1244 lines changed or deleted | 1197 lines changed or added |