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

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 dump_config (Init *init, char *msg)
 Dump the current configuration to stdout for debugging purposes.
void mapp_initialization (Init *init, int argc, char **argv)
 Main initialization function for MAPP - Menu Application.
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_char (const char *o, const char *name, const char *value)
 Print an option and its value in a formatted manner.
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_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_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_config (Init *init)
 parse the configuration file specified in init->minitrc and set Init struct values accordingly
int parse_opt_args (Init *init, int argc, char **argv)
 Parse command-line options and set Init struct values accordingly.
int write_config (Init *init)
 Write the current configuration to a file specified in init->minitrc.
void zero_opt_args (Init *init)
 Initialize optional arguments in the Init struct to default values.

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

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 907 of file init.c.

907 {
908 char ts[MAXLEN];
909 char ts2[MAXLEN];
910 char *e;
911
912 if (!file_name || !*file_name) {
913 *file_spec = '\0';
914 return false;
915 }
916 if (dir) {
917 strnz__cpy(ts, dir, MAXLEN - 1);
918 } else {
919 e = getenv("MAPP_DIR");
920 if (e) {
921 strnz__cpy(ts, e, MAXLEN - 1);
922 } else {
923 strnz__cpy(ts, "~/menuapp", MAXLEN - 1);
924 }
925 }
926 trim_path(ts);
927 strnz__cpy(ts2, ts, MAXLEN - 1);
928 // construct the full file specification
929 // check that the file exists and is readable
930 strnz__cpy(file_spec, ts2, MAXLEN - 1);
931 strnz__cat(file_spec, "/", MAXLEN - 1);
932 strnz__cat(file_spec, file_name, MAXLEN - 1);
933 return true;
934}
#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:435
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:464
bool trim_path(char *)
Trims trailing spaces and slashes from directory path in place.
Definition futil.c:922

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.

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

Definition at line 939 of file init.c.

939 {
940 fprintf(stdout, "\nC-Menu %s\n", CM_VERSION);
941 fprintf(stdout, "\nC-Menu %s\n", CM_VERSION);
942 fprintf(stdout, "C version: %ld\n", __STDC_VERSION__);
943}
#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 1005 of file init.c.

1005 {
1006 SIO *sio = init->sio;
1007 opt_prt_str("-a:", "--minitrc", init->minitrc);
1008 opt_prt_str("-k:", " parent_cmd", init->parent_cmd);
1009 opt_prt_int("-C:", " cols", init->cols);
1010 opt_prt_int("-L:", " lines", init->lines);
1011 opt_prt_int("-n:", " select_max", init->select_max);
1012 opt_prt_str("-o:", " out_spec", init->out_spec);
1013 opt_prt_int("-X:", " begx", init->begx);
1014 opt_prt_int("-Y:", " begy", init->begy);
1015 opt_prt_str("-A:", " cmd_all", init->cmd_all);
1016 opt_prt_str("-c:", " cmd", init->cmd);
1017 opt_prt_str("-d:", "--mapp_spec", init->mapp_spec);
1018 opt_prt_str(" ", " help_spec", init->help_spec);
1019 opt_prt_str("-i:", " in_spec", init->in_spec);
1020 opt_prt_str("-R:", " receiver_cmd", init->receiver_cmd);
1021 opt_prt_str("-S:", " provider_cmd", init->provider_cmd);
1022 opt_prt_str(" ", " title", init->title);
1023 opt_prt_bool("-e:", " f_erase_remainder", init->f_erase_remainder);
1024 opt_prt_bool("-a ", " f_strip_ansi", init->f_strip_ansi);
1025 opt_prt_bool("-s ", " f_squeeze", init->f_squeeze);
1026 opt_prt_bool("-x:", " f_ignore_case", init->f_ignore_case);
1027 opt_prt_bool("-N:", " f_ln", init->f_ln);
1028 opt_prt_int("-t:", " tab_stop", init->tab_stop);
1029 opt_prt_int("-w:", " wait_timeout", wait_timeout);
1030 opt_prt_str("-u ", " brackets", init->brackets);
1031 opt_prt_str("-f:", " fill_char", init->fill_char);
1032 opt_prt_str(" ", " editor", init->editor);
1033 opt_prt_str(" ", " bg_clr_x", sio->bg_clr_x);
1034 opt_prt_str(" ", " bo_clr_x", sio->bo_clr_x);
1035 opt_prt_str(" ", " fg_clr_x", sio->fg_clr_x);
1036 opt_prt_str(" ", " ln_bg_clr_x", sio->ln_bg_clr_x);
1037 opt_prt_str(" ", " ln_clr_x", sio->ln_clr_x);
1038 opt_prt_double(" ", " blue_gamma", sio->blue_gamma);
1039 opt_prt_double(" ", " gray_gamma", sio->gray_gamma);
1040 opt_prt_double(" ", " green_gamma", sio->green_gamma);
1041 opt_prt_double(" ", " red_gamma", sio->red_gamma);
1042 opt_prt_str(" ", " black", sio->black);
1043 opt_prt_str(" ", " red", sio->red);
1044 opt_prt_str(" ", " green", sio->green);
1045 opt_prt_str(" ", " yellow", sio->yellow);
1046 opt_prt_str(" ", " blue", sio->blue);
1047 opt_prt_str(" ", " magenta", sio->magenta);
1048 opt_prt_str(" ", " cyan", sio->cyan);
1049 opt_prt_str(" ", " white", sio->white);
1050 opt_prt_str(" ", " orange", sio->orange);
1051 opt_prt_str(" ", " bblack", sio->bblack);
1052 opt_prt_str(" ", " bred", sio->bred);
1053 opt_prt_str(" ", " bgreen", sio->bgreen);
1054 opt_prt_str(" ", " byellow", sio->byellow);
1055 opt_prt_str(" ", " bblue", sio->bblue);
1056 opt_prt_str(" ", " bmagenta", sio->bmagenta);
1057 opt_prt_str(" ", " bcyan", sio->bcyan);
1058 opt_prt_str(" ", " bwhite", sio->bwhite);
1059 opt_prt_str(" ", " borange", sio->borange);
1060 opt_prt_str(" ", "--mapp_data", init->mapp_data);
1061 opt_prt_str(" ", "--mapp_help", init->mapp_help);
1062 opt_prt_str(" ", "--mapp_home", init->mapp_home);
1063 opt_prt_str(" ", "--mapp_msrc", init->mapp_msrc);
1064 opt_prt_str(" ", "--mapp_user", init->mapp_user);
1065 (void)fprintf(stdout, "\n%s\n\n", msg);
1066}
Init * init
Definition init.c:74
int wait_timeout
Definition futil.c:144
SIO * sio
Definition dwin.c:80
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:962
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:984
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:996
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:973
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:696

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

< menu specification file

< background color

< foreground color

< bold color

< line number olor

< line number background

< erase remainder on enter

< field enclosure brackets

< field fill character

Definition at line 328 of file init.c.

328 {
329 char term[MAXLEN];
330 char tmp_str[MAXLEN];
331 char *e;
332 setlocale(LC_ALL, "en_US.UTF-8");
333 SIO *sio = init->sio;
334 if (!init) {
335 ssnprintf(tmp_str, sizeof(tmp_str), "%s",
336 "init struct not allocated on entry");
337 abend(-1, tmp_str);
338 exit(-1);
339 }
340#ifdef DEBUG_LOG
342#endif
343 e = getenv("CMENU_HOME");
344 if (!e || *e == '\0')
345 strnz__cpy(init->mapp_home, "~/menuapp", MAXLEN);
346 else
347 strnz__cpy(init->mapp_home, e, MAXLEN);
348
349 if (init->mapp_home[0] != '\0') {
350 expand_tilde(init->mapp_home, MAXLEN - 1);
351 if (!verify_dir(init->mapp_home, R_OK))
352 abend(-1, "MAPP_HOME directory invalid");
353 }
354 // CMENU_RC should be an absolute path
355 e = getenv("CMENU_RC");
356 if (!e || *e == '\0') {
357 strnz__cpy(init->minitrc, init->mapp_home, MAXLEN - 1);
358 strnz__cat(init->minitrc, "/.minitrc", MAXLEN);
359 } else
360 strnz__cpy(init->minitrc, e, MAXLEN);
361 if (init->mapp_user[0] == '\0') {
362 strnz__cpy(init->mapp_user, init->mapp_home, MAXLEN - 1);
363 strnz__cat(init->mapp_user, "/user", MAXLEN - 1);
364 }
365 if (init->mapp_msrc[0] == '\0') {
366 strnz__cpy(init->mapp_msrc, init->mapp_home, MAXLEN - 1);
367 strnz__cat(init->mapp_msrc, "/msrc", MAXLEN - 1);
368 }
369 if (init->mapp_data[0] == '\0') {
370 strnz__cpy(init->mapp_data, init->mapp_home, MAXLEN - 1);
371 strnz__cat(init->mapp_data, "/data", MAXLEN - 1);
372 }
373 if (init->mapp_help[0] == '\0') {
374 strnz__cpy(init->mapp_help, init->mapp_home, MAXLEN - 1);
375 strnz__cat(init->mapp_help, "/help", MAXLEN - 1);
376 }
377 init->mapp_spec[0] = '\0';
378 // Set default colors and settings in SIO struct
379 // These can be overridden by the config file or command-line options
380 // Included here to ensure SIO has valid defaults even if config parsing fails
381 strnz__cpy(sio->bg_clr_x, "#000007",
382 COLOR_LEN - 1);
383 strnz__cpy(sio->fg_clr_x, "#c0c0c0",
384 COLOR_LEN - 1);
385 strnz__cpy(sio->bo_clr_x, "#f00000", COLOR_LEN - 1);
386 strnz__cpy(sio->ln_clr_x, "#0070ff",
387 COLOR_LEN - 1);
388 strnz__cpy(sio->ln_bg_clr_x, "#101010",
389 COLOR_LEN - 1);
390 init->f_erase_remainder = true;
391 init->brackets[0] = '\0';
392 strnz__cpy(init->fill_char, "_", MAXLEN - 1);
393 e = getenv("TERM");
394 if (e == nullptr || *e == '\0')
395 strnz__cpy(term, "xterm-256color", MAXLEN);
396 else
397 strnz__cpy(term, e, MAXLEN - 1);
398 e = getenv("EDITOR");
399 if (e && *e != '\0')
400 strnz__cpy(init->editor, "vi", MAXLEN - 1);
401 else
402 strnz__cpy(init->editor, e, MAXLEN - 1);
404 init->mapp_spec[0] = '\0';
405 init->argc = argc;
406 argp_parse(&argp, argc, argv, 0, 0, init);
407 if (f_write_config) {
409 exit(EXIT_SUCCESS);
410 }
411 if (f_dump_config) {
412 dump_config(init, "Current Configuration");
413 exit(EXIT_SUCCESS);
414 }
415}
#define COLOR_LEN
Definition cm.h:216
bool f_dump_config
Definition init.c:69
bool f_write_config
Definition init.c:68
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1588
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:311
bool expand_tilde(char *, int)
Replaces "~/" in string with the user's home directory.
Definition futil.c:904
void open_cmenu_log()
Open new C-Menu log file.
Definition futil.c:1528
bool verify_dir(char *, int)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:1050
void dump_config(Init *, char *)
Dump the current configuration to stdout for debugging purposes.
Definition init.c:1005
int write_config(Init *init)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:797
int parse_config(Init *)
parse the configuration file specified in init->minitrc and set Init struct values accordingly
Definition init.c:476

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__cat(), 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

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 996 of file init.c.

996 {
997 fprintf(stdout, "%3s %-15s: %s\n", o, name, value ? "true" : "false");
998}

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

This function is used to display the current configuration options and their values in a readable format.

Definition at line 951 of file init.c.

951 {
952 fprintf(stdout, "%3s %-15s: %s\n", o, name, value);
953}

◆ 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

This function is used to display the current configuration options and their double values in a readable format.

Definition at line 984 of file init.c.

984 {
985 fprintf(stdout, "%3s %-15s: %0.2f\n", o, name, value);
986}

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

This function is used to display the current configuration options and their integer values in a readable format.

Definition at line 973 of file init.c.

973 {
974 fprintf(stdout, "%3s %-15s: %d\n", o, name, value);
975}

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

This function is used to display the current configuration options and their integer values in a readable format.

Definition at line 962 of file init.c.

962 {
963 fprintf(stdout, "%3s %-15s: %s\n", o, name, value);
964}

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

Lines beginning with '#" are comments, discard. Copy line to tmp_str removing quotes, spaces, semicolons, and newlines. Record structure is "parse key=value pairs". Skip lines without '='. Set init struct values based on key. Skip unknown keys.

Definition at line 476 of file init.c.

476 {
477 char ts[MAXLEN];
478 char *sp, *dp;
479 char tmp_str[MAXLEN];
480 SIO *sio = init->sio;
481 if (!init->minitrc[0]) {
482 char *e = getenv("MINITRC");
483 if (e)
484 strnz__cpy(init->minitrc, e, MAXLEN - 1);
485 else
486 strnz__cpy(init->minitrc, "~/.minitrc", MAXLEN - 1);
487 }
488 expand_tilde(init->minitrc, MAXLEN - 1);
489 FILE *config_fp = fopen(init->minitrc, "r");
490 if (!config_fp) {
491 fprintf(stderr, "failed to read file: %s\n", init->minitrc);
492 return (-1);
493 }
494 while (fgets(ts, sizeof(ts), config_fp)) {
495 if (ts[0] != '#') {
496 sp = ts;
497 dp = tmp_str;
498 while (*sp != '\0') {
499 if (*sp == '\n') {
500 *dp = *sp = '\0';
501 } else {
502 if (*sp != '"' && *sp != ' ' && *sp != ';') {
503 *dp++ = *sp;
504 }
505 sp++;
506 }
507 }
508 *dp = '\0';
509 char *key = strtok(tmp_str, "=");
510 char *value = strtok(nullptr, "=");
511 if (value == nullptr)
512 continue;
513 if (!strcmp(key, "minitrc")) {
514 strnz__cpy(init->minitrc, value, MAXLEN - 1);
515 continue;
516 }
517 if (!strcmp(key, "lines")) {
518 init->lines = atoi(value);
519 continue;
520 }
521 if (!strcmp(key, "cols")) {
522 init->cols = atoi(value);
523 continue;
524 }
525 if (!strcmp(key, "begy")) {
526 init->begy = atoi(value);
527 continue;
528 }
529 if (!strcmp(key, "begx")) {
530 init->begx = atoi(value);
531 continue;
532 }
533 if (!strcmp(key, "fg_clr_x")) {
534 strnz__cpy(sio->fg_clr_x, value, COLOR_LEN - 1);
535 continue;
536 }
537 if (!strcmp(key, "bg_clr_x")) {
538 strnz__cpy(sio->bg_clr_x, value, COLOR_LEN - 1);
539 continue;
540 }
541 if (!strcmp(key, "f_ln")) {
542 init->f_ln = str_to_bool(value);
543 continue;
544 }
545 if (!strcmp(key, "bo_clr_x")) {
546 strnz__cpy(sio->bo_clr_x, value, COLOR_LEN - 1);
547 continue;
548 }
549 if (!strcmp(key, "ln_clr_x")) {
550 strnz__cpy(sio->ln_clr_x, value, COLOR_LEN - 1);
551 continue;
552 }
553 if (!strcmp(key, "ln_bg_clr_x")) {
554 strnz__cpy(sio->ln_bg_clr_x, value, COLOR_LEN - 1);
555 continue;
556 }
557 if (!strcmp(key, "red_gamma")) {
558 sio->red_gamma = str_to_double(value);
559 continue;
560 }
561 if (!strcmp(key, "green_gamma")) {
562 sio->green_gamma = str_to_double(value);
563 continue;
564 }
565 if (!strcmp(key, "blue_gamma")) {
566 sio->blue_gamma = str_to_double(value);
567 continue;
568 }
569 if (!strcmp(key, "gray_gamma")) {
570 sio->gray_gamma = str_to_double(value);
571 continue;
572 }
573 if (!strcmp(key, "f_at_end_remove")) {
574 init->f_at_end_remove = str_to_bool(value);
575 continue;
576 }
577 if (!strcmp(key, "f_erase_remainder")) {
578 init->f_erase_remainder = str_to_bool(value);
579 continue;
580 }
581 if (!strcmp(key, "brackets")) {
582 strnz__cpy(init->brackets, value, 2);
583 continue;
584 }
585 if (!strcmp(key, "fill_char")) {
586 strnz__cpy(init->fill_char, value, 2);
587 continue;
588 }
589 if (!strcmp(key, "f_ignore_case")) {
590 init->f_ignore_case = str_to_bool(value);
591 continue;
592 }
593 if (!strcmp(key, "f_squeeze")) {
594 init->f_squeeze = str_to_bool(value);
595 continue;
596 }
597 if (!strcmp(key, "f_strip_ansi")) {
598 init->f_strip_ansi = str_to_bool(value);
599 continue;
600 }
601 if (!strcmp(key, "select_max")) {
602 init->select_max = atoi(value);
603 continue;
604 }
605 if (!strcmp(key, "tab_stop")) {
606 init->tab_stop = atoi(value);
607 continue;
608 }
609 if (!strcmp(key, "wait_timeout")) {
610 wait_timeout = atoi(value);
611 continue;
612 }
613 if (!strcmp(key, "title")) {
614 strnz__cpy(init->title, value, MAXLEN - 1);
615 continue;
616 }
617 if (!strcmp(key, "cmd")) {
618 strnz__cpy(init->cmd, value, MAXLEN - 1);
619 continue;
620 }
621 if (!strcmp(key, "cmd_all")) {
622 strnz__cpy(init->cmd_all, value, MAXLEN - 1);
623 continue;
624 }
625 if (!strcmp(key, "parent_cmd")) {
626 strnz__cpy(init->parent_cmd, value, MAXLEN - 1);
627 continue;
628 }
629 if (!strcmp(key, "provider_cmd")) {
630 strnz__cpy(init->provider_cmd, value, MAXLEN - 1);
631 continue;
632 }
633 if (!strcmp(key, "receiver_cmd")) {
634 strnz__cpy(init->receiver_cmd, value, MAXLEN - 1);
635 continue;
636 }
637 if (!strcmp(key, "nt_fg")) {
638 strnz__cpy(sio->nt_fg, value, COLOR_LEN - 1);
639 continue;
640 }
641 if (!strcmp(key, "nt_bg")) {
642 strnz__cpy(sio->nt_bg, value, COLOR_LEN - 1);
643 continue;
644 }
645 if (!strcmp(key, "nt_rev_fg")) {
646 strnz__cpy(sio->nt_rev_fg, value, COLOR_LEN - 1);
647 continue;
648 }
649 if (!strcmp(key, "nt_rev_bg")) {
650 strnz__cpy(sio->nt_rev_bg, value, COLOR_LEN - 1);
651 continue;
652 }
653 if (!strcmp(key, "nt_hl_fg")) {
654 strnz__cpy(sio->nt_hl_fg, value, COLOR_LEN - 1);
655 continue;
656 }
657 if (!strcmp(key, "nt_hl_bg")) {
658 strnz__cpy(sio->nt_hl_bg, value, COLOR_LEN - 1);
659 continue;
660 }
661 if (!strcmp(key, "nt_hl_rev_fg")) {
662 strnz__cpy(sio->nt_hl_rev_fg, value, COLOR_LEN - 1);
663 continue;
664 }
665 if (!strcmp(key, "nt_hl_rev_bg")) {
666 strnz__cpy(sio->nt_hl_rev_bg, value, COLOR_LEN - 1);
667 continue;
668 }
669 if (!strcmp(key, "nt_hl_rev_fg")) {
670 strnz__cpy(sio->nt_hl_rev_fg, value, COLOR_LEN - 1);
671 continue;
672 }
673 if (!strcmp(key, "bg")) {
674 strnz__cpy(sio->bg, value, COLOR_LEN - 1);
675 continue;
676 }
677 if (!strcmp(key, "black")) {
678 strnz__cpy(sio->black, value, COLOR_LEN - 1);
679 continue;
680 }
681 if (!strcmp(key, "red")) {
682 strnz__cpy(sio->red, value, COLOR_LEN - 1);
683 continue;
684 }
685 if (!strcmp(key, "green")) {
686 strnz__cpy(sio->green, value, COLOR_LEN - 1);
687 continue;
688 }
689 if (!strcmp(key, "yellow")) {
690 strnz__cpy(sio->yellow, value, COLOR_LEN - 1);
691 continue;
692 }
693 if (!strcmp(key, "blue")) {
694 strnz__cpy(sio->blue, value, COLOR_LEN - 1);
695 continue;
696 }
697 if (!strcmp(key, "magenta")) {
698 strnz__cpy(sio->magenta, value, COLOR_LEN - 1);
699 continue;
700 }
701 if (!strcmp(key, "cyan")) {
702 strnz__cpy(sio->cyan, value, COLOR_LEN - 1);
703 continue;
704 }
705 if (!strcmp(key, "white")) {
706 strnz__cpy(sio->white, value, COLOR_LEN - 1);
707 continue;
708 }
709 if (!strcmp(key, "orange")) {
710 strnz__cpy(sio->orange, value, COLOR_LEN - 1);
711 continue;
712 }
713 if (!strcmp(key, "bblack")) {
714 strnz__cpy(sio->bblack, value, COLOR_LEN - 1);
715 continue;
716 }
717 if (!strcmp(key, "bred")) {
718 strnz__cpy(sio->bred, value, COLOR_LEN - 1);
719 continue;
720 }
721 if (!strcmp(key, "bgreen")) {
722 strnz__cpy(sio->bgreen, value, COLOR_LEN - 1);
723 continue;
724 }
725 if (!strcmp(key, "byellow")) {
726 strnz__cpy(sio->byellow, value, COLOR_LEN - 1);
727 continue;
728 }
729 if (!strcmp(key, "bblue")) {
730 strnz__cpy(sio->bblue, value, COLOR_LEN - 1);
731 continue;
732 }
733 if (!strcmp(key, "bmagenta")) {
734 strnz__cpy(sio->bmagenta, value, COLOR_LEN - 1);
735 continue;
736 }
737 if (!strcmp(key, "bcyan")) {
738 strnz__cpy(sio->bcyan, value, COLOR_LEN - 1);
739 continue;
740 }
741 if (!strcmp(key, "bwhite")) {
742 strnz__cpy(sio->bwhite, value, COLOR_LEN - 1);
743 continue;
744 }
745 if (!strcmp(key, "borange")) {
746 strnz__cpy(sio->borange, value, COLOR_LEN - 1);
747 continue;
748 }
749 if (!strcmp(key, "bg")) {
750 strnz__cpy(sio->bg, value, COLOR_LEN - 1);
751 continue;
752 }
753 if (!strcmp(key, "editor")) {
754 strnz__cpy(init->editor, value, MAXLEN - 1);
755 continue;
756 }
757 if (!strcmp(key, "mapp_spec")) {
758 strnz__cpy(init->mapp_spec, value, MAXLEN - 1);
759 continue;
760 }
761 if (!strcmp(key, "mapp_data")) {
762 strnz__cpy(init->mapp_data, value, MAXLEN - 1);
763 continue;
764 }
765 if (!strcmp(key, "mapp_help")) {
766 strnz__cpy(init->mapp_help, value, MAXLEN - 1);
767 continue;
768 }
769 if (!strcmp(key, "mapp_home")) {
770 strnz__cpy(init->mapp_home, value, MAXLEN - 1);
771 continue;
772 }
773 if (!strcmp(key, "mapp_msrc")) {
774 strnz__cpy(init->mapp_msrc, value, MAXLEN - 1);
775 continue;
776 }
777 if (!strcmp(key, "mapp_user")) {
778 strnz__cpy(init->mapp_user, value, MAXLEN - 1);
779 continue;
780 }
781 }
782 }
783 (void)fclose(config_fp);
784 return 0;
785}
bool str_to_bool(const char *)
Converts String to boolean true or false.
Definition futil.c:875
double str_to_double(char *)
converts string to double
Definition futil.c:863

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::nt_bg, SIO::nt_fg, SIO::nt_hl_bg, SIO::nt_hl_fg, SIO::nt_hl_rev_bg, SIO::nt_hl_rev_fg, SIO::nt_rev_bg, SIO::nt_rev_fg, 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:

◆ parse_opt_args()

int parse_opt_args ( Init * init,
int argc,
char ** argv )

Parse command-line options and set Init struct values accordingly.

Parameters
init- pointer to Init struct to be populated with option values
argc- argument count from main()
argv- argument vector from main()
Returns
0 on success, -1 on failure

This function uses the argp library to parse command-line options defined in the options array. It updates the Init struct with values from the options and handles any special flags for dumping or writing configuration.

Definition at line 427 of file init.c.

427 {
428 init->argc = destroy_argv(init->argc, init->argv);
429 argp_parse(&argp, argc, argv, 0, 0, init);
430 return 0;
431}
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:385

References Init::argc, Init::argv, and destroy_argv().

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

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

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 797 of file init.c.

797 {
798 char *e;
799 char minitrc_dmp[MAXLEN];
800 char tmp_str[MAXLEN];
801 SIO *sio = init->sio;
802 e = getenv("HOME");
803 if (e) {
804 strnz__cpy(minitrc_dmp, e, MAXLEN - 1);
805 strnz__cat(minitrc_dmp, "/", MAXLEN - 1);
806 strnz__cat(minitrc_dmp, "menuapp/minitrc.dmp", MAXLEN - 1);
807 ;
808 } else {
809 strnz__cpy(minitrc_dmp, "./minitrc.dmp", MAXLEN - 1);
810 }
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);
814 return (-1);
815 }
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",
833 init->f_erase_remainder ? "true" : "false");
834 (void)fprintf(minitrc_fp, "%s=%s\n", "f_strip_ansi",
835 init->f_strip_ansi ? "true" : "false");
836 (void)fprintf(minitrc_fp, "%s=%s\n", "f_squeeze",
837 init->f_squeeze ? "true" : "false");
838 (void)fprintf(minitrc_fp, "%s=%s\n", "f_ignore_case",
839 init->f_ignore_case ? "true" : "false");
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);
855
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);
858
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);
861
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);
864
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);
867
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);
891 strnz__cpy(tmp_str, "Configuration written to file: ", MAXLEN - 1);
892 strnz__cat(tmp_str, minitrc_dmp, MAXLEN - 1);
893 Perror(tmp_str);
894 return 0;
895}
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1162

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, SIO::nt_bg, SIO::nt_fg, SIO::nt_hl_bg, SIO::nt_hl_fg, SIO::nt_hl_rev_bg, SIO::nt_hl_rev_fg, SIO::nt_rev_bg, SIO::nt_rev_fg, 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 442 of file init.c.

442 {
443 init->lines = 0;
444 init->cols = 0;
445 init->begx = 0;
446 init->begy = 0;
447 init->f_mapp_desc = false;
448 init->f_provider_cmd = false;
449 init->f_receiver_cmd = false;
450 init->f_title = false;
451 init->f_mapp_spec = false;
452 init->f_help_spec = false;
453 init->f_in_spec = false;
454 init->f_out_spec = false;
455 init->mapp_spec[0] = init->help_spec[0] = '\0';
456 init->provider_cmd[0] = init->receiver_cmd[0] = '\0';
457 init->title[0] = '\0';
458 init->cmd[0] = init->cmd_all[0] = '\0';
459 init->parent_cmd[0] = '\0';
460 init->in_spec[0] = init->out_spec[0] = '\0';
461 init->help_spec[0] = '\0';
462 init->in_spec[0] = '\0';
463 init->out_spec[0] = '\0';
464}

References Init::begx, Init::begy, Init::cmd, Init::cmd_all, Init::cols, 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::lines, Init::mapp_spec, Init::out_spec, Init::parent_cmd, Init::provider_cmd, Init::receiver_cmd, and Init::title.

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

Here is the caller graph for this function: