C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Field Edit and Entry

Functions for handling field editing and entry. More...

Functions

int field_editor (Form *form)
 Accept input for a field.
int form_display_field_n (Form *form, int n)
 Display field n.
int form_display_field (Form *form)
 Display current field.
int form_display_field_brackets (Form *form)
 Display brackets around current field if set.
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.
void mk_filler (char *s, int fl)
 Create filler string for field.
void left_justify (char *s)
 Left justify string by removing leading spaces.
void right_justify (char *s, int fl)
 Right justify string by removing trailing spaces and adding leadingspaces.
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 numeric (char *d, char *s)
 Extract numeric characters from source string to destination string.

Detailed Description

Functions for handling field editing and entry.

This module provides functions for handling field editing and entry within in the C-Menu Form library. It includes functionality for accepting user input for fields, displaying fields, formatting field content based on specified formats, validating field input, and creating filler strings for fields. The module supports various field formats such as strings, decimal integers, hexadecimal integers, floating-point numbers, currency, dates, and times. It also handles user interactions such as navigation keys and mouse events for editing fields. The functions in this module are designed to be used in conjunction with the overall C-Menu Form library to create interactive forms in a text-based user interface.

Function Documentation

◆ field_editor()

int field_editor ( Form * form)

Accept input for a field.

Parameters
formPointer to Form structure
Returns
int Key code of action taken
Note
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 59 of file fields.c.

59 {
60 bool f_insert = FALSE;
61 int in_key;
62 char *s, *d;
63 WINDOW *win = form->win;
64
65 int flin = form->field[form->fidx]->line;
66 int fcol = form->field[form->fidx]->col;
67 int flen = form->field[form->fidx]->len;
68 int ff = form->field[form->fidx]->ff;
69 char *accept_s = form->field[form->fidx]->accept_s;
70 char *filler_s = form->field[form->fidx]->filler_s;
71 form_fmt_field(form, accept_s);
72 click_x = click_y = -1;
73 char *fstart = accept_s;
74 char *fend = fstart + flen;
75 int x = fcol;
76 char *p = fstart = accept_s;
77 char *str_end = p + strlen(p);
78 in_key = 0;
79 if (f_insert)
80 set_chyron_key_cp(form->chyron, 18, "INS", KEY_IC,
82 else
83 set_chyron_key_cp(form->chyron, 18, "INS", KEY_IC, cp_reverse);
84 compile_chyron(form->chyron);
85 display_chyron(form->win, form->chyron, form->lines - 1, form->chyron->l);
86
87 while (1) {
88 if (in_key == 0) {
89 mvwaddstr(win, flin, fcol, filler_s);
90 mvwaddstr(win, flin, fcol, accept_s);
91 wmove(win, flin, x);
92 tcflush(0, TCIFLUSH);
93 wmove(win, flin, x);
94 in_key = xwgetch(win, form->chyron, -1);
95 }
96 switch (in_key) {
99 case KEY_F(10):
100 form_fmt_field(form, accept_s);
102 if (form_validate_field(form) != 0)
103 continue;
104 return (in_key);
106 case KEY_BREAK:
107 case KEY_F(9):
109 in_key = KEY_F(9);
110 return (in_key);
112 case 'H':
113 case KEY_F(1):
114 return (in_key);
115 case KEY_BTAB:
116 case KEY_UP:
117 form_fmt_field(form, accept_s);
119 in_key = KEY_UP;
120 return (in_key);
122 case '\t':
123 case KEY_DOWN:
124 form_fmt_field(form, accept_s);
126 in_key = KEY_DOWN;
127 return (in_key);
129 case KEY_END:
130 case Ctrl('e'):
131 while (*p != '\0')
132 p++;
133 x = fcol + (p - fstart);
134 in_key = 0;
135 continue;
139 case '\n':
140 case KEY_ENTER:
141 if (form->f_erase_remainder)
142 *p = '\0';
143 form_fmt_field(form, accept_s);
145 in_key = KEY_ENTER;
146 return (in_key);
148 case KEY_IC:
149 if (f_insert) {
150 f_insert = FALSE;
151 set_chyron_key_cp(form->chyron, 18, "INS", KEY_IC, cp_reverse);
152 } else {
153 f_insert = TRUE;
154 set_chyron_key_cp(form->chyron, 18, "INS", KEY_IC,
156 }
157 compile_chyron(form->chyron);
158 display_chyron(form->win, form->chyron, form->lines - 1,
159 form->chyron->l);
160 in_key = 0;
161 continue;
163 case KEY_DC:
164 s = p + 1;
165 d = p;
166 while (*s != '\0')
167 *d++ = *s++;
168 *d = '\0';
169 str_end = d;
170 f_insert = FALSE;
171 in_key = 0;
172 continue;
174 case KEY_HOME:
175 case Ctrl('a'):
176 p = fstart;
177 x = fcol;
178 in_key = 0;
179 continue;
181 case KEY_BACKSPACE:
182 if (p > fstart) {
183 p--;
184 x--;
185 }
186 s = p + 1;
187 d = p;
188 while (*s != '\0')
189 *d++ = *s++;
190 *d = '\0';
191 str_end = d;
192 in_key = 0;
193 continue;
195 case KEY_LEFT:
196 if (p > fstart) {
197 p--;
198 x--;
199 }
200 in_key = 0;
201 continue;
203 case KEY_RIGHT:
204 if (p < fend && p < str_end) {
205 p++;
206 x++;
207 }
208 in_key = 0;
209 continue;
211 case KEY_MOUSE:
213 x = click_x;
214 flin = click_y;
215 flen = form->field[form->fidx]->len;
216 ff = form->field[form->fidx]->ff; /* ff - field forat */
217 accept_s = form->field[form->fidx]->accept_s;
218 filler_s = form->field[form->fidx]->filler_s;
219 form_fmt_field(form, accept_s);
220 fstart = accept_s;
221 fend = fstart + flen;
222 str_end = fstart + strlen(fstart);
223 p = fstart + (x - form->field[form->fidx]->col);
224 if (p > str_end)
225 x -= p - str_end;
226 p = min(p, str_end);
227 in_key = 0;
228 continue;
229 default:
230 if (p >= fend) {
231 in_key = 0;
232 continue;
233 }
235 switch (ff) {
237 case FF_STRING:
238 break;
241 case FF_DECIMAL_INT:
242 if ((in_key >= '0' && in_key <= '9') || in_key == '.')
243 break;
244 beep();
245 in_key = 0;
246 continue;
249 case FF_HEX_INT:
250 if ((in_key >= '0' && in_key <= '9') ||
251 (in_key >= 'A' && in_key <= 'F') ||
252 (in_key >= 'a' && in_key <= 'f'))
253 break;
254 beep();
255 in_key = 0;
256 continue;
259 case FF_FLOAT:
260 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
261 (in_key == '-' && p == fstart))
262 break;
263 beep();
264 in_key = 0;
265 continue;
268 case FF_DOUBLE:
269 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
270 (in_key == '-' && p == fstart))
271 break;
272 beep();
273 in_key = 0;
274 continue;
278 case FF_CURRENCY:
279 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
280 (in_key == '-' && p == fstart))
281 break;
282 beep();
283 in_key = 0;
284 continue;
286 case FF_YYYYMMDD:
287 if (in_key >= '0' && in_key <= '9')
288 break;
289 beep();
290 in_key = 0;
291 continue;
293 case FF_HHMMSS:
294 if (in_key >= '0' && in_key <= '9')
295 break;
296 beep();
297 in_key = 0;
298 continue;
300 case FF_APR:
301 if ((in_key >= '0' && in_key <= '9') || in_key == '.')
302 break;
303 beep();
304 in_key = 0;
305 continue;
306 default:
307 Perror("field_editor() invalid format");
308 break;
309 }
310 if (in_key >= ' ') {
311 if (f_insert) {
312 if (str_end < fend) {
313 s = str_end - 1;
314 d = str_end;
315 while (s >= p)
316 *d-- = *s--;
317 *p++ = in_key;
318 str_end++;
319 x++;
320 }
321 } else {
322 if (p < fend) {
323 if (p < str_end) {
324 *p++ = in_key;
325 x++;
326 } else if (p == str_end) {
327 *p++ = in_key;
328 *p = '\0';
329 str_end = p;
330 x++;
331 }
332 }
333 }
334 in_key = 0;
335 continue;
336 }
337 }
338 }
339}
int form_yx_to_fidx(Form *, int, int)
@ FF_DECIMAL_INT
Definition form.h:51
@ FF_STRING
Definition form.h:49
@ FF_HEX_INT
Definition form.h:53
@ FF_YYYYMMDD
Definition form.h:62
@ FF_HHMMSS
Definition form.h:64
@ FF_CURRENCY
Definition form.h:59
@ FF_FLOAT
Definition form.h:55
@ FF_DOUBLE
Definition form.h:57
@ FF_APR
Definition form.h:66
Form * form
Definition mem.c:47
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:55
#define Ctrl(c)
Definition cm.h:33
#define TRUE
Definition iloan.c:19
#define FALSE
Definition iloan.c:18
WINDOW * win
Definition dwin.c:113
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Definition dwin.c:297
int click_x
Definition dwin.c:45
int click_y
Definition dwin.c:44
int cp_reverse_highlight
Definition dwin.c:140
int cp_reverse
Definition dwin.c:139
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
Definition dwin.c:1359
void set_chyron_key_cp(Chyron *, int, char *, int, int)
Set chyron key.
Definition dwin.c:237
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Definition dwin.c:268
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1110
int form_fmt_field(Form *, char *)
Format field according to its format type.
Definition fields.c:421
int form_display_field(Form *)
Display current field.
Definition fields.c:369
int form_validate_field(Form *)
Validate current field based on flags.
Definition fields.c:588

References Field::accept_s, Form::chyron, click_x, click_y, Field::col, compile_chyron(), cp_reverse, cp_reverse_highlight, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_display_field()

int form_display_field ( Form * form)

Display current field.

Parameters
formPointer to Form structure
Returns
0 on success, non-zero on error
Note
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 369 of file fields.c.

369 {
370 WINDOW *win = form->win;
371 int flin = form->field[form->fidx]->line;
372 int fcol = form->field[form->fidx]->col;
374 mvwaddstr(win, flin, fcol, form->field[form->fidx]->filler_s);
375 mvwaddstr(win, flin, fcol, form->field[form->fidx]->display_s);
376 // wrefresh(win);
377 return 0;
378}
int form_display_field_brackets(Form *)
Display brackets around current field if set.
Definition fields.c:389

References Field::col, Field::display_s, Form::fidx, Form::field, Field::filler_s, form_display_field_brackets(), Field::line, and Form::win.

Referenced by field_editor(), and form_display_field_n().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_display_field_brackets()

int form_display_field_brackets ( Form * form)

Display brackets around current field if set.

Parameters
formPointer to Form structure
Returns
0 on success, non-zero on error
Note
This function checks if the form's brackets array has non-empty values for both the left and right brackets. If so, it retrieves the line and column information for the current field and uses the form's box window to display the left bracket at the start of the field and the right bracket at the end of the field. The display is refreshed to show the brackets around the field.

Definition at line 389 of file fields.c.

389 {
390 int flin, fcol;
391 if (form->brackets[0] != '\0' && form->brackets[1] != '\0') {
392 WINDOW *box = form->box;
393 flin = form->field[form->fidx]->line + 1;
394 fcol = form->field[form->fidx]->col;
395 wmove(box, flin, fcol);
396 waddch(box, form->brackets[0]);
397 wmove(box, flin, fcol + form->field[form->fidx]->len + 1);
398 waddch(box, form->brackets[1]);
399 wrefresh(box);
400 }
401 return 0;
402}

References Form::box, Form::brackets, Field::col, Form::fidx, Form::field, Field::len, and Field::line.

Referenced by form_display_field().

Here is the caller graph for this function:

◆ form_display_field_n()

int form_display_field_n ( Form * form,
int n )

Display field n.

Parameters
formPointer to Form structure
nField index to display
Returns
0 on success, non-zero on error
Note
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 351 of file fields.c.

351 {
352 int fidx = form->fidx;
353 form->fidx = n;
355 form->fidx = fidx;
356 return 0;
357}

References Form::fidx, and form_display_field().

Referenced by form_display_fields().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_fmt_field()

int form_fmt_field ( Form * form,
char * s )

Format field according to its format type.

Parameters
formPointer to Form structure
sInput string to format
Returns
0 on success, non-zero on error
Note
This function 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. The function handles various format types, including strings, decimal integers, hexadecimal integers, floating-point numbers, currency, dates, and times. It 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.

Format field according to its format type

Parameters
formPointer to Form structure
sInput string to format
Returns
0 on success, non-zero on error
Note
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:
char field_s[FIELD_MAXLEN];
int decimal_int_n = 0;
int hex_int_n = 0;
float float_n = 0.0;
double double_n = 0.0;
double currency_n = 0.0;
struct Date { int yyyy; int mm; int dd; };
struct Time { int hh; int mm; int ss; };
#define FIELD_MAXLEN
Definition form.h:18
supports format types: FF_STRING, FF_DECIMAL_INT, FF_HEX_INT, FF_FLOAT, FF_DOUBLE, FF_CURRENCY, FF_YYYYMMDD, FF_HHMMSS, FF_APR with appropriate formatting and validation for each type.
Handles field length and filler string creation.
As the roadmap indicates, these data types are just a start and more complex types and formats may be added in the future.
These data types are not suitable for financial, scientific, or high-precision applications. They are intended for basic data entry and display in a text-based user interface.
In the future, we will aqdd support for additional data types and formats such as: dates with time zones, timestamps, percentages, scientific notation, and custom user-defined formats.
For high precision applications, we will be integrating support for 128-bit binary coded decimal (BCD) types and arbitrary precision decimal types using libraries such as the GNU MPFR library, IBM's decNumber, Rust Decimal, or the Intel Decimal Floating-Point Math Library.
C-Menu Form converts each field's input string into internal numeric binary based on the field's specified format. The internal numberic binary is then formated and displayed, verifying the user's input and Form's interpretation of the user's input.

Definition at line 421 of file fields.c.

421 {
484 strnz__cpy(form->field[form->fidx]->input_s, s, FIELD_MAXLEN - 1);
485 char *input_s = form->field[form->fidx]->input_s;
486 char *accept_s = form->field[form->fidx]->accept_s;
487 char *display_s = form->field[form->fidx]->display_s;
488 char *filler_s = form->field[form->fidx]->filler_s;
489 int ff = form->field[form->fidx]->ff;
490 int fl = form->field[form->fidx]->len;
491
492 char field_s[FIELD_MAXLEN];
493 int decimal_int_n = 0;
494 int hex_int_n = 0;
495 float float_n = 0.0;
496 double double_n = 0.0;
497 double currency_n = 0.0;
498
499 struct {
500 int yyyy;
501 int mm;
502 int dd;
503 } Date;
504 Date.yyyy = Date.mm = Date.dd = 0;
505 struct {
506 int hh;
507 int mm;
508 int ss;
509 } Time;
510 Time.hh = Time.mm = Time.ss = 0;
511 strnz(accept_s, fl);
512 switch (ff) {
513 case FF_STRING:
514 left_justify(s);
515 trim(s);
516 strnz__cpy(input_s, s, FIELD_MAXLEN - 1);
517 strnz__cpy(accept_s, s, FIELD_MAXLEN - 1);
518 strnz__cpy(display_s, s, FIELD_MAXLEN - 1);
519 break;
520 case FF_DECIMAL_INT:
521 sscanf(input_s, "%d", &decimal_int_n);
522 sprintf(accept_s, "%d", decimal_int_n);
523 sprintf(display_s, "%d", decimal_int_n);
524 right_justify(display_s, fl);
525 break;
526 case FF_HEX_INT:
527 sscanf(input_s, "%x", &hex_int_n);
528 sprintf(accept_s, "%d", hex_int_n);
529 sprintf(display_s, "%x", hex_int_n);
530 right_justify(display_s, fl);
531 break;
532 case FF_FLOAT:
533 sscanf(input_s, "%f", &float_n);
534 sprintf(accept_s, "%f", float_n);
535 sprintf(display_s, "%f", float_n);
536 right_justify(display_s, fl);
537 break;
538 case FF_DOUBLE:
539 sscanf(input_s, "%lf", &double_n);
540 sprintf(accept_s, "%lf", double_n);
541 sprintf(display_s, "%lf", double_n);
542 right_justify(display_s, fl);
543 break;
544 case FF_CURRENCY:
545 numeric(field_s, input_s);
546 sscanf(field_s, "%lf", &currency_n);
547 sprintf(accept_s, "%.2lf", currency_n);
548 sprintf(display_s, "%'.2lf", currency_n);
549 right_justify(display_s, fl);
550 break;
551 case FF_YYYYMMDD:
552 Date.yyyy = Date.mm = Date.dd = 0;
553 strnz__cpy(field_s, input_s, FIELD_MAXLEN - 1);
554 sscanf(field_s, "%4d%2d%2d", &Date.yyyy, &Date.mm, &Date.dd);
555 sprintf(accept_s, "%04d%02d%02d", Date.yyyy, Date.mm, Date.dd);
556 if (is_valid_date(Date.yyyy, Date.mm, Date.dd))
557 sprintf(display_s, "%04d-%02d-%02d", Date.yyyy, Date.mm, Date.dd);
558 break;
559 case FF_HHMMSS:
560 Time.hh = Time.mm = Time.ss = 0;
561 strnz__cpy(field_s, input_s, FIELD_MAXLEN - 1);
562 sscanf(field_s, "%2d%2d%2d", &Time.hh, &Time.mm, &Time.ss);
563 sprintf(accept_s, "%02d%02d%02d", Time.hh, Time.mm, Time.ss);
564 if (is_valid_time(Time.hh, Time.mm, Time.ss))
565 sprintf(display_s, "%02d:%02d:%02d", Time.hh, Time.mm, Time.ss);
566 break;
567 case FF_APR:
568 sscanf(input_s, "%lf", &double_n);
569 sprintf(accept_s, "%lf", double_n);
570 sprintf(display_s, "%0.3lf", double_n);
571 right_justify(display_s, fl);
572 break;
573 default:
574 Perror("form_fmt_field() invalid format");
575 break;
576 }
577 strnz(accept_s, fl);
578 left_justify(accept_s);
579 mk_filler(filler_s, fl);
580 return 0;
581}
void numeric(char *, char *)
Extract numeric characters from source string to destination string.
Definition fields.c:709
void right_justify(char *, int)
Right justify string by removing trailing spaces and adding leadingspaces.
Definition fields.c:646
bool is_valid_date(int, int, int)
Check if a given date is valid, including leap years.
Definition fields.c:672
void left_justify(char *)
Left justify string by removing leading spaces.
Definition fields.c:634
bool is_valid_time(int, int, int)
Check if a given time is valid.
Definition fields.c:693
void mk_filler(char *, int)
Create filler string for field.
Definition fields.c:617
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
size_t trim(char *)
Trims leading and trailing spaces from string s in place.
Definition futil.c:118
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:340

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_validate_field()

int form_validate_field ( Form * form)

Validate current field based on flags.

Parameters
formPointer to Form structure
Returns
0 if valid, 1 if invalid
Note
Very underdeveloped - only checks F_NOTBLANK and F_NOMETAS

Definition at line 588 of file fields.c.

588 {
589 int n = form->fidx;
590 char *p = form->field[n]->accept_s;
591 if (form->field[n]->ff & F_NOTBLANK) {
592 char *s = form->field[n]->accept_s;
593 while (*s++ == ' ')
594 ;
595 if (*s == '\0') {
596 Perror("blank field not allowed");
597 return (1);
598 }
599 }
600 if (form->field[n]->ff & F_NOMETAS) {
601 if (strpbrk(p, "*?[]") != 0) {
602 Perror("metacharacters not allowed");
603 return (1);
604 }
605 }
606 return (0);
607}
#define F_NOTBLANK
Definition form.h:21
#define F_NOMETAS
Definition form.h:20

References Field::accept_s, Field::ff, Form::fidx, Form::field, and Perror().

Referenced by field_editor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_valid_date()

bool is_valid_date ( int yyyy,
int mm,
int dd )

Check if a given date is valid, including leap years.

Parameters
yyyyYear
mmMonth
ddDay
Returns
true if the date is valid, false otherwise
Note
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 672 of file fields.c.

672 {
673 if (yyyy < 1 || mm < 1 || mm > 12 || dd < 1)
674 return false;
675 int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
676 if ((yyyy % 4 == 0 && yyyy % 100 != 0) || (yyyy % 400 == 0))
677 days_in_month[2] = 29;
678 if (dd > days_in_month[mm])
679 return false;
680 return true;
681}

Referenced by form_fmt_field().

Here is the caller graph for this function:

◆ is_valid_time()

bool is_valid_time ( int hh,
int mm,
int ss )

Check if a given time is valid.

Parameters
hhHour
mmMinute
ssSecond
Returns
true if the time is valid, false otherwise
Note
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 693 of file fields.c.

693 {
694 if (hh < 0 || hh > 23 || mm < 0 || mm > 59 || ss < 0 || ss > 59)
695 return false;
696 return true;
697}

Referenced by form_fmt_field().

Here is the caller graph for this function:

◆ left_justify()

void left_justify ( char * s)

Left justify string by removing leading spaces.

Parameters
sString to left justify
Note
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 634 of file fields.c.

634{ trim(s); }

References trim().

Referenced by form_fmt_field().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mk_filler()

void mk_filler ( char * s,
int fl )

Create filler string for field.

Parameters
sFiller string to create
flField length
Note
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 617 of file fields.c.

617 {
618 char *e = s + fl;
619 unsigned char c;
620
621 c = form->fill_char[0];
622 while (s != e)
623 *s++ = c;
624 *s = '\0';
625}

References Form::fill_char, and form.

Referenced by form_fmt_field().

Here is the caller graph for this function:

◆ numeric()

void numeric ( char * d,
char * s )

Extract numeric characters from source string to destination string.

Parameters
dDestination string
sSource string
Note
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 709 of file fields.c.

709 {
710 while (*s != '\0') {
711 if (*s == '-' || *s == '.' || (*s >= '0' && *s <= '9'))
712 *d++ = *s++;
713 else
714 s++;
715 }
716 *d = '\0';
717}

Referenced by form_fmt_field().

Here is the caller graph for this function:

◆ right_justify()

void right_justify ( char * s,
int fl )

Right justify string by removing trailing spaces and adding leadingspaces.

Parameters
sString to right justify
flField length
Note
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 646 of file fields.c.

646 {
647 char *p = s;
648 char *d = s + fl;
649 trim(s);
650 *d = '\0';
651 while (*s != '\0') {
652 s++;
653 }
654 while (s != p) {
655 *(--d) = *(--s);
656 }
657 while (d != p) {
658 *(--d) = ' ';
659 }
660}

References trim().

Referenced by form_fmt_field().

Here is the call graph for this function:
Here is the caller graph for this function: