Commit cc6ee66d291bbba064b144281b0e8b3d0085b329
1 parent
4b7d100d
Exists in
master
and in
5 other branches
Iniciando implementação da função "cut" respeitando os atributos
Showing
1 changed file
with
30 additions
and
12 deletions
Show diff stats
src/lib3270/selection.c
| @@ -378,7 +378,7 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) | @@ -378,7 +378,7 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) | ||
| 378 | char * ret; | 378 | char * ret; |
| 379 | size_t buflen = (hSession->rows * (hSession->cols+1))+1; | 379 | size_t buflen = (hSession->rows * (hSession->cols+1))+1; |
| 380 | size_t sz = 0; | 380 | size_t sz = 0; |
| 381 | - unsigned short attr = 0; | 381 | + unsigned short attr = 0xFFFF; |
| 382 | 382 | ||
| 383 | if(!(lib3270_connected(hSession) && hSession->text)) | 383 | if(!(lib3270_connected(hSession) && hSession->text)) |
| 384 | { | 384 | { |
| @@ -390,14 +390,6 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) | @@ -390,14 +390,6 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok) | ||
| 390 | 390 | ||
| 391 | baddr = 0; | 391 | baddr = 0; |
| 392 | 392 | ||
| 393 | - if(tok) | ||
| 394 | - { | ||
| 395 | - attr = hSession->text[baddr].attr; | ||
| 396 | - ret[sz++] = tok; | ||
| 397 | - ret[sz++] = (attr & 0x0F); | ||
| 398 | - ret[sz++] = ((attr & 0xF0) >> 4); | ||
| 399 | - } | ||
| 400 | - | ||
| 401 | for(row=0;row < hSession->rows;row++) | 393 | for(row=0;row < hSession->rows;row++) |
| 402 | { | 394 | { |
| 403 | int cr = 0; | 395 | int cr = 0; |
| @@ -634,8 +626,9 @@ int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) | @@ -634,8 +626,9 @@ int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) | ||
| 634 | return saddr; | 626 | return saddr; |
| 635 | } | 627 | } |
| 636 | 628 | ||
| 637 | -LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | 629 | +char * cut_text(H3270 *hSession, char tok) |
| 638 | { | 630 | { |
| 631 | + unsigned short attr = 0xFFFF; | ||
| 639 | 632 | ||
| 640 | CHECK_SESSION_HANDLE(hSession); | 633 | CHECK_SESSION_HANDLE(hSession); |
| 641 | 634 | ||
| @@ -656,6 +649,8 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -656,6 +649,8 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 656 | { | 649 | { |
| 657 | int end; | 650 | int end; |
| 658 | size_t szText; | 651 | size_t szText; |
| 652 | + size_t buflen; | ||
| 653 | + size_t bufpos = 0; | ||
| 659 | int daddr; /* Destination addr */ | 654 | int daddr; /* Destination addr */ |
| 660 | int dattr; /* Destination addr attribute */ | 655 | int dattr; /* Destination addr attribute */ |
| 661 | int saddr; /* Source addr (First field after the selected area) */ | 656 | int saddr; /* Source addr (First field after the selected area) */ |
| @@ -674,8 +669,10 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -674,8 +669,10 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 674 | dattr = lib3270_field_attribute(hSession,daddr); /* Get first attribute */ | 669 | dattr = lib3270_field_attribute(hSession,daddr); /* Get first attribute */ |
| 675 | 670 | ||
| 676 | szText = (end-daddr)+1; | 671 | szText = (end-daddr)+1; |
| 672 | + buflen = szText; | ||
| 673 | + bufpos = 0; | ||
| 677 | 674 | ||
| 678 | - text = lib3270_malloc(szText+1); | 675 | + text = lib3270_malloc(buflen+1); |
| 679 | 676 | ||
| 680 | saddr = daddr+szText; | 677 | saddr = daddr+szText; |
| 681 | sattr = lib3270_field_attribute(hSession,saddr); | 678 | sattr = lib3270_field_attribute(hSession,saddr); |
| @@ -685,7 +682,21 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -685,7 +682,21 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 685 | if(hSession->ea_buf[daddr].fa) | 682 | if(hSession->ea_buf[daddr].fa) |
| 686 | dattr = hSession->ea_buf[daddr].fa; | 683 | dattr = hSession->ea_buf[daddr].fa; |
| 687 | 684 | ||
| 688 | - text[f] = hSession->text[daddr].chr; | 685 | + if((bufpos+10) > buflen) |
| 686 | + { | ||
| 687 | + buflen += 100; | ||
| 688 | + text = lib3270_realloc(text,buflen); | ||
| 689 | + } | ||
| 690 | + | ||
| 691 | + if(tok && attr != hSession->text[daddr].attr) | ||
| 692 | + { | ||
| 693 | + attr = hSession->text[daddr].attr; | ||
| 694 | + text[bufpos++] = tok; | ||
| 695 | + text[bufpos++] = (attr & 0x0F); | ||
| 696 | + text[bufpos++] = ((attr & 0xF0) >> 4); | ||
| 697 | + } | ||
| 698 | + | ||
| 699 | + text[bufpos++] = hSession->text[daddr].chr; | ||
| 689 | 700 | ||
| 690 | if(!FA_IS_PROTECTED(dattr)) | 701 | if(!FA_IS_PROTECTED(dattr)) |
| 691 | saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); | 702 | saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); |
| @@ -693,6 +704,9 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -693,6 +704,9 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 693 | daddr++; | 704 | daddr++; |
| 694 | } | 705 | } |
| 695 | 706 | ||
| 707 | + text[bufpos++] = 0; | ||
| 708 | + text = lib3270_realloc(text,bufpos); | ||
| 709 | + | ||
| 696 | // Move contents of the current field | 710 | // Move contents of the current field |
| 697 | while(daddr < (maxlen-1) && !hSession->ea_buf[daddr].fa) | 711 | while(daddr < (maxlen-1) && !hSession->ea_buf[daddr].fa) |
| 698 | { | 712 | { |
| @@ -712,6 +726,10 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -712,6 +726,10 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 712 | return NULL; | 726 | return NULL; |
| 713 | } | 727 | } |
| 714 | 728 | ||
| 729 | +LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 730 | +{ | ||
| 731 | + return cut_text(hSession,0); | ||
| 732 | +} | ||
| 715 | 733 | ||
| 716 | LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end) | 734 | LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end) |
| 717 | { | 735 | { |