Changeset c9334b1
- Timestamp:
- Jun 30, 2003, 5:19:35 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- cf83b7a
- Parents:
- 6a87084
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r6a87084 rc9334b1 6 6 Bug fix to make zwrite -m work with -c/-i 7 7 Fix in autoconf for des425 8 Reformatted editwin.c and added capability of doing password 9 echoing 8 10 9 11 2.0.5 -
editwin.c
rd09e5a1 rc9334b1 9 9 #define INCR 5000 10 10 11 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) { 11 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) 12 { 12 13 /* initialize the editwin e. 13 14 * 'win' is an already initialzed curses window that will be used by editwin … … 35 36 e->lock=0; 36 37 e->dotsend=0; 38 e->echochar='\0'; 37 39 if (win) werase(win); 38 40 } 39 41 40 void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols) { 42 void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols) 43 { 41 44 e->curswin=w; 42 45 e->winlines=winlines; … … 48 51 } 49 52 50 WINDOW *owl_editwin_get_curswin(owl_editwin *e) { 53 /* echo the character 'ch' for each normal character keystroke, 54 * excepting locktext. This is useful for entering passwords etc. If 55 * ch=='\0' characters are echo'd normally 56 */ 57 void owl_editwin_set_echochar(owl_editwin *e, int ch) 58 { 59 e->echochar=ch; 60 } 61 62 WINDOW *owl_editwin_get_curswin(owl_editwin *e) 63 { 51 64 return(e->curswin); 52 65 } 53 66 54 void owl_editwin_set_history(owl_editwin *e, owl_history *h) { 67 void owl_editwin_set_history(owl_editwin *e, owl_history *h) 68 { 55 69 e->hist=h; 56 70 } 57 71 58 owl_history *owl_editwin_get_history(owl_editwin *e) { 72 owl_history *owl_editwin_get_history(owl_editwin *e) 73 { 59 74 return(e->hist); 60 75 } 61 76 62 void owl_editwin_set_dotsend(owl_editwin *e) { 77 void owl_editwin_set_dotsend(owl_editwin *e) 78 { 63 79 e->dotsend=1; 64 80 } 65 81 66 int owl_editwin_limit_maxcols(int v, int maxv) { 82 int owl_editwin_limit_maxcols(int v, int maxv) 83 { 67 84 if (maxv > 5 && v > maxv) { 68 85 return(maxv); … … 72 89 } 73 90 74 void owl_editwin_set_locktext(owl_editwin *e, char *text) { 75 /* set text to be 'locked in' at the beginning of the buffer, any 76 previous text (including locked text) will be overwritten */ 91 /* set text to be 'locked in' at the beginning of the buffer, any 92 * previous text (including locked text) will be overwritten 93 */ 94 void owl_editwin_set_locktext(owl_editwin *e, char *text) 95 { 77 96 78 97 int x, y; … … 91 110 } 92 111 93 int owl_editwin_get_style(owl_editwin *e) { 112 int owl_editwin_get_style(owl_editwin *e) 113 { 94 114 return(e->style); 95 115 } 96 116 97 void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h) { 117 void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h) 118 { 98 119 char *ptr; 99 120 … … 119 140 } 120 141 121 void owl_editwin_fullclear(owl_editwin *e) { 122 /* completly reinitialize the buffer */ 142 /* completly reinitialize the buffer */ 143 void owl_editwin_fullclear(owl_editwin *e) 144 { 123 145 owl_free(e->buff); 124 146 owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist); 125 147 } 126 148 127 void owl_editwin_clear(owl_editwin *e) { 128 /* clear all text except for locktext and put the cursor at the beginning */ 149 /* clear all text except for locktext and put the cursor at the 150 * beginning 151 */ 152 void owl_editwin_clear(owl_editwin *e) 153 { 154 129 155 int lock; 130 156 int dotsend=e->dotsend; … … 155 181 156 182 157 void _owl_editwin_addspace(owl_editwin *e) { 158 /* malloc more space for the buffer */ 183 /* malloc more space for the buffer */ 184 void _owl_editwin_addspace(owl_editwin *e) 185 { 159 186 e->buff=owl_realloc(e->buff, e->allocated+INCR); 160 187 if (!e->buff) { … … 165 192 } 166 193 167 void owl_editwin_recenter(owl_editwin *e) { 194 void owl_editwin_recenter(owl_editwin *e) 195 { 168 196 e->topline=e->buffy-(e->winlines/2); 169 197 if (e->topline<0) e->topline=0; … … 171 199 } 172 200 173 void owl_editwin_redisplay(owl_editwin *e, int update) { 174 /* regenerate the text on the curses window */ 175 /* if update == 1 then do a doupdate(), otherwise do not */ 201 /* regenerate the text on the curses window */ 202 /* if update == 1 then do a doupdate(), otherwise do not */ 203 void owl_editwin_redisplay(owl_editwin *e, int update) 204 { 176 205 177 206 char *ptr1, *ptr2, *ptr3, *buff; 178 int i ;207 int i, j; 179 208 180 209 werase(e->curswin); … … 212 241 strncpy(buff, ptr1, ptr3-ptr1); 213 242 buff[ptr3-ptr1]='\0'; 214 waddstr(e->curswin, buff); 243 if (e->echochar=='\0') { 244 waddstr(e->curswin, buff); 245 } else { 246 /* translate to echochar, *except* for the locktext */ 247 int len; 248 int dolocklen=e->lock-(ptr1-e->buff); 249 250 for (i=0; i<dolocklen; i++) { 251 waddch(e->curswin, buff[i]); 252 } 253 len=strlen(buff); 254 for (i=0; i<len-dolocklen; i++) { 255 waddch(e->curswin, e->echochar); 256 } 257 } 215 258 wmove(e->curswin, e->buffy-e->topline, e->buffx); 216 259 wnoutrefresh(e->curswin); … … 222 265 223 266 224 int _owl_editwin_linewrap_word(owl_editwin *e) { 225 /* linewrap the word just before the cursor.226 * returns 0 on success227 * returns -1 if we could not wrap.228 */ 229 267 /* linewrap the word just before the cursor. 268 * returns 0 on success 269 * returns -1 if we could not wrap. 270 */ 271 int _owl_editwin_linewrap_word(owl_editwin *e) 272 { 230 273 int i, z; 231 274 … … 250 293 } 251 294 252 void owl_editwin_insert_char(owl_editwin *e, char c) { 253 /* insert a character at the current point (shift later 254 * characters over) */ 295 /* insert a character at the current point (shift later 296 * characters over) 297 */ 298 void owl_editwin_insert_char(owl_editwin *e, char c) 299 { 255 300 256 301 int z, i, ret; … … 306 351 } 307 352 308 void owl_editwin_overwrite_char(owl_editwin *e, char c) { 309 /* overwrite the character at the current point with 'c' */ 353 /* overwrite the character at the current point with 'c' */ 354 void owl_editwin_overwrite_char(owl_editwin *e, char c) 355 { 310 356 int z; 311 357 … … 348 394 } 349 395 350 void owl_editwin_delete_char(owl_editwin *e) { 351 /* delete the character at the current point, following chars 352 * shift left. 353 */ 396 /* delete the character at the current point, following chars 397 * shift left. 398 */ 399 void owl_editwin_delete_char(owl_editwin *e) 400 { 354 401 int z, i; 355 402 … … 368 415 } 369 416 370 void owl_editwin_transpose_chars(owl_editwin *e) { 371 /* Swap the character at point with the character at point-1 and372 * advance the pointer. If point is at beginning of buffer do373 * nothing. If point is after the last character swap point-1 with374 * point-2. (Behaves as observed in tcsh and emacs).375 */ 376 417 /* Swap the character at point with the character at point-1 and 418 * advance the pointer. If point is at beginning of buffer do 419 * nothing. If point is after the last character swap point-1 with 420 * point-2. (Behaves as observed in tcsh and emacs). 421 */ 422 void owl_editwin_transpose_chars(owl_editwin *e) 423 { 377 424 int z; 378 425 char tmp; … … 399 446 } 400 447 401 void owl_editwin_insert_string(owl_editwin *e, char *string) { 402 /* insert 'string' at the current point, later text is shifted 403 * right 404 */ 448 /* insert 'string' at the current point, later text is shifted 449 * right 450 */ 451 void owl_editwin_insert_string(owl_editwin *e, char *string) 452 { 405 453 int i, j; 406 454 … … 411 459 } 412 460 413 void owl_editwin_overwrite_string(owl_editwin *e, char *string) { 461 /* write 'string' at the current point, overwriting text that is 462 * already there 463 */ 464 465 void owl_editwin_overwrite_string(owl_editwin *e, char *string) 466 { 414 467 int i, j; 415 /* write 'string' at the current point, overwriting text that is416 * already there417 */418 468 419 469 j=strlen(string); … … 423 473 } 424 474 425 int _owl_editwin_get_index_from_xy(owl_editwin *e) { 426 /* get the index into e->buff for the current cursor 427 * position. 428 */ 475 /* get the index into e->buff for the current cursor 476 * position. 477 */ 478 int _owl_editwin_get_index_from_xy(owl_editwin *e) 479 { 429 480 int i; 430 481 char *ptr1, *ptr2; … … 459 510 } 460 511 461 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) { 512 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) 513 { 462 514 int z, i; 463 515 … … 474 526 } 475 527 476 void owl_editwin_adjust_for_locktext(owl_editwin *e) { 528 void owl_editwin_adjust_for_locktext(owl_editwin *e) 529 { 477 530 /* if we happen to have the cursor over locked text 478 531 * move it to be out of the locktext region */ … … 482 535 } 483 536 484 void owl_editwin_backspace(owl_editwin *e) { 537 void owl_editwin_backspace(owl_editwin *e) 538 { 485 539 /* delete the char before the current one 486 540 * and shift later chars left … … 493 547 } 494 548 495 void owl_editwin_key_up(owl_editwin *e) { 549 void owl_editwin_key_up(owl_editwin *e) 550 { 496 551 if (e->buffy > 0) e->buffy--; 497 552 if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) { … … 507 562 } 508 563 509 void owl_editwin_key_down(owl_editwin *e) { 564 void owl_editwin_key_down(owl_editwin *e) 565 { 510 566 /* move down if we can */ 511 567 if (e->buffy+1 < owl_editwin_get_numlines(e)) e->buffy++; … … 525 581 } 526 582 527 void owl_editwin_key_left(owl_editwin *e) { 583 void owl_editwin_key_left(owl_editwin *e) 584 { 528 585 /* move left if we can, and maybe up a line */ 529 586 if (e->buffx>0) { … … 543 600 } 544 601 545 void owl_editwin_key_right(owl_editwin *e) { 602 void owl_editwin_key_right(owl_editwin *e) 603 { 546 604 int i; 547 605 … … 564 622 } 565 623 566 void owl_editwin_move_to_nextword(owl_editwin *e) { 624 void owl_editwin_move_to_nextword(owl_editwin *e) 625 { 567 626 int i, x; 568 627 … … 600 659 } 601 660 602 void owl_editwin_move_to_previousword(owl_editwin *e) { 603 /* go backwards to the last non-space character */ 661 /* go backwards to the last non-space character 662 */ 663 void owl_editwin_move_to_previousword(owl_editwin *e) 664 { 604 665 int i, x; 605 666 … … 635 696 636 697 637 void owl_editwin_delete_nextword(owl_editwin *e) { 698 void owl_editwin_delete_nextword(owl_editwin *e) 699 { 638 700 int z; 639 701 … … 660 722 } 661 723 662 void owl_editwin_delete_previousword(owl_editwin *e) { 724 void owl_editwin_delete_previousword(owl_editwin *e) 725 { 663 726 /* go backwards to the last non-space character, then delete chars */ 664 727 int i, startpos, endpos; … … 672 735 } 673 736 674 void owl_editwin_delete_to_endofline(owl_editwin *e) { 737 void owl_editwin_delete_to_endofline(owl_editwin *e) 738 { 675 739 int i; 676 740 … … 694 758 } 695 759 696 void owl_editwin_move_to_line_end(owl_editwin *e) { 760 void owl_editwin_move_to_line_end(owl_editwin *e) 761 { 697 762 e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy); 698 763 } 699 764 700 void owl_editwin_move_to_line_start(owl_editwin *e) { 765 void owl_editwin_move_to_line_start(owl_editwin *e) 766 { 701 767 e->buffx=0; 702 768 owl_editwin_adjust_for_locktext(e); 703 769 } 704 770 705 void owl_editwin_move_to_end(owl_editwin *e) { 771 void owl_editwin_move_to_end(owl_editwin *e) 772 { 706 773 /* go to last char */ 707 774 e->buffy=owl_editwin_get_numlines(e)-1; … … 715 782 } 716 783 717 void owl_editwin_move_to_top(owl_editwin *e) { 784 void owl_editwin_move_to_top(owl_editwin *e) 785 { 718 786 _owl_editwin_set_xy_by_index(e, 0); 719 787 … … 724 792 } 725 793 726 void owl_editwin_fill_paragraph(owl_editwin *e) { 794 void owl_editwin_fill_paragraph(owl_editwin *e) 795 { 727 796 int i, save; 728 797 … … 787 856 788 857 /* returns if only whitespace remains */ 789 int owl_editwin_is_at_end(owl_editwin *e) { 858 int owl_editwin_is_at_end(owl_editwin *e) 859 { 790 860 int cur=_owl_editwin_get_index_from_xy(e); 791 return only_whitespace(e->buff+cur); 792 } 793 794 int owl_editwin_check_dotsend(owl_editwin *e) { 861 return (only_whitespace(e->buff+cur)); 862 } 863 864 int owl_editwin_check_dotsend(owl_editwin *e) 865 { 795 866 int i; 796 867 … … 811 882 } 812 883 813 void owl_editwin_post_process_char(owl_editwin *e, int j) { 884 void owl_editwin_post_process_char(owl_editwin *e, int j) 885 { 814 886 /* check if we need to scroll down */ 815 887 if (e->buffy-e->topline >= e->winlines) { … … 823 895 } 824 896 825 void owl_editwin_process_char(owl_editwin *e, int j) { 897 void owl_editwin_process_char(owl_editwin *e, int j) 898 { 826 899 if (j == ERR) return; 827 900 if (j>127 || ((j<32) && (j!=10) && (j!=13))) { … … 832 905 } 833 906 834 char *owl_editwin_get_text(owl_editwin *e) { 907 char *owl_editwin_get_text(owl_editwin *e) 908 { 835 909 return(e->buff+e->lock); 836 910 } 837 911 838 int owl_editwin_get_numchars_on_line(owl_editwin *e, int line) { 912 int owl_editwin_get_numchars_on_line(owl_editwin *e, int line) 913 { 839 914 int i; 840 915 char *ptr1, *ptr2; … … 861 936 } 862 937 863 int owl_editwin_get_numlines(owl_editwin *e) { 938 int owl_editwin_get_numlines(owl_editwin *e) 939 { 864 940 return(owl_text_num_lines(e->buff)); 865 941 } -
owl.h
r290f290 rc9334b1 349 349 int lock; 350 350 int dotsend; 351 int echochar; 351 352 } owl_editwin; 352 353
Note: See TracChangeset
for help on using the changeset viewer.