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

Create, populate, and destroy main data structures for C-Menu. More...

Functions

Form * destroy_form (Init *init)
 Destroy Form structure.
Init * destroy_init (Init *init)
 Destroy Init structure.
Menu * destroy_menu (Init *init)
 Destroy Menu structure.
Pick * destroy_pick (Init *init)
 Destroy Pick structure.
View * destroy_view (Init *init)
 Destroy View structure.
bool init_form_files (Init *init, int argc, char **argv)
 Initialize Form file specifications.
bool init_menu_files (Init *init, int argc, char **argv)
 Initialize Menu file specifications.
bool init_pick_files (Init *init, int argc, char **argv)
 Initialize Pick file specifications.
bool init_view_files (Init *init)
 Initialize View file specifications.
Form * new_form (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Form structure.
Init * new_init (int argc, char **argv)
 Create and initialize Init structure.
Menu * new_menu (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Menu structure.
Pick * new_pick (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Pick structure.
View * new_view (Init *init)
 Create and initialize View structure.
bool verify_spec_arg (char *spec, char *org_spec, char *dir, char *alt_dir, uint mode)
 Verify file specification argument.

Detailed Description

Create, populate, and destroy main data structures for C-Menu.

C-Menu main data structures
Init - main structure for initialization and global data
Menu - menu description, help, and state
Pick - pick description, help, and state
Form - form description, help, and state
View - view description, help, and state

Function Documentation

◆ destroy_form()

Form * destroy_form ( Init * init)

Destroy Form structure.

Parameters
initstructure
Returns
nullptr

Definition at line 267 of file mem.c.

267 {
268 uint i;
269
270 if (!init->form)
271 return nullptr;
272 for (i = 0; i < FIELD_MAXCNT; i++) {
273 if (init->form->field[i])
274 free(init->form->field[i]);
275 init->form->field[i] = nullptr;
276 }
277 for (i = 0; i < FIELD_MAXCNT; i++) {
278 if (init->form->text[i])
279 free(init->form->text[i]);
280 init->form->text[i] = nullptr;
281 }
282 free(init->form);
283 init->form = nullptr;
284 init->form_cnt--;
285 return init->form;
286}
#define FIELD_MAXCNT
Definition form.h:19
Form * form
Definition common.h:189
int form_cnt
Definition common.h:190
Text * text[FIELD_MAXCNT]
Definition form.h:340
Field * field[FIELD_MAXCNT]
Definition form.h:353

References Form::field, Init::form, Init::form_cnt, and Form::text.

Referenced by destroy_init(), init_form(), and popup_form().

Here is the caller graph for this function:

◆ destroy_init()

Init * destroy_init ( Init * init)

Destroy Init structure.

Parameters
initstructure
Returns
nullptr

Definition at line 91 of file mem.c.

91 {
92 if (!init)
93 return nullptr;
94 if (init->menu) {
95 init->menu = destroy_menu(init);
96 init->menu = nullptr;
97 }
98 if (init->form) {
99 init->form = destroy_form(init);
100 init->form = nullptr;
101 }
102 if (init->pick) {
103 init->pick = destroy_pick(init);
104 init->pick = nullptr;
105 }
106 init->argc = destroy_argv(init->argc, init->argv);
107 if (init->argv != nullptr)
108 free(init->argv);
109 if (init != nullptr) {
110 free(init);
111 init = nullptr;
112 }
113 init_cnt--;
114 return init;
115}
int init_cnt
Definition mem.c:28
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:468
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:147
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:267
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:217
int argc
Definition common.h:133
Menu * menu
Definition common.h:187
char ** argv
Definition common.h:134
Pick * pick
Definition common.h:191

References Init::argc, Init::argv, destroy_argv(), destroy_form(), destroy_menu(), destroy_pick(), Init::form, init_cnt, Init::menu, and Init::pick.

Referenced by cmenu_shutdown(), and main().

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

◆ destroy_menu()

Menu * destroy_menu ( Init * init)

Destroy Menu structure.

Parameters
initstructure
Returns
nullptr

Definition at line 147 of file mem.c.

147 {
148 menu = init->menu;
149 for (menu->line_idx = 0; menu->line_idx < menu->item_count;
150 menu->line_idx++) {
151 if (menu->line[menu->line_idx]) {
152 if (menu->line[menu->line_idx]->raw_text != nullptr)
153 free(menu->line[menu->line_idx]->raw_text);
154 if (menu->line[menu->line_idx]->command_str != nullptr)
155 free(menu->line[menu->line_idx]->command_str);
156 if (menu->line[menu->line_idx]->choice_text != nullptr)
157 free(menu->line[menu->line_idx]->choice_text);
158 free(menu->line[menu->line_idx]);
159 menu->line[menu->line_idx] = nullptr;
160 }
161 }
162 free(init->menu);
163 init->menu = nullptr;
164 menu = nullptr;
165 init->menu_cnt--;
166 return init->menu;
167}
Menu * menu
Definition mem.c:35
int menu_cnt
Definition common.h:188

References Line::choice_text, Line::command_str, Menu::item_count, Menu::line, Menu::line_idx, Init::menu, menu, Init::menu_cnt, and Line::raw_text.

Referenced by destroy_init(), menu_engine(), and popup_menu().

Here is the caller graph for this function:

◆ destroy_pick()

Pick * destroy_pick ( Init * init)

Destroy Pick structure.

Parameters
initstructure
Returns
nullptr

Definition at line 217 of file mem.c.

217 {
218 if (!init->pick)
219 return nullptr;
220
221 for (pick->m_idx = 0; pick->m_idx < OBJ_MAXCNT; pick->m_idx++) {
222 if (pick->m_object[pick->m_idx] != nullptr)
223 free(pick->m_object[pick->m_idx]);
224 // if (pick->d_object[pick->d_idx] != nullptr)
225 // free(pick->d_object[pick->d_idx]);
226 }
227 free(pick->m_object);
228 free(pick->d_object);
229 free(pick);
230 init->pick = nullptr;
231 init->pick_cnt--;
232 return init->pick;
233}
#define OBJ_MAXCNT
Definition pick.h:21
Pick * pick
Definition mem.c:36
int pick_cnt
Definition common.h:192

References Pick::d_object, Pick::m_idx, Pick::m_object, Init::pick, pick, and Init::pick_cnt.

Referenced by destroy_init(), and popup_pick().

Here is the caller graph for this function:

◆ destroy_view()

View * destroy_view ( Init * init)

Destroy View structure.

Parameters
initstructure
Returns
nullptr

Definition at line 337 of file mem.c.

337 {
338 if (!init->view)
339 return nullptr;
340 view = init->view;
341 view->argc = destroy_argv(view->argc, view->argv);
342 free(view->argv);
343 free(view);
344 init->view = nullptr;
345 view = nullptr;
346 init->view_cnt--;
347 return init->view;
348}
View * view
Definition mem.c:38
View * view
Definition common.h:193
int view_cnt
Definition common.h:194

References View::argc, View::argv, destroy_argv(), Init::view, view, and Init::view_cnt.

Referenced by cmenu_shutdown(), destroy_pick_view(), main(), and popup_view().

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

◆ init_form_files()

bool init_form_files ( Init * init,
int argc,
char ** argv )

Initialize Form file specifications.

Parameters
initpointer to init structure
argc- number of arguments in argv
argv- Arguments may have been provided by command line ~/.minitrc, environment variables, or calling program interal to C-Menu

Positional args: [pick desc], [in_file], [out_file], [help_file]

Definition at line 634 of file mem.c.

634 {
635 char tmp_str[MAXLEN];
636 int optind = 0;
637 form->f_mapp_spec =
638 verify_spec_arg(form->mapp_spec, init->mapp_spec, init->mapp_msrc,
639 _("~/menuapp/msrc"), R_OK);
640 form->f_in_spec = verify_spec_arg(form->in_spec, init->in_spec,
641 init->mapp_data, _("~/menuapp/data"), R_OK);
642 form->f_out_spec =
643 verify_spec_arg(form->out_spec, init->out_spec, init->mapp_data,
644 _("~/menuapp/data"), W_OK | S_QUIET);
645 if (init->provider_cmd[0] != '\0') {
646 form->f_provider_cmd =
647 verify_spec_arg(form->provider_cmd, init->provider_cmd,
648 _("~/menuapp/bin"), _("$PATH"), X_OK | S_QUIET);
649 }
650 if (init->cmd[0] != '\0') {
651 form->f_cmd = verify_spec_arg(form->cmd, init->cmd, _("~/menuapp/bin"),
652 _("$PATH"), X_OK | S_QUIET);
653 }
654 if (init->receiver_cmd[0] != '\0') {
655 form->f_receiver_cmd =
656 verify_spec_arg(form->receiver_cmd, init->receiver_cmd,
657 _("~/menuapp/bin"), _("$PATH"), X_OK | S_QUIET);
658 }
659 form->f_help_spec =
660 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
661 _("~/menuapp/help"), R_OK);
662 if (optind < argc && !form->f_mapp_spec) {
663 form->f_mapp_spec =
664 verify_spec_arg(form->mapp_spec, argv[optind], init->mapp_msrc,
665 _("~/menuapp/msrc"), R_OK);
666 if (form->f_mapp_spec)
667 optind++;
668 }
669 if (optind < argc && !form->f_in_spec) {
670 form->f_in_spec =
671 verify_spec_arg(form->in_spec, argv[optind], init->mapp_data,
672 _("~/menuapp/data"), R_OK);
673 if (form->f_in_spec)
674 optind++;
675 }
676 if (optind < argc && !form->f_out_spec) {
677 form->f_out_spec =
678 verify_spec_arg(form->out_spec, argv[optind], init->mapp_data,
679 _("~/menuapp/data"), W_OK | S_QUIET);
680 if (form->f_out_spec)
681 optind++;
682 }
683 if (optind < argc && !form->f_provider_cmd) {
684 if (argv[optind][0] != '\0') {
685 form->f_provider_cmd =
686 verify_spec_arg(form->provider_cmd, argv[optind],
687 _("~/menuapp/bin"), nullptr, X_OK | S_QUIET);
688 if (!form->f_provider_cmd) {
689 base_name(tmp_str, argv[optind]);
690 form->f_provider_cmd =
691 locate_file_in_path(form->provider_cmd, tmp_str);
692 }
693 }
694 optind++;
695 }
696 if (optind < argc && !form->f_cmd) {
697 if (argv[optind][0] != '\0') {
698 form->f_cmd =
699 verify_spec_arg(form->cmd, argv[optind], _("~/menuapp/bin"),
700 nullptr, X_OK | S_QUIET);
701 if (!form->f_cmd) {
702 base_name(tmp_str, argv[optind]);
703 form->f_cmd = locate_file_in_path(form->cmd, tmp_str);
704 }
705 }
706 optind++;
707 }
708 if (optind < argc && !form->f_receiver_cmd) {
709 if (argv[optind][0] != '\0') {
710 form->f_receiver_cmd =
711 verify_spec_arg(form->receiver_cmd, argv[optind],
712 _("~/menuapp/bin"), nullptr, X_OK | S_QUIET);
713 if (!form->f_receiver_cmd) {
714 base_name(tmp_str, argv[optind]);
715 form->f_receiver_cmd =
716 locate_file_in_path(form->receiver_cmd, tmp_str);
717 }
718 }
719 optind++;
720 }
721 if (optind < argc && !form->f_help_spec) {
722 form->f_help_spec =
723 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
724 _("~/menuapp/help"), R_OK);
725 if (form->f_help_spec)
726 optind++;
727 }
728 if (form->cmd[0] != '\0')
729 expand_tilde(form->cmd, MAXLEN - 1);
730 if (form->provider_cmd[0] != '\0')
731 expand_tilde(form->provider_cmd, MAXLEN - 1);
732 if (form->receiver_cmd[0] != '\0')
733 expand_tilde(form->receiver_cmd, MAXLEN - 1);
734 form->f_erase_remainder = init->f_erase_remainder;
735 if (form->title[0] == '\0' && init->title[0] != '\0') {
736 strip_quotes(init->title);
737 strnz__cpy(form->title, init->title, MAXLEN - 1);
738 }
739 form->f_multiple_cmd_args = init->f_multiple_cmd_args;
740 return true;
741}
#define S_QUIET
Definition cm.h:264
Form * form
Definition mem.c:37
#define MAXLEN
Definition curskeys.c:15
#define _(String)
Definition amort.c:23
bool locate_file_in_path(char *, char *)
Locates a file in the system PATH.
Definition futil.c:1296
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition whence.c:291
bool strip_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:710
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:989
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1132
bool verify_spec_arg(char *spec, char *org_spec, char *dir, char *alt_dir, uint mode)
Verify file specification argument.
Definition mem.c:361
char title[MAXLEN]
Definition common.h:132
char mapp_data[MAXLEN]
Definition common.h:151
char mapp_help[MAXLEN]
Definition common.h:152
char in_spec[MAXLEN]
Definition common.h:171
char mapp_msrc[MAXLEN]
Definition common.h:153
bool f_erase_remainder
Definition common.h:144
char mapp_spec[MAXLEN]
Definition common.h:179
char receiver_cmd[MAXLEN]
Definition common.h:124
bool f_multiple_cmd_args
Definition common.h:142
char provider_cmd[MAXLEN]
Definition common.h:123
char out_spec[MAXLEN]
Definition common.h:172
char cmd[MAXLEN]
Definition common.h:125
char help_spec[MAXLEN]
Definition common.h:180

References base_name(), Form::cmd, Init::cmd, expand_tilde(), Form::f_cmd, Form::f_erase_remainder, Init::f_erase_remainder, Form::f_help_spec, Form::f_in_spec, Form::f_mapp_spec, Form::f_multiple_cmd_args, Init::f_multiple_cmd_args, Form::f_out_spec, Form::f_provider_cmd, Form::f_receiver_cmd, form, Form::help_spec, Init::help_spec, Form::in_spec, Init::in_spec, locate_file_in_path(), Init::mapp_data, Init::mapp_help, Init::mapp_msrc, Form::mapp_spec, Init::mapp_spec, Form::out_spec, Init::out_spec, Form::provider_cmd, Init::provider_cmd, Form::receiver_cmd, Init::receiver_cmd, strip_quotes(), strnz__cpy(), Form::title, Init::title, and verify_spec_arg().

Referenced by new_form().

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

◆ init_menu_files()

bool init_menu_files ( Init * init,
int argc,
char ** argv )

Initialize Menu file specifications.

Parameters
initstructure
argc- number of arguments in argv
argv- Arguments may have been provided by command line, ~/.minitrc, environment variables, or calling program interal to C-Menu

Positional args: [menu desc], [help file]

Definition at line 483 of file mem.c.

483 {
484 char tmp_str[MAXLEN];
485 int optind = 0;
486 if (optind < argc && !init->f_mapp_spec) {
487 menu->f_mapp_spec =
488 verify_spec_arg(menu->mapp_spec, argv[optind], init->mapp_msrc,
489 _("~/menuapp/msrc"), R_OK);
490 if (menu->f_mapp_spec)
491 optind++;
492 }
493 if (optind < argc && !menu->f_help_spec) {
494 menu->f_help_spec =
495 verify_spec_arg(menu->help_spec, argv[optind], init->mapp_help,
496 _("~/menuapp/help"), R_OK);
497 if (menu->f_help_spec)
498 optind++;
499 }
500 if (!menu->f_mapp_spec) {
501 menu->f_mapp_spec = verify_spec_arg(
502 menu->mapp_spec, _("~/menuapp/msrc/main.m"), nullptr, nullptr, R_OK);
503 if (!menu->f_mapp_spec) {
504 strnz__cpy(tmp_str, _("menu cannot read description file "),
505 MAXLEN - 1);
506 strnz__cat(tmp_str, menu->mapp_spec, MAXLEN - 1);
507 ui_abend(-1, tmp_str);
508 }
509 }
510 if (!menu->f_help_spec) {
511 menu->f_help_spec =
512 verify_spec_arg(menu->help_spec, _("~/menuapp/help/menu.help"),
513 nullptr, nullptr, R_OK);
514 if (!menu->f_help_spec) {
515 strnz__cpy(tmp_str, _("menu cannot read help file "), MAXLEN - 1);
516 strnz__cat(tmp_str, menu->help_spec, MAXLEN - 1);
517 ui_abend(-1, tmp_str);
518 }
519 }
520 return true;
521}
void ui_abend(int ec, char *s)
Convert multibyte string to complex character array.
Definition ui_common.c:362
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition whence.c:320

References Menu::f_help_spec, Init::f_mapp_spec, Menu::f_mapp_spec, Menu::help_spec, Init::mapp_help, Init::mapp_msrc, Menu::mapp_spec, menu, strnz__cat(), strnz__cpy(), ui_abend(), and verify_spec_arg().

Referenced by new_menu().

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

◆ init_pick_files()

bool init_pick_files ( Init * init,
int argc,
char ** argv )

Initialize Pick file specifications.

Parameters
initstructure
argc- number of arguments in argv
argv- Arguments may have been provided by command line, ~/.minitrc, environment variables, or calling program interal to C-Menu

Positional args: [pick desc], [in_file], [out_file], [help_file]

Definition at line 531 of file mem.c.

531 {
532 char tmp_str[MAXLEN];
533 int optind = 1;
534 pick->f_in_spec = verify_spec_arg(pick->in_spec, init->in_spec,
535 init->mapp_data, _("~/menuapp/data"), R_OK);
536 pick->f_out_spec =
537 verify_spec_arg(pick->out_spec, init->out_spec, init->mapp_data,
538 _("~/menuapp/data"), W_OK | S_QUIET);
539 if (init->provider_cmd[0] != '\0') {
540 pick->f_provider_cmd =
541 verify_spec_arg(pick->provider_cmd, init->provider_cmd,
542 _("~/menuapp/bin"), _("$PATH"), X_OK | S_QUIET);
543 }
544 if (init->cmd[0] != '\0') {
545 pick->f_cmd = verify_spec_arg(pick->cmd, init->cmd, _("~/menuapp/bin"),
546 _("$PATH"), X_OK | S_QUIET);
547 }
548 if (init->receiver_cmd[0] != '\0') {
549 pick->f_receiver_cmd =
550 verify_spec_arg(pick->receiver_cmd, init->receiver_cmd,
551 _("~/menuapp/bin"), _("$PATH"), X_OK | S_QUIET);
552 }
553 if (init->title[0])
554 strnz__cpy(pick->title, init->title, MAXLEN - 1);
555 pick->f_help_spec =
556 verify_spec_arg(pick->help_spec, init->help_spec, init->mapp_help,
557 _("~/menuapp/help"), R_OK);
558 if (optind < argc && !pick->f_in_spec) {
559 pick->f_in_spec =
560 verify_spec_arg(pick->in_spec, argv[optind], init->mapp_data,
561 _("~/menuapp/data"), R_OK);
562 if (pick->f_in_spec)
563 optind++;
564 }
565 if (optind < argc && !pick->f_out_spec) {
566 pick->f_out_spec =
567 verify_spec_arg(pick->out_spec, argv[optind], init->mapp_data,
568 _("~/menuapp/data"), W_OK | S_QUIET);
569 if (pick->f_out_spec)
570 optind++;
571 }
572 if (optind < argc && !pick->f_provider_cmd) {
573 if (argv[optind][0] != '\0') {
574 pick->f_provider_cmd =
575 verify_spec_arg(pick->provider_cmd, argv[optind],
576 _("~/menuapp/bin"), nullptr, X_OK | S_QUIET);
577 if (!pick->f_provider_cmd) {
578 base_name(tmp_str, argv[optind]);
579 pick->f_provider_cmd =
580 locate_file_in_path(pick->provider_cmd, tmp_str);
581 }
582 }
583 optind++;
584 }
585 if (optind < argc && !pick->f_cmd) {
586 if (argv[optind][0] != '\0') {
587 pick->f_cmd =
588 verify_spec_arg(pick->cmd, argv[optind], _("~/menuapp/bin"),
589 nullptr, X_OK | S_QUIET);
590 if (!pick->f_cmd) {
591 base_name(tmp_str, argv[optind]);
592 pick->f_cmd = locate_file_in_path(pick->cmd, tmp_str);
593 }
594 }
595 optind++;
596 }
597 if (optind < argc && !pick->f_receiver_cmd) {
598 if (argv[optind][0] != '\0') {
599 pick->f_receiver_cmd =
600 verify_spec_arg(pick->receiver_cmd, argv[optind],
601 _("~/menuapp/bin"), nullptr, X_OK | S_QUIET);
602 if (!pick->f_receiver_cmd) {
603 base_name(tmp_str, argv[optind]);
604 pick->f_receiver_cmd =
605 locate_file_in_path(pick->receiver_cmd, tmp_str);
606 }
607 }
608 optind++;
609 }
610 if (optind < argc && !pick->f_help_spec) {
611 pick->f_help_spec =
612 verify_spec_arg(pick->help_spec, argv[optind], init->mapp_help,
613 _("~/menuapp/help"), R_OK);
614 if (pick->f_help_spec)
615 optind++;
616 }
617 if (pick->provider_cmd[0] != '\0')
618 expand_tilde(pick->provider_cmd, MAXLEN - 1);
619 if (pick->receiver_cmd[0] != '\0')
620 expand_tilde(pick->receiver_cmd, MAXLEN - 1);
621 pick->select_max = init->select_max;
622 pick->f_read_theme = init->f_read_theme;
623 pick->f_multiple_cmd_args = init->f_multiple_cmd_args;
624 pick->p_view_files = init->p_view_files;
625 return true;
626}
bool f_read_theme
Definition common.h:145
int select_max
Definition common.h:184
bool p_view_files
Definition common.h:137

References base_name(), Init::cmd, Pick::cmd, expand_tilde(), Pick::f_cmd, Pick::f_help_spec, Pick::f_in_spec, Init::f_multiple_cmd_args, Pick::f_multiple_cmd_args, Pick::f_out_spec, Pick::f_provider_cmd, Init::f_read_theme, Pick::f_read_theme, Pick::f_receiver_cmd, Init::help_spec, Pick::help_spec, Init::in_spec, Pick::in_spec, locate_file_in_path(), Init::mapp_data, Init::mapp_help, Init::out_spec, Pick::out_spec, Init::p_view_files, Pick::p_view_files, pick, Init::provider_cmd, Pick::provider_cmd, Init::receiver_cmd, Pick::receiver_cmd, Init::select_max, Pick::select_max, strnz__cpy(), Init::title, Pick::title, and verify_spec_arg().

Referenced by new_pick().

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

◆ init_view_files()

bool init_view_files ( Init * init)

Initialize View file specifications.

Parameters
initstructure

Positional args: pick desc, in_file, out_file, help_file

Definition at line 746 of file mem.c.

746 {
747 char *e;
748 view = init->view;
749 view->lines = init->lines;
750 view->cols = init->cols;
751 view->begy = init->begy;
752 view->begx = init->begx;
753 view->f_ignore_case = init->f_ignore_case;
754 view->f_at_end_remove = init->f_at_end_remove;
755 view->f_squeeze = init->f_squeeze;
756 view->tab_stop = init->tab_stop;
757 view->f_ln = init->f_ln;
758 view->wrap = init->wrap;
759 view->h_shift = init->h_shift;
760 e = getenv(_("VIEW_HELP_FILE"));
761 if (e && e[0] != '\0') {
762 strnz__cpy(view->help_spec, e, MAXLEN - 1);
763 }
764 view->f_help_spec =
765 verify_spec_arg(view->help_spec, view->help_spec, init->mapp_help,
766 _("~/menuapp/help"), R_OK);
767 if (!view->f_help_spec) {
768 strnz__cpy(view->help_spec, init->mapp_home, MAXLEN - 1);
769 strnz__cat(view->help_spec, _("/help/"), MAXLEN - 1);
770 strnz__cat(view->help_spec, VIEW_HELP_FILE, MAXLEN - 1);
771 }
772 strnz__cpy(view->provider_cmd, init->provider_cmd, MAXLEN - 1);
773 strnz__cpy(view->receiver_cmd, init->receiver_cmd, MAXLEN - 1);
774 strnz__cpy(view->cmd_all, init->cmd_all, MAXLEN - 1);
775 if (view->cmd[0] != '\0')
776 expand_tilde(view->cmd, MAXLEN - 1);
777 if (view->provider_cmd[0] != '\0')
778 expand_tilde(view->provider_cmd, MAXLEN - 1);
779 if (view->receiver_cmd[0] != '\0')
780 expand_tilde(view->receiver_cmd, MAXLEN - 1);
781 if (view->title[0] == '\0') {
782 if (init->title[0] != '\0') {
783 strnz__cpy(view->title, init->title, MAXLEN - 1);
784 } else {
785 if (view->provider_cmd[0] != '\0')
786 strnz__cpy(view->title, view->provider_cmd, MAXLEN - 1);
787 else {
788 if (view->argv != nullptr && view->argv[0] != nullptr &&
789 view->argv[0][0] != '\0') {
790 strnz__cpy(view->title, view->argv[0], MAXLEN - 1);
791 } else
792 strnz__cpy(view->title, _("C-Menu View"), MAXLEN - 1);
793 }
794 }
795 }
796 strip_quotes(view->title);
797 if (view->tab_stop == 0)
798 view->tab_stop = 4;
799 return true;
800}
#define VIEW_HELP_FILE
Definition common.h:38
int begx
Definition common.h:121
char cmd_all[MAXLEN]
Definition common.h:126
int cols
Definition common.h:119
int tab_stop
Definition common.h:185
char mapp_home[MAXLEN]
Definition common.h:150
bool f_squeeze
Definition common.h:140
int begy
Definition common.h:120
int h_shift
Definition common.h:186
bool wrap
Definition common.h:147
bool f_ln
Definition common.h:146
bool f_at_end_remove
Definition common.h:138
bool f_ignore_case
Definition common.h:136
int lines
Definition common.h:118

References View::argv, Init::begx, View::begx, Init::begy, View::begy, View::cmd, Init::cmd_all, View::cmd_all, Init::cols, View::cols, expand_tilde(), Init::f_at_end_remove, View::f_at_end_remove, View::f_help_spec, Init::f_ignore_case, View::f_ignore_case, Init::f_ln, View::f_ln, Init::f_squeeze, View::f_squeeze, Init::h_shift, View::h_shift, View::help_spec, Init::lines, View::lines, Init::mapp_help, Init::mapp_home, Init::provider_cmd, View::provider_cmd, Init::receiver_cmd, View::receiver_cmd, strip_quotes(), strnz__cat(), strnz__cpy(), Init::tab_stop, View::tab_stop, Init::title, View::title, verify_spec_arg(), Init::view, view, Init::wrap, and View::wrap.

Referenced by new_view().

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

◆ new_form()

Form * new_form ( Init * init,
int argc,
char ** argv,
uint begy,
uint begx )

Create and initialize Form structure.

Parameters
initstructure
argc- number of arguments in argv
argv- Arguments may have been provided by command line, ~/.minitrc, environment variables, or calling program interal to C-Menu
begy,begx- initial position of form window

Definition at line 244 of file mem.c.

244 {
245 init->form = (Form *)calloc(1, sizeof(Form));
246 if (!init->form) {
247 ui_abend(-1, _("calloc form failed"));
248 return nullptr;
249 }
250 init->form_cnt++;
251 form = init->form;
252 if (!init_form_files(init, argc, argv)) {
253 ui_abend(-1, _("init_form_files failed"));
254 return nullptr;
255 }
256 strnz__cpy(form->brackets, init->brackets, 3);
257 strnz__cpy(form->fill_char, init->fill_char, MAXLEN - 1);
258 form->begy = begy;
259 form->begx = begx;
260 return init->form;
261}
bool init_form_files(Init *init, int argc, char **argv)
Initialize Form file specifications.
Definition mem.c:634
char fill_char[2]
Definition common.h:149
char brackets[3]
Definition common.h:148
Definition form.h:146

References Form::begx, Form::begy, Form::brackets, Init::brackets, Form::fill_char, Init::fill_char, form, Init::form, Init::form_cnt, init_form_files(), strnz__cpy(), and ui_abend().

Referenced by init_form().

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

◆ new_init()

Init * new_init ( int argc,
char ** argv )

Create and initialize Init structure.

Parameters
argc,argv- arguments

calloc initializes all fields to zero/nullptr idiomatic directory usage:

init->mapp_msrc description files
init->mapp_help help files
init->mapp_data in, out, data files
init->mapp_user executable scripts
init->mapp_bin binary executables

Initialize file specifications in priority order:

1 - Default values
2 - Configuration file
3 - Environment variables
4 - Command line positional arguments
5 - Command line option arguments

Definition at line 60 of file mem.c.

60 {
61 int i = 0;
62 Init *init = calloc(1, sizeof(Init));
63 if (init == nullptr) {
64 ui_abend(-1, _("calloc init failed"));
65 return nullptr;
66 }
67 init->argv = calloc(MAXARGS + 1, sizeof(char *));
68 if (init->argv == nullptr) {
69 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d, errno: %d"), __FILE__,
70 __LINE__ - 4, errno);
71 ssnprintf(em1, MAXLEN - 1, _("%s"), strerror(errno));
72 ssnprintf(em2, MAXLEN - 1, "view->argv = calloc(%d, %d) failed\n",
73 (MAXARGS + 1), sizeof(char *));
74 ui_display_error(em0, em1, em2, nullptr);
75 exit(EXIT_FAILURE);
76 }
77 init->argc = argc;
78 for (i = 0; i < init->argc; i++)
79 init->argv[i] = argv[i];
80 init->argv[i] = nullptr;
81
82 init_cnt++;
83 return init;
84}
#define MAXARGS
Definition cm.h:64
char em1[MAXLEN]
Definition ui_common.c:47
char em2[MAXLEN]
Definition ui_common.c:48
char em0[MAXLEN]
Definition ui_common.c:46
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
int ui_display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition ui_common.c:1200
Gathers runtime information for C-Menu Menu, Form, Pick, and View components, used for passing common...
Definition common.h:116

References Init::argc, Init::argv, em0, em1, em2, init_cnt, ssnprintf(), ui_abend(), and ui_display_error().

Referenced by main().

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

◆ new_menu()

Menu * new_menu ( Init * init,
int argc,
char ** argv,
uint begy,
uint begx )

Create and initialize Menu structure.

Parameters
initstructure
argc- number of arguments in argv
argv- Arguments may have been provided by command line, ~/.minitrc, environment variables, or calling program interal to C-Menu
begy,begx- initial position of menu window

Definition at line 126 of file mem.c.

126 {
127 init->menu = (Menu *)calloc(1, sizeof(Menu));
128 if (!init->menu) {
129 ui_abend(-1, _("calloc menu failed"));
130 return nullptr;
131 }
132 init->menu_cnt++;
133 menu = init->menu;
134 if (!init_menu_files(init, argc, argv)) {
135 ui_abend(-1, _("init_menu_files failed"));
136 return nullptr;
137 }
138 menu->begy = begy;
139 menu->begx = begx;
140 return init->menu;
141}
bool init_menu_files(Init *init, int argc, char **argv)
Initialize Menu file specifications.
Definition mem.c:483
The Menu structure is the main data structure for the menu application, containing all the informatio...
Definition menu.h:104

References Menu::begx, Menu::begy, init_menu_files(), Init::menu, menu, Init::menu_cnt, and ui_abend().

Referenced by main(), and popup_menu().

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

◆ new_pick()

Pick * new_pick ( Init * init,
int argc,
char ** argv,
uint begy,
uint begx )

Create and initialize Pick structure.

Parameters
initstructure
argc- number of arguments in argv
argv- Arguments may have been provided by command line, ~/.minitrc, environment variables, or calling program interal to C-Menu
begy,begx- initial position of pick window

Definition at line 178 of file mem.c.

178 {
179 init->pick = (Pick *)calloc(1, sizeof(Pick));
180 if (!init->pick) {
181 ui_perror(_("calloc pick failed"));
182 return nullptr;
183 }
184 init->pick_cnt++;
185 pick = init->pick;
186 if (!init_pick_files(init, argc, argv)) {
187 ui_abend(-1, _("init_pick_files failed"));
188 return nullptr;
189 }
190 pick->m_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
191 if (pick->m_object == nullptr) {
192 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 1);
193 ssnprintf(em1, MAXLEN - 1,
194 "calloc pick->m_object = calloc(%d, %d) failed\n",
195 OBJ_MAXCNT + 1, sizeof(char *));
196 ui_display_error(em0, em1, nullptr, nullptr);
197 ui_abend(-1, _("User terminated program"));
198 }
199 pick->d_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
200 if (pick->d_object == nullptr) {
201 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 1);
202 ssnprintf(em1, MAXLEN - 1,
203 "calloc pick->d_object = calloc(%d, %d) failed\n",
204 OBJ_MAXCNT + 1, sizeof(char *));
205 ui_display_error(em0, em1, nullptr, nullptr);
206 ui_abend(-1, _("User terminated program"));
207 }
208 pick->begy = begy;
209 pick->begx = begx;
210 return init->pick;
211}
bool init_pick_files(Init *init, int argc, char **argv)
Initialize Pick file specifications.
Definition mem.c:531
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition ui_common.c:1257
Pick data structure.
Definition pick.h:25

References Pick::begx, Pick::begy, Pick::d_object, em0, em1, init_pick_files(), Pick::m_object, Init::pick, pick, Init::pick_cnt, ssnprintf(), ui_abend(), ui_display_error(), and ui_perror().

Referenced by init_pick().

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

◆ new_view()

View * new_view ( Init * init)

Create and initialize View structure.

Parameters
initstructure

Definition at line 291 of file mem.c.

291 {
292 init->view_cnt++;
293 init->view = (View *)calloc(1, sizeof(View));
294 if (!init->view) {
295 free(init->view);
296 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d, errno: %d"), __FILE__,
297 __LINE__ - 1, errno);
298 ssnprintf(em1, MAXLEN - 1, _("%s"), strerror(errno));
299 ssnprintf(em2, MAXLEN - 1, "init->view = calloc(%d) failed\n",
300 sizeof(View));
301 ui_display_error(em0, em1, em2, nullptr);
302 ui_abend(-1, _("calloc init->view failed"));
303 return nullptr;
304 }
305 view = init->view;
306 view->argc = init->argc;
307 if (view->argc > 0) {
308 view->argv = calloc(view->argc + 1, sizeof(char *));
309 if (view->argv == nullptr) {
310 free(view->argv);
311 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d, errno: %d"), __FILE__,
312 __LINE__ - 1, errno);
313 ssnprintf(em1, MAXLEN - 1, _("%s"), strerror(errno));
314 ssnprintf(em2, MAXLEN - 1, "view->argv = calloc(%d, %d) failed\n",
315 view->argc, sizeof(char *));
316 ui_display_error(em0, em1, em2, nullptr);
317 ui_abend(-1, _("User terminated program"));
318 return nullptr;
319 }
320 int s = 0;
321 int d = 0;
322 while (s < init->argc)
323 view->argv[d++] = strnz_dup(init->argv[s++], MAXLEN - 1);
324 view->argv[d] = nullptr;
325 }
326 if (!init_view_files(init)) {
327 ui_abend(-1, _("init_view_files failed"));
328 return nullptr;
329 }
330 return view;
331}
char * strnz_dup(char *, size_t)
Allocates memory for and duplicates string s up to length l or until line feed or carriage return.
Definition futil.c:642
bool init_view_files(Init *init)
Initialize View file specifications.
Definition mem.c:746
Definition view.h:59

References Init::argc, View::argc, Init::argv, View::argv, em0, em1, em2, init_view_files(), ssnprintf(), strnz_dup(), ui_abend(), ui_display_error(), Init::view, view, and Init::view_cnt.

Referenced by main(), new_pick_view(), and popup_view().

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

◆ verify_spec_arg()

bool verify_spec_arg ( char * spec,
char * org_spec,
char * dir,
char * alt_dir,
uint mode )

Verify file specification argument.

Parameters
spec- menu->spec, form->spec, etc.
org_spec- init->._spec | argv[optind]
dir- init->._. directory
alt_dir- literal, _("~/menuapp/data"), etc.
mode- R_OK, W_OK, X_OK, WC_OK, S_QUIET

mode is a bitwise OR of the following flags: S_QUIET - suppress error messages WC_OK - write create ok

Returns
bool - true if file verified

preserve quotes

preserve quotes

Definition at line 361 of file mem.c.

362 {
363 bool f_dir = false;
364 bool f_spec = false;
365 bool f_quote = true;
366 char *s1;
367 char *s2;
368 char s1_s[MAXLEN] = {};
369 char s2_s[MAXLEN] = {};
370 char file_name[MAXLEN] = {};
371 char try_spec[MAXLEN] = {};
372 char idio_spec[MAXLEN] = {};
373
374 if (!org_spec[0])
375 return false;
376 idio_spec[0] = '\0';
377 // try the provided spec as is, with quotes stripped for file name parsing
378 strnz__cpy(try_spec, org_spec, MAXLEN - 1);
379 f_quote = stripz_quotes(try_spec);
380
381 s1 = strtok(try_spec, " \t\n");
382 strnz__cpy(s1_s, s1, MAXLEN - 1);
383
384 s2 = strtok(nullptr, "\n");
385 strnz__cpy(s2_s, s2, MAXLEN - 1);
386
387 strnz__cpy(file_name, s1, MAXLEN - 1);
388 strnz__cpy(try_spec, file_name, MAXLEN - 1);
389
390 canonicalize_file_spec(try_spec);
391
392 if (try_spec[0]) {
393 expand_tilde(try_spec, MAXLEN - 1);
394 if (try_spec[0] == '/') {
395 // try absolute path as is, with quotes stripped for file name parsing
396 f_spec = verify_file(try_spec, mode);
397 if (f_quote)
399 strnz__cpy(spec, org_spec, MAXLEN - 1);
400 else
401 strnz__cpy(spec, try_spec, MAXLEN - 1);
402 return f_spec;
403
404 } else {
405 if (!f_dir && dir[0]) {
406 if (strcmp(dir, _("$PATH")) == 0) {
407 strnz__cpy(try_spec, file_name, MAXLEN - 1);
408 f_spec = locate_file_in_path(try_spec, file_name);
409 } else {
410 strnz__cpy(try_spec, dir, MAXLEN - 1);
411 expand_tilde(try_spec, MAXLEN - 1);
412 f_dir = verify_dir(try_spec, mode);
413 if (f_dir) {
414 // directory is valid, append file_name and verify file
415 strnz__cat(try_spec, "/", MAXLEN - 1);
416 strnz__cat(try_spec, file_name, MAXLEN - 1);
417 strnz__cpy(idio_spec, try_spec, MAXLEN - 1);
418 if (mode & S_WCOK)
419 f_spec = true;
420 else
421 f_spec = verify_file(idio_spec, mode | S_QUIET);
422 }
423 }
424 }
425 if (!f_spec && alt_dir && alt_dir[0] != '\0') {
426 if (strcmp(alt_dir, _("$PATH")) == 0) {
427 strnz__cpy(try_spec, file_name, MAXLEN - 1);
428 f_spec = locate_file_in_path(try_spec, file_name);
429 } else {
430 strnz__cpy(try_spec, alt_dir, MAXLEN - 1);
431 expand_tilde(try_spec, MAXLEN - 1);
432 f_dir = verify_dir(try_spec, mode);
433 if (f_dir) {
434 strnz__cat(try_spec, "/", MAXLEN - 1);
435 strnz__cat(try_spec, file_name, MAXLEN - 1);
436 if (mode & S_WCOK)
437 f_spec = true;
438 else
439 f_spec = verify_file(try_spec, mode | S_QUIET);
440 }
441 }
442 }
443 if (!f_spec) {
444 strnz__cpy(try_spec, ".", MAXLEN - 1);
445 strnz__cat(try_spec, "/", MAXLEN - 1);
446 strnz__cat(try_spec, file_name, MAXLEN - 1);
447 f_spec = verify_file(try_spec, mode | S_QUIET);
448 }
449 if (!f_spec && mode == W_OK) {
450 strnz__cpy(try_spec, idio_spec, MAXLEN - 1);
451 FILE *fp = fopen(try_spec, "a");
452 if (fp) {
453 fclose(fp);
454 f_spec = true;
455 }
456 }
457 if (f_quote)
459 strnz__cpy(spec, org_spec, MAXLEN - 1);
460 else if (f_spec)
461 strnz__cpy(spec, try_spec, MAXLEN - 1);
462 if (try_spec[0] == '\0' && idio_spec[0] != '\0')
463 strnz__cpy(spec, idio_spec, MAXLEN - 1);
464 else
465 strnz__cpy(spec, try_spec, MAXLEN - 1);
466 if (s2_s[0] != '\0') {
467 strnz__cat(spec, " ", MAXLEN - 1);
468 strnz__cat(spec, s2_s, MAXLEN - 1);
469 }
470 return f_spec;
471 }
472 }
473 return false;
474}
#define S_WCOK
Definition cm.h:263
size_t canonicalize_file_spec(char *)
Removes quotes and trims at first space.
Definition futil.c:1350
bool stripz_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:723
bool verify_file(char *, uint)
Verifies that the file specified by "in_spec" exists and is accessible with the permissions specified...
Definition futil.c:1249
bool verify_dir(char *, uint)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:1198

References canonicalize_file_spec(), expand_tilde(), locate_file_in_path(), stripz_quotes(), strnz__cat(), strnz__cpy(), verify_dir(), and verify_file().

Referenced by enter_file_spec(), init_form_files(), init_menu_files(), init_pick_files(), init_view_files(), and new_pick_view().

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