Commit 7b3a48204f9716bcf5c777ee1f39c1d7fbb36eb1

Authored by Perry Werneck
1 parent d0ffcc12

Changing "cut" methods to use the same code for "get".

src/lib3270/selection/actions.c
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin 18 * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19 * St, Fifth Floor, Boston, MA 02110-1301 USA 19 * St, Fifth Floor, Boston, MA 02110-1301 USA
20 * 20 *
21 - * Este programa está nomeado como selection.c e possui - linhas de código. 21 + * Este programa está nomeado como - e possui - linhas de código.
22 * 22 *
23 * Contatos: 23 * Contatos:
24 * 24 *
src/lib3270/selection/selection.c
@@ -241,7 +241,21 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba @@ -241,7 +241,21 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba
241 return rc; 241 return rc;
242 } 242 }
243 243
244 -static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) 244 +static void clear_chr(H3270 *hSession, int baddr)
  245 +{
  246 + hSession->text[baddr].chr = ' ';
  247 +
  248 + hSession->ea_buf[baddr].cc = EBC_null;
  249 + hSession->ea_buf[baddr].cs = 0;
  250 +
  251 + hSession->cbk.update( hSession,
  252 + baddr,
  253 + hSession->text[baddr].chr,
  254 + hSession->text[baddr].attr,
  255 + baddr == hSession->cursor_addr );
  256 +}
  257 +
  258 +static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok, Boolean cut)
245 { 259 {
246 int row, col, baddr; 260 int row, col, baddr;
247 char * ret; 261 char * ret;
@@ -258,6 +272,7 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) @@ -258,6 +272,7 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok)
258 ret = lib3270_malloc(buflen); 272 ret = lib3270_malloc(buflen);
259 273
260 baddr = 0; 274 baddr = 0;
  275 + unsigned char fa = 0;
261 276
262 for(row=0;row < hSession->rows;row++) 277 for(row=0;row < hSession->rows;row++)
263 { 278 {
@@ -265,6 +280,10 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) @@ -265,6 +280,10 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok)
265 280
266 for(col = 0; col < hSession->cols;col++) 281 for(col = 0; col < hSession->cols;col++)
267 { 282 {
  283 + if(hSession->ea_buf[baddr].fa) {
  284 + fa = hSession->ea_buf[baddr].fa;
  285 + }
  286 +
268 if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) 287 if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)
269 { 288 {
270 if(tok && attr != hSession->text[baddr].attr) 289 if(tok && attr != hSession->text[baddr].attr)
@@ -273,10 +292,16 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) @@ -273,10 +292,16 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok)
273 ret[sz++] = tok; 292 ret[sz++] = tok;
274 ret[sz++] = (attr & 0x0F); 293 ret[sz++] = (attr & 0x0F);
275 ret[sz++] = ((attr & 0xF0) >> 4); 294 ret[sz++] = ((attr & 0xF0) >> 4);
  295 +
276 } 296 }
277 297
278 cr++; 298 cr++;
279 ret[sz++] = hSession->text[baddr].chr; 299 ret[sz++] = hSession->text[baddr].chr;
  300 +
  301 + if(cut && !FA_IS_PROTECTED(fa)) {
  302 + clear_chr(hSession,baddr);
  303 + }
  304 +
280 } 305 }
281 baddr++; 306 baddr++;
282 } 307 }
@@ -455,8 +480,27 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) @@ -455,8 +480,27 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession)
455 if(!lib3270_connected(hSession)) 480 if(!lib3270_connected(hSession))
456 return NULL; 481 return NULL;
457 482
  483 + return get_text(hSession,0,0,0);
  484 +}
  485 +
  486 +LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession)
  487 +{
  488 + CHECK_SESSION_HANDLE(hSession);
458 489
459 - return get_text(hSession,0,0); 490 + if(!hSession->selected || hSession->select.start == hSession->select.end)
  491 + return NULL;
  492 +
  493 + if(!lib3270_connected(hSession))
  494 + return NULL;
  495 +
  496 + return get_text(hSession,0,0,1);
  497 +}
  498 +
  499 +/*
  500 +
  501 +LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession)
  502 +{
  503 + return cut_text(hSession,0);
460 } 504 }
461 505
462 static void copy_chr(H3270 *hSession, int from, int to) 506 static void copy_chr(H3270 *hSession, int from, int to)
@@ -476,20 +520,6 @@ static void copy_chr(H3270 *hSession, int from, int to) @@ -476,20 +520,6 @@ static void copy_chr(H3270 *hSession, int from, int to)
476 to == hSession->cursor_addr ); 520 to == hSession->cursor_addr );
477 } 521 }
478 522
479 -static void clear_chr(H3270 *hSession, int baddr)  
480 -{  
481 - hSession->text[baddr].chr = ' ';  
482 -  
483 - hSession->ea_buf[baddr].cc = EBC_null;  
484 - hSession->ea_buf[baddr].cs = 0;  
485 -  
486 - hSession->cbk.update( hSession,  
487 - baddr,  
488 - hSession->text[baddr].chr,  
489 - hSession->text[baddr].attr,  
490 - baddr == hSession->cursor_addr );  
491 -}  
492 -  
493 int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) 523 int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr)
494 { 524 {
495 if(hSession->ea_buf[saddr].fa) 525 if(hSession->ea_buf[saddr].fa)
@@ -528,10 +558,10 @@ char * cut_text(H3270 *hSession, char tok) @@ -528,10 +558,10 @@ char * cut_text(H3270 *hSession, char tok)
528 size_t szText; 558 size_t szText;
529 size_t buflen; 559 size_t buflen;
530 size_t bufpos = 0; 560 size_t bufpos = 0;
531 - int daddr; /* Destination addr */  
532 - int dattr; /* Destination addr attribute */  
533 - int saddr; /* Source addr (First field after the selected area) */  
534 - int sattr; /* Source addr attribute */ 561 + int daddr; // Destination addr
  562 + int dattr; // Destination addr attribute
  563 + int saddr; // Source addr (First field after the selected area)
  564 + int sattr; // Source addr attribute
535 char *text; 565 char *text;
536 size_t maxlen = hSession->rows * hSession->cols; 566 size_t maxlen = hSession->rows * hSession->cols;
537 size_t f; 567 size_t f;
@@ -543,7 +573,7 @@ char * cut_text(H3270 *hSession, char tok) @@ -543,7 +573,7 @@ char * cut_text(H3270 *hSession, char tok)
543 if(daddr >= end) 573 if(daddr >= end)
544 return NULL; 574 return NULL;
545 575
546 - dattr = lib3270_field_attribute(hSession,daddr); /* Get first attribute */ 576 + dattr = lib3270_field_attribute(hSession,daddr); // Get first attribute
547 577
548 szText = (end-daddr)+1; 578 szText = (end-daddr)+1;
549 buflen = szText; 579 buflen = szText;
@@ -603,8 +633,4 @@ char * cut_text(H3270 *hSession, char tok) @@ -603,8 +633,4 @@ char * cut_text(H3270 *hSession, char tok)
603 return NULL; 633 return NULL;
604 } 634 }
605 635
606 -LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession)  
607 -{  
608 - return cut_text(hSession,0);  
609 -}  
610 - 636 +*/