| 1 |
.\"*************************************************************************** |
| 2 |
.\" Copyright 2018-2024,2025 Thomas E. Dickey * |
| 3 |
.\" Copyright 1998-2006,2010 Free Software Foundation, Inc. * |
| 4 |
.\" * |
| 5 |
.\" Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 |
.\" copy of this software and associated documentation files (the * |
| 7 |
.\" "Software"), to deal in the Software without restriction, including * |
| 8 |
.\" without limitation the rights to use, copy, modify, merge, publish, * |
| 9 |
.\" distribute, distribute with modifications, sublicense, and/or sell * |
| 10 |
.\" copies of the Software, and to permit persons to whom the Software is * |
| 11 |
.\" furnished to do so, subject to the following conditions: * |
| 12 |
.\" * |
| 13 |
.\" The above copyright notice and this permission notice shall be included * |
| 14 |
.\" in all copies or substantial portions of the Software. * |
| 15 |
.\" * |
| 16 |
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 |
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 |
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 |
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 |
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 |
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 |
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 |
.\" * |
| 24 |
.\" Except as contained in this notice, the name(s) of the above copyright * |
| 25 |
.\" holders shall not be used in advertising or otherwise to promote the * |
| 26 |
.\" sale, use or other dealings in this Software without prior written * |
| 27 |
.\" authorization. * |
| 28 |
.\"*************************************************************************** |
| 29 |
.\" |
| 30 |
.\" $Id: form_fieldtype.3x,v 1.51 2025/01/19 00:51:10 tom Exp $ |
| 31 |
.TH fieldtype 3FORM 2025-01-18 "ncurses 6.6" "Library calls" |
| 32 |
.ie \n(.g \{\ |
| 33 |
.ds `` \(lq |
| 34 |
.ds '' \(rq |
| 35 |
.\} |
| 36 |
.el \{\ |
| 37 |
.ie t .ds `` `` |
| 38 |
.el .ds `` "" |
| 39 |
.ie t .ds '' '' |
| 40 |
.el .ds '' "" |
| 41 |
.\} |
| 42 |
. |
| 43 |
.de bP |
| 44 |
.ie n .IP \(bu 4 |
| 45 |
.el .IP \(bu 2 |
| 46 |
.. |
| 47 |
.SH NAME |
| 48 |
\fBform_fieldtype\fP \- |
| 49 |
define validation-field types |
| 50 |
.SH SYNOPSIS |
| 51 |
.nf |
| 52 |
\fB#include <form.h> |
| 53 |
.PP |
| 54 |
\fBFIELDTYPE *new_fieldtype( |
| 55 |
\fBbool (* const \fIfield_check\fB)(FIELD *, const void *),\fR |
| 56 |
\fBbool (* const \fIchar_check\fB)(int, const void *));\fR |
| 57 |
\fBint free_fieldtype(FIELDTYPE *\fIfieldtype\fB);\fR |
| 58 |
.PP |
| 59 |
\fBint set_fieldtype_arg(\fP |
| 60 |
\fBFIELDTYPE *\fIfieldtype\fB,\fR |
| 61 |
\fBvoid *(* const \fImake_arg\fB)(va_list *),\fR |
| 62 |
\fBvoid *(* const \fIcopy_arg\fB)(const void *),\fR |
| 63 |
\fBvoid (* const \fIfree_arg\fB)(void *));\fR |
| 64 |
\fBint set_fieldtype_choice(\fP |
| 65 |
\fBFIELDTYPE *\fIfieldtype\fB,\fR |
| 66 |
\fBbool (* const \fInext_choice\fB)(FIELD *, const void *),\fR |
| 67 |
\fBbool (* const \fIprev_choice\fB)(FIELD *, const void *));\fR |
| 68 |
.PP |
| 69 |
\fBFIELDTYPE *link_fieldtype(FIELDTYPE *\fItype1\fB,\fR |
| 70 |
\fBFIELDTYPE *\fItype2\fB);\fR |
| 71 |
.fi |
| 72 |
.SH DESCRIPTION |
| 73 |
.SS new_fieldtype |
| 74 |
The function \fBnew_fieldtype\fP creates a new field type usable for data |
| 75 |
validation. |
| 76 |
Its parameters are function pointers: |
| 77 |
.TP 5 |
| 78 |
\fIfield_check\fP |
| 79 |
This function checks the |
| 80 |
validity of an entered data string whenever the user attempts to leave a field. |
| 81 |
It has two arguments: |
| 82 |
.RS |
| 83 |
.bP |
| 84 |
The (FIELD *) argument is passed in so the validation predicate can see the |
| 85 |
field's buffer, sizes and other attributes. |
| 86 |
.bP |
| 87 |
The second argument is an |
| 88 |
argument-block structure, about which more below. |
| 89 |
.RE |
| 90 |
.TP 5 |
| 91 |
\fIchar_check\fP |
| 92 |
This function validates input characters as they are entered. |
| 93 |
The form library passes it the character to be checked |
| 94 |
and a pointer to an argument-block structure. |
| 95 |
.SS free_fieldtype |
| 96 |
The \fBfree_fieldtype\fP function |
| 97 |
frees the space allocated for a given validation type by \fBnew_fieldtype\fP. |
| 98 |
.SS set_fieldtype_arg |
| 99 |
The function \fBset_fieldtype_arg\fP associates |
| 100 |
three storage-management functions with a field type: |
| 101 |
.TP 5 |
| 102 |
\fImake_arg\fP |
| 103 |
This function is automatically applied to the |
| 104 |
list of arguments you give \fBset_field_type\fP when attaching validation |
| 105 |
to a field. |
| 106 |
It stores the arguments in an allocated argument-block |
| 107 |
object which is used when validating input. |
| 108 |
.TP 5 |
| 109 |
\fIcopy_arg\fP |
| 110 |
This function may be used by applications to copy argument-blocks. |
| 111 |
.TP 5 |
| 112 |
\fIfree_arg\fP |
| 113 |
Frees an argument-block structure. |
| 114 |
.PP |
| 115 |
You must supply the \fImake_arg\fP function. |
| 116 |
The other two are optional: you may supply |
| 117 |
.I NULL |
| 118 |
for them. |
| 119 |
In this case, the form library assumes |
| 120 |
that \fImake_arg\fP does not allocate memory but simply loads the |
| 121 |
argument into a single scalar value. |
| 122 |
.SS set_fieldtype_choice |
| 123 |
The form driver requests \fBREQ_NEXT_CHOICE\fP and \fBREQ_PREV_CHOICE\fP assume |
| 124 |
that the possible values of a field form an ordered set, and provide the forms |
| 125 |
user with a way to move through the set. |
| 126 |
.PP |
| 127 |
The \fBset_fieldtype_choice\fP |
| 128 |
function allows forms programmers to define successor and predecessor functions |
| 129 |
for the field type. |
| 130 |
These functions take the field pointer and an |
| 131 |
argument-block structure as arguments. |
| 132 |
.SS link_fieldtype |
| 133 |
The function \fBlink_fieldtype\fP creates |
| 134 |
a new field type from the two given types. |
| 135 |
They are connected by a logical \*(``or\*(''. |
| 136 |
.SH RETURN VALUE |
| 137 |
The pointer-valued routines return NULL on error. |
| 138 |
They set \fBerrno\fP according to their success: |
| 139 |
.TP 5 |
| 140 |
.B E_OK |
| 141 |
The routine succeeded. |
| 142 |
.TP 5 |
| 143 |
.B E_BAD_ARGUMENT |
| 144 |
Routine detected an incorrect or out-of-range argument. |
| 145 |
.TP 5 |
| 146 |
.B E_SYSTEM_ERROR |
| 147 |
System error occurred, e.g., malloc failure. |
| 148 |
.PP |
| 149 |
The integer-valued routines return one of the following codes on |
| 150 |
error: |
| 151 |
.TP 5 |
| 152 |
.B E_OK |
| 153 |
The routine succeeded. |
| 154 |
.TP 5 |
| 155 |
.B E_BAD_ARGUMENT |
| 156 |
Routine detected an incorrect or out-of-range argument. |
| 157 |
.TP 5 |
| 158 |
.B E_CONNECTED |
| 159 |
The field is already connected to a form. |
| 160 |
.TP 5 |
| 161 |
.B E_CURRENT |
| 162 |
The field is the current field. |
| 163 |
.TP 5 |
| 164 |
.B E_SYSTEM_ERROR |
| 165 |
System error occurred (see \fBerrno\fP(3)). |
| 166 |
.SH PORTABILITY |
| 167 |
These routines emulate the System V forms library. |
| 168 |
They were not supported on |
| 169 |
Version 7 or BSD versions. |
| 170 |
.SH AUTHORS |
| 171 |
Juergen Pfeifer. |
| 172 |
Manual pages and adaptation for new curses by Eric S. Raymond. |
| 173 |
.SH SEE ALSO |
| 174 |
\fB\%ncurses\fP(3NCURSES), |
| 175 |
\fB\%form\fP(3FORM), |
| 176 |
\fB\%field_validation\fP(3FORM) |