form_fieldtype(3X)
π form_fieldtype(3X) π
okay bestie, gather round, because this is the library calls corner of the manual and today we're talking about form_fieldtype β aka how you invent your own validation field types for curses forms. it's giving "build-a-bear but for data validation" and honestly? iconic. π§Έβ¨
β¨ NAME β¨
form_fieldtype β define validation-field types π
πΈ SYNOPSIS πΈ
#include <form.h>
FIELDTYPE *new_fieldtype(
bool (* const field_check)(FIELD *, const void *),
bool (* const char_check)(int, const void *));
int free_fieldtype(FIELDTYPE *fieldtype);
int set_fieldtype_arg(
FIELDTYPE *fieldtype,
void *(* const make_arg)(va_list *),
void *(* const copy_arg)(const void *),
void (* const free_arg)(void *));
int set_fieldtype_choice(
FIELDTYPE *fieldtype,
bool (* const next_choice)(FIELD *, const void *),
bool (* const prev_choice)(FIELD *, const void *));
FIELDTYPE *link_fieldtype(FIELDTYPE *type1,
FIELDTYPE *type2);
π¦ DESCRIPTION π¦
π« new_fieldtype
new_fieldtype creates a brand-new field type that you can use for data validation. no cap, it's literally the birth of a validation vibe. π
its parameters are function pointers, and here's the tea on each one:
field_checkβ this one checks whether an entered data string is valid whenever the user tries to leave a field. it has two arguments:- the
(FIELD *)argument gets passed in so the validation predicate can peek at the field's buffer, sizes, and other attributes π - the second argument is an argument-block structure β more on that below, bestie
- the
char_checkβ this one validates input characters as they're being entered. the form library hands it the character to check plus a pointer to an argument-block structure. it's the bouncer at the door of your field fr fr πͺ
π« free_fieldtype
free_fieldtype frees the space that new_fieldtype allocated for a given validation type. it's the clean-up-your-room of functions. π§Ήβ¨
π« set_fieldtype_arg
set_fieldtype_arg associates three storage-management functions with a field type:
make_argβ this function gets automatically applied to the list of arguments you giveset_field_typewhen you attach validation to a field. it stores those arguments in an allocated argument-block object, which is what gets used when validating input. πcopy_argβ this one may be used by applications to copy argument-blocks.free_argβ frees an argument-block structure.
β οΈ you must supply themake_argfunction. the other two are optional β you may supplyNULLfor them. in that case, the form library assumes thatmake_argdoes not allocate memory but simply loads the argument into a single scalar value. noted. π
π« set_fieldtype_choice
the form driver requests REQ_NEXT_CHOICE and REQ_PREV_CHOICE assume that the possible values of a field form an ordered set, and they give the forms user a way to move through that set. it's a little carousel of choices, honestly adorable. π
set_fieldtype_choice lets forms programmers define successor and predecessor functions for the field type. these functions take the field pointer and an argument-block structure as arguments.
π« link_fieldtype
link_fieldtype creates a new field type out of the two given types. they're connected by a logical "or". two types, one destiny, periodt. π
π₯ RETURN VALUE π₯
the pointer-valued routines return NULL on error. they set errno according to their success:
E_OKβ the routine succeeded. slay. βE_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument. π©E_SYSTEM_ERRORβ system error occurred, e.g.,mallocfailure. π
the integer-valued routines return one of the following codes on error:
E_OKβ the routine succeeded.E_BAD_ARGUMENTβ routine detected an incorrect or out-of-range argument.E_CONNECTEDβ the field is already connected to a form.E_CURRENTβ the field is the current field.E_SYSTEM_ERRORβ system error occurred (seeerrno(3)).
π PORTABILITY π
these routines emulate the System V forms library. they were not supported on Version 7 or BSD versions. so if you're time-traveling to the 70s, sorry bestie, no fieldtype for you. π°οΈπ
π AUTHORS π
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond.
(we love a credited legend π«Ά)
β SEE ALSO β
curses(3X), form(3X), form_field_validation(3X)
and that's the whole page, gorgeous. this came to you courtesy of ncurses 6.6, dated 2025-01-18 β go forth and define your validation types, you absolute main character π πβ¨
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2006,2010 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms