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

Capture Data from the Environment, Command Line, and Configuration File and Populate the Init and SIO Data Structures. More...

Functions

void mapp_initialization (Init *init, int argc, char **argv)
 Main initialization function for MAPP - Menu Application.
void zero_opt_args (Init *init)
 Initialize optional arguments in the Init struct to default values.
int parse_config (Init *init)
 parse the configuration file specified in init->minitrc and set Init struct values accordingly
int write_config (Init *init)
 Write the current configuration to a file specified in init->minitrc.
bool derive_file_spec (char *file_spec, char *dir, char *file_name)
 Derive full file specification from directory and file name.
void display_version ()
 Display the version information of the application.
void opt_prt_char (const char *o, const char *name, const char *value)
 Print an option and its value in a formatted manner.
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 opt_prt_int (const char *o, const char *name, int value)
 Print an option and its value in a formatted manner for integer values.
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_bool (const char *o, const char *name, bool value)
 Print an option and its value in a formatted manner for boolean values.
void dump_config (Init *init, char *msg)
 Dump the current configuration to stdout for debugging purposes.

Detailed Description

Capture Data from the Environment, Command Line, and Configuration File and Populate the Init and SIO Data Structures.

    SIO   Struct for screen I/O settings (colors, gamma, etc.)
    Init  Struct for application settings (file paths, commands, flags, etc.)

Function Documentation

◆ derive_file_spec()

bool derive_file_spec ( char * file_spec,
char * dir,
char * file_name )

Derive full file specification from directory and file name.

Parameters
file_spec- output full file specification
dir- directory path
file_name- file name
Returns
true if file_spec is derived, false otherwise
Note
If dir is nullptr, use MAPP_DIR environment variable or default directory ~/menuapp
file_spec should be a pre-allocated char array of size MAXLEN to hold the resulting file specification

Definition at line 821 of file init.c.

821 {
822 char ts[MAXLEN];
823 char ts2[MAXLEN];
824 char *e;
825
826 if (!file_name || !*file_name) {
827 *file_spec = '\0';
828 return false;
829 }
830 if (dir) {
831 strnz__cpy(ts, dir, MAXLEN - 1);
832 } else {
833 e = getenv("MAPP_DIR");
834 if (e) {
835 strnz__cpy(ts, e, MAXLEN - 1);
836 } else {
837 strnz__cpy(ts, "~/menuapp", MAXLEN - 1);
838 }
839 }
840 trim_path(ts);
841 strnz__cpy(ts2, ts, MAXLEN - 1);
842 // construct the full file specification
843 // check that the file exists and is readable
844 strnz__cpy(file_spec, ts2, MAXLEN - 1);
845 strnz__cat(file_spec, "/", MAXLEN - 1);
846 strnz__cat(file_spec, file_name, MAXLEN - 1);
847 return true;
848}
#define MAXLEN
Definition curskeys.c:15
char * file_name[MAXLEN+1]
Definition whence.c:25
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:298
bool trim_path(char *)
Trims trailing spaces and slashes from directory path in place.
Definition futil.c:713

References strnz__cat(), strnz__cpy(), and trim_path().

Here is the call graph for this function:

◆ display_version()

void display_version ( )

Display the version information of the application.

Note
The version information is defined in the mapp_version variable and is printed to stdout when this function is called.

Definition at line 853 of file init.c.

853 {
854 fprintf(stdout, "\nC-Menu %s\n", CM_VERSION);
855 fprintf(stdout, "\nC-Menu %s\n", CM_VERSION);
856 fprintf(stdout, "C version: %ld\n", __STDC_VERSION__);
857}
#define CM_VERSION
Definition version.h:7

◆ dump_config()

void dump_config ( Init * init,
char * msg )

Dump the current configuration to stdout for debugging purposes.

Parameters
init- pointer to Init struct containing the current configuration
msg- string to print before dumping the configuration to stdout in a readable format, prefixed by the provided title string.

Definition at line 919 of file init.c.

919 {
920 SIO *sio = init->sio;
921 opt_prt_str("-a:", "--minitrc", init->minitrc);
922 opt_prt_str("-k:", " parent_cmd", init->parent_cmd);
923 opt_prt_int("-C:", " cols", init->cols);
924 opt_prt_int("-L:", " lines", init->lines);
925 opt_prt_int("-n:", " select_max", init->select_max);
926 opt_prt_str("-o:", " out_spec", init->out_spec);
927 opt_prt_int("-X:", " begx", init->begx);
928 opt_prt_int("-Y:", " begy", init->begy);
929 opt_prt_str("-A:", " cmd_all", init->cmd_all);
930 opt_prt_str("-c:", " cmd", init->cmd);
931 opt_prt_str("-d:", "--mapp_spec", init->mapp_spec);
932 opt_prt_str(" ", " help_spec", init->help_spec);
933 opt_prt_str("-i:", " in_spec", init->in_spec);
934 opt_prt_str("-R:", " receiver_cmd", init->receiver_cmd);
935 opt_prt_str("-S:", " provider_cmd", init->provider_cmd);
936 opt_prt_str(" ", " title", init->title);
937 opt_prt_bool("-e:", " f_erase_remainder", init->f_erase_remainder);
938 opt_prt_bool("-a ", " f_strip_ansi", init->f_strip_ansi);
939 opt_prt_bool("-s ", " f_squeeze", init->f_squeeze);
940 opt_prt_bool("-x:", " f_ignore_case", init->f_ignore_case);
941 opt_prt_bool("-N:", " f_ln", init->f_ln);
942 opt_prt_int("-t:", " tab_stop", init->tab_stop);
943 opt_prt_int("-w:", " wait_timeout", wait_timeout);
944 opt_prt_str("-u ", " brackets", init->brackets);
945 opt_prt_str("-f:", " fill_char", init->fill_char);
946 opt_prt_str(" ", " editor", init->editor);
947 opt_prt_str(" ", " bg_clr_x", sio->bg_clr_x);
948 opt_prt_str(" ", " bo_clr_x", sio->bo_clr_x);
949 opt_prt_str(" ", " fg_clr_x", sio->fg_clr_x);
950 opt_prt_str(" ", " ln_bg_clr_x", sio->ln_bg_clr_x);
951 opt_prt_str(" ", " ln_clr_x", sio->ln_clr_x);
952 opt_prt_double(" ", " blue_gamma", sio->blue_gamma);
953 opt_prt_double(" ", " gray_gamma", sio->gray_gamma);
954 opt_prt_double(" ", " green_gamma", sio->green_gamma);
955 opt_prt_double(" ", " red_gamma", sio->red_gamma);
956 opt_prt_str(" ", " black", sio->black);
957 opt_prt_str(" ", " red", sio->red);
958 opt_prt_str(" ", " green", sio->green);
959 opt_prt_str(" ", " yellow", sio->yellow);
960 opt_prt_str(" ", " blue", sio->blue);
961 opt_prt_str(" ", " magenta", sio->magenta);
962 opt_prt_str(" ", " cyan", sio->cyan);
963 opt_prt_str(" ", " white", sio->white);
964 opt_prt_str(" ", " orange", sio->orange);
965 opt_prt_str(" ", " bblack", sio->bblack);
966 opt_prt_str(" ", " bred", sio->bred);
967 opt_prt_str(" ", " bgreen", sio->bgreen);
968 opt_prt_str(" ", " byellow", sio->byellow);
969 opt_prt_str(" ", " bblue", sio->bblue);
970 opt_prt_str(" ", " bmagenta", sio->bmagenta);
971 opt_prt_str(" ", " bcyan", sio->bcyan);
972 opt_prt_str(" ", " bwhite", sio->bwhite);
973 opt_prt_str(" ", " borange", sio->borange);
974 opt_prt_str(" ", "--mapp_data", init->mapp_data);
975 opt_prt_str(" ", "--mapp_help", init->mapp_help);
976 opt_prt_str(" ", "--mapp_home", init->mapp_home);
977 opt_prt_str(" ", "--mapp_msrc", init->mapp_msrc);
978 opt_prt_str(" ", "--mapp_user", init->mapp_user);
979 (void)fprintf(stdout, "\n%s\n\n", msg);
980}
Init * init
Definition common.h:186
int wait_timeout
Definition futil.c:98
SIO * sio
Definition dwin.c:77
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.
Definition init.c:876
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.
Definition init.c:898
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.
Definition init.c:910
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.
Definition init.c:887
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:626

References SIO::bblack, SIO::bblue, SIO::bcyan, Init::begx, Init::begy, SIO::bg_clr_x, SIO::bgreen, SIO::black, SIO::blue, SIO::blue_gamma, SIO::bmagenta, SIO::bo_clr_x, SIO::borange, Init::brackets, SIO::bred, SIO::bwhite, SIO::byellow, Init::cmd, Init::cmd_all, Init::cols, SIO::cyan, Init::editor, Init::f_erase_remainder, Init::f_ignore_case, Init::f_ln, Init::f_squeeze, Init::f_strip_ansi, SIO::fg_clr_x, Init::fill_char, SIO::gray_gamma, SIO::green, SIO::green_gamma, Init::help_spec, Init::in_spec, Init::lines, SIO::ln_bg_clr_x, SIO::ln_clr_x, SIO::magenta, Init::mapp_data, Init::mapp_help, Init::mapp_home, Init::mapp_msrc, Init::mapp_spec, Init::mapp_user, Init::minitrc, opt_prt_bool(), opt_prt_double(), opt_prt_int(), opt_prt_str(), SIO::orange, Init::out_spec, Init::parent_cmd, Init::provider_cmd, Init::receiver_cmd, SIO::red, SIO::red_gamma, Init::select_max, Init::sio, Init::tab_stop, Init::title, wait_timeout, SIO::white, and SIO::yellow.

Referenced by mapp_initialization().

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

◆ mapp_initialization()

void mapp_initialization ( Init * init,
int argc,
char ** argv )

Main initialization function for MAPP - Menu Application.

Parameters
init- pointer to Init struct to be initialized
argc- argument count from main()
argv- argument vector from main()
1. Read environment variables and set defaults
2. Parse configuration file
3. Parse command-line options
4. Set up SIO struct with colors and other settings
5. Handle special options like help and version

< background color

< foreground color

< bold color

< line number olor

< line number background

< erase remainder on enter

< field enclosure brackets

< field fill character

< menu specification file

Definition at line 324 of file init.c.

324 {
325 char term[MAXLEN];
326 char tmp_str[MAXLEN];
327 char *e;
328 setlocale(LC_ALL, "en_US.UTF-8");
329 SIO *sio = init->sio;
330 if (!init) {
331 ssnprintf(tmp_str, sizeof(tmp_str), "%s",
332 "init struct not allocated on entry");
333 abend(-1, tmp_str);
334 exit(-1);
335 }
336
337 e = getenv("CMENU_HOME");
338 if (!e || *e == '\0')
339 strnz__cpy(init->mapp_home, "~/menuapp", MAXLEN);
340 else
341 strnz__cpy(init->mapp_home, e, MAXLEN);
342 e = getenv("CMENU_RC");
343 if (!e || *e == '\0')
344 strnz__cpy(init->minitrc, "~/menuapp/.minitrc", MAXLEN);
345 else
346 strnz__cpy(init->minitrc, e, MAXLEN);
347 if (init->minitrc[0] == '\0')
348 strnz__cpy(init->minitrc, "~/.minitrc", MAXLEN - 1);
349 strnz__cpy(sio->bg_clr_x, "#000007", COLOR_LEN - 1);
350 strnz__cpy(sio->fg_clr_x, "#c0c0c0", COLOR_LEN - 1);
351 strnz__cpy(sio->bo_clr_x, "#f00000", COLOR_LEN - 1);
352 strnz__cpy(sio->ln_clr_x, "#0070ff", COLOR_LEN - 1);
353 strnz__cpy(sio->ln_bg_clr_x, "#101010",
354 COLOR_LEN - 1);
355 init->f_erase_remainder = true;
356 init->brackets[0] = '\0';
357 strnz__cpy(init->fill_char, "_", MAXLEN - 1);
358 init->mapp_spec[0] = '\0';
359 strnz__cpy(init->mapp_home, "~/menuapp", MAXLEN - 1);
360 strnz__cpy(init->mapp_user, "~/menuapp/user", MAXLEN - 1);
361 strnz__cpy(init->mapp_msrc, "~/menuapp/msrc", MAXLEN - 1);
362 strnz__cpy(init->mapp_data, "~/menuapp/data", MAXLEN - 1);
363 strnz__cpy(init->mapp_help, "~/menuapp/help", MAXLEN - 1);
364
365 e = getenv("TERM");
366 if (e == nullptr || *e == '\0')
367 strnz__cpy(term, "xterm-256color", MAXLEN);
368 else
369 strnz__cpy(term, e, MAXLEN - 1);
370 e = getenv("EDITOR");
371 if (e && *e != '\0')
372 strnz__cpy(init->editor, "vi", MAXLEN - 1);
373 else
374 strnz__cpy(init->editor, e, MAXLEN - 1);
376 init->argc = argc;
377 argp_parse(&argp, argc, argv, 0, 0, init);
378 if (f_write_config) {
380 exit(EXIT_SUCCESS);
381 }
382 if (f_dump_config) {
383 dump_config(init, "Current Configuration");
384 exit(EXIT_SUCCESS);
385 }
386 if (init->mapp_home[0] != '\0') {
387 expand_tilde(init->mapp_home, MAXLEN - 1);
388 if (!verify_dir(init->mapp_home, R_OK))
389 abend(-1, "MAPP_HOME directory invalid");
390 }
391}
#define COLOR_LEN
Definition cm.h:180
bool f_dump_config
Definition init.c:68
bool f_write_config
Definition init.c:67
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1331
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:147
bool expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
Definition futil.c:684
bool verify_dir(char *, int)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:841
void dump_config(Init *, char *)
Dump the current configuration to stdout for debugging purposes.
Definition init.c:919
int write_config(Init *init)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:723
int parse_config(Init *)
parse the configuration file specified in init->minitrc and set Init struct values accordingly
Definition init.c:438

References abend(), Init::argc, SIO::bg_clr_x, SIO::bo_clr_x, Init::brackets, dump_config(), Init::editor, expand_tilde(), f_dump_config, Init::f_erase_remainder, f_write_config, SIO::fg_clr_x, Init::fill_char, SIO::ln_bg_clr_x, SIO::ln_clr_x, Init::mapp_data, Init::mapp_help, Init::mapp_home, Init::mapp_msrc, Init::mapp_spec, Init::mapp_user, Init::minitrc, parse_config(), Init::sio, ssnprintf(), strnz__cpy(), verify_dir(), and write_config().

Referenced by main().

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

◆ opt_prt_bool()

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.

Parameters
o- option flag (e.g., "-z")
name- option name (e.g., "f_squeeze")
value- boolean option value to print
Note
This function is used to display the current configuration options and their boolean values in a readable format, printing "true" or "false" based on the value.

Definition at line 910 of file init.c.

910 {
911 fprintf(stdout, "%3s %-15s: %s\n", o, name, value ? "true" : "false");
912}

Referenced by dump_config().

Here is the caller graph for this function:

◆ opt_prt_char()

void opt_prt_char ( const char * o,
const char * name,
const char * value )

Print an option and its value in a formatted manner.

Parameters
o- option flag (e.g., "-a:")
name- option name (e.g., "--minitrc")
value- option value to print
Note
This function is used to display the current configuration options and their values in a readable format.

Definition at line 865 of file init.c.

865 {
866 fprintf(stdout, "%3s %-15s: %s\n", o, name, value);
867}

◆ opt_prt_double()

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.

Parameters
o- option flag (e.g., "-r:")
name- option name (e.g., "red_gamma")
value- double option value to print
Note
This function is used to display the current configuration options and their double values in a readable format.

Definition at line 898 of file init.c.

898 {
899 fprintf(stdout, "%3s %-15s: %0.2f\n", o, name, value);
900}

Referenced by dump_config().

Here is the caller graph for this function:

◆ opt_prt_int()

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.

Parameters
o- option flag (e.g., "-C:")
name- option name (e.g., "--cols")
value- integer option value to print
Note
This function is used to display the current configuration options and their integer values in a readable format.

Definition at line 887 of file init.c.

887 {
888 fprintf(stdout, "%3s %-15s: %d\n", o, name, value);
889}

Referenced by dump_config().

Here is the caller graph for this function:

◆ opt_prt_str()

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.

Parameters
o- option flag (e.g., "-C:")
name- option name (e.g., "--cols")
value- integer option value to print
Note
This function is used to display the current configuration options and their integer values in a readable format.

Definition at line 876 of file init.c.

876 {
877 fprintf(stdout, "%3s %-15s: %s\n", o, name, value);
878}

Referenced by dump_config().

Here is the caller graph for this function:

◆ parse_config()

int parse_config ( Init * init)

parse the configuration file specified in init->minitrc and set Init struct values accordingly

Returns
on success, -1 on failure
Note
lines beginning with '#" are comments, discard @note copy line to tmp_str removing quotes, spaces, semicolons, and newlines @note record structure is "parse key=value pairs"
skip lines without '='
set init struct values based on key
skips unknown keys

Definition at line 438 of file init.c.

438 {
439 char ts[MAXLEN];
440 char *sp, *dp;
441 char tmp_str[MAXLEN];
442 SIO *sio = init->sio;
443 if (!init->minitrc[0]) {
444 char *e = getenv("MINITRC");
445 if (e)
446 strnz__cpy(init->minitrc, e, MAXLEN - 1);
447 else
448 strnz__cpy(init->minitrc, "~/.minitrc", MAXLEN - 1);
449 }
450 expand_tilde(init->minitrc, MAXLEN - 1);
451 FILE *config_fp = fopen(init->minitrc, "r");
452 if (!config_fp) {
453 fprintf(stderr, "failed to read file: %s\n", init->minitrc);
454 return (-1);
455 }
456 while (fgets(ts, sizeof(ts), config_fp)) {
457 if (ts[0] != '#') {
458 sp = ts;
459 dp = tmp_str;
460 while (*sp != '\0') {
461 if (*sp == '\n') {
462 *dp = *sp = '\0';
463 } else {
464 if (*sp != '"' && *sp != ' ' && *sp != ';') {
465 *dp++ = *sp;
466 }
467 sp++;
468 }
469 }
470 *dp = '\0';
471 char *key = strtok(tmp_str, "=");
472 char *value = strtok(nullptr, "=");
473 if (value == nullptr)
474 continue;
475 if (!strcmp(key, "minitrc")) {
476 strnz__cpy(init->minitrc, value, MAXLEN - 1);
477 continue;
478 }
479 if (!strcmp(key, "lines")) {
480 init->lines = atoi(value);
481 continue;
482 }
483 if (!strcmp(key, "cols")) {
484 init->cols = atoi(value);
485 continue;
486 }
487 if (!strcmp(key, "begy")) {
488 init->begy = atoi(value);
489 continue;
490 }
491 if (!strcmp(key, "begx")) {
492 init->begx = atoi(value);
493 continue;
494 }
495 if (!strcmp(key, "fg_clr_x")) {
496 strnz__cpy(sio->fg_clr_x, value, COLOR_LEN - 1);
497 continue;
498 }
499 if (!strcmp(key, "bg_clr_x")) {
500 strnz__cpy(sio->bg_clr_x, value, COLOR_LEN - 1);
501 continue;
502 }
503 if (!strcmp(key, "f_ln")) {
504 init->f_ln = str_to_bool(value);
505 continue;
506 }
507 if (!strcmp(key, "bo_clr_x")) {
508 strnz__cpy(sio->bo_clr_x, value, COLOR_LEN - 1);
509 continue;
510 }
511 if (!strcmp(key, "ln_clr_x")) {
512 strnz__cpy(sio->ln_clr_x, value, COLOR_LEN - 1);
513 continue;
514 }
515 if (!strcmp(key, "ln_bg_clr_x")) {
516 strnz__cpy(sio->ln_bg_clr_x, value, COLOR_LEN - 1);
517 continue;
518 }
519 if (!strcmp(key, "red_gamma")) {
520 sio->red_gamma = str_to_double(value);
521 continue;
522 }
523 if (!strcmp(key, "green_gamma")) {
524 sio->green_gamma = str_to_double(value);
525 continue;
526 }
527 if (!strcmp(key, "blue_gamma")) {
528 sio->blue_gamma = str_to_double(value);
529 continue;
530 }
531 if (!strcmp(key, "gray_gamma")) {
532 sio->gray_gamma = str_to_double(value);
533 continue;
534 }
535 if (!strcmp(key, "f_at_end_remove")) {
536 init->f_at_end_remove = str_to_bool(value);
537 continue;
538 }
539 if (!strcmp(key, "f_erase_remainder")) {
540 init->f_erase_remainder = str_to_bool(value);
541 continue;
542 }
543 if (!strcmp(key, "brackets")) {
544 strnz__cpy(init->brackets, value, 2);
545 continue;
546 }
547 if (!strcmp(key, "fill_char")) {
548 strnz__cpy(init->fill_char, value, 2);
549 continue;
550 }
551 if (!strcmp(key, "f_ignore_case")) {
552 init->f_ignore_case = str_to_bool(value);
553 continue;
554 }
555 if (!strcmp(key, "f_squeeze")) {
556 init->f_squeeze = str_to_bool(value);
557 continue;
558 }
559 if (!strcmp(key, "f_strip_ansi")) {
560 init->f_strip_ansi = str_to_bool(value);
561 continue;
562 }
563 if (!strcmp(key, "select_max")) {
564 init->select_max = atoi(value);
565 continue;
566 }
567 if (!strcmp(key, "tab_stop")) {
568 init->tab_stop = atoi(value);
569 continue;
570 }
571 if (!strcmp(key, "wait_timeout")) {
572 wait_timeout = atoi(value);
573 continue;
574 }
575 if (!strcmp(key, "title")) {
576 strnz__cpy(init->title, value, MAXLEN - 1);
577 continue;
578 }
579 if (!strcmp(key, "cmd")) {
580 strnz__cpy(init->cmd, value, MAXLEN - 1);
581 continue;
582 }
583 if (!strcmp(key, "cmd_all")) {
584 strnz__cpy(init->cmd_all, value, MAXLEN - 1);
585 continue;
586 }
587 if (!strcmp(key, "parent_cmd")) {
588 strnz__cpy(init->parent_cmd, value, MAXLEN - 1);
589 continue;
590 }
591 if (!strcmp(key, "provider_cmd")) {
592 strnz__cpy(init->provider_cmd, value, MAXLEN - 1);
593 continue;
594 }
595 if (!strcmp(key, "receiver_cmd")) {
596 strnz__cpy(init->receiver_cmd, value, MAXLEN - 1);
597 continue;
598 }
599 if (!strcmp(key, "bg")) {
600 strnz__cpy(sio->bg, value, COLOR_LEN - 1);
601 continue;
602 }
603 if (!strcmp(key, "black")) {
604 strnz__cpy(sio->black, value, COLOR_LEN - 1);
605 continue;
606 }
607 if (!strcmp(key, "red")) {
608 strnz__cpy(sio->red, value, COLOR_LEN - 1);
609 continue;
610 }
611 if (!strcmp(key, "green")) {
612 strnz__cpy(sio->green, value, COLOR_LEN - 1);
613 continue;
614 }
615 if (!strcmp(key, "yellow")) {
616 strnz__cpy(sio->yellow, value, COLOR_LEN - 1);
617 continue;
618 }
619 if (!strcmp(key, "blue")) {
620 strnz__cpy(sio->blue, value, COLOR_LEN - 1);
621 continue;
622 }
623 if (!strcmp(key, "magenta")) {
624 strnz__cpy(sio->magenta, value, COLOR_LEN - 1);
625 continue;
626 }
627 if (!strcmp(key, "cyan")) {
628 strnz__cpy(sio->cyan, value, COLOR_LEN - 1);
629 continue;
630 }
631 if (!strcmp(key, "white")) {
632 strnz__cpy(sio->white, value, COLOR_LEN - 1);
633 continue;
634 }
635 if (!strcmp(key, "orange")) {
636 strnz__cpy(sio->orange, value, COLOR_LEN - 1);
637 continue;
638 }
639 if (!strcmp(key, "bblack")) {
640 strnz__cpy(sio->bblack, value, COLOR_LEN - 1);
641 continue;
642 }
643 if (!strcmp(key, "bred")) {
644 strnz__cpy(sio->bred, value, COLOR_LEN - 1);
645 continue;
646 }
647 if (!strcmp(key, "bgreen")) {
648 strnz__cpy(sio->bgreen, value, COLOR_LEN - 1);
649 continue;
650 }
651 if (!strcmp(key, "byellow")) {
652 strnz__cpy(sio->byellow, value, COLOR_LEN - 1);
653 continue;
654 }
655 if (!strcmp(key, "bblue")) {
656 strnz__cpy(sio->bblue, value, COLOR_LEN - 1);
657 continue;
658 }
659 if (!strcmp(key, "bmagenta")) {
660 strnz__cpy(sio->bmagenta, value, COLOR_LEN - 1);
661 continue;
662 }
663 if (!strcmp(key, "bcyan")) {
664 strnz__cpy(sio->bcyan, value, COLOR_LEN - 1);
665 continue;
666 }
667 if (!strcmp(key, "bwhite")) {
668 strnz__cpy(sio->bwhite, value, COLOR_LEN - 1);
669 continue;
670 }
671 if (!strcmp(key, "borange")) {
672 strnz__cpy(sio->borange, value, COLOR_LEN - 1);
673 continue;
674 }
675 if (!strcmp(key, "bg")) {
676 strnz__cpy(sio->bg, value, COLOR_LEN - 1);
677 continue;
678 }
679 if (!strcmp(key, "editor")) {
680 strnz__cpy(init->editor, value, MAXLEN - 1);
681 continue;
682 }
683 if (!strcmp(key, "mapp_spec")) {
684 strnz__cpy(init->mapp_spec, value, MAXLEN - 1);
685 continue;
686 }
687 if (!strcmp(key, "mapp_data")) {
688 strnz__cpy(init->mapp_data, value, MAXLEN - 1);
689 continue;
690 }
691 if (!strcmp(key, "mapp_help")) {
692 strnz__cpy(init->mapp_help, value, MAXLEN - 1);
693 continue;
694 }
695 if (!strcmp(key, "mapp_home")) {
696 strnz__cpy(init->mapp_home, value, MAXLEN - 1);
697 continue;
698 }
699 if (!strcmp(key, "mapp_msrc")) {
700 strnz__cpy(init->mapp_msrc, value, MAXLEN - 1);
701 continue;
702 }
703 if (!strcmp(key, "mapp_user")) {
704 strnz__cpy(init->mapp_user, value, MAXLEN - 1);
705 continue;
706 }
707 }
708 }
709 (void)fclose(config_fp);
710 return 0;
711}
bool str_to_bool(const char *)
Converts String to boolean true or false.
Definition futil.c:649
double str_to_double(char *)
converts string to double
Definition futil.c:637

References SIO::bblack, SIO::bblue, SIO::bcyan, Init::begx, Init::begy, SIO::bg, SIO::bg_clr_x, SIO::bgreen, SIO::black, SIO::blue, SIO::blue_gamma, SIO::bmagenta, SIO::bo_clr_x, SIO::borange, Init::brackets, SIO::bred, SIO::bwhite, SIO::byellow, Init::cmd, Init::cmd_all, Init::cols, SIO::cyan, Init::editor, expand_tilde(), Init::f_at_end_remove, Init::f_erase_remainder, Init::f_ignore_case, Init::f_ln, Init::f_squeeze, Init::f_strip_ansi, SIO::fg_clr_x, Init::fill_char, SIO::gray_gamma, SIO::green, SIO::green_gamma, Init::lines, SIO::ln_bg_clr_x, SIO::ln_clr_x, SIO::magenta, Init::mapp_data, Init::mapp_help, Init::mapp_home, Init::mapp_msrc, Init::mapp_spec, Init::mapp_user, Init::minitrc, SIO::orange, Init::parent_cmd, Init::provider_cmd, Init::receiver_cmd, SIO::red, SIO::red_gamma, Init::select_max, Init::sio, str_to_bool(), str_to_double(), strnz__cpy(), Init::tab_stop, Init::title, wait_timeout, SIO::white, and SIO::yellow.

Referenced by mapp_initialization().

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

◆ write_config()

int write_config ( Init * init)

Write the current configuration to a file specified in init->minitrc.

Parameters
init- pointer to Init struct containing current configuration
Returns
0 on success, -1 on failure
Note
The configuration is written in key=value format, one per line
Lines beginning with '#' are comments and are ignored when reading the config file
The file is created if it does not exist, and overwritten if it does exist

Definition at line 723 of file init.c.

723 {
724 char *e;
725 char minitrc_dmp[MAXLEN];
726 char tmp_str[MAXLEN];
727 SIO *sio = init->sio;
728 e = getenv("HOME");
729 if (e) {
730 strnz__cpy(minitrc_dmp, e, MAXLEN - 1);
731 strnz__cat(minitrc_dmp, "/", MAXLEN - 1);
732 strnz__cat(minitrc_dmp, "menuapp/minitrc.dmp", MAXLEN - 1);
733 ;
734 } else {
735 strnz__cpy(minitrc_dmp, "./minitrc.dmp", MAXLEN - 1);
736 }
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);
740 return (-1);
741 }
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",
759 init->f_erase_remainder ? "true" : "false");
760 (void)fprintf(minitrc_fp, "%s=%s\n", "f_strip_ansi",
761 init->f_strip_ansi ? "true" : "false");
762 (void)fprintf(minitrc_fp, "%s=%s\n", "f_squeeze",
763 init->f_squeeze ? "true" : "false");
764 (void)fprintf(minitrc_fp, "%s=%s\n", "f_ignore_case",
765 init->f_ignore_case ? "true" : "false");
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);
804 strnz__cpy(tmp_str, "Configuration written to file: ", MAXLEN - 1);
805 strnz__cat(tmp_str, minitrc_dmp, MAXLEN - 1);
806 Perror(tmp_str);
807 return 0;
808}
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1110

References SIO::bblack, SIO::bblue, SIO::bcyan, Init::begx, Init::begy, SIO::bg_clr_x, SIO::bgreen, SIO::black, SIO::blue, SIO::blue_gamma, SIO::bmagenta, SIO::bo_clr_x, Init::brackets, SIO::bred, SIO::bwhite, SIO::byellow, Init::cmd, Init::cmd_all, Init::cols, SIO::cyan, Init::editor, Init::f_erase_remainder, Init::f_ignore_case, Init::f_ln, Init::f_squeeze, Init::f_strip_ansi, SIO::fg_clr_x, Init::fill_char, SIO::gray_gamma, SIO::green, SIO::green_gamma, Init::help_spec, Init::in_spec, Init::lines, SIO::ln_bg_clr_x, SIO::ln_clr_x, SIO::magenta, Init::mapp_data, Init::mapp_help, Init::mapp_home, Init::mapp_msrc, Init::mapp_spec, Init::mapp_user, Init::out_spec, Init::parent_cmd, Perror(), Init::provider_cmd, Init::receiver_cmd, SIO::red, SIO::red_gamma, Init::select_max, Init::sio, strnz__cat(), strnz__cpy(), Init::tab_stop, Init::title, wait_timeout, SIO::white, and SIO::yellow.

Referenced by mapp_initialization(), and menu_cmd_processor().

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

◆ zero_opt_args()

void zero_opt_args ( Init * init)

Initialize optional arguments in the Init struct to default values.

Parameters
init- pointer to Init struct to be initialized This function sets all optional argument fields in the Init struct to their default values before parsing command-line options or configuration file. This ensures that any fields not specified by the user will have known default values.

Definition at line 408 of file init.c.

408 {
409 init->f_mapp_desc = false;
410 init->f_provider_cmd = false;
411 init->f_receiver_cmd = false;
412 init->f_title = false;
413 init->f_mapp_spec = false;
414 init->f_help_spec = false;
415 init->f_in_spec = false;
416 init->f_out_spec = false;
417 init->mapp_spec[0] = init->help_spec[0] = '\0';
418 init->provider_cmd[0] = init->receiver_cmd[0] = '\0';
419 init->title[0] = '\0';
420 init->cmd[0] = init->cmd_all[0] = '\0';
421 init->parent_cmd[0] = '\0';
422 init->in_spec[0] = init->out_spec[0] = '\0';
423 init->help_spec[0] = '\0';
424 init->in_spec[0] = '\0';
425 init->out_spec[0] = '\0';
426}

References Init::cmd, Init::cmd_all, Init::f_help_spec, Init::f_in_spec, Init::f_mapp_desc, Init::f_mapp_spec, Init::f_out_spec, Init::f_provider_cmd, Init::f_receiver_cmd, Init::f_title, Init::help_spec, Init::in_spec, Init::mapp_spec, Init::out_spec, Init::parent_cmd, Init::provider_cmd, Init::receiver_cmd, and Init::title.

Referenced by menu_cmd_processor(), popup_form(), popup_menu(), popup_pick(), and popup_view().

Here is the caller graph for this function: