1 /* $OpenBSD: frm_data.c,v 1.6 2001/01/22 18:02:14 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998,2000 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 * 33 ****************************************************************************/ 34 35 #include "form.priv.h" 36 37 MODULE_ID("$From: frm_data.c,v 1.7 2000/12/10 02:09:38 tom Exp $") 38 39 /*--------------------------------------------------------------------------- 40 | Facility : libnform 41 | Function : bool data_behind(const FORM *form) 42 | 43 | Description : Check for off-screen data behind. This is nearly trivial 44 | becose the begin of a field is fixed. 45 | 46 | Return Values : TRUE - there are off-screen data behind 47 | FALSE - there are no off-screen data behind 48 +--------------------------------------------------------------------------*/ 49 NCURSES_EXPORT(bool) 50 data_behind (const FORM *form) 51 { 52 bool result = FALSE; 53 54 if (form && (form->status & _POSTED) && form->current) 55 { 56 FIELD *field; 57 58 field = form->current; 59 if (!Single_Line_Field(field)) 60 { 61 result = (form->toprow==0) ? FALSE : TRUE; 62 } 63 else 64 { 65 result = (form->begincol==0) ? FALSE : TRUE; 66 } 67 } 68 return(result); 69 } 70 71 /*--------------------------------------------------------------------------- 72 | Facility : libnform 73 | Function : static char * After_Last_Non_Pad_Position( 74 | char *buffer, 75 | int len, 76 | int pad) 77 | 78 | Description : Find the last position in the buffer that doesn't 79 | contain a padding character. 80 | 81 | Return Values : The pointer to this position 82 +--------------------------------------------------------------------------*/ 83 INLINE 84 static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad) 85 { 86 char *end = buffer + len; 87 88 assert(buffer && len>=0); 89 while ( (buffer < end) && (*(end-1)==pad) ) 90 end--; 91 92 return end; 93 } 94 95 #define SMALL_BUFFER_SIZE (80) 96 97 /*--------------------------------------------------------------------------- 98 | Facility : libnform 99 | Function : bool data_ahead(const FORM *form) 100 | 101 | Description : Check for off-screen data ahead. This is more difficult 102 | because a dynamic field has a variable end. 103 | 104 | Return Values : TRUE - there are off-screen data ahead 105 | FALSE - there are no off-screen data ahead 106 +--------------------------------------------------------------------------*/ 107 NCURSES_EXPORT(bool) 108 data_ahead (const FORM *form) 109 { 110 bool result = FALSE; 111 112 if (form && (form->status & _POSTED) && form->current) 113 { 114 static char buffer[SMALL_BUFFER_SIZE + 1]; 115 FIELD *field; 116 bool large_buffer; 117 bool cursor_moved = FALSE; 118 char *bp; 119 char *found_content; 120 int pos; 121 122 field = form->current; 123 assert(form->w); 124 125 large_buffer = (field->cols > SMALL_BUFFER_SIZE); 126 if (large_buffer) 127 bp = (char *)malloc((size_t)(field->cols) + 1); 128 else 129 bp = buffer; 130 131 assert(bp); 132 133 if (Single_Line_Field(field)) 134 { 135 int check_len; 136 137 pos = form->begincol + field->cols; 138 while (pos < field->dcols) 139 { 140 check_len = field->dcols - pos; 141 if ( check_len >= field->cols ) 142 check_len = field->cols; 143 cursor_moved = TRUE; 144 wmove(form->w,0,pos); 145 winnstr(form->w,bp,check_len); 146 found_content = 147 After_Last_Non_Pad_Position(bp,check_len,field->pad); 148 if (found_content==bp) 149 pos += field->cols; 150 else 151 { 152 result = TRUE; 153 break; 154 } 155 } 156 } 157 else 158 { 159 pos = form->toprow + field->rows; 160 while (pos < field->drows) 161 { 162 cursor_moved = TRUE; 163 wmove(form->w,pos,0); 164 pos++; 165 winnstr(form->w,bp,field->cols); 166 found_content = 167 After_Last_Non_Pad_Position(bp,field->cols,field->pad); 168 if (found_content!=bp) 169 { 170 result = TRUE; 171 break; 172 } 173 } 174 } 175 176 if (large_buffer) 177 free(bp); 178 179 if (cursor_moved) 180 wmove(form->w,form->currow,form->curcol); 181 } 182 return(result); 183 } 184 185 /* frm_data.c ends here */ 186