|
C-Menu 0.2.9
A User Interface Toolkit
|
File mapping, user input, command processing, and display logic. More...
Functions | |
| int | field_editor (Form *form) |
| Accept input for a field. | |
| int | form_display_field (Form *form) |
| Display current field. | |
| int | form_display_field_n (Form *form, int n) |
| Display field n. | |
| int | form_fmt_field (Form *form, char *s) |
| Format field according to its format type. | |
| int | form_validate_field (Form *form) |
| Validate current field based on flags. | |
| bool | is_valid_date (int yyyy, int mm, int dd) |
| Check if a given date is valid, including leap years. | |
| bool | is_valid_time (int hh, int mm, int ss) |
| Check if a given time is valid. | |
| void | left_justify (char *s) |
| Left justify string by removing leading spaces. | |
| void | mk_filler (char *s, int fl) |
| Create filler string for field. | |
| void | numeric (char *d, char *s) |
| Extract numeric characters from source string to destination string. | |
| void | right_justify (char *s, int fl) |
| Right justify string by removing trailing spaces and adding leadingspaces. | |
File mapping, user input, command processing, and display logic.
Main loop for field editing and entry
This function handles the main loop for field editing and entry. It processes user input, including character input, navigation keys, and mouse events, to allow the user to edit the content of a field. The function validates input based on the field's specified format and updates the display accordingly. It returns the key code of the action taken, such as accepting the field, tabbing to the next field, or breaking out of the input loop.
| int field_editor | ( | Form * | form | ) |
Accept input for a field.
| form | Pointer to Form structure |
Handles character input, navigation keys, and mouse events for field editing. Validates input based on field format and updates display. Returns key code of action taken (e.g., accept field, tab to next field, break out of input loop).
KEY_F(10) is the default key for accepting the field and moving to the next field
KEY_F(9) Cancels the current operation
KEY_UP, KEY_BTAB moves to the previous field
KEY_DOWN, TAB moves to the next field
KEY_END moves cursor to end of field
< Enter accepts the field and moves to the next field if form->f_erase_remainder is set, it will clear the remaining characters above and after the current cursor location
KEY_IC toggles insert mode
KEY_DC deletes character at cursor
KEY_HOME moves cursor to start of field
KEY_BACKSPACE deletes character before cursor
KEY_LEFT moves cursor left one character
KEY_RIGHT moves cursor right one character
Handles mouse events for field editing
Validates fields based on format
FF_STRING accepts all printable characters and spaces
FF_DECIMAL_INT accepts digits 0 through 9 and decimal point ('.')
FF_HEX_INT accepts digits 0 through 9 and letters A through F (case-insensitive)
FF_FLOAT accepts digits 0 through 9 and decimal point ('.') and negative operator ('-') at the start of the field
FF_DOUBLE accepts digits 0 through 9 and decimal point ('.') and negative operator ('-') at the start of the field
FF_CURRENCY accepts digits 0 through 9 and decimal point ('.') and negative operator ('-') at the start of the field
FF_YYYYMMDD accepts digits 0 through 9
FF_HHMMSS accepts digits 0 through 9
FF_APR accepts digits 0 through 9 and decimal point ('.')
Definition at line 55 of file fields.c.
References Field::accept_s, Form::box, Form::chyron, click_x, click_y, Field::col, compile_chyron(), cp_nt_hl_rev, cp_nt_rev, display_chyron(), Form::f_erase_remainder, Field::ff, FF_APR, FF_CURRENCY, FF_DECIMAL_INT, FF_DOUBLE, FF_FLOAT, FF_HEX_INT, FF_HHMMSS, FF_STRING, FF_YYYYMMDD, Form::fidx, Form::field, Field::filler_s, form_display_field(), form_fmt_field(), form_validate_field(), form_yx_to_fidx(), Chyron::l, Field::len, Field::line, Form::lines, Perror(), set_chyron_key_cp(), Form::win, and xwgetch().
Referenced by field_navigator().
| int form_display_field | ( | Form * | form | ) |
Display current field.
| form | Pointer to Form structure |
This function displays the current field based on the form's current field index (fidx). It retrieves the line and column information for the current field, displays any brackets if set, and then displays the field's content using the display_s string. The function ensures that the field is displayed correctly within the form's window and refreshes the display to show the updated field content.
Definition at line 366 of file fields.c.
References Field::col, Field::display_s, Form::fidx, Form::field, Field::filler_s, Field::line, and Form::win.
Referenced by field_editor(), and form_display_field_n().
| int form_display_field_n | ( | Form * | form, |
| int | n ) |
Display field n.
This function temporarily sets the form's current field index (fidx) to n, calls form_display_field() to display that field, and then restores the original fidx value. This allows for displaying a specific field without permanently changing the form's current field index.
Definition at line 348 of file fields.c.
References Form::fidx, and form_display_field().
| int form_fmt_field | ( | Form * | form, |
| char * | s ) |
Format field according to its format type.
| form | Pointer to Form structure |
| s | Input string to format |
takes the input string for the current field and formats it according to the field's specified format type (ff). It updates the accept_s and display_s strings for the field based on the formatted value. Handles various format types, including strings, decimal integers, hexadecimal integers, floating-point numbers, currency, dates, and times. Uses helper functions for validation and formatting, such as is_valid_date(), is_valid_time(), numeric(), right_justify(), left_justify(), and strnzcpy(). The function ensures that the formatted output fits within the field's length and creates a filler string for the field as needed. The function also handles error cases, such as invalid formats, and provides feedback through error messages. It is designed to be extensible, allowing for additional format types to be added in the future as needed. Assumes that the input string is well-formed and does not contain malicious content. Input validation and sanitization should be performed at a higher level in the application to ensure security and robustness. The function currently does not handle localization or internationalization of number formats, such as different decimal separators or currency symbols. Future enhancements may include support for locale-specific formatting. Error handling is basic; future versions may include more detailed error reporting and logging mechanisms. Performance optimizations may be considered for handling large volumes of data or high-frequency updates in real-time applications. The following variables and structures are used in this function:
Definition at line 417 of file fields.c.
References Field::accept_s, Field::display_s, Field::ff, FF_APR, FF_CURRENCY, FF_DECIMAL_INT, FF_DOUBLE, FF_FLOAT, FF_HEX_INT, FF_HHMMSS, FF_STRING, FF_YYYYMMDD, Form::fidx, Form::field, Field::filler_s, Field::input_s, is_valid_date(), is_valid_time(), left_justify(), Field::len, mk_filler(), numeric(), Perror(), right_justify(), strnz(), strnz__cpy(), and trim().
Referenced by field_editor(), and form_read_data().
| int form_validate_field | ( | Form * | form | ) |
Validate current field based on flags.
| form | Pointer to Form structure |
Very underdeveloped - only checks F_NOTBLANK and F_NOMETAS
Definition at line 522 of file fields.c.
References Field::accept_s, Field::ff, Form::fidx, Form::field, and Perror().
Referenced by field_editor().
| bool is_valid_date | ( | int | yyyy, |
| int | mm, | ||
| int | dd ) |
Check if a given date is valid, including leap years.
| yyyy | Year |
| mm | Month |
| dd | Day |
This function checks if the provided year, month, and day constitute a valid date. It accounts for leap years when determining the number of days in February. The function returns true if the date is valid and false if it is not.
Definition at line 606 of file fields.c.
Referenced by form_fmt_field().
| bool is_valid_time | ( | int | hh, |
| int | mm, | ||
| int | ss ) |
Check if a given time is valid.
| hh | Hour |
| mm | Minute |
| ss | Second |
This function checks if the provided hour, minute, and second constitute a valid time. It ensures that hours are between 0 and 23, minutes and seconds are between 0 and 59. The function returns true if the time is valid and false if it is not.
Definition at line 627 of file fields.c.
Referenced by form_fmt_field().
| void left_justify | ( | char * | s | ) |
Left justify string by removing leading spaces.
| s | String to left justify |
This function takes a string s and removes any leading spaces, effectively left-justifying the text. It does this by finding the first non-space character and shifting the string to the left, overwriting the leading spaces. The resulting string is null-terminated.
Definition at line 568 of file fields.c.
References trim().
Referenced by form_fmt_field().
| void mk_filler | ( | char * | s, |
| int | fl ) |
Create filler string for field.
| s | Filler string to create |
| fl | Field length |
Fills the string s with the fill character specified in the form's fill_char array, repeated for the length of the field (fl). The resulting string is null-terminated. This filler string can be used to display empty fields or to clear the field area before displaying new content.
Definition at line 551 of file fields.c.
References Form::fill_char, and form.
Referenced by form_fmt_field().
| void numeric | ( | char * | d, |
| char * | s ) |
Extract numeric characters from source string to destination string.
| d | Destination string |
| s | Source string |
This function takes a source string s and extracts only the numeric characters (digits 0-9), as well as dashes ('-') and periods ('.'), copying them into the destination string d. The resulting string in d is null-terminated. This is useful for processing input that may contain non-numeric characters, allowing the application to focus on the numeric content for further processing or validation.
Definition at line 643 of file fields.c.
Referenced by form_fmt_field().
| void right_justify | ( | char * | s, |
| int | fl ) |
Right justify string by removing trailing spaces and adding leadingspaces.
This function takes a string s and right-justifies it within a field of length fl. It first removes any trailing spaces from the string, then shifts the characters to the right end of the field, filling the left side with spaces. The resulting string is null-terminated and fits within the specified field length.
Definition at line 580 of file fields.c.
References trim().
Referenced by form_fmt_field().