2
3
4
5
6
7
8
11
12
13
14
15
16
17
18
86static char doc[] =
"C-Menu - User Interface Toolkit";
87static char args_doc[] =
"[INPUT] [OUTPUT] [HELP] [ARG4] [ARG5]";
90static struct argp_option options[] = {
91 {
"f_dump_config",
'D', 0, 0,
"dump configuration", 0},
92 {
"f_write_config",
'W', 0, 0,
"write configuration", 0},
93 {
"minitrc",
'a',
"file_spec", 0,
"configuration file spec", 1},
94 {
"parent_cmd",
'k', 0, 0,
"parent command", 1},
95 {
"begx",
'X',
"number", 0,
"begin on column", 2},
96 {
"begy",
'Y',
"number", 0,
"begin on line", 2},
97 {
"cols",
'C',
"number", 0,
"width in columns", 2},
98 {
"lines",
'L',
"number", 0,
"height in lines", 2},
99 {
"out_spec",
'o',
"file_spec", 0,
"output spec", 2},
100 {
"select_max",
'n',
"number", 0,
"number of selections", 2},
101 {
"cmd",
'c',
"file_spec", 0,
"view cmd, first file", 3},
102 {
"cmd_all",
'A',
"file_spec", 0,
"view cmd, all files", 3},
103 {
"help_spec",
'H',
"file_spec", 0,
"help spec", 3},
104 {
"in_spec",
'i',
"file_spec", 0,
"input spec", 3},
105 {
"mapp_spec",
'd',
"file_spec", 0,
"description spec", 3},
106 {
"provider_cmd",
'S',
"file_spec", 0,
"execute provider of piped input", 3},
107 {
"receiver_cmd",
'R',
"file_spec", 0,
"execute receiver of piped output",
109 {
"title",
'T',
"text", 0,
"Window title", 3},
110 {
"wait_timeout",
'w',
"seconds", 0,
"Wait timer", 3},
111 {
"f_erase_remainder",
'e',
"bool", 0,
"erase remainder of line on enter",
113 {
"f_strip_ansi",
'j',
"bool", 0,
"always strip ansi when writing", 4},
114 {
"f_squeeze",
's',
"bool", 0,
"squeeze multiple blank lines", 4},
115 {
"f_ignore_case",
'x',
"bool", 0,
"ignore case in search", 4},
116 {
"f_ln",
'N',
"bool", OPTION_ARG_OPTIONAL,
"line numbers in view", 5},
117 {
"fill_char",
'f',
"char", 0,
"field fill_char", 5},
118 {
"brackets",
'u',
"text", 0,
"brackets around fields", 5},
119 {
"editor",
CM_EDITOR,
"text", 0,
"default editor", 8},
120 {
"tab_stop",
't',
"number", 0,
"number of spaces per tab", 5},
121 {
"bg_clr_x",
BG_XCLR,
"hex_clr", 0,
"background color", 6},
122 {
"bo_clr_x",
BO_XCLR,
"hex_clr", 0,
"border color", 6},
123 {
"fg_clr_x",
FG_XCLR,
"hex_clr", 0,
"foreground color", 6},
124 {
"ln__bg_clr_x",
LN_BG_CLR,
"hex_clr", 0,
"line number background", 6},
125 {
"ln_clr_x",
LN_XCLR,
"hex_clr", 0,
"line number color", 6},
126 {
"blue_gamma",
GM_BLUE,
"float", 0,
"blue_gamma (View)", 7},
127 {
"gray_gamma",
GM_GRAY,
"float", 0,
"gray gamma (View)", 7},
128 {
"green_gamma",
GM_GREEN,
"float", 0,
"green gamma (View)", 7},
129 {
"red_gamma",
GM_RED,
"float", 0,
"red gamma (View)", 7},
130 {
"black",
XBLACK,
"hex_clr", 0,
"black (#000000)", 8},
131 {
"red",
XRED,
"hex_clr", 0,
"red (#bf0000)", 8},
132 {
"green",
XGREEN,
"hex_clr", 0,
"green (#00cf00)", 8},
133 {
"yellow",
XYELLOW,
"hex_clr", 0,
"yellow (#efbf00)", 8},
134 {
"blue",
XBLUE,
"hex_clr", 0,
"blue (#0000FF)", 8},
135 {
"magenta",
XMAGENTA,
"hex_clr", 0,
"magenta (#9f009f)", 8},
136 {
"cyan",
XCYAN,
"hex_clr", 0,
"cyan (#00dfdf)", 8},
137 {
"white",
XWHITE,
"hex_clr", 0,
"white (#d0d0d0)", 8},
138 {
"bblack",
XBBLACK,
"hex_clr", 0,
"bright black (#7f7f7f)", 8},
139 {
"bred",
XBRED,
"hex_clr", 0,
"bright red (#FF3737)", 8},
140 {
"bgreen",
XBGREEN,
"hex_clr", 0,
"bright green (#00FF7f)", 8},
141 {
"byellow",
XBYELLOW,
"hex_clr", 0,
"bright yellow (#FFeF00)", 8},
142 {
"bblue",
XBBLUE,
"hex_clr", 0,
"bright blue (#00cfFF)", 8},
143 {
"bmagenta",
XMAGENTA,
"hex_clr", 0,
"bright magenta (#FF00FF)", 8},
144 {
"bcyan",
XBCYAN,
"hex_clr", 0,
"bright cyan (#00FFFF)", 8},
145 {
"bwhite",
XBWHITE,
"hex_clr", 0,
"bright white (#FFFFFF)", 8},
146 {
"mapp_data",
MAPP_DATA,
"directory", 0,
"data directory", 9},
147 {
"mapp_help",
MAPP_HELP,
"directory", 0,
"help directory", 9},
148 {
"mapp_home",
MAPP_HOME,
"directory", 0,
"home directory", 9},
149 {
"mapp_msrc",
MAPP_MSRC,
"directory", 0,
"source directory", 9},
150 {
"mapp_user",
MAPP_USER,
"directory", 0,
"user directory", 9},
154static error_t parse_opt(
int key,
char *arg,
struct argp_state *state) {
155 Init *init = state->input;
156 SIO *sio = init
->sio;
298 if (state->arg_num >= 35)
300 init
->argv[state->arg_num] = strdup(arg);
303 init
->argc = state->arg_num;
307 return ARGP_ERR_UNKNOWN;
312static struct argp argp = {options, parse_opt, args_doc, doc,
316
317
318
319
320
321
322
323
324
325
326
327
332 setlocale(LC_ALL,
"en_US.UTF-8");
333 SIO *sio = init
->sio;
336 "init struct not allocated on entry");
343 e = getenv(
"CMENU_HOME");
344 if (!e || *e ==
'\0')
352 abend(-1
, "MAPP_HOME directory invalid");
355 e = getenv(
"CMENU_RC");
356 if (!e || *e ==
'\0') {
394 if (e ==
nullptr || *e ==
'\0')
398 e = getenv(
"EDITOR");
406 argp_parse(&argp, argc, argv, 0, 0, init);
417
418
419
420
421
422
423
424
425
426
429 argp_parse(&argp, argc, argv, 0, 0, init);
434
435
436
437
438
439
440
441
466
467
468
469
470
471
472
473
474
475
480 SIO *sio = init
->sio;
482 char *e = getenv(
"MINITRC");
489 FILE *config_fp = fopen(init
->minitrc,
"r");
491 fprintf(stderr,
"failed to read file: %s\n", init
->minitrc);
494 while (fgets(ts,
sizeof(ts), config_fp)) {
498 while (*sp !=
'\0') {
502 if (*sp !=
'"' && *sp !=
' ' && *sp !=
';') {
509 char *key = strtok(tmp_str,
"=");
510 char *value = strtok(
nullptr,
"=");
513 if (!strcmp(key,
"minitrc")) {
517 if (!strcmp(key,
"lines")) {
521 if (!strcmp(key,
"cols")) {
525 if (!strcmp(key,
"begy")) {
529 if (!strcmp(key,
"begx")) {
533 if (!strcmp(key,
"fg_clr_x")) {
537 if (!strcmp(key,
"bg_clr_x")) {
541 if (!strcmp(key,
"f_ln")) {
545 if (!strcmp(key,
"bo_clr_x")) {
549 if (!strcmp(key,
"ln_clr_x")) {
553 if (!strcmp(key,
"ln_bg_clr_x")) {
557 if (!strcmp(key,
"red_gamma")) {
561 if (!strcmp(key,
"green_gamma")) {
565 if (!strcmp(key,
"blue_gamma")) {
569 if (!strcmp(key,
"gray_gamma")) {
573 if (!strcmp(key,
"f_at_end_remove")) {
577 if (!strcmp(key,
"f_erase_remainder")) {
581 if (!strcmp(key,
"brackets")) {
585 if (!strcmp(key,
"fill_char")) {
589 if (!strcmp(key,
"f_ignore_case")) {
593 if (!strcmp(key,
"f_squeeze")) {
597 if (!strcmp(key,
"f_strip_ansi")) {
601 if (!strcmp(key,
"select_max")) {
605 if (!strcmp(key,
"tab_stop")) {
609 if (!strcmp(key,
"wait_timeout")) {
613 if (!strcmp(key,
"title")) {
617 if (!strcmp(key,
"cmd")) {
621 if (!strcmp(key,
"cmd_all")) {
625 if (!strcmp(key,
"parent_cmd")) {
629 if (!strcmp(key,
"provider_cmd")) {
633 if (!strcmp(key,
"receiver_cmd")) {
637 if (!strcmp(key,
"nt_fg")) {
641 if (!strcmp(key,
"nt_bg")) {
645 if (!strcmp(key,
"nt_rev_fg")) {
649 if (!strcmp(key,
"nt_rev_bg")) {
653 if (!strcmp(key,
"nt_hl_fg")) {
657 if (!strcmp(key,
"nt_hl_bg")) {
661 if (!strcmp(key,
"nt_hl_rev_fg")) {
665 if (!strcmp(key,
"nt_hl_rev_bg")) {
669 if (!strcmp(key,
"nt_hl_rev_fg")) {
673 if (!strcmp(key,
"bg")) {
677 if (!strcmp(key,
"black")) {
681 if (!strcmp(key,
"red")) {
685 if (!strcmp(key,
"green")) {
689 if (!strcmp(key,
"yellow")) {
693 if (!strcmp(key,
"blue")) {
697 if (!strcmp(key,
"magenta")) {
701 if (!strcmp(key,
"cyan")) {
705 if (!strcmp(key,
"white")) {
709 if (!strcmp(key,
"orange")) {
713 if (!strcmp(key,
"bblack")) {
717 if (!strcmp(key,
"bred")) {
721 if (!strcmp(key,
"bgreen")) {
725 if (!strcmp(key,
"byellow")) {
729 if (!strcmp(key,
"bblue")) {
733 if (!strcmp(key,
"bmagenta")) {
737 if (!strcmp(key,
"bcyan")) {
741 if (!strcmp(key,
"bwhite")) {
745 if (!strcmp(key,
"borange")) {
749 if (!strcmp(key,
"bg")) {
753 if (!strcmp(key,
"editor")) {
757 if (!strcmp(key,
"mapp_spec")) {
761 if (!strcmp(key,
"mapp_data")) {
765 if (!strcmp(key,
"mapp_help")) {
769 if (!strcmp(key,
"mapp_home")) {
773 if (!strcmp(key,
"mapp_msrc")) {
777 if (!strcmp(key,
"mapp_user")) {
783 (
void)fclose(config_fp);
787
788
789
790
791
792
793
794
795
796
801 SIO *sio = init
->sio;
811 FILE *minitrc_fp = fopen(minitrc_dmp,
"w");
812 if (minitrc_fp == (FILE *)0) {
813 fprintf(stderr,
"failed to open file: %s\n", minitrc_dmp);
816 (
void)fprintf(minitrc_fp,
"# %s\n",
"~/.minitrc");
817 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"parent_cmd", init
->parent_cmd);
818 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"cols", init
->cols);
819 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"lines", init
->lines);
820 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"select_max", init
->select_max);
821 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"out_spec", init
->out_spec);
822 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"begx", init
->begx);
823 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"begy", init
->begy);
824 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cmd_all", init
->cmd_all);
825 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cmd", init
->cmd);
826 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_spec", init
->mapp_spec);
827 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"help_spec", init
->help_spec);
828 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"in_spec", init
->in_spec);
829 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"receiver_cmd", init
->receiver_cmd);
830 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"provider_cmd", init
->provider_cmd);
831 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"title", init
->title);
832 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_erase_remainder",
834 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_strip_ansi",
836 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_squeeze",
838 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_ignore_case",
840 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"f_ln", init
->f_ln ?
"true" :
"false");
841 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"brackets", init
->brackets);
842 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"fill_char", init
->fill_char);
843 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"editor", init
->editor);
844 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"tab_stop", init
->tab_stop);
845 (
void)fprintf(minitrc_fp,
"%s=%d\n",
"wait_timeout",
wait_timeout);
846 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bg_clr_x", sio
->bg_clr_x);
847 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bo_clr_x", sio
->bo_clr_x);
848 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"fg_clr_x", sio
->fg_clr_x);
849 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"ln_bg_clr_x", sio
->ln_bg_clr_x);
850 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"ln_clr_x", sio
->ln_clr_x);
851 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"blue_gamma", sio
->blue_gamma);
852 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"gray_gamma", sio
->gray_gamma);
853 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"green_gamma", sio
->green_gamma);
854 (
void)fprintf(minitrc_fp,
"%s=%0.2f\n",
"red_gamma", sio
->red_gamma);
856 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_fg", sio
->nt_fg);
857 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_bg", sio
->nt_bg);
859 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_hl_fg", sio
->nt_hl_fg);
860 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_hl_bg", sio
->nt_hl_bg);
862 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_rev_fg", sio
->nt_rev_fg);
863 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_rev_bg", sio
->nt_rev_bg);
865 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_hl_rev_fg", sio
->nt_hl_rev_fg);
866 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"nt_hl_rev_bg", sio
->nt_hl_rev_bg);
868 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"black", sio
->black);
869 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"red", sio
->red);
870 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"green", sio
->green);
871 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"yellow", sio
->yellow);
872 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"blue", sio
->blue);
873 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"magenta", sio
->magenta);
874 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"cyan", sio
->cyan);
875 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"white", sio
->white);
876 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bblack", sio
->bblack);
877 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bred", sio
->bred);
878 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bgreen", sio
->bgreen);
879 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"byellow", sio
->byellow);
880 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bblue", sio
->bblue);
881 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bmagenta", sio
->bmagenta);
882 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bcyan", sio
->bcyan);
883 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"bwhite", sio
->bwhite);
884 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"editor", init
->editor);
885 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_data", init
->mapp_data);
886 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_help", init
->mapp_help);
887 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_home", init
->mapp_home);
888 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_msrc", init
->mapp_msrc);
889 (
void)fprintf(minitrc_fp,
"%s=%s\n",
"mapp_user", init
->mapp_user);
890 (
void)fclose(minitrc_fp);
897
898
899
900
901
902
903
904
905
906
912 if (!file_name || !*file_name) {
919 e = getenv(
"MAPP_DIR");
936
937
938
942 fprintf(stdout,
"C version: %ld\n", __STDC_VERSION__);
945
946
947
948
949
950
952 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value);
955
956
957
958
959
960
961
962void opt_prt_str(
const char *o,
const char *name,
const char *value) {
963 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value);
966
967
968
969
970
971
972
974 fprintf(stdout,
"%3s %-15s: %d\n", o, name, value);
977
978
979
980
981
982
983
985 fprintf(stdout,
"%3s %-15s: %0.2f\n", o, name, value);
988
989
990
991
992
993
994
995
997 fprintf(stdout,
"%3s %-15s: %s\n", o, name, value ?
"true" :
"false");
1000
1001
1002
1003
1004
1006 SIO *sio = init
->sio;
1065 (
void)fprintf(stdout,
"\n%s\n\n", msg);
#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
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
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.
bool expand_tilde(char *, int)
Replaces "~/" in string with the user's home directory.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
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.
int parse_opt_args(Init *, int, char **)
Parse command-line options and set Init struct values accordingly.
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 nt_hl_rev_bg[COLOR_LEN]
char nt_rev_bg[COLOR_LEN]
char nt_rev_fg[COLOR_LEN]
char ln_bg_clr_x[COLOR_LEN]
char nt_hl_rev_fg[COLOR_LEN]