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
  • 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 give set_field_type when 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 the make_arg function. the other two are optional β€” you may supply NULL for them. in that case, the form library assumes that make_arg does 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 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., malloc failure. πŸ’€

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 (see errno(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