C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Field Editor

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, uint 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 (uint yyyy, uint mm, uint dd)
 Check if a given date is valid, including leap years.
bool is_valid_time (uint hh, uint mm, uint ss)
 Check if a given time is valid.
void left_justify (char *s)
 Left justify string by removing leading spaces.
void numeric (char *d, char *s)
 Extract numeric characters from source string to destination string.
void right_justify (char *, uint)
 Right justify string by removing trailing spaces and adding leadingspaces.

Detailed Description

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.

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

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_F10 is the default key for accepting the field and moving to the next field

KEY_F09 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 48 of file fields.c.

48 {
49 bool f_insert = false;
50 int in_key;
51 char *s, *d;
53 UiEvent event;
54 uint maxy, maxx;
55 if (form->fidx >= form->fcnt)
56 form->fcnt = 0;
57 uint flin = form->field[form->fidx]->line;
58 uint fcol = form->field[form->fidx]->col;
59 uint flen = form->field[form->fidx]->len;
60 uint ff = form->field[form->fidx]->ff;
61 char *accept_s = form->field[form->fidx]->accept_s;
62 form_fmt_field(form, accept_s);
63 click_x = click_y = -1;
64 char *fstart = accept_s;
65 char *fend = fstart + flen;
66 uint x = fcol;
67 char *p = fstart = accept_s;
68 char *str_end = p + strlen(p);
69 in_key = 0;
70 if (f_insert)
71 set_chyron_key_cb(form->chyron, 18, "INS", KEY_IC, cell_nt_hl_rev);
72 else
73 set_chyron_key_cb(form->chyron, 18, "INS", KEY_IC, cell_nt_rev);
74 compile_chyron(form->chyron);
75 display_chyron(sfc, 1, form->chyron, form->lines - 1, form->chyron->l);
76
77 while (1) {
78 if (in_key == 0) {
79 form_fmt_field(form, accept_s);
81 tcflush(0, TCIFLUSH);
82 ui_cursor_move(sfc, WIN, flin, x);
83 in_key = ui_get_event_multi(sfc, WIN, &event, -1);
84 ui_getmaxyx(sfc, WIN, &maxy, &maxx);
85 if (event.in_win == WIN && event.y == maxy - 1)
86 in_key = get_chyron_key(form->chyron, event.x);
87 }
88 ui_curs_set(0);
89 switch (in_key) {
92 case KEY_F10:
93 form_fmt_field(form, accept_s);
95 if (form_validate_field(form) != 0)
96 continue;
97 return (in_key);
99 case KEY_BREAK:
100 case KEY_F09:
102 in_key = KEY_F09;
103 return (in_key);
105 case 'H':
106 case KEY_F01:
107 return (in_key);
108 case UI_KEY_BTAB:
109 case KEY_UP:
110 form_fmt_field(form, accept_s);
112 in_key = KEY_UP;
113 return (in_key);
115 case '\t':
116 case KEY_DOWN:
117 form_fmt_field(form, accept_s);
119 in_key = KEY_DOWN;
120 return (in_key);
122 case KEY_END:
123 case Ctrl('e'):
124 while (*p != '\0')
125 p++;
126 x = fcol + (p - fstart);
127 in_key = 0;
128 continue;
132 case '\n':
133 case KEY_ENTER:
134 if (form->f_erase_remainder)
135 *p = '\0';
136 form_fmt_field(form, accept_s);
138 in_key = KEY_ENTER;
139 return (in_key);
141 case KEY_IC:
142 if (f_insert) {
143 f_insert = false;
144 set_chyron_key_cb(form->chyron, 18, "INS", KEY_IC, cell_nt_rev);
145 } else {
146 f_insert = true;
147 set_chyron_key_cb(form->chyron, 18, "INS", KEY_IC,
149 }
150 compile_chyron(form->chyron);
151 display_chyron(sfc, 1, form->chyron, form->lines - 1,
152 form->chyron->l);
153 in_key = 0;
154 continue;
156 case KEY_DC:
157 s = p + 1;
158 d = p;
159 while (*s != '\0')
160 *d++ = *s++;
161 *d = '\0';
162 str_end = d;
163 f_insert = false;
164 in_key = 0;
165 continue;
167 case KEY_HOME:
168 case Ctrl('a'):
169 p = fstart;
170 x = fcol;
171 in_key = 0;
172 continue;
174 case KEY_BACKSPACE:
175 if (p > fstart) {
176 p--;
177 x--;
178 }
179 s = p + 1;
180 d = p;
181 while (*s != '\0')
182 *d++ = *s++;
183 *d = '\0';
184 str_end = d;
185 in_key = 0;
186 continue;
188 case KEY_LEFT:
189 if (p > fstart) {
190 p--;
191 x--;
192 }
193 in_key = 0;
194 continue;
196 case KEY_RIGHT:
197 if (p < fend && p < str_end) {
198 p++;
199 x++;
200 }
201 in_key = 0;
202 continue;
204 case KEY_MOUSE:
206 x = click_x;
207 flin = click_y;
208 flen = form->field[form->fidx]->len;
209 ff = form->field[form->fidx]->ff; /* ff - field forat */
210 accept_s = form->field[form->fidx]->accept_s;
211 // filler_s = form->field[form->fidx]->filler_s;
212 form_fmt_field(form, accept_s);
213 fstart = accept_s;
214 fend = fstart + flen;
215 str_end = fstart + strlen(fstart);
216 p = fstart + (x - form->field[form->fidx]->col);
217 if (p > str_end)
218 x -= p - str_end;
219 p = min(p, str_end);
220 in_key = 0;
221 continue;
222 default:
223 if (p >= fend) {
224 in_key = 0;
225 continue;
226 }
228 switch (ff) {
230 case FF_STRING:
231 break;
234 case FF_DECIMAL_INT:
235 if ((in_key >= '0' && in_key <= '9') || in_key == '.')
236 break;
237 in_key = 0;
238 continue;
241 case FF_HEX_INT:
242 if ((in_key >= '0' && in_key <= '9') ||
243 (in_key >= 'A' && in_key <= 'F') ||
244 (in_key >= 'a' && in_key <= 'f'))
245 break;
246 in_key = 0;
247 continue;
250 case FF_FLOAT:
251 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
252 (in_key == '-' && p == fstart))
253 break;
254 in_key = 0;
255 continue;
258 case FF_DOUBLE:
259 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
260 (in_key == '-' && p == fstart))
261 break;
262 in_key = 0;
263 continue;
267 case FF_CURRENCY:
268 if ((in_key >= '0' && in_key <= '9') || in_key == '.' ||
269 (in_key == '-' && p == fstart))
270 break;
271 in_key = 0;
272 continue;
274 case FF_YYYYMMDD:
275 if (in_key >= '0' && in_key <= '9')
276 break;
277 in_key = 0;
278 continue;
280 case FF_HHMMSS:
281 if (in_key >= '0' && in_key <= '9')
282 break;
283 in_key = 0;
284 continue;
286 case FF_APR:
287 if ((in_key >= '0' && in_key <= '9') || in_key == '.')
288 break;
289 in_key = 0;
290 continue;
291 default:
292 Perror("field_editor() invalid format");
293 break;
294 }
295 if (in_key < ' ' || in_key > '~') {
296 in_key = 0;
297 continue;
298 }
299 if (f_insert) {
300 if (str_end < fend) {
301 s = str_end - 1;
302 d = str_end;
303 while (s >= p)
304 *d-- = *s--;
305 *p++ = in_key;
306 str_end++;
307 x++;
308 }
309 } else {
310 if (p < fend) {
311 if (p < str_end) {
312 if (p == accept_s && in_key == ' ') {
313 d = accept_s;
314 s = accept_s + 1;
315 while (*s != '\0')
316 *d++ = *s++;
317 *d = '\0';
318 in_key = 0;
319 continue;
320 }
321 *p++ = in_key;
322 x++;
323 } else if (p == str_end) {
324 *p++ = in_key;
325 *p = '\0';
326 str_end = p;
327 x++;
328 }
329 }
330 }
331 in_key = 0;
332 continue;
333 }
334 }
335}
@ FF_DECIMAL_INT
Definition form.h:50
@ FF_STRING
Definition form.h:48
@ FF_HEX_INT
Definition form.h:52
@ FF_YYYYMMDD
Definition form.h:61
@ FF_HHMMSS
Definition form.h:63
@ FF_CURRENCY
Definition form.h:58
@ FF_FLOAT
Definition form.h:54
@ FF_DOUBLE
Definition form.h:56
@ FF_APR
Definition form.h:65
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
#define Ctrl(c)
Definition cm.h:54
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:727
@ UI_KEY_BTAB
Definition ui_backend.h:49
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:28
int ui_get_event_multi(UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
int sfc_ptr
Definition nckeys.c:47
int ui_curs_set(int visibility)
Definition ui_ncurses.c:737
void ui_getmaxyx(UiSurface *s, uint w, uint *lines, uint *cols)
Definition ui_ncurses.c:676
#define KEY_F01
#define KEY_F09
#define KEY_F10
#define KEY_RIGHT
#define KEY_DC
#define KEY_BACKSPACE
#define KEY_DOWN
#define KEY_BREAK
#define KEY_END
#define KEY_ENTER
#define KEY_MOUSE
#define KEY_IC
#define KEY_LEFT
#define KEY_HOME
#define KEY_UP
Form * form
Definition mem.c:37
uint form_yx_to_fidx(Form *, uint, uint)
UiCell cell_nt_hl_rev
Definition dwin.c:97
int click_x
Definition dwin.c:45
int click_y
Definition dwin.c:44
UiCell cell_nt_rev
Definition dwin.c:95
int form_display_accept_field(Form *)
Definition fields.c:387
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841
void set_chyron_key_cb(Chyron *chyron, uint k, char *s, uint kc, UiCell cell_base)
Set chyron key with color pair (cp).
Definition dwin.c:1021
void compile_chyron(Chyron *chyron)
construct the chyron string from the chyron structure
Definition dwin.c:1110
int get_chyron_key(Chyron *chyron, uint x)
Get keycode from chyron.
Definition dwin.c:1186
void display_chyron(UiSurface *sfc, uint w, Chyron *chyron, uint line, uint col)
Display chyron on the specified line and column of the surface.
Definition dwin.c:1163
int form_fmt_field(Form *form, char *s)
Format field according to its format type.
Definition fields.c:448
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:544
uint in_win
Definition ui_backend.h:110
A drawable surface in the NotCurses backend.

References Field::accept_s, cell_nt_hl_rev, cell_nt_rev, Form::chyron, click_x, click_y, Field::col, compile_chyron(), display_chyron(), Form::f_erase_remainder, Form::fcnt, 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, form_display_accept_field(), form_display_field(), form_fmt_field(), form_validate_field(), form_yx_to_fidx(), get_chyron_key(), UiEvent::in_win, Chyron::l, Field::len, Field::line, Form::lines, Perror(), set_chyron_key_cb(), sfc_ptr, ui_curs_set(), ui_cursor_move(), ui_get_event_multi(), ui_getmaxyx(), UI_KEY_BTAB, ui_surface, WIN, UiEvent::x, and UiEvent::y.

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

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 {
371 uint y = form->field[form->fidx]->line;
372 uint x = form->field[form->fidx]->col;
373
374 uint pos = 0;
375 mbstr_to_cellstr(form->field[form->fidx]->filler_cc, form->field[form->fidx]->filler_s, &cell_nt, &pos,
376 form->field[form->fidx]->len + 1);
377 ui_mvwadd_wchnstr(sfc, WIN, y, x, form->field[form->fidx]->filler_cc, form->field[form->fidx]->len);
378 ui_render();
379
380 pos = 0;
381 mbstr_to_cellstr(form->field[form->fidx]->display_cc, form->field[form->fidx]->display_s, &cell_nt, &pos,
382 form->field[form->fidx]->len + 1);
383 ui_mvwadd_wchnstr(sfc, WIN, y, x, form->field[form->fidx]->display_cc, form->field[form->fidx]->len);
384 ui_render();
385 return 0;
386}
void ui_render()
Definition ui_ncurses.c:800
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
UiCell cell_nt
Definition dwin.c:94
uint mbstr_to_cellstr(UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *pos, const uint atmost)
Convert multibyte string to complex character array.
Definition dwin.c:480

References cell_nt, Field::col, Field::display_cc, Field::display_s, Form::fidx, Form::field, Field::filler_cc, Field::filler_s, Field::len, Field::line, mbstr_to_cellstr(), sfc_ptr, ui_mvwadd_wchnstr(), ui_render(), ui_surface, and 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_n()

int form_display_field_n ( Form * form,
uint n )

Display field n.

Parameters
formPointer to Form structure
nField index to display
Returns
0 on success, non-zero on error

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 347 of file fields.c.

347 {
348 uint fidx = form->fidx;
349 form->fidx = n;
351 form->fidx = fidx;
352 return 0;
353}

References Form::fidx, and form_display_field().

Here is the call 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

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
Definition cm.h:57
uint mm
Definition cm.h:59
uint dd
Definition cm.h:60
uint yyyy
Definition cm.h:58
Definition cm.h:63
uint hh
Definition cm.h:64
uint mm
Definition cm.h:65
uint ss
Definition cm.h:66

Definition at line 448 of file fields.c.

448 {
449 strnz__cpy(form->field[form->fidx]->input_s, s, FIELD_MAXLEN - 1);
450 char *input_s = form->field[form->fidx]->input_s;
451 char *accept_s = form->field[form->fidx]->accept_s;
452 char *display_s = form->field[form->fidx]->display_s;
453 // char *filler_s = form->field[form->fidx]->filler_s;
454 uint ff = form->field[form->fidx]->ff;
455 uint fl = form->field[form->fidx]->len;
456
457 char field_s[FIELD_MAXLEN];
458 uint decimal_int_n = 0;
459 uint hex_int_n = 0;
460 float float_n = 0.0;
461 double double_n = 0.0;
462 double currency_n = 0.0;
463 Date date;
464 date.yyyy = date.mm = date.dd = 0;
465 Time time;
466 time.hh = time.mm = time.ss = 0;
467
468 strnz(accept_s, fl);
469 switch (ff) {
470 case FF_STRING:
471 left_justify(s);
472 trim(s);
473 strnz__cpy(input_s, s, FIELD_MAXLEN - 1);
474 strnz__cpy(accept_s, s, FIELD_MAXLEN - 1);
475 strnz__cpy(display_s, s, FIELD_MAXLEN - 1);
476 break;
477 case FF_DECIMAL_INT:
478 sscanf(input_s, "%d", &decimal_int_n);
479 sprintf(accept_s, "%d", decimal_int_n);
480 sprintf(display_s, "%d", decimal_int_n);
481 right_justify(display_s, fl);
482 break;
483 case FF_HEX_INT:
484 sscanf(input_s, "%x", &hex_int_n);
485 sprintf(accept_s, "%d", hex_int_n);
486 sprintf(display_s, "%x", hex_int_n);
487 right_justify(display_s, fl);
488 break;
489 case FF_FLOAT:
490 sscanf(input_s, "%f", &float_n);
491 sprintf(accept_s, "%f", float_n);
492 sprintf(display_s, "%f", float_n);
493 right_justify(display_s, fl);
494 break;
495 case FF_DOUBLE:
496 sscanf(input_s, "%lf", &double_n);
497 sprintf(accept_s, "%lf", double_n);
498 sprintf(display_s, "%lf", double_n);
499 right_justify(display_s, fl);
500 break;
501 case FF_CURRENCY:
502 numeric(field_s, input_s);
503 sscanf(field_s, "%lf", &currency_n);
504 sprintf(accept_s, "%.2lf", currency_n);
505 sprintf(display_s, "%'.2lf", currency_n);
506 right_justify(display_s, fl);
507 break;
508 case FF_YYYYMMDD:
509 date.yyyy = date.mm = date.dd = 0;
510 strnz__cpy(field_s, input_s, FIELD_MAXLEN - 1);
511 sscanf(field_s, "%4d%2d%2d", &date.yyyy, &date.mm, &date.dd);
512 sprintf(accept_s, "%04d%02d%02d", date.yyyy, date.mm, date.dd);
513 if (is_valid_date(date.yyyy, date.mm, date.dd))
514 sprintf(display_s, "%04d-%02d-%02d", date.yyyy, date.mm, date.dd);
515 break;
516 case FF_HHMMSS:
517 time.hh = time.mm = time.ss = 0;
518 strnz__cpy(field_s, input_s, FIELD_MAXLEN - 1);
519 sscanf(field_s, "%2d%2d%2d", &time.hh, &time.mm, &time.ss);
520 sprintf(accept_s, "%02d%02d%02d", time.hh, time.mm, time.ss);
521 if (is_valid_time(time.hh, time.mm, time.ss))
522 sprintf(display_s, "%02d:%02d:%02d", time.hh, time.mm, time.ss);
523 break;
524 case FF_APR:
525 sscanf(input_s, "%lf", &double_n);
526 sprintf(accept_s, "%lf", double_n);
527 sprintf(display_s, "%0.3lf", double_n);
528 right_justify(display_s, fl);
529 break;
530 default:
531 Perror("form_fmt_field() invalid format");
532 break;
533 }
534 strnz(accept_s, fl);
535 left_justify(accept_s);
536 return 0;
537}
bool is_valid_date(uint yyyy, uint mm, uint dd)
Check if a given date is valid, including leap years.
Definition fields.c:611
void numeric(char *d, char *s)
Extract numeric characters from source string to destination string.
Definition fields.c:648
bool is_valid_time(uint hh, uint mm, uint ss)
Check if a given time is valid.
Definition fields.c:632
void right_justify(char *, uint)
Right justify string by removing trailing spaces and adding leadingspaces.
Definition fields.c:585
void left_justify(char *s)
Left justify string by removing leading spaces.
Definition fields.c:572
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537
size_t trim(char *)
Trims leading and trailing spaces from string s in place.
Definition futil.c:384
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:608

References Field::accept_s, Date::dd, 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, Time::hh, Field::input_s, is_valid_date(), is_valid_time(), left_justify(), Field::len, Date::mm, Time::mm, numeric(), Perror(), right_justify(), Time::ss, strnz(), strnz__cpy(), trim(), and Date::yyyy.

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

Very underdeveloped - only checks F_NOTBLANK and F_NOMETAS

Definition at line 544 of file fields.c.

544 {
545 uint n = form->fidx;
546 char *p = form->field[n]->accept_s;
547 if (form->field[n]->ff & F_NOTBLANK) {
548 char *s = form->field[n]->accept_s;
549 while (*s++ == ' ')
550 ;
551 if (*s == '\0') {
552 Perror("blank field not allowed");
553 return (1);
554 }
555 }
556 if (form->field[n]->ff & F_NOMETAS) {
557 if (strpbrk(p, "*?[]") != 0) {
558 Perror("metacharacters not allowed");
559 return (1);
560 }
561 }
562 return (0);
563}
#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 ( uint yyyy,
uint mm,
uint dd )

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

Parameters
yyyyYear
mmMonth
ddDay
Returns
true if the date is valid, false otherwise

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 611 of file fields.c.

611 {
612 if (yyyy < 1 || mm < 1 || mm > 12 || dd < 1)
613 return false;
614 uint days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
615 if ((yyyy % 4 == 0 && yyyy % 100 != 0) || (yyyy % 400 == 0))
616 days_in_month[2] = 29;
617 if (dd > days_in_month[mm])
618 return false;
619 return true;
620}

◆ is_valid_time()

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

Check if a given time is valid.

Parameters
hhHour
mmMinute
ssSecond
Returns
true if the time is valid, false otherwise

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 632 of file fields.c.

632 {
633 if (hh > 23 || mm > 59 || ss > 59)
634 return false;
635 return true;
636}

◆ left_justify()

void left_justify ( char * s)

Left justify string by removing leading spaces.

Parameters
sString 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 572 of file fields.c.

572{ trim(s); }

◆ numeric()

void numeric ( char * d,
char * s )

Extract numeric characters from source string to destination string.

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

648 {
649 while (*s != '\0') {
650 if (*s == '-' || *s == '.' || (*s >= '0' && *s <= '9'))
651 *d++ = *s++;
652 else
653 s++;
654 }
655 *d = '\0';
656}

◆ right_justify()

void right_justify ( char * s,
uint fl )

Right justify string by removing trailing spaces and adding leadingspaces.

Parameters
sString to right justify
flField length

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 585 of file fields.c.

585 {
586 char *p = s;
587 char *d = s + fl;
588 trim(s);
589 *d = '\0';
590 while (*s != '\0') {
591 s++;
592 }
593 while (s != p) {
594 *(--d) = *(--s);
595 }
596 while (d != p) {
597 *(--d) = ' ';
598 }
599}