2
3
4
5
6
7
8
26char ff_tbl[][26] = {
"string",
"decimal_int",
"hex_int",
"float",
"double",
27 "currency",
"yyyymmdd",
"hhmmss",
"apr",
""};
36
37
38
39
40
41
42
43
44
47
48
49
50
51
52
53
54
56 bool f_insert =
FALSE;
59 WINDOW *win = form
->win;
69 char *fstart = accept_s;
70 char *fend = fstart + flen;
72 char *p = fstart = accept_s;
73 char *str_end = p + strlen(p);
84 mvwaddstr(win, flin, fcol, filler_s);
85 mvwaddstr(win, flin, fcol, accept_s);
93
128 x = fcol + (p - fstart);
132
133
199 if (p < fend && p < str_end) {
216 fend = fstart + flen;
217 str_end = fstart + strlen(fstart);
235
237 if ((in_key >=
'0' && in_key <=
'9') || in_key ==
'.')
243
245 if ((in_key >=
'0' && in_key <=
'9') ||
246 (in_key >=
'A' && in_key <=
'F') ||
247 (in_key >=
'a' && in_key <=
'f'))
253
255 if ((in_key >=
'0' && in_key <=
'9') || in_key ==
'.' ||
256 (in_key ==
'-' && p == fstart))
262
264 if ((in_key >=
'0' && in_key <=
'9') || in_key ==
'.' ||
265 (in_key ==
'-' && p == fstart))
271
272
274 if ((in_key >=
'0' && in_key <=
'9') || in_key ==
'.' ||
275 (in_key ==
'-' && p == fstart))
282 if (in_key >=
'0' && in_key <=
'9')
289 if (in_key >=
'0' && in_key <=
'9')
296 if ((in_key >=
'0' && in_key <=
'9') || in_key ==
'.')
302 Perror("field_editor() invalid format");
305 if (in_key <
' ' || in_key >
'~') {
310 if (str_end < fend) {
324 }
else if (p == str_end) {
339
340
341
342
343
344
345
346
347
356
357
358
359
360
361
362
363
364
365
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
427 int decimal_int_n = 0;
430 double double_n = 0.0;
431 double currency_n = 0.0;
438 Date.yyyy = Date.mm = Date.dd = 0;
444 Time.hh = Time.mm = Time.ss = 0;
455 sscanf(input_s,
"%d", &decimal_int_n);
456 sprintf(accept_s,
"%d", decimal_int_n);
457 sprintf(display_s,
"%d", decimal_int_n);
461 sscanf(input_s,
"%x", &hex_int_n);
462 sprintf(accept_s,
"%d", hex_int_n);
463 sprintf(display_s,
"%x", hex_int_n);
467 sscanf(input_s,
"%f", &float_n);
468 sprintf(accept_s,
"%f", float_n);
469 sprintf(display_s,
"%f", float_n);
473 sscanf(input_s,
"%lf", &double_n);
474 sprintf(accept_s,
"%lf", double_n);
475 sprintf(display_s,
"%lf", double_n);
480 sscanf(field_s,
"%lf", ¤cy_n);
481 sprintf(accept_s,
"%.2lf", currency_n);
482 sprintf(display_s,
"%'.2lf", currency_n);
486 Date.yyyy = Date.mm = Date.dd = 0;
488 sscanf(field_s,
"%4d%2d%2d", &Date.yyyy, &Date.mm, &Date.dd);
489 sprintf(accept_s,
"%04d%02d%02d", Date.yyyy, Date.mm, Date.dd);
491 sprintf(display_s,
"%04d-%02d-%02d", Date.yyyy, Date.mm, Date.dd);
494 Time.hh = Time.mm = Time.ss = 0;
496 sscanf(field_s,
"%2d%2d%2d", &Time.hh, &Time.mm, &Time.ss);
497 sprintf(accept_s,
"%02d%02d%02d", Time.hh, Time.mm, Time.ss);
499 sprintf(display_s,
"%02d:%02d:%02d", Time.hh, Time.mm, Time.ss);
502 sscanf(input_s,
"%lf", &double_n);
503 sprintf(accept_s,
"%lf", double_n);
504 sprintf(display_s,
"%0.3lf", double_n);
508 Perror("form_fmt_field() invalid format");
517
518
519
520
521
535 if (strpbrk(p,
"*?[]") != 0) {
536 Perror("metacharacters not allowed");
543
544
545
546
547
548
549
550
561
562
563
564
565
566
567
570
571
572
573
574
575
576
577
578
579
596
597
598
599
600
601
602
603
604
605
607 if (yyyy < 1 || mm < 1 || mm > 12 || dd < 1)
609 int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
610 if ((yyyy % 4 == 0 && yyyy % 100 != 0) || (yyyy % 400 == 0))
611 days_in_month[2] = 29;
612 if (dd > days_in_month[mm])
617
618
619
620
621
622
623
624
625
626
628 if (hh < 0 || hh > 23 || mm < 0 || mm > 59 || ss < 0 || ss > 59)
633
634
635
636
637
638
639
640
641
642
645 if (*s ==
'-' || *s ==
'.' || (*s >=
'0' && *s <=
'9'))
int form_yx_to_fidx(Form *, int, int)
#define min(x, y)
min macro evaluates two expressions, returning least result
int xwgetch(WINDOW *, Chyron *, int)
Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line,...
int Perror(char *)
Display a simple error message window or print to stderr.
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Display chyron on window.
void set_chyron_key_cp(Chyron *, int, char *, int, int)
Set chyron key with color pair (cp).
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
int form_fmt_field(Form *, char *)
Format field according to its format type.
int field_editor(Form *)
Accept input for a field.
void numeric(char *, char *)
Extract numeric characters from source string to destination string.
void right_justify(char *, int)
Right justify string by removing trailing spaces and adding leadingspaces.
bool is_valid_date(int, int, int)
Check if a given date is valid, including leap years.
void left_justify(char *)
Left justify string by removing leading spaces.
bool is_valid_time(int, int, int)
Check if a given time is valid.
int form_display_field_n(Form *, int)
Display field n.
void mk_filler(char *, int)
Create filler string for field.
int form_display_field(Form *)
Display current field.
int form_validate_field(Form *)
Validate current field based on flags.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
size_t trim(char *)
Trims leading and trailing spaces from string s in place.
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
char display_s[FIELD_MAXLEN]
char accept_s[FIELD_MAXLEN]
char input_s[FIELD_MAXLEN]
char filler_s[FIELD_MAXLEN]
Field * field[FIELD_MAXCNT]