1.\" $NetBSD: forms.3,v 1.16 2004/11/24 12:09:13 wiz Exp $ 2.\" 3.\" Copyright (c) 2001 4.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au 5.\" 6.\" This code is donated to The NetBSD Foundation by the author. 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. The name of the Author may not be used to endorse or promote 17.\" products derived from this software without specific prior written 18.\" permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.\" 32.Dd November 24, 2004 33.Dt FORMS 3 34.Os 35.Sh NAME 36.Nm form 37.Nd form library 38.Sh LIBRARY 39.Lb libform 40.Sh SYNOPSIS 41.In form.h 42.Sh DESCRIPTION 43The 44.Nm 45library provides a terminal independent form system using the 46.Xr curses 3 47library. 48Before using the 49.Nm 50functions the terminal must be set up by 51.Xr curses 3 52using the 53.Fn initscr 54function or similar. 55Programs using 56.Nm 57functions must be linked with the 58.Xr curses 3 59library 60.Fl lcurses . 61.Pp 62The 63.Nm 64library provides facilities for defining form fields, placing a form on the 65terminal screen, assign pre and post change operations and setting the 66attributes of both the form and its fields. 67.Ss Defining default attributes for forms and fields 68The 69.Nm 70library allows any settable attribute or option of both the form and field 71objects to be defined such that any new form or field automatically inherits 72the value as default. 73Setting the default value will not affect any field or 74form that has already been created but will be applied to subsequent objects. 75To set the default attribute or option the set routine is passed a 76.Dv NULL 77pointer in the field or form parameter when calling the set routine. 78The current default value can be retrieved by calling the get routine with a 79.Dv NULL 80pointer for the field or form parameter. 81.Pp 82.Bl -column set_fieldtype_choiceXX 83.It Sy "Form Routine Name" Ta Sy "Manual Page Name" 84.It current_field Ta Xr form_page 3 85.It data_ahead Ta Xr form_data 3 86.It data_behind Ta Xr form_data 3 87.It dup_field Ta Xr form_field_new 3 88.It dynamic_field_info Ta Xr form_field_info 3 89.It field_arg Ta Xr form_field_validation 3 90.It field_back Ta Xr form_field_attributes 3 91.It field_buffer Ta Xr form_field_buffer 3 92.It field_count Ta Xr form_field 3 93.It field_fore Ta Xr form_field_attributes 3 94.It field_index Ta Xr form_page 3 95.It field_info Ta Xr form_field_info 3 96.It field_init Ta Xr form_hook 3 97.It field_just Ta Xr form_field_just 3 98.It field_opts Ta Xr form_field_opts 3 99.It field_opts_off Ta Xr form_field_opts 3 100.It field_opts_on Ta Xr form_field_opts 3 101.It field_pad Ta Xr form_field_attributes 3 102.It field_status Ta Xr form_field_buffer 3 103.It field_term Ta Xr form_hook 3 104.It field_type Ta Xr form_field_validation 3 105.It field_userptr Ta Xr form_field_userptr 3 106.It form_driver Ta Xr form_driver 3 107.It form_fields Ta Xr form_field 3 108.It form_init Ta Xr form_hook 3 109.It form_max_page Ta Xr form_page 3 110.It form_opts Ta Xr form_opts 3 111.It form_opts_off Ta Xr form_opts 3 112.It form_opts_on Ta Xr form_opts 3 113.It form_page Ta Xr form_page 3 114.It form_sub Ta Xr form_win 3 115.It form_term Ta Xr form_hook 3 116.It form_userptr Ta Xr form_userptr 3 117.It form_win Ta Xr form_win 3 118.It free_field Ta Xr form_field_new 3 119.It free_fieldtype Ta Xr form_fieldtype 3 120.It free_form Ta Xr form_new 3 121.It link_field Ta Xr form_field_new 3 122.It link_fieldtype Ta Xr form_fieldtype 3 123.It move_field Ta Xr form_field 3 124.It new_field Ta Xr form_field_new 3 125.It new_fieldtype Ta Xr form_fieldtype 3 126.It new_form Ta Xr form_new 3 127.It new_page Ta Xr form_new_page 3 128.It pos_form_cursor Ta Xr form_cursor 3 129.It post_form Ta Xr form_post 3 130.It scale_form Ta Xr form_win 3 131.It set_current_field Ta Xr form_page 3 132.It set_field_back Ta Xr form_field_attributes 3 133.It set_field_buffer Ta Xr form_field_buffer 3 134.It set_field_fore Ta Xr form_field_attributes 3 135.It set_field_init Ta Xr form_hook 3 136.It set_field_just Ta Xr form_field_just 3 137.It set_field_opts Ta Xr form_field_opts 3 138.It set_field_pad Ta Xr form_field_attributes 3 139.It set_field_printf Ta Xr form_field_buffer 3 140.It set_field_status Ta Xr form_field_buffer 3 141.It set_field_term Ta Xr form_hook 3 142.It set_field_type Ta Xr form_field_validation 3 143.It set_field_userptr Ta Xr form_field_userptr 3 144.It set_fieldtype_arg Ta Xr form_fieldtype 3 145.It set_fieldtype_choice Ta Xr form_fieldtype 3 146.It set_form_fields Ta Xr form_field 3 147.It set_form_init Ta Xr form_hook 3 148.It set_form_opts Ta Xr form_opts 3 149.It set_form_page Ta Xr form_page 3 150.It set_form_sub Ta Xr form_win 3 151.It set_form_term Ta Xr form_hook 3 152.It set_form_userptr Ta Xr form_userptr 3 153.It set_form_win Ta Xr form_win 3 154.It set_max_field Ta Xr form_field_buffer 3 155.It set_new_page Ta Xr form_new_page 3 156.It unpost_form Ta Xr form_post 3 157.El 158.Sh RETURN VALUES 159Any function returning a string pointer will return 160.Dv NULL 161if an error occurs. 162Functions returning an integer will return one of the following: 163.Bl -column set_fieldtype_choiceXX 164.It Dv E_OK Ta No The function was successful. 165.It Dv E_SYSTEM_ERROR Ta No There was a system error during the call. 166.It Dv E_BAD_ARGUMENT Ta No One or more of the arguments passed to \ 167the function was incorrect. 168.It Dv E_POSTED Ta No The form is already posted. 169.It Dv E_CONNECTED Ta No A field was already connected to a form. 170.It Dv E_BAD_STATE Ta No The function was called from within an \ 171initialization or termination routine. 172.It Dv E_NO_ROOM Ta No The form does not fit within the subwindow. 173.It Dv E_NOT_POSTED Ta No The form is not posted. 174.It Dv E_UNKNOWN_COMMAND Ta No The form driver does not recognize the \ 175request passed to it. 176.It Dv E_NOT_SELECTABLE Ta No The field could not be selected. 177.It Dv E_NOT_CONNECTED Ta No The field is not connected to a form. 178.It Dv E_REQUEST_DENIED Ta No The form driver could not process the request. 179.It Dv E_INVALID_FIELD Ta No The field is invalid. 180.It Dv E_CURRENT Ta No The field is the active one on the form. 181.El 182.Sh SEE ALSO 183.Xr curses 3 , 184.Xr menus 3 185.Sh NOTES 186This implementation of the forms library does depart in behavior 187subtly from the original AT\*[Am]T implementation. 188Some of the more notable departures are: 189.Pp 190.Bl -tag -width "The TAB character" -compact 191.It field wrapping 192For multi-line fields the data will be wrapped as it is entered, this 193does not happen in the AT\*[Am]T implementation. 194.It buffer 0 195In this implementation, the contents of buffer 0 are always current 196regardless of whether the field has been validated or not. 197.It circular fields 198In the AT\*[Am]T implementation fields are circular on a page, that is, a 199next field from the last field will go to the first field on the 200current page. 201In this implementation a next field request on the last 202field of a page will result in the forms library positioning the 203cursor on the first field of the next page. 204If the field is the last 205field in the form then going to the next field will be denied, in the 206AT\*[Am]T it would result in the cursor being placed on the first field of 207the first page. 208.It buffer returns 209In this implementation only the data entered by the user in the form 210field will be returned, unlike the AT\*[Am]T library which would return the 211contents of the field padded to the size of the field with the pad 212character. 213.It The TAB character 214The handling of the TAB character in fields varies between 215implementations. 216In ncurses attempting to set a field contents with a 217string containing a TAB will result in an error and will not allow a 218TAB to be entered into a field. 219The AT\*[Am]T library statically 220converts tabs to the equivalent number of spaces when the field buffer 221is set but the form driver will not allow a TAB to be inserted into 222the field buffer. 223This implementation allows TAB when setting the 224field buffer and also will allow TAB to be inserted into a field 225buffer via the form driver and correctly calculates the cursor 226position allowing for expansion of the TAB character. 227.It set_field_printf 228This function is a 229.Nx 230extension and must not be used in portable code. 231.It Dv O_REFORMAT 232This field option is a 233.Nx 234extension and must not be used in portable code. 235.El 236