Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 42667
Collapse All | Expand All

(-)gpm-1.20.1_orig/src/gpm.c (-1 / +188 lines)
Lines 21-26 Link Here
21
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22
 ********/
22
 ********/
23
23
24
/*
25
 * Xwindow Copy&Paste patch
26
 * (c) 2004 Alex Efros <powerman-asdf@yandex.ru>
27
 */
28
24
#include <stdio.h>
29
#include <stdio.h>
25
#include <stdlib.h>
30
#include <stdlib.h>
26
#include <string.h>        /* strerror(); ?!?  */
31
#include <string.h>        /* strerror(); ?!?  */
Lines 39-50 Link Here
39
44
40
#include <linux/vt.h>      /* VT_GETSTATE */
45
#include <linux/vt.h>      /* VT_GETSTATE */
41
#include <linux/serial.h>  /* for serial console check */
46
#include <linux/serial.h>  /* for serial console check */
42
#include <sys/kd.h>        /* KDGETMODE */
47
#include <sys/kd.h>        /* KDGETMODE */ /* XCaP: E_TABSZ GIO_SCRNMAP */
43
#include <termios.h>       /* winsize */
48
#include <termios.h>       /* winsize */
44
49
45
#include "headers/gpmInt.h"
50
#include "headers/gpmInt.h"
46
#include "headers/message.h"
51
#include "headers/message.h"
47
52
53
/* XCaP start */
54
#include <ctype.h>             /* isspace()    */
55
#include "headers/xcap.h"
56
/* XCaP end */
57
48
/* who the f*** runs gpm without glibc? doesn't have dietlibc __socklent_t? */
58
/* who the f*** runs gpm without glibc? doesn't have dietlibc __socklent_t? */
49
#if !defined(__GLIBC__)
59
#if !defined(__GLIBC__)
50
   typedef unsigned int __socklen_t;
60
   typedef unsigned int __socklen_t;
Lines 198-203 Link Here
198
}
208
}
199
209
200
/*-------------------------------------------------------------------*/
210
/*-------------------------------------------------------------------*/
211
212
/* XCaP start */
213
/* inword() from /usr/src/linux-2.4.19/drivers/char/selection.c */
214
static inline int inword(const unsigned char c) {
215
    return ( inwordLut[c>>5] >> (c & 0x1F) ) & 1;
216
}
217
/* atedge() from /usr/src/linux-2.4.19/drivers/char/selection.c */
218
static inline int atedge(const int p, int size_row)
219
{
220
    /* p+2 changed to p+1 because kernel operate with screen address */
221
    return (!(p % size_row) || !((p + 1) % size_row));
222
}
223
/* XCaP end */
224
201
static inline void selection_copy(int x1, int y1, int x2, int y2, int mode)
225
static inline void selection_copy(int x1, int y1, int x2, int y2, int mode)
202
{
226
{
203
/*
227
/*
Lines 208-213 Link Here
208
   unsigned short *arg = (unsigned short *)buf + 1;
232
   unsigned short *arg = (unsigned short *)buf + 1;
209
   int fd;
233
   int fd;
210
234
235
    /* XCaP start */
236
    int i, j;		    /* loop variables */
237
    FILE *co_fptr;	    /* file with current console image */
238
    char scr[SCR_SIZE];	    /* current console image */
239
    int scr_lth;	    /* current console image size */
240
    char scrmap[E_TABSZ];   /* current screen map for inverse translation */
241
    int p1, p2;		    /* cursor top/left and bottom/right position */
242
    int n1, n2;		    /* selection top/left and bottom/right position */
243
    int tmp;		    /* temp integer */
244
    char *bp, *obp;	    /* temp pointers to fill sel_buffer */
245
246
    /* read data from the console */
247
    if( ((co_fptr=fopen("/dev/vcs0","r"))==NULL) && /* usual /dev/ */
248
	((co_fptr=fopen("/dev/vcc/0","r"))==NULL) ) /* devfs /dev/ */
249
	    gpm_report(GPM_PR_OOPS, "open /dev/vcs0 or /dev/vcc/0");
250
    scr_lth = fread(&scr, sizeof(char), SCR_SIZE-1, co_fptr);
251
    fclose(co_fptr);
252
    scr[scr_lth] = 0;
253
    /* unmap font translation */
254
    /* ... is it possible to use kernel's inverse_translate() here? */
255
    if ((fd=open_console(O_RDONLY))<0)
256
	gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN_CON);
257
    if (ioctl(fd,GIO_SCRNMAP,&scrmap))
258
	gpm_report(GPM_PR_OOPS,"GIO_SCRNMAP");
259
    close(fd);
260
    for (j=0; j<scr_lth; j++) {
261
	for (i=0; i<E_TABSZ; i++)
262
	    if ((unsigned char) scrmap[i] == (unsigned char) scr[j])
263
		break;
264
	scr[j] = (char) i;
265
    }
266
    /* calc start-position and how many bytes to copy */
267
    if (y1>y2) { tmp=y1; y1=y2; y2=tmp; tmp=x1; x1=x2; x2=tmp; }
268
    if (y1==y2 && x1>x2) { tmp=x1; x1=x2; x2=tmp; }
269
    p1 = (y1-1)*win.ws_col+x1-1;
270
    p2 = (y2-1)*win.ws_col+x2-1;
271
    n1 = 0;
272
    n2 = 0;
273
    /* selection logic from /usr/src/linux-2.4.19/drivers/char/selection.c */
274
    if (mode==0) { /* character-by-character selection */
275
	n1=p1;
276
	n2=p2;
277
    }
278
    if (mode==1) { /* word-by-word selection */
279
	tmp = isspace(scr[p1]);
280
	for (n1 = p1; ; p1--) {
281
	    if ((tmp && !isspace(scr[p1])) || (!tmp && !inword(scr[p1])))
282
		break;
283
	    n1 = p1;
284
	    if (!(p1 % win.ws_col))
285
		break;
286
	}
287
	tmp = isspace(scr[p2]);
288
	for (n2 = p2; ; p2++) {
289
	    if ((tmp && !isspace(scr[p2])) || (!tmp && !inword(scr[p2])))
290
		break;
291
	    n2 = p2;
292
	    if (!((p2+1) % win.ws_col))
293
		break;
294
	}
295
    }
296
    if (mode==2) { /* line-by-line selection */
297
	n1 = p1 - p1 % win.ws_col;
298
	n2 = p2 + win.ws_col - p2 % win.ws_col - 1;
299
    }
300
    /* select to end of line if on trailing space */
301
    if (n2 > n1 && !atedge(n2, win.ws_col) && isspace(scr[n2])) {
302
	for (p2 = n2+1; ; p2++)
303
	    if (!isspace(scr[p2]) || atedge(p2, win.ws_col))
304
		break;
305
	if (isspace(scr[p2]))
306
	    n2 = p2;
307
    }
308
    /* save selection to sel_buffer */
309
    if (mode<3) {
310
	/* is the buffer big enough? */
311
	if(((n2-n1+1)>=sel_buffer_lth) && ((n2-n1+1)>=SCR_SIZE)) {
312
	    free(sel_buffer);
313
	    sel_buffer=malloc((n2-n1+1)+1);
314
	}
315
	/* save selection, replacĂ… trailing spaces to \n in each line */
316
	bp = sel_buffer;
317
	obp= sel_buffer;
318
	for (i = n1; i <= n2; i++ ) {
319
	    *bp = scr[i];
320
	    if (!isspace(*bp++))
321
		obp = bp;
322
	    if (! ((i+1) % win.ws_col)) {
323
		if (obp != bp) {
324
		    bp = obp;
325
		    *bp++ = '\n';
326
		}
327
		obp = bp;
328
	    }
329
	}
330
	sel_buffer_lth = bp - sel_buffer;
331
	*(sel_buffer+sel_buffer_lth) = 0;
332
    }
333
    /* XCaP end */
334
211
   buf[sizeof(short)-1] = 2;  /* set selection */
335
   buf[sizeof(short)-1] = 2;  /* set selection */
212
336
213
   arg[0]=(unsigned short)x1;
337
   arg[0]=(unsigned short)x1;
Lines 239-244 Link Here
239
   char c=3;
363
   char c=3;
240
   int fd;
364
   int fd;
241
365
366
    /* XCaP start */
367
    int i;
368
    struct stat X0;
369
    FILE *xcb;
370
    /* XCaP start */
371
    
242
   if (!opt_aged && (0 != opt_age_limit) &&
372
   if (!opt_aged && (0 != opt_age_limit) &&
243
      (last_selection_time + opt_age_limit < time(0))) {
373
      (last_selection_time + opt_age_limit < time(0))) {
244
      opt_aged = 1;
374
      opt_aged = 1;
Lines 249-268 Link Here
249
      return;
379
      return;
250
   } 
380
   } 
251
381
382
    /* XCaP start */
383
    /* check Xwindow: if Xwindow not active - xcb freeze for 6 sec :( */
384
    if (stat("/tmp/.X11-unix/X0", &X0) != -1) {
385
	if (!(xcb=popen("/usr/bin/xcb -d :0 -p 0", "r")))
386
	    gpm_report(GPM_PR_OOPS,"open pipe");
387
	/* read Xwindow clipboard into current selection */
388
	if ((i = fread(sel_buffer, sizeof(char), SCR_SIZE-1, xcb)) > 0)
389
	    *(sel_buffer+(sel_buffer_lth=i)) = 0;
390
	if (!WIFEXITED(pclose(xcb)))
391
	    gpm_report(GPM_PR_OOPS,"close pipe");
392
    }
393
    fd=open_console(O_WRONLY);
394
    for(i=0; i<sel_buffer_lth; i++)
395
	if (ioctl(fd,TIOCSTI,&sel_buffer[i]) < 0)
396
	    gpm_report(GPM_PR_OOPS,"TIOCSTI");
397
    close(fd);
398
    return;		/* never paste from kernel buffer */
399
    /* XCaP end */
400
401
/* XCaP replaced this:
402
252
   fd=open_console(O_WRONLY);
403
   fd=open_console(O_WRONLY);
253
   if(ioctl(fd, TIOCLINUX, &c) < 0)
404
   if(ioctl(fd, TIOCLINUX, &c) < 0)
254
      gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX);
405
      gpm_report(GPM_PR_OOPS,GPM_MESS_IOCTL_TIOCLINUX);
255
   close(fd);
406
   close(fd);
407
408
 */
409
 
256
}
410
}
257
411
258
/*-------------------------------------------------------------------*/
412
/*-------------------------------------------------------------------*/
259
static  inline int do_selection(Gpm_Event *event)  /* returns 0, always */
413
static  inline int do_selection(Gpm_Event *event)  /* returns 0, always */
260
{
414
{
261
   static int x1=1, y1=1, x2, y2;
415
   static int x1=1, y1=1, x2, y2;
416
   
417
    /* XCaP start */
418
    struct stat X0;
419
    FILE *xcb;
420
    /* XCaP end */
421
    
262
#define UNPOINTER() 0
422
#define UNPOINTER() 0
263
423
264
   x2=event->x; y2=event->y;
424
   x2=event->x; y2=event->y;
265
   switch(GPM_BARE_EVENTS(event->type)) {
425
   switch(GPM_BARE_EVENTS(event->type)) {
426
       
427
    /* XCaP start */
428
    case GPM_UP:
429
	if(event->buttons==GPM_B_LEFT) {
430
	    /* check Xwindow: if Xwindow not active - xcb freeze for 6 sec :( */
431
	    if (stat("/tmp/.X11-unix/X0", &X0) != -1) {
432
		if (!(xcb=popen("/usr/bin/xcb -d :0 -s 0", "w")))
433
		    gpm_report(GPM_PR_OOPS,"open pipe");
434
		/* send currect selection to Xwindow clipboard */
435
		fwrite(sel_buffer, sizeof(char), sel_buffer_lth, xcb);
436
		if (!WIFEXITED(pclose(xcb)))
437
		    gpm_report(GPM_PR_OOPS,"close pipe");
438
	    }
439
	    /*resize sel_buffer back to "normal" size*/
440
	    if(sel_buffer_lth>SCR_SIZE) {
441
		free(sel_buffer);
442
		sel_buffer=malloc(SCR_SIZE);
443
		sel_buffer_lth=SCR_SIZE;
444
	    }
445
	}
446
    /* XCaP end */
447
266
      case GPM_MOVE:
448
      case GPM_MOVE:
267
         if (x2<1) x2++; else if (x2>maxx) x2--;
449
         if (x2<1) x2++; else if (x2>maxx) x2--;
268
         if (y2<1) y2++; else if (y2>maxy) y2--;
450
         if (y2<1) y2++; else if (y2>maxy) y2--;
Lines 966-971 Link Here
966
      maxfd=max(fd, maxfd);
1148
      maxfd=max(fd, maxfd);
967
   }
1149
   }
968
1150
1151
    /* XCaP start */
1152
    sel_buffer=malloc(SCR_SIZE);
1153
    sel_buffer_lth=SCR_SIZE;
1154
    /* XCaP end */
1155
969
/*....................................... catch interesting signals */
1156
/*....................................... catch interesting signals */
970
1157
971
   signal(SIGTERM, gpm_killed);
1158
   signal(SIGTERM, gpm_killed);
(-)gpm-1.20.1_orig/src/gpn.c (-3 / +17 lines)
Lines 24-29 Link Here
24
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25
 ********/
25
 ********/
26
26
27
/*
28
 * Xwindow Copy&Paste patch
29
 * (c) 2004 Alex Efros <powerman-asdf@yandex.ru>
30
 */
31
27
#include <stdio.h>
32
#include <stdio.h>
28
#include <stdlib.h>
33
#include <stdlib.h>
29
#include <string.h>        /* strerror(); ?!? memcpy() */
34
#include <string.h>        /* strerror(); ?!? memcpy() */
Lines 56-61 Link Here
56
#include "headers/gpmInt.h"
61
#include "headers/gpmInt.h"
57
#include "headers/gpm.h"
62
#include "headers/gpm.h"
58
63
64
#include "headers/xcap.h"
65
59
extern int errno;
66
extern int errno;
60
67
61
/*===================================================================*/
68
/*===================================================================*/
Lines 102-108 Link Here
102
   };
109
   };
103
110
104
111
105
#define inwordLut (long_array+1)
112
//#define inwordLut (long_array+1)
106
113
107
   for (i=0; charset[i]; ) {
114
   for (i=0; charset[i]; ) {
108
      i += getsym(charset+i, &this);
115
      i += getsym(charset+i, &this);
Lines 111-119 Link Here
111
      else
118
      else
112
         next = this;
119
         next = this;
113
      for (c = this; c <= next; c++)
120
      for (c = this; c <= next; c++)
114
         inwordLut[c>>5] |= 1 << (c&0x1F);
121
         //inwordLut[c>>5] |= 1 << (c&0x1F);
122
	 (long_array+1)[c>>5] |= 1 << (c&0x1F);
115
   }
123
   }
116
  
124
125
    /* XCaP */
126
    /* used in mode=1 (word-by-word selection) */
127
    for (i=0; i<8; i++) 
128
	inwordLut[i] = long_array[i+1];
129
    /* XCaP */
130
   
117
   if ((fd=open(option.consolename, O_WRONLY)) < 0) {
131
   if ((fd=open(option.consolename, O_WRONLY)) < 0) {
118
      /* try /dev/console, if /dev/tty0 failed -- is that really senseful ??? */
132
      /* try /dev/console, if /dev/tty0 failed -- is that really senseful ??? */
119
      free(option.consolename); /* allocated by main */
133
      free(option.consolename); /* allocated by main */
(-)gpm-1.20.1_orig/src/headers/xcap.h (+13 lines)
Line 0 Link Here
1
/*
2
 * Xwindow Copy&Paste patch
3
 * (c) 2004 Alex Efros <powerman-asdf@yandex.ru>
4
 */
5
6
#define SCR_SIZE 10240	/* current console image, for 80x25 needed only 2000 */
7
8
#include <asm/types.h>	/* __u32 */
9
__u32 inwordLut[8];	/* used in gpn.c and gpm.c */
10
11
char *sel_buffer;	/* buffer with current selection */
12
int sel_buffer_lth;	/* size of buffer with current selection */
13

Return to bug 42667