Commit 439de7090757bc80a9b53cea7b0ed78e3e625f08
1 parent
fdbb730e
Exists in
master
and in
3 other branches
Implementação parcial do comando "cut"
Showing
2 changed files
with
82 additions
and
37 deletions
Show diff stats
ctlr.c
| @@ -2259,9 +2259,10 @@ static void ctlr_blanks(H3270 *session) | @@ -2259,9 +2259,10 @@ static void ctlr_blanks(H3270 *session) | ||
| 2259 | } | 2259 | } |
| 2260 | 2260 | ||
| 2261 | 2261 | ||
| 2262 | -/* | ||
| 2263 | - * Change a character in the 3270 buffer. | ||
| 2264 | - * Removes any field attribute defined at that location. | 2262 | +/** |
| 2263 | + * Change a character in the 3270 buffer, removes any field attribute defined at that location. | ||
| 2264 | + * | ||
| 2265 | + * | ||
| 2265 | */ | 2266 | */ |
| 2266 | void ctlr_add(H3270 *hSession, int baddr, unsigned char c, unsigned char cs) | 2267 | void ctlr_add(H3270 *hSession, int baddr, unsigned char c, unsigned char cs) |
| 2267 | { | 2268 | { |
| @@ -2430,17 +2431,19 @@ void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int mo | @@ -2430,17 +2431,19 @@ void ctlr_bcopy(H3270 *hSession, int baddr_from, int baddr_to, int count, int mo | ||
| 2430 | } | 2431 | } |
| 2431 | 2432 | ||
| 2432 | #if defined(X3270_ANSI) /*[*/ | 2433 | #if defined(X3270_ANSI) /*[*/ |
| 2433 | -/* | ||
| 2434 | - * Erase a region of the 3270 buffer, optionally clearing extended attributes | ||
| 2435 | - * as well. | 2434 | +/** |
| 2435 | + * Erase a region of the 3270 buffer, optionally clearing extended attributes as well. | ||
| 2436 | + * | ||
| 2437 | + * @param hSession Session handle | ||
| 2438 | + * | ||
| 2436 | */ | 2439 | */ |
| 2437 | -void ctlr_aclear(H3270 *session, int baddr, int count, int clear_ea) | 2440 | +void ctlr_aclear(H3270 *hSession, int baddr, int count, int clear_ea) |
| 2438 | { | 2441 | { |
| 2439 | - if (memcmp((char *) &session->ea_buf[baddr], (char *) session->zero_buf, | 2442 | + if (memcmp((char *) &hSession->ea_buf[baddr], (char *) hSession->zero_buf, |
| 2440 | count * sizeof(struct lib3270_ea))) { | 2443 | count * sizeof(struct lib3270_ea))) { |
| 2441 | - (void) memset((char *) &session->ea_buf[baddr], 0, | 2444 | + (void) memset((char *) &hSession->ea_buf[baddr], 0, |
| 2442 | count * sizeof(struct lib3270_ea)); | 2445 | count * sizeof(struct lib3270_ea)); |
| 2443 | - REGION_CHANGED(session,baddr, baddr + count); | 2446 | + REGION_CHANGED(hSession,baddr, baddr + count); |
| 2444 | } | 2447 | } |
| 2445 | /* XXX: What about clear_ea? */ | 2448 | /* XXX: What about clear_ea? */ |
| 2446 | } | 2449 | } |
selection.c
| @@ -532,6 +532,58 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | @@ -532,6 +532,58 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | ||
| 532 | return get_text(hSession,0); | 532 | return get_text(hSession,0); |
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | +static void copy_chr(H3270 *hSession, int from, int to) | ||
| 536 | +{ | ||
| 537 | + if(hSession->text[from].chr == hSession->text[to].chr) | ||
| 538 | + return; | ||
| 539 | + | ||
| 540 | + hSession->text[to].chr = hSession->text[from].chr; | ||
| 541 | + | ||
| 542 | + memcpy(&hSession->ea_buf[to], &hSession->ea_buf[from],sizeof(struct lib3270_ea)); | ||
| 543 | + hSession->ea_buf[from].fa = 0; | ||
| 544 | + | ||
| 545 | + hSession->update( hSession, | ||
| 546 | + to, | ||
| 547 | + hSession->text[to].chr, | ||
| 548 | + hSession->text[to].attr, | ||
| 549 | + to == hSession->cursor_addr ); | ||
| 550 | +} | ||
| 551 | + | ||
| 552 | +static void clear_chr(H3270 *hSession, int baddr) | ||
| 553 | +{ | ||
| 554 | + hSession->text[baddr].chr = ' '; | ||
| 555 | + | ||
| 556 | + hSession->ea_buf[baddr].cc = EBC_null; | ||
| 557 | + hSession->ea_buf[baddr].cs = 0; | ||
| 558 | + | ||
| 559 | + hSession->update( hSession, | ||
| 560 | + baddr, | ||
| 561 | + hSession->text[baddr].chr, | ||
| 562 | + hSession->text[baddr].attr, | ||
| 563 | + baddr == hSession->cursor_addr ); | ||
| 564 | +} | ||
| 565 | + | ||
| 566 | +int cut_addr(H3270 *hSession, int daddr, int saddr, int maxlen, int *sattr) | ||
| 567 | +{ | ||
| 568 | + if(hSession->ea_buf[saddr].fa) | ||
| 569 | + *sattr = hSession->ea_buf[saddr++].fa; | ||
| 570 | + | ||
| 571 | +/* | ||
| 572 | + if(FA_IS_PROTECTED(*sattr)) | ||
| 573 | + { | ||
| 574 | + saddr = lib3270_get_next_unprotected(hSession,saddr); | ||
| 575 | + *sattr = lib3270_field_attribute(hSession,saddr); | ||
| 576 | + } | ||
| 577 | +*/ | ||
| 578 | + | ||
| 579 | + if(FA_IS_PROTECTED(*sattr) || saddr >= maxlen) | ||
| 580 | + clear_chr(hSession,daddr); | ||
| 581 | + else | ||
| 582 | + copy_chr(hSession,saddr++,daddr); | ||
| 583 | + | ||
| 584 | + return saddr; | ||
| 585 | +} | ||
| 586 | + | ||
| 535 | LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | 587 | LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) |
| 536 | { | 588 | { |
| 537 | 589 | ||
| @@ -559,10 +611,13 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -559,10 +611,13 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 559 | int saddr; /* Source addr (First field after the selected area) */ | 611 | int saddr; /* Source addr (First field after the selected area) */ |
| 560 | int sattr; /* Source addr attribute */ | 612 | int sattr; /* Source addr attribute */ |
| 561 | char *text; | 613 | char *text; |
| 614 | + size_t maxlen = hSession->rows * hSession->cols; | ||
| 562 | int f; | 615 | int f; |
| 563 | 616 | ||
| 564 | get_selected_addr(hSession,&daddr,&end); | 617 | get_selected_addr(hSession,&daddr,&end); |
| 565 | 618 | ||
| 619 | + lib3270_set_cursor_address(hSession,daddr); | ||
| 620 | + | ||
| 566 | if(daddr >= end) | 621 | if(daddr >= end) |
| 567 | return NULL; | 622 | return NULL; |
| 568 | 623 | ||
| @@ -583,36 +638,23 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | @@ -583,36 +638,23 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) | ||
| 583 | text[f] = hSession->text[daddr].chr; | 638 | text[f] = hSession->text[daddr].chr; |
| 584 | 639 | ||
| 585 | if(!FA_IS_PROTECTED(dattr)) | 640 | if(!FA_IS_PROTECTED(dattr)) |
| 586 | - { | ||
| 587 | - if(hSession->ea_buf[saddr].fa) | ||
| 588 | - sattr = hSession->ea_buf[saddr].fa; | ||
| 589 | - | ||
| 590 | - if(FA_IS_PROTECTED(sattr)) | ||
| 591 | - { | ||
| 592 | - saddr = lib3270_get_next_unprotected(hSession,saddr); | ||
| 593 | - sattr = lib3270_field_attribute(hSession,saddr); | ||
| 594 | - } | ||
| 595 | - | ||
| 596 | - if(!FA_IS_PROTECTED(sattr)) | ||
| 597 | - { | ||
| 598 | - if(hSession->text[daddr].chr != hSession->text[saddr].chr) | ||
| 599 | - { | ||
| 600 | - hSession->text[daddr].chr = hSession->text[saddr].chr; | ||
| 601 | - hSession->update(hSession,daddr,hSession->text[daddr].chr,hSession->text[daddr].attr,daddr == hSession->cursor_addr); | ||
| 602 | - } | ||
| 603 | - | ||
| 604 | - if(hSession->text[saddr].chr != ' ') | ||
| 605 | - { | ||
| 606 | - hSession->text[saddr].chr = ' '; | ||
| 607 | - hSession->update(hSession,saddr,hSession->text[saddr].chr,hSession->text[saddr].attr,saddr == hSession->cursor_addr); | ||
| 608 | - } | ||
| 609 | - | ||
| 610 | - saddr++; | ||
| 611 | - } | ||
| 612 | - } | 641 | + saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); |
| 642 | + | ||
| 643 | + daddr++; | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + // Move contents of the current field | ||
| 647 | + while(daddr < (maxlen-1) && !hSession->ea_buf[daddr].fa) | ||
| 648 | + { | ||
| 649 | + saddr = cut_addr(hSession,daddr,saddr,maxlen,&sattr); | ||
| 613 | daddr++; | 650 | daddr++; |
| 614 | } | 651 | } |
| 615 | 652 | ||
| 653 | + if(!hSession->ea_buf[daddr].fa) | ||
| 654 | + clear_chr(hSession,daddr); | ||
| 655 | + | ||
| 656 | + hSession->changed(hSession,0,maxlen); | ||
| 657 | + | ||
| 616 | lib3270_unselect(hSession); | 658 | lib3270_unselect(hSession); |
| 617 | return text; | 659 | return text; |
| 618 | } | 660 | } |