unsigned char *p = selspace; unsigned long *q = selstart;  while (q < selend) { int nl = FALSE; unsigned long *lineend = q - (q-text) % (cols+1) + cols; unsigned long *nlpos = lineend;  if (!(*nlpos & ATTR_WRAPPED)) { while ((nlpos[-1] & CHAR_MASK) == 0x20 && nlpos > q) nlpos--; if (nlpos < selend) nl = TRUE; } while (q < nlpos && q < selend) { #if 0  static const char poorman2[] = "* # HTFFCRLF\xB0 \xB1 NLVT+ + + + + - - - - - + + + + | <=>=PI!=\xA3 \xB7 "; #endif  int ch = (*q & CHAR_MASK);  #if 0 if ((*q & ATTR_LINEDRW) && ch >= 0x60 && ch < 0x7F) { int x; *p++ = poorman2[2*(ch-0x60)]; if ( (x = poorman2[2*(ch-0x60)+1]) != ' ') *p++ = x; } else #endif #if 0 if ((*q & ATTR_GBCHR) && ch == '#') *p++ = (unsigned char) 0xA3; else #endif *p++ = (unsigned char) ch; q++; } if (nl) { int i; for (i=0; i<sizeof(sel_nl); i++) *p++ = sel_nl[i]; } q = lineend + 1;        } write_clip (selspace, p - selspace, FALSE);
clipme(selstart, selend, selspace);
void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {    unsigned long *selpoint;        if (y<0) y = 0;    if (y>=rows) y = rows-1;    if (x<0) {        if (y > 0) {            x = cols-1;            y--;        } else            x = 0;    }    if (x>=cols) x = cols-1;    selpoint = disptop + y * (cols+1);    if ((selpoint[cols]&LATTR_MODE) != LATTR_NORM)	selpoint += x/2;    else	selpoint += x;    if (b == MB_SELECT && a == MA_CLICK) {	deselect();	selstate = ABOUT_TO;	selanchor = selpoint;	selmode = SM_CHAR;    } else if (b == MB_SELECT && (a == MA_2CLK || a == MA_3CLK)) {	deselect();	selmode = (a == MA_2CLK ? SM_WORD : SM_LINE);	selstate = DRAGGING;	selstart = selanchor = selpoint;	selend = selstart + 1;	sel_spread();    } else if ((b == MB_SELECT && a == MA_DRAG) ||	       (b == MB_EXTEND && a != MA_RELEASE)) {	if (selstate == ABOUT_TO && selanchor == selpoint)	    return;	if (b == MB_EXTEND && a != MA_DRAG && selstate == SELECTED) {	    if (selpoint-selstart < (selend-selstart)/2)		selanchor = selend - 1;	    else		selanchor = selstart;	    selstate = DRAGGING;	}	if (selstate != ABOUT_TO && selstate != DRAGGING)	    selanchor = selpoint;	selstate = DRAGGING;	if (selpoint < selanchor) {	    selstart = selpoint;	    selend = selanchor + 1;	} else {	    selstart = selanchor;	    selend = selpoint + 1;	}	sel_spread();    } else if ((b == MB_SELECT || b == MB_EXTEND) && a == MA_RELEASE) {	if (selstate == DRAGGING) {	    /*	     * We've completed a selection. We now transfer the	     * data to the clipboard.	     */	    unsigned char *p = selspace;	    unsigned long *q = selstart;	    while (q < selend) {		int nl = FALSE;		unsigned long *lineend = q - (q-text) % (cols+1) + cols;		unsigned long *nlpos = lineend;		if (!(*nlpos & ATTR_WRAPPED)) {		    while ((nlpos[-1] & CHAR_MASK) == 0x20 && nlpos > q)			nlpos--;		    if (nlpos < selend)			nl = TRUE;		}		while (q < nlpos && q < selend)		{#if 0		    /* VT Specials -> ISO8859-1  */		    static const char poorman2[] = "* # HTFFCRLF\xB0 \xB1 NLVT+ + + + + - - - - - + + + + | <=>=PI!=\xA3 \xB7 ";#endif		    int ch = (*q & CHAR_MASK);#if 0		    if ((*q & ATTR_LINEDRW) && ch >= 0x60 && ch < 0x7F) {			int x;			*p++ = poorman2[2*(ch-0x60)];			if ( (x = poorman2[2*(ch-0x60)+1]) != ' ')			    *p++ = x;		    } else#endif#if 0		    if ((*q & ATTR_GBCHR) && ch == '#')			*p++ = (unsigned char) 0xA3;		    else#endif			*p++ = (unsigned char) ch;		    q++;		}		if (nl) {		    int i;		    for (i=0; i<sizeof(sel_nl); i++)			*p++ = sel_nl[i];		}		q = lineend + 1;       /* start of next line */	    }	    write_clip (selspace, p - selspace, FALSE);	    selstate = SELECTED;	} else	    selstate = NO_SELECTION;    } else if (b == MB_PASTE && (a==MA_CLICK || a==MA_2CLK || a==MA_3CLK)) {	char *data;	int len;	get_clip((void **) &data, &len);	if (data) {	    char *p, *q;	    if (paste_buffer) sfree(paste_buffer);	    paste_pos = paste_hold = paste_len = 0;	    paste_buffer = smalloc(len);	    p = q = data;	    while (p < data+len) {		while (p < data+len &&		       !(p <= data+len-sizeof(sel_nl) &&			 !memcmp(p, sel_nl, sizeof(sel_nl))))		    p++;		{		    int i;		    unsigned char c;		    for(i=0;i<p-q;i++)		    {			c=xlat_kbd2tty(q[i]);			paste_buffer[paste_len++] = c;		    }		}		if (p <= data+len-sizeof(sel_nl) &&		    !memcmp(p, sel_nl, sizeof(sel_nl))) {		    paste_buffer[paste_len++] = '\r';		    p += sizeof(sel_nl);		}		q = p;	    }	    /* Assume a small paste will be OK in one go. */	    if (paste_len<256) {	        ldisc->send (paste_buffer, paste_len);	        if (paste_buffer) sfree(paste_buffer);		paste_buffer = 0;	        paste_pos = paste_hold = paste_len = 0;	    }	}	get_clip(NULL, NULL);    }    term_update();}