xref: /netbsd-src/lib/libform/forms.3 (revision 01869ca4d24a86379a68731bf9706a9f0820fe4e)
1*01869ca4Swiz.\"	$NetBSD: forms.3,v 1.17 2017/07/03 21:32:50 wiz Exp $
2e1a3174bSblymn.\"
3e1a3174bSblymn.\" Copyright (c) 2001
4e1a3174bSblymn.\"	Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
5e1a3174bSblymn.\"
6e1a3174bSblymn.\" This code is donated to The NetBSD Foundation by the author.
7e1a3174bSblymn.\"
8e1a3174bSblymn.\" Redistribution and use in source and binary forms, with or without
9e1a3174bSblymn.\" modification, are permitted provided that the following conditions
10e1a3174bSblymn.\" are met:
11e1a3174bSblymn.\" 1. Redistributions of source code must retain the above copyright
12e1a3174bSblymn.\"    notice, this list of conditions and the following disclaimer.
13e1a3174bSblymn.\" 2. Redistributions in binary form must reproduce the above copyright
14e1a3174bSblymn.\"    notice, this list of conditions and the following disclaimer in the
15e1a3174bSblymn.\"    documentation and/or other materials provided with the distribution.
16e1a3174bSblymn.\" 3. The name of the Author may not be used to endorse or promote
17e1a3174bSblymn.\"    products derived from this software without specific prior written
18e1a3174bSblymn.\"    permission.
19e1a3174bSblymn.\"
20e1a3174bSblymn.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
21e1a3174bSblymn.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22e1a3174bSblymn.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23e1a3174bSblymn.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
24e1a3174bSblymn.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25e1a3174bSblymn.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26e1a3174bSblymn.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27e1a3174bSblymn.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28e1a3174bSblymn.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29e1a3174bSblymn.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30e1a3174bSblymn.\" SUCH DAMAGE.
31e1a3174bSblymn.\"
32a7804596Swiz.Dd November 24, 2004
33e1a3174bSblymn.Dt FORMS 3
34e1a3174bSblymn.Os
35e1a3174bSblymn.Sh NAME
36e1a3174bSblymn.Nm form
37e1a3174bSblymn.Nd form library
38e1a3174bSblymn.Sh LIBRARY
39e1a3174bSblymn.Lb libform
40e1a3174bSblymn.Sh SYNOPSIS
41472351e1Swiz.In form.h
42e1a3174bSblymn.Sh DESCRIPTION
43e1a3174bSblymnThe
44b454907bSwiz.Nm
45f8d84962Swizlibrary provides a terminal independent form system using the
46e1a3174bSblymn.Xr curses 3
4703c12ea0Swizlibrary.
4803c12ea0SwizBefore using the
49f8d84962Swiz.Nm
50e1a3174bSblymnfunctions the terminal must be set up by
51e1a3174bSblymn.Xr curses 3
52e1a3174bSblymnusing the
53e1a3174bSblymn.Fn initscr
5403c12ea0Swizfunction or similar.
5503c12ea0SwizPrograms using
56b454907bSwiz.Nm
57e1a3174bSblymnfunctions must be linked with the
58e1a3174bSblymn.Xr curses 3
59e1a3174bSblymnlibrary
60b454907bSwiz.Fl lcurses .
61e1a3174bSblymn.Pp
62e1a3174bSblymnThe
63b454907bSwiz.Nm
64f8d84962Swizlibrary provides facilities for defining form fields, placing a form on the
65e1a3174bSblymnterminal screen, assign pre and post change operations and setting the
66f8d84962Swizattributes of both the form and its fields.
67b454907bSwiz.Ss Defining default attributes for forms and fields
68e1a3174bSblymnThe
69b454907bSwiz.Nm
70e1a3174bSblymnlibrary allows any settable attribute or option of both the form and field
71e1a3174bSblymnobjects to be defined such that any new form or field automatically inherits
7203c12ea0Swizthe value as default.
7303c12ea0SwizSetting the default value will not affect any field or
74e1a3174bSblymnform that has already been created but will be applied to subsequent objects.
756cbd2718SwizTo set the default attribute or option the set routine is passed a
766cbd2718Swiz.Dv NULL
7703c12ea0Swizpointer in the field or form parameter when calling the set routine.
7803c12ea0SwizThe current default value can be retrieved by calling the get routine with a
796cbd2718Swiz.Dv NULL
806cbd2718Swizpointer for the field or form parameter.
81e1a3174bSblymn.Pp
826cbd2718Swiz.Bl -column set_fieldtype_choiceXX
836cbd2718Swiz.It Sy "Form Routine Name" Ta Sy "Manual Page Name"
846cbd2718Swiz.It current_field Ta Xr form_page 3
856cbd2718Swiz.It data_ahead Ta Xr form_data 3
866cbd2718Swiz.It data_behind Ta Xr form_data 3
876cbd2718Swiz.It dup_field Ta Xr form_field_new 3
886cbd2718Swiz.It dynamic_field_info Ta Xr form_field_info 3
896cbd2718Swiz.It field_arg Ta Xr form_field_validation 3
906cbd2718Swiz.It field_back Ta Xr form_field_attributes 3
916cbd2718Swiz.It field_buffer Ta Xr form_field_buffer 3
926cbd2718Swiz.It field_count Ta Xr form_field 3
936cbd2718Swiz.It field_fore Ta Xr form_field_attributes 3
946cbd2718Swiz.It field_index Ta Xr form_page 3
956cbd2718Swiz.It field_info Ta Xr form_field_info 3
966cbd2718Swiz.It field_init Ta Xr form_hook 3
976cbd2718Swiz.It field_just Ta Xr form_field_just 3
986cbd2718Swiz.It field_opts Ta Xr form_field_opts 3
996cbd2718Swiz.It field_opts_off Ta Xr form_field_opts 3
1006cbd2718Swiz.It field_opts_on Ta Xr form_field_opts 3
1016cbd2718Swiz.It field_pad Ta Xr form_field_attributes 3
1026cbd2718Swiz.It field_status Ta Xr form_field_buffer 3
1036cbd2718Swiz.It field_term Ta Xr form_hook 3
1046cbd2718Swiz.It field_type Ta Xr form_field_validation 3
1056cbd2718Swiz.It field_userptr Ta Xr form_field_userptr 3
1066cbd2718Swiz.It form_driver Ta Xr form_driver 3
1076cbd2718Swiz.It form_fields Ta Xr form_field 3
1086cbd2718Swiz.It form_init Ta Xr form_hook 3
1096cbd2718Swiz.It form_max_page Ta Xr form_page 3
1106cbd2718Swiz.It form_opts Ta Xr form_opts 3
1116cbd2718Swiz.It form_opts_off Ta Xr form_opts 3
1126cbd2718Swiz.It form_opts_on Ta Xr form_opts 3
1136cbd2718Swiz.It form_page Ta Xr form_page 3
1146cbd2718Swiz.It form_sub Ta Xr form_win 3
1156cbd2718Swiz.It form_term Ta Xr form_hook 3
1166cbd2718Swiz.It form_userptr Ta Xr form_userptr 3
1176cbd2718Swiz.It form_win Ta Xr form_win 3
1186cbd2718Swiz.It free_field Ta Xr form_field_new 3
1196cbd2718Swiz.It free_fieldtype Ta Xr form_fieldtype 3
1206cbd2718Swiz.It free_form Ta Xr form_new 3
1216cbd2718Swiz.It link_field Ta Xr form_field_new 3
1226cbd2718Swiz.It link_fieldtype Ta Xr form_fieldtype 3
1236cbd2718Swiz.It move_field Ta Xr form_field 3
1246cbd2718Swiz.It new_field Ta Xr form_field_new 3
1256cbd2718Swiz.It new_fieldtype Ta Xr form_fieldtype 3
1266cbd2718Swiz.It new_form Ta Xr form_new 3
1276cbd2718Swiz.It new_page Ta Xr form_new_page 3
1286cbd2718Swiz.It pos_form_cursor Ta Xr form_cursor 3
1296cbd2718Swiz.It post_form Ta Xr form_post 3
1306cbd2718Swiz.It scale_form Ta Xr form_win 3
1316cbd2718Swiz.It set_current_field Ta Xr form_page 3
1326cbd2718Swiz.It set_field_back Ta Xr form_field_attributes 3
1336cbd2718Swiz.It set_field_buffer Ta Xr form_field_buffer 3
1346cbd2718Swiz.It set_field_fore Ta Xr form_field_attributes 3
1356cbd2718Swiz.It set_field_init Ta Xr form_hook 3
1366cbd2718Swiz.It set_field_just Ta Xr form_field_just 3
1376cbd2718Swiz.It set_field_opts Ta Xr form_field_opts 3
1386cbd2718Swiz.It set_field_pad Ta Xr form_field_attributes 3
1396cbd2718Swiz.It set_field_printf Ta Xr form_field_buffer 3
1406cbd2718Swiz.It set_field_status Ta Xr form_field_buffer 3
1416cbd2718Swiz.It set_field_term Ta Xr form_hook 3
1426cbd2718Swiz.It set_field_type Ta Xr form_field_validation 3
1436cbd2718Swiz.It set_field_userptr Ta Xr form_field_userptr 3
1446cbd2718Swiz.It set_fieldtype_arg Ta Xr form_fieldtype 3
1456cbd2718Swiz.It set_fieldtype_choice Ta Xr form_fieldtype 3
1466cbd2718Swiz.It set_form_fields Ta Xr form_field 3
1476cbd2718Swiz.It set_form_init Ta Xr form_hook 3
1486cbd2718Swiz.It set_form_opts Ta Xr form_opts 3
1496cbd2718Swiz.It set_form_page Ta Xr form_page 3
1506cbd2718Swiz.It set_form_sub Ta Xr form_win 3
1516cbd2718Swiz.It set_form_term Ta Xr form_hook 3
1526cbd2718Swiz.It set_form_userptr Ta Xr form_userptr 3
1536cbd2718Swiz.It set_form_win Ta Xr form_win 3
1546cbd2718Swiz.It set_max_field Ta Xr form_field_buffer 3
1556cbd2718Swiz.It set_new_page Ta Xr form_new_page 3
1566cbd2718Swiz.It unpost_form Ta Xr form_post 3
1576cbd2718Swiz.El
158e1a3174bSblymn.Sh RETURN VALUES
1596cbd2718SwizAny function returning a string pointer will return
1606cbd2718Swiz.Dv NULL
1616cbd2718Swizif an error occurs.
16203c12ea0SwizFunctions returning an integer will return one of the following:
1636cbd2718Swiz.Bl -column set_fieldtype_choiceXX
1646cbd2718Swiz.It Dv E_OK Ta No The function was successful.
1656cbd2718Swiz.It Dv E_SYSTEM_ERROR Ta No There was a system error during the call.
1666cbd2718Swiz.It Dv E_BAD_ARGUMENT Ta No One or more of the arguments passed to \
1676cbd2718Swizthe function was incorrect.
1686cbd2718Swiz.It Dv E_POSTED Ta No The form is already posted.
1696cbd2718Swiz.It Dv E_CONNECTED Ta No A field was already connected to a form.
1706cbd2718Swiz.It Dv E_BAD_STATE Ta No The function was called from within an \
1716cbd2718Swizinitialization or termination routine.
1726cbd2718Swiz.It Dv E_NO_ROOM Ta No The form does not fit within the subwindow.
1736cbd2718Swiz.It Dv E_NOT_POSTED Ta No The form is not posted.
1746cbd2718Swiz.It Dv E_UNKNOWN_COMMAND Ta No The form driver does not recognize the \
1756cbd2718Swizrequest passed to it.
1766cbd2718Swiz.It Dv E_NOT_SELECTABLE Ta No The field could not be selected.
1776cbd2718Swiz.It Dv E_NOT_CONNECTED Ta No The field is not connected to a form.
1786cbd2718Swiz.It Dv E_REQUEST_DENIED Ta No The form driver could not process the request.
1796cbd2718Swiz.It Dv E_INVALID_FIELD Ta No The field is invalid.
1806cbd2718Swiz.It Dv E_CURRENT Ta No The field is the active one on the form.
1816cbd2718Swiz.El
182e1a3174bSblymn.Sh SEE ALSO
183b454907bSwiz.Xr curses 3 ,
184b454907bSwiz.Xr menus 3
185d70e5167Sblymn.Sh NOTES
186c286c475SperryThis implementation of the forms library does depart in behavior
187*01869ca4Swizsubtly from the original AT&T implementation.
18803c12ea0SwizSome of the more notable departures are:
189d70e5167Sblymn.Pp
190293fb86aSkim.Bl -tag -width "The TAB character" -compact
191d70e5167Sblymn.It field wrapping
192c286c475SperryFor multi-line fields the data will be wrapped as it is entered, this
193*01869ca4Swizdoes not happen in the AT&T implementation.
194d70e5167Sblymn.It buffer 0
195d70e5167SblymnIn this implementation, the contents of buffer 0 are always current
196d70e5167Sblymnregardless of whether the field has been validated or not.
197d70e5167Sblymn.It circular fields
198*01869ca4SwizIn the AT&T implementation fields are circular on a page, that is, a
199d70e5167Sblymnnext field from the last field will go to the first field on the
200c286c475Sperrycurrent page.
20103c12ea0SwizIn this implementation a next field request on the last
202d70e5167Sblymnfield of a page will result in the forms library positioning the
20303c12ea0Swizcursor on the first field of the next page.
20403c12ea0SwizIf the field is the last
205d70e5167Sblymnfield in the form then going to the next field will be denied, in the
206*01869ca4SwizAT&T it would result in the cursor being placed on the first field of
207d70e5167Sblymnthe first page.
208d70e5167Sblymn.It buffer returns
209d70e5167SblymnIn this implementation only the data entered by the user in the form
210*01869ca4Swizfield will be returned, unlike the AT&T library which would return the
211d70e5167Sblymncontents of the field padded to the size of the field with the pad
212d70e5167Sblymncharacter.
213759e545dSblymn.It The TAB character
214759e545dSblymnThe handling of the TAB character in fields varies between
21503c12ea0Swizimplementations.
21603c12ea0SwizIn ncurses attempting to set a field contents with a
217759e545dSblymnstring containing a TAB will result in an error and will not allow a
21803c12ea0SwizTAB to be entered into a field.
219*01869ca4SwizThe AT&T library statically
220759e545dSblymnconverts tabs to the equivalent number of spaces when the field buffer
221759e545dSblymnis set but the form driver will not allow a TAB to be inserted into
22203c12ea0Swizthe field buffer.
22303c12ea0SwizThis implementation allows TAB when setting the
224759e545dSblymnfield buffer and also will allow TAB to be inserted into a field
225759e545dSblymnbuffer via the form driver and correctly calculates the cursor
226759e545dSblymnposition allowing for expansion of the TAB character.
227c4f23a93Sblymn.It set_field_printf
2286cbd2718SwizThis function is a
2296cbd2718Swiz.Nx
2306cbd2718Swizextension and must not be used in portable code.
231a7804596Swiz.It Dv O_REFORMAT
23219f07fb2SblymnThis field option is a
23319f07fb2Sblymn.Nx
23419f07fb2Sblymnextension and must not be used in portable code.
235d70e5167Sblymn.El
236