refresh.c (84334) | refresh.c (148834) |
---|---|
1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. | 1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. |
16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors | 16 * 3. Neither the name of the University nor the names of its contributors |
21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * | 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
36 * $NetBSD: refresh.c,v 1.16 2001/01/10 07:45:42 jdolecek Exp $ | 32 * $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ |
37 */ 38 39#if !defined(lint) && !defined(SCCSID) 40static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; 41#endif /* not lint && not SCCSID */ 42#include <sys/cdefs.h> | 33 */ 34 35#if !defined(lint) && !defined(SCCSID) 36static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; 37#endif /* not lint && not SCCSID */ 38#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/lib/libedit/refresh.c 84334 2001-10-01 23:00:29Z obrien $"); | 39__FBSDID("$FreeBSD: head/lib/libedit/refresh.c 148834 2005-08-07 20:55:59Z stefanf $"); |
44 45/* 46 * refresh.c: Lower level screen refreshing functions 47 */ 48#include "sys.h" 49#include <stdio.h> | 40 41/* 42 * refresh.c: Lower level screen refreshing functions 43 */ 44#include "sys.h" 45#include <stdio.h> |
46#include <ctype.h> |
|
50#include <unistd.h> 51#include <string.h> 52 53#include "el.h" 54 55private void re_addc(EditLine *, int); 56private void re_update_line(EditLine *, char *, char *, int); 57private void re_insert (EditLine *, char *, int, int, char *, int); 58private void re_delete(EditLine *, char *, int, int, int); 59private void re_fastputc(EditLine *, int); 60private void re__strncopy(char *, char *, size_t); | 47#include <unistd.h> 48#include <string.h> 49 50#include "el.h" 51 52private void re_addc(EditLine *, int); 53private void re_update_line(EditLine *, char *, char *, int); 54private void re_insert (EditLine *, char *, int, int, char *, int); 55private void re_delete(EditLine *, char *, int, int, int); 56private void re_fastputc(EditLine *, int); 57private void re__strncopy(char *, char *, size_t); |
61private void re__copy_and_pad(char *, char *, size_t); | 58private void re__copy_and_pad(char *, const char *, size_t); |
62 63#ifdef DEBUG_REFRESH | 59 60#ifdef DEBUG_REFRESH |
64private void re_printstr(EditLine *, char *, char *, char *); | 61private void re_printstr(EditLine *, const char *, char *, char *); |
65#define __F el->el_errfile 66#define ELRE_ASSERT(a, b, c) do \ | 62#define __F el->el_errfile 63#define ELRE_ASSERT(a, b, c) do \ |
67 if (a) { \ | 64 if (/*CONSTCOND*/ a) { \ |
68 (void) fprintf b; \ 69 c; \ 70 } \ | 65 (void) fprintf b; \ 66 c; \ 67 } \ |
71 while (0) | 68 while (/*CONSTCOND*/0) |
72#define ELRE_DEBUG(a, b) ELRE_ASSERT(a,b,;) 73 74/* re_printstr(): 75 * Print a string on the debugging pty 76 */ 77private void | 69#define ELRE_DEBUG(a, b) ELRE_ASSERT(a,b,;) 70 71/* re_printstr(): 72 * Print a string on the debugging pty 73 */ 74private void |
78re_printstr(EditLine *el, char *str, char *f, char *t) | 75re_printstr(EditLine *el, const char *str, char *f, char *t) |
79{ 80 81 ELRE_DEBUG(1, (__F, "%s:\"", str)); 82 while (f < t) 83 ELRE_DEBUG(1, (__F, "%c", *f++ & 0177)); 84 ELRE_DEBUG(1, (__F, "\"\r\n")); 85} 86#else --- 4 unchanged lines hidden (view full) --- 91 92/* re_addc(): 93 * Draw c, expanding tabs, control chars etc. 94 */ 95private void 96re_addc(EditLine *el, int c) 97{ 98 | 76{ 77 78 ELRE_DEBUG(1, (__F, "%s:\"", str)); 79 while (f < t) 80 ELRE_DEBUG(1, (__F, "%c", *f++ & 0177)); 81 ELRE_DEBUG(1, (__F, "\"\r\n")); 82} 83#else --- 4 unchanged lines hidden (view full) --- 88 89/* re_addc(): 90 * Draw c, expanding tabs, control chars etc. 91 */ 92private void 93re_addc(EditLine *el, int c) 94{ 95 |
99 c = (unsigned char)c; 100 | |
101 if (isprint(c)) { 102 re_putc(el, c, 1); 103 return; 104 } 105 if (c == '\n') { /* expand the newline */ 106 int oldv = el->el_refresh.r_cursor.v; 107 re_putc(el, '\0', 0); /* assure end of line */ 108 if (oldv == el->el_refresh.r_cursor.v) { /* XXX */ --- 94 unchanged lines hidden (view full) --- 203 204 /* temporarily draw rprompt to calculate its size */ 205 prompt_print(el, EL_RPROMPT); 206 207 /* reset the Drawing cursor */ 208 el->el_refresh.r_cursor.h = 0; 209 el->el_refresh.r_cursor.v = 0; 210 | 96 if (isprint(c)) { 97 re_putc(el, c, 1); 98 return; 99 } 100 if (c == '\n') { /* expand the newline */ 101 int oldv = el->el_refresh.r_cursor.v; 102 re_putc(el, '\0', 0); /* assure end of line */ 103 if (oldv == el->el_refresh.r_cursor.v) { /* XXX */ --- 94 unchanged lines hidden (view full) --- 198 199 /* temporarily draw rprompt to calculate its size */ 200 prompt_print(el, EL_RPROMPT); 201 202 /* reset the Drawing cursor */ 203 el->el_refresh.r_cursor.h = 0; 204 el->el_refresh.r_cursor.v = 0; 205 |
206 if (el->el_line.cursor >= el->el_line.lastchar) { 207 if (el->el_map.current == el->el_map.alt 208 && el->el_line.lastchar != el->el_line.buffer) 209 el->el_line.cursor = el->el_line.lastchar - 1; 210 else 211 el->el_line.cursor = el->el_line.lastchar; 212 } 213 |
|
211 cur.h = -1; /* set flag in case I'm not set */ 212 cur.v = 0; 213 214 prompt_print(el, EL_PROMPT); 215 216 /* draw the current input buffer */ 217#if notyet 218 termsz = el->el_term.t_size.h * el->el_term.t_size.v; --- 93 unchanged lines hidden (view full) --- 312/* re_goto_bottom(): 313 * used to go to last used screen line 314 */ 315protected void 316re_goto_bottom(EditLine *el) 317{ 318 319 term_move_to_line(el, el->el_refresh.r_oldcv); | 214 cur.h = -1; /* set flag in case I'm not set */ 215 cur.v = 0; 216 217 prompt_print(el, EL_PROMPT); 218 219 /* draw the current input buffer */ 220#if notyet 221 termsz = el->el_term.t_size.h * el->el_term.t_size.v; --- 93 unchanged lines hidden (view full) --- 315/* re_goto_bottom(): 316 * used to go to last used screen line 317 */ 318protected void 319re_goto_bottom(EditLine *el) 320{ 321 322 term_move_to_line(el, el->el_refresh.r_oldcv); |
320 term__putc('\r'); | |
321 term__putc('\n'); 322 re_clear_display(el); 323 term__flush(); 324} 325 326 327/* re_insert(): 328 * insert num characters of s into d (in front of the character) 329 * at dat, maximum length of d is dlen 330 */ 331private void 332/*ARGSUSED*/ | 323 term__putc('\n'); 324 re_clear_display(el); 325 term__flush(); 326} 327 328 329/* re_insert(): 330 * insert num characters of s into d (in front of the character) 331 * at dat, maximum length of d is dlen 332 */ 333private void 334/*ARGSUSED*/ |
333re_insert(EditLine *el, char *d, int dat, int dlen, char *s, int num) | 335re_insert(EditLine *el __unused, 336 char *d, int dat, int dlen, char *s, int num) |
334{ 335 char *a, *b; 336 337 if (num <= 0) 338 return; 339 if (num > dlen - dat) 340 num = dlen - dat; 341 --- 26 unchanged lines hidden (view full) --- 368} 369 370 371/* re_delete(): 372 * delete num characters d at dat, maximum length of d is dlen 373 */ 374private void 375/*ARGSUSED*/ | 337{ 338 char *a, *b; 339 340 if (num <= 0) 341 return; 342 if (num > dlen - dat) 343 num = dlen - dat; 344 --- 26 unchanged lines hidden (view full) --- 371} 372 373 374/* re_delete(): 375 * delete num characters d at dat, maximum length of d is dlen 376 */ 377private void 378/*ARGSUSED*/ |
376re_delete(EditLine *el, char *d, int dat, int dlen, int num) | 379re_delete(EditLine *el __unused, 380 char *d, int dat, int dlen, int num) |
377{ 378 char *a, *b; 379 380 if (num <= 0) 381 return; 382 if (dat + num >= dlen) { 383 d[dat] = '\0'; 384 return; --- 516 unchanged lines hidden (view full) --- 901 ELRE_DEBUG(1, (__F, "done.\r\n")); 902} 903 904 905/* re__copy_and_pad(): 906 * Copy string and pad with spaces 907 */ 908private void | 381{ 382 char *a, *b; 383 384 if (num <= 0) 385 return; 386 if (dat + num >= dlen) { 387 d[dat] = '\0'; 388 return; --- 516 unchanged lines hidden (view full) --- 905 ELRE_DEBUG(1, (__F, "done.\r\n")); 906} 907 908 909/* re__copy_and_pad(): 910 * Copy string and pad with spaces 911 */ 912private void |
909re__copy_and_pad(char *dst, char *src, size_t width) | 913re__copy_and_pad(char *dst, const char *src, size_t width) |
910{ | 914{ |
911 int i; | 915 size_t i; |
912 913 for (i = 0; i < width; i++) { 914 if (*src == '\0') 915 break; 916 *dst++ = *src++; 917 } 918 919 for (; i < width; i++) --- 7 unchanged lines hidden (view full) --- 927 * Move to the new cursor position 928 */ 929protected void 930re_refresh_cursor(EditLine *el) 931{ 932 char *cp, c; 933 int h, v, th; 934 | 916 917 for (i = 0; i < width; i++) { 918 if (*src == '\0') 919 break; 920 *dst++ = *src++; 921 } 922 923 for (; i < width; i++) --- 7 unchanged lines hidden (view full) --- 931 * Move to the new cursor position 932 */ 933protected void 934re_refresh_cursor(EditLine *el) 935{ 936 char *cp, c; 937 int h, v, th; 938 |
939 if (el->el_line.cursor >= el->el_line.lastchar) { 940 if (el->el_map.current == el->el_map.alt 941 && el->el_line.lastchar != el->el_line.buffer) 942 el->el_line.cursor = el->el_line.lastchar - 1; 943 else 944 el->el_line.cursor = el->el_line.lastchar; 945 } 946 |
|
935 /* first we must find where the cursor is... */ 936 h = el->el_prompt.p_pos.h; 937 v = el->el_prompt.p_pos.v; 938 th = el->el_term.t_size.h; /* optimize for speed */ 939 940 /* do input buffer to el->el_line.cursor */ 941 for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) { | 947 /* first we must find where the cursor is... */ 948 h = el->el_prompt.p_pos.h; 949 v = el->el_prompt.p_pos.v; 950 th = el->el_term.t_size.h; /* optimize for speed */ 951 952 /* do input buffer to el->el_line.cursor */ 953 for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) { |
942 c = (unsigned char)*cp; | 954 c = *cp; |
943 h++; /* all chars at least this long */ 944 945 if (c == '\n') {/* handle newline in data part too */ 946 h = 0; 947 v++; 948 } else { 949 if (c == '\t') { /* if a tab, to next tab stop */ 950 while (h & 07) { --- 98 unchanged lines hidden (view full) --- 1049 if (iscntrl((unsigned char) c)) { /* if control char, do caret */ 1050 char mc = (c == 0177) ? '?' : (toascii(c) | 0100); 1051 re_fastputc(el, '^'); 1052 re_fastputc(el, mc); 1053 } else if (isprint((unsigned char) c)) { /* normal char */ 1054 re_fastputc(el, c); 1055 } else { 1056 re_fastputc(el, '\\'); | 955 h++; /* all chars at least this long */ 956 957 if (c == '\n') {/* handle newline in data part too */ 958 h = 0; 959 v++; 960 } else { 961 if (c == '\t') { /* if a tab, to next tab stop */ 962 while (h & 07) { --- 98 unchanged lines hidden (view full) --- 1061 if (iscntrl((unsigned char) c)) { /* if control char, do caret */ 1062 char mc = (c == 0177) ? '?' : (toascii(c) | 0100); 1063 re_fastputc(el, '^'); 1064 re_fastputc(el, mc); 1065 } else if (isprint((unsigned char) c)) { /* normal char */ 1066 re_fastputc(el, c); 1067 } else { 1068 re_fastputc(el, '\\'); |
1057 re_fastputc(el, (int) ((((unsigned int) c >> 6) & 7) + '0')); 1058 re_fastputc(el, (int) ((((unsigned int) c >> 3) & 7) + '0')); | 1069 re_fastputc(el, (int)(((((unsigned int)c) >> 6) & 3) + '0')); 1070 re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0')); |
1059 re_fastputc(el, (c & 7) + '0'); 1060 } 1061 term__flush(); 1062} 1063 1064 1065/* re_clear_display(): 1066 * clear the screen buffers so that new new prompt starts fresh. --- 37 unchanged lines hidden --- | 1071 re_fastputc(el, (c & 7) + '0'); 1072 } 1073 term__flush(); 1074} 1075 1076 1077/* re_clear_display(): 1078 * clear the screen buffers so that new new prompt starts fresh. --- 37 unchanged lines hidden --- |