2
3
4
5
6
7
8
11
12
13
14
15
16
17
18
85static char doc[] =
"C-Menu - User Interface Toolkit";
86static char args_doc[] =
"[INPUT] [OUTPUT] [HELP] [ARG4] [ARG5]";
89static struct argp_option options[] = {
90 {
"f_dump_config",
'D', 0, 0,
"dump configuration", 0},
91 {
"f_write_config",
'W', 0, 0,
"write configuration", 0},
92 {
"minitrc",
'a',
"file_spec", 0,
"configuration file spec", 1},
93 {
"parent_cmd",
'k', 0, 0,
"parent command", 1},
94 {
"begx",
'X',
"number", 0,
"begin on column", 2},
95 {
"begy",
'Y',
"number", 0,
"begin on line", 2},
96 {
"cols",
'C',
"number", 0,
"width in columns", 2},
97 {
"lines",
'L',
"number", 0,
"height in lines", 2},
98 {
"out_spec",
'o',
"file_spec", 0,
"output spec", 2},
99 {
"select_max",
'n',
"number", 0,
"number of selections", 2},
100 {
"cmd",
'c',
"file_spec", 0,
"view cmd, first file", 3},
101 {
"cmd_all",
'A',
"file_spec", 0,
"view cmd, all files", 3},
102 {
"help_spec",
'H',
"file_spec", 0,
"help spec", 3},
103 {
"in_spec",
'i',
"file_spec", 0,
"input spec", 3},
104 {
"mapp_spec",
'd',
"file_spec", 0,
"description spec", 3},
105 {
"provider_cmd",
'S',
"file_spec", 0,
"execute provider of piped input", 3},
106 {
"receiver_cmd",
'R',
"file_spec", 0,
"execute receiver of piped output",
108 {
"title",
'T',
"text", 0,
"Window title", 3},
109 {
"wait_timeout",
'w',
"seconds", 0,
"Wait timer", 3},
110 {
"f_erase_remainder",
'e',
"bool", 0,
"erase remainder of line on enter",
112 {
"f_strip_ansi",
'j',
"bool", 0,
"always strip ansi when writing", 4},
113 {
"f_squeeze",
's',
"bool", 0,
"squeeze multiple blank lines", 4},
114 {
"f_ignore_case",
'x',
"bool", 0,
"ignore case in search", 4},
115 {
"f_ln",
'N',
"bool", 0,
"line numbers in view", 5},
116 {
"fill_char",
'f',
"char", 0,
"field fill_char", 5},
117 {
"brackets",
'u',
"text", 0,
"brackets around fields", 5},
118 {
"editor",
CM_EDITOR,
"text", 0,
"default editor", 8},
119 {
"tab_stop",
't',
"number", 0,
"number of spaces per tab", 5},
120 {
"bg_clr_x",
BG_XCLR,
"hex_clr", 0,
"background color", 6},
121 {
"bo_clr_x",
BO_XCLR,
"hex_clr", 0,
"border color", 6},
122 {
"fg_clr_x",
FG_XCLR,
"hex_clr", 0,
"foreground color", 6},
123 {
"ln__bg_clr_x",
LN_BG_CLR,
"hex_clr", 0,
"line number background", 6},
124 {
"ln_clr_x",
LN_XCLR,
"hex_clr", 0,
"line number color", 6},
125 {
"blue_gamma",
GM_BLUE,
"float", 0,
"blue_gamma (View)", 7},
126 {
"gray_gamma",
GM_GRAY,
"float", 0,
"gray gamma (View)", 7},
127 {
"green_gamma",
GM_GREEN,
"float", 0,
"green gamma (View)", 7},
128 {
"red_gamma",
GM_RED,
"float", 0,
"red gamma (View)", 7},
129 {
"black",
XBLACK,
"hex_clr", 0,
"black (#000000)", 8},
130 {
"red",
XRED,
"hex_clr", 0,
"red (#bf0000)", 8},
131 {
"green",
XGREEN,
"hex_clr", 0,
"green (#00cf00)", 8},
132 {
"yellow",
XYELLOW,
"hex_clr", 0,
"yellow (#efbf00)", 8},
133 {
"blue",
XBLUE,
"hex_clr", 0,
"blue (#0000FF)", 8},
134 {
"magenta",
XMAGENTA,
"hex_clr", 0,
"magenta (#9f009f)", 8},
135 {
"cyan",
XCYAN,
"hex_clr", 0,
"cyan (#00dfdf)", 8},
136 {
"white",
XWHITE,
"hex_clr", 0,
"white (#d0d0d0)", 8},
137 {
"bblack",
XBBLACK,
"hex_clr", 0,
"bright black (#7f7f7f)", 8},
138 {
"bred",
XBRED,
"hex_clr", 0,
"bright red (#FF3737)", 8},
139 {
"bgreen",
XBGREEN,
"hex_clr", 0,
"bright green (#00FF7f)", 8},
140 {
"byellow",
XBYELLOW,
"hex_clr", 0,
"bright yellow (#FFeF00)", 8},
141 {
"bblue",
XBBLUE,
"hex_clr", 0,
"bright blue (#00cfFF)", 8},
142 {
"bmagenta",
XMAGENTA,
"hex_clr", 0,
"bright magenta (#FF00FF)", 8},
143 {
"bcyan",
XBCYAN,
"hex_clr", 0,
"bright cyan (#00FFFF)", 8},
144 {
"bwhite",
XBWHITE,
"hex_clr", 0,
"bright white (#FFFFFF)", 8},
145 {
"mapp_data",
MAPP_DATA,
"directory", 0,
"data directory", 9},
146 {
"mapp_help",
MAPP_HELP,
"directory", 0,
"help directory", 9},
147 {
"mapp_home",
MAPP_HOME,
"directory", 0,
"home directory", 9},
148 {
"mapp_msrc",
MAPP_MSRC,
"directory", 0,
"source directory", 9},
149 {
"mapp_user",
MAPP_USER,
"directory", 0,
"user directory", 9},
153static error_t parse_opt(
int key,
char *arg,
struct argp_state *state) {
154 Init *init = state->input;
155 SIO *sio = init
->sio;
294 if (state->arg_num >= 5)
296 init
->argv[state->arg_num] = arg;
299 init
->argc = state->arg_num;
300 init
->argv[state->arg_num + 1] = NULL;
303 return ARGP_ERR_UNKNOWN;
308static struct argp argp = {options, parse_opt, args_doc, doc,
312
313
314
315
316
317
318
319
320
321
322
323
328 setlocale(LC_ALL,
"en_US.UTF-8");
329 SIO *sio = init
->sio;
332 "init struct not allocated on entry");
337 e = getenv(
"CMENU_HOME");
338 if (!e || *e ==
'\0')
342 e = getenv(
"CMENU_RC");
343 if (!e || *e ==
'\0')
366 if (e ==
nullptr || *e ==
'\0')
370 e = getenv(
"EDITOR");
377 argp_parse(&argp, argc, argv, 0, 0, init);
389 abend(-1
, "MAPP_HOME directory invalid");
395 argp_parse(&argp, argc, argv, 0, 0, init);
400
401
402
403
404
405
406
407
428
429
430
431
432
433
434
435
436
437
442 SIO *sio = init
->sio;
444 char *e = getenv(
"MINITRC");
451 FILE *config_fp = fopen(init
->minitrc,
"r");
453 fprintf(stderr,
"failed to read file: %s\n", init
->minitrc);
456 while (fgets(ts,
sizeof(ts), config_fp)) {
460 while (*sp !=
'\0') {
464 if (*sp !=
'"' && *sp !=
' ' && *sp !=
';') {
471 char *key = strtok(tmp_str,
"=");
472 char *value = strtok(
nullptr,
"=");
475 if (!strcmp(key,
"minitrc")) {
479 if (!strcmp(key,
"lines")) {
483 if (!strcmp(key,
"cols")) {
487 if (!strcmp(key,
"begy")) {
491 if (!strcmp(key,
"begx")) {
495 if (!strcmp(key,
"fg_clr_x")) {
499 if (!strcmp(key,
"bg_clr_x")) {
503 if (!strcmp(key,
"f_ln")) {
507 if (!strcmp(key,
"bo_clr_x")) {
511 if (!strcmp(key,
"ln_clr_x")) {
515 if (!strcmp(key,
"ln_bg_clr_x")) {
519 if (!strcmp(key,
"red_gamma")) {
523 if (!strcmp(key,
"green_gamma")) {
527 if (!strcmp(key,
"blue_gamma")) {
531 if (!strcmp(key,
"gray_gamma")) {
535 if (!strcmp(key,
"f_at_end_remove")) {
539 if (!strcmp(key,
"f_erase_remainder")) {
543 if (!strcmp(key,
"brackets")) {
547 if (!strcmp(key,
"fill_char")) {
551 if (!strcmp(key,
"f_ignore_case")) {
555 if (!strcmp(key,
"f_squeeze")) {
559 if (!strcmp(key,
"f_strip_ansi")) {
563 if (!strcmp(key,
"select_max")) {
567 if (!strcmp(key,
"tab_stop")) {
571 if (!strcmp(key,
"wait_timeout")) {
575 if (!strcmp(key,
"title")) {
579 if (!strcmp(key,
"cmd")) {
583 if (!strcmp(key,
"cmd_all")) {
587 if (!strcmp(key,
"parent_cmd")) {
591 if (!strcmp(key,
"provider_cmd")) {
595 if (!strcmp(key,
"receiver_cmd")) {
599 if (!strcmp(key,
"bg")) {
603 if (!strcmp(key,
"black")) {
607 if (!strcmp(key,
"red")) {
611 if (!strcmp(key,
"green")) {
615 if (!strcmp(key,
"yellow")) {
619 if (!strcmp(key,
"blue")) {
623 if (!strcmp(key,
"magenta")) {
627 if (!strcmp(key,
"cyan")) {
631 if (!strcmp(key,
"white")) {
635 if (!strcmp(key,
"orange")) {
639 if (!strcmp(key,
"bblack")) {
643 if (!strcmp(key,
"bred")) {
647 if (!strcmp(key,
"bgreen")) {
651 if (!strcmp(key,
"byellow")) {
655 if (!strcmp(key,
"bblue")) {
659 if (!strcmp(key,
"bmagenta")) {
663 if (!strcmp(key,
"bcyan")) {
667 if (!strcmp(key,
"bwhite")) {
671 if (!strcmp(key,
"borange")) {
675 if (!strcmp(key,
"bg")) {
679 if (!strcmp(key,
"editor")) {
683 if (!strcmp(key,
"mapp_spec")) {
687 if (!strcmp(key,
"mapp_data")) {
691 if (!strcmp(key,
"mapp_help")) {
695 if (!strcmp(key,
"mapp_home")) {
699 if (!strcmp(key,
"mapp_msrc")) {
703 if (!strcmp(key,
"mapp_user")) {
709 (
void)fclose(config_fp);
713
714
715
716
717
718
719
720
721
722
727 SIO *sio = init
->sio;
737 FILE *minitrc_fp = fopen(minitrc_dmp,
"w");
738 if (minitrc_fp == (FILE *)0) {
739 fprintf(stderr,
"failed to open file: %s\n", minitrc_dmp);
742 (
void)fprintf(minitrc_fp,
"# %s\n",
"~/.minitrc");
743 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"parent_cmd", init
->parent_cmd);
744 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"cols", init
->cols);
745 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"lines", init
->lines);
746 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"select_max", init
->select_max);
747 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"out_spec", init
->out_spec);
748 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"begx", init
->begx);
749 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"begy", init
->begy);
750 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cmd_all", init
->cmd_all);
751 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cmd", init
->cmd);
752 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_spec", init
->mapp_spec);
753 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"help_spec", init
->help_spec);
754 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"in_spec", init
->in_spec);
755 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"receiver_cmd", init
->receiver_cmd);
756 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"provider_cmd", init
->provider_cmd);
757 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"title", init
->title);
758 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_erase_remainder",
760 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_strip_ansi",
762 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_squeeze",
764 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_ignore_case",
766 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_ln", init
->f_ln ?
"true" :
"false");
767 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"brackets", init
->brackets);
768 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"fill_char", init
->fill_char);
769 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"editor", init
->editor);
770 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"tab_stop", init
->tab_stop);
771 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"wait_timeout",
wait_timeout);
772 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bg_clr_x", sio
->bg_clr_x);
773 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bo_clr_x", sio
->bo_clr_x);
774 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"fg_clr_x", sio
->fg_clr_x);
775 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"ln_bg_clr_x", sio
->ln_bg_clr_x);
776 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"ln_clr_x", sio
->ln_clr_x);
777 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"blue_gamma", sio
->blue_gamma);
778 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"gray_gamma", sio
->gray_gamma);
779 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"green_gamma", sio
->green_gamma);
780 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"red_gamma", sio
->red_gamma);
781 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"black", sio
->black);
782 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"red", sio
->red);
783 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"green", sio
->green);
784 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"yellow", sio
->yellow);
785 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"blue", sio
->blue);
786 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"magenta", sio
->magenta);
787 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cyan", sio
->cyan);
788 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"white", sio
->white);
789 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bblack", sio
->bblack);
790 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bred", sio
->bred);
791 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bgreen", sio
->bgreen);
792 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"byellow", sio
->byellow);
793 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bblue", sio
->bblue);
794 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bmagenta", sio
->bmagenta);
795 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bcyan", sio
->bcyan);
796 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bwhite", sio
->bwhite);
797 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"editor", init
->editor);
798 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_data", init
->mapp_data);
799 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_help", init
->mapp_help);
800 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_home", init
->mapp_home);
801 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_msrc", init
->mapp_msrc);
802 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_user", init
->mapp_user);
803 (
void)fclose(minitrc_fp);
810
811
812
813
814
815
816
817
818
819
820
826 if (!file_name || !*file_name) {
833 e = getenv(
"MAPP_DIR");
850
851
852
856 fprintf(stdout,
"C version: %ld\n", __STDC_VERSION__);
859
860
861
862
863
864
866 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value);
869
870
871
872
873
874
875
876void opt_prt_str(
const char *o,
const char *name,
const char *value) {
877 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value);
880
881
882
883
884
885
886
888 fprintf(stdout,
"%3s %-15s: %d\n", o, name, value);
891
892
893
894
895
896
897
899 fprintf(stdout,
"%3s %-15s: %0.2f\n", o, name, value);
902
903
904
905
906
907
908
909
911 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value ?
"true" :
"false");
914
915
916
917
918
920 SIO *sio = init
->sio;
979 (
void)fprintf(stdout,
"\n%s\n\n", msg);
int parse_opt_args(Init *, int, char **)
#define min(x, y)
min macro evaluates two expressions, returning least result
bool str_to_bool(const char *)
Converts String to boolean true or false.
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
const char * argp_program_version
const char * argp_program_bug_address
int Perror(char *)
Display a simple error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
double str_to_double(char *)
converts string to double
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
bool expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
bool verify_dir(char *, int)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
bool trim_path(char *)
Trims trailing spaces and slashes from directory path in place.
void opt_prt_str(const char *o, const char *name, const char *value)
Print an option and its value in a formatted manner for integer values.
void dump_config(Init *, char *)
Dump the current configuration to stdout for debugging purposes.
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
void display_version()
Display the version information of the application.
void opt_prt_double(const char *o, const char *name, double value)
Print an option and its value in a formatted manner for double values.
void opt_prt_char(const char *o, const char *name, const char *value)
Print an option and its value in a formatted manner.
int write_config(Init *)
Write the current configuration to a file specified in init->minitrc.
void opt_prt_bool(const char *o, const char *name, bool value)
Print an option and its value in a formatted manner for boolean values.
void opt_prt_int(const char *o, const char *name, int value)
Print an option and its value in a formatted manner for integer values.
int parse_config(Init *)
parse the configuration file specified in init->minitrc and set Init struct values accordingly
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
char receiver_cmd[MAXLEN]
char provider_cmd[MAXLEN]
char ln_bg_clr_x[COLOR_LEN]