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