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

Formdestroy_form (Init *init)
 Destroy Form structure.
Initdestroy_init (Init *init)
 Destroy Init structure.
Menudestroy_menu (Init *init)
 Destroy Menu structure.
Pickdestroy_pick (Init *init)
 Destroy Pick structure.
Viewdestroy_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.
Formnew_form (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Form structure.
Initnew_init (int argc, char **argv)
 Create and initialize Init structure.
Menunew_menu (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Menu structure.
Picknew_pick (Init *init, int argc, char **argv, uint begy, uint begx)
 Create and initialize Pick structure.
Viewnew_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 275 of file mem.c.

275 {
276 uint i;
277
278 if (!init->form)
279 return nullptr;
280 for (i = 0; i < FIELD_MAXCNT; i++) {
281 if (init->form->field[i])
282 free(init->form->field[i]);
283 init->form->field[i] = nullptr;
284 }
285 for (i = 0; i < FIELD_MAXCNT; i++) {
286 if (init->form->text[i])
287 free(init->form->text[i]);
288 init->form->text[i] = nullptr;
289 }
290 free(init->form);
291 init->form = nullptr;
292 init->form_cnt--;
293 return init->form;
294}
#define FIELD_MAXCNT
Definition form.h:19
Form * form
Definition common.h:185
int form_cnt
Definition common.h:186
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 95 of file mem.c.

95 {
96 if (!init)
97 return nullptr;
98 if (init->sio) {
99 free(init->sio);
100 init->sio = nullptr;
101 }
102 if (init->menu) {
103 init->menu = destroy_menu(init);
104 init->menu = nullptr;
105 }
106 if (init->form) {
107 init->form = destroy_form(init);
108 init->form = nullptr;
109 }
110 if (init->pick) {
111 init->pick = destroy_pick(init);
112 init->pick = nullptr;
113 }
114 init->argc = destroy_argv(init->argc, init->argv);
115 if (init->argv != nullptr)
116 free(init->argv);
117 if (init != nullptr) {
118 free(init);
119 init = nullptr;
120 }
121 init_cnt--;
122 return init;
123}
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:487
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:155
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:275
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:225
SIO * sio
Definition common.h:114
int argc
Definition common.h:130
Menu * menu
Definition common.h:183
char ** argv
Definition common.h:131
Pick * pick
Definition common.h:187

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

Referenced by 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 155 of file mem.c.

155 {
156 menu = init->menu;
157 for (menu->line_idx = 0; menu->line_idx < menu->item_count;
158 menu->line_idx++) {
159 if (menu->line[menu->line_idx]) {
160 if (menu->line[menu->line_idx]->raw_text != nullptr)
161 free(menu->line[menu->line_idx]->raw_text);
162 if (menu->line[menu->line_idx]->command_str != nullptr)
163 free(menu->line[menu->line_idx]->command_str);
164 if (menu->line[menu->line_idx]->choice_text != nullptr)
165 free(menu->line[menu->line_idx]->choice_text);
166 free(menu->line[menu->line_idx]);
167 menu->line[menu->line_idx] = nullptr;
168 }
169 }
170 free(init->menu);
171 init->menu = nullptr;
172 menu = nullptr;
173 init->menu_cnt--;
174 return init->menu;
175}
Menu * menu
Definition mem.c:35
int menu_cnt
Definition common.h:184

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 225 of file mem.c.

225 {
226 if (!init->pick)
227 return nullptr;
228
229 for (pick->m_idx = 0; pick->m_idx < OBJ_MAXCNT; pick->m_idx++) {
230 if (pick->m_object[pick->m_idx] != nullptr)
231 free(pick->m_object[pick->m_idx]);
232 // if (pick->d_object[pick->d_idx] != nullptr)
233 // free(pick->d_object[pick->d_idx]);
234 }
235 free(pick->m_object);
236 free(pick->d_object);
237 free(pick);
238 init->pick = nullptr;
239 init->pick_cnt--;
240 return init->pick;
241}
#define OBJ_MAXCNT
Definition pick.h:17
Pick * pick
Definition mem.c:36
int pick_cnt
Definition common.h:188

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 345 of file mem.c.

345 {
346 view = init->view;
347 if (!view)
348 return nullptr;
349 view->argc = destroy_argv(view->argc, view->argv);
350 free(view->argv);
351 free(view);
352 init->view = nullptr;
353 view = nullptr;
354 init->view_cnt--;
355 return init->view;
356}
View * view
Definition mem.c:38
View * view
Definition common.h:189
int view_cnt
Definition common.h:190

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

Referenced by 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 642 of file mem.c.

642 {
643 char tmp_str[MAXLEN];
644 int optind = 0;
645 form->f_mapp_spec =
646 verify_spec_arg(form->mapp_spec, init->mapp_spec, init->mapp_msrc,
647 "~/menuapp/msrc", R_OK);
648 form->f_in_spec = verify_spec_arg(form->in_spec, init->in_spec,
649 init->mapp_data, "~/menuapp/data", R_OK);
650 form->f_out_spec =
651 verify_spec_arg(form->out_spec, init->out_spec, init->mapp_data,
652 "~/menuapp/data", W_OK | S_QUIET);
653 if (init->provider_cmd[0] != '\0') {
654 form->f_provider_cmd =
655 verify_spec_arg(form->provider_cmd, init->provider_cmd,
656 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
657 }
658 if (init->cmd[0] != '\0') {
659 form->f_cmd = verify_spec_arg(form->cmd, init->cmd, "~/menuapp/bin",
660 "$PATH", X_OK | S_QUIET);
661 }
662 if (init->receiver_cmd[0] != '\0') {
663 form->f_receiver_cmd =
664 verify_spec_arg(form->receiver_cmd, init->receiver_cmd,
665 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
666 }
667 form->f_help_spec =
668 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
669 "~/menuapp/help", R_OK);
670 if (optind < argc && !form->f_mapp_spec) {
671 form->f_mapp_spec =
672 verify_spec_arg(form->mapp_spec, argv[optind], init->mapp_msrc,
673 "~/menuapp/msrc", R_OK);
674 if (form->f_mapp_spec)
675 optind++;
676 }
677 if (optind < argc && !form->f_in_spec) {
678 form->f_in_spec =
679 verify_spec_arg(form->in_spec, argv[optind], init->mapp_data,
680 "~/menuapp/data", R_OK);
681 if (form->f_in_spec)
682 optind++;
683 }
684 if (optind < argc && !form->f_out_spec) {
685 form->f_out_spec =
686 verify_spec_arg(form->out_spec, argv[optind], init->mapp_data,
687 "~/menuapp/data", W_OK | S_QUIET);
688 if (form->f_out_spec)
689 optind++;
690 }
691 if (optind < argc && !form->f_provider_cmd) {
692 if (argv[optind][0] != '\0') {
693 form->f_provider_cmd =
694 verify_spec_arg(form->provider_cmd, argv[optind],
695 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
696 if (!form->f_provider_cmd) {
697 base_name(tmp_str, argv[optind]);
698 form->f_provider_cmd =
699 locate_file_in_path(form->provider_cmd, tmp_str);
700 }
701 }
702 optind++;
703 }
704 if (optind < argc && !form->f_cmd) {
705 if (argv[optind][0] != '\0') {
706 form->f_cmd =
707 verify_spec_arg(form->cmd, argv[optind], "~/menuapp/bin",
708 nullptr, X_OK | S_QUIET);
709 if (!form->f_cmd) {
710 base_name(tmp_str, argv[optind]);
711 form->f_cmd = locate_file_in_path(form->cmd, tmp_str);
712 }
713 }
714 optind++;
715 }
716 if (optind < argc && !form->f_receiver_cmd) {
717 if (argv[optind][0] != '\0') {
718 form->f_receiver_cmd =
719 verify_spec_arg(form->receiver_cmd, argv[optind],
720 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
721 if (!form->f_receiver_cmd) {
722 base_name(tmp_str, argv[optind]);
723 form->f_receiver_cmd =
724 locate_file_in_path(form->receiver_cmd, tmp_str);
725 }
726 }
727 optind++;
728 }
729 if (optind < argc && !form->f_help_spec) {
730 form->f_help_spec =
731 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
732 "~/menuapp/help", R_OK);
733 if (form->f_help_spec)
734 optind++;
735 }
736 if (form->cmd[0] != '\0')
737 expand_tilde(form->cmd, MAXLEN - 1);
738 if (form->provider_cmd[0] != '\0')
739 expand_tilde(form->provider_cmd, MAXLEN - 1);
740 if (form->receiver_cmd[0] != '\0')
741 expand_tilde(form->receiver_cmd, MAXLEN - 1);
742 form->f_erase_remainder = init->f_erase_remainder;
743 if (form->title[0] == '\0' && init->title[0] != '\0') {
744 strip_quotes(init->title);
745 strnz__cpy(form->title, init->title, MAXLEN - 1);
746 }
747 form->f_multiple_cmd_args = init->f_multiple_cmd_args;
748 return true;
749}
#define S_QUIET
Definition cm.h:328
Form * form
Definition mem.c:37
#define MAXLEN
Definition curskeys.c:15
bool locate_file_in_path(char *, char *)
Locates a file in the system PATH.
Definition futil.c:1270
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537
bool strip_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:711
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:963
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1106
bool verify_spec_arg(char *spec, char *org_spec, char *dir, char *alt_dir, uint mode)
Verify file specification argument.
Definition mem.c:369
char title[MAXLEN]
Definition common.h:129
char mapp_data[MAXLEN]
Definition common.h:148
char mapp_help[MAXLEN]
Definition common.h:149
char in_spec[MAXLEN]
Definition common.h:168
char mapp_msrc[MAXLEN]
Definition common.h:150
bool f_erase_remainder
Definition common.h:141
char mapp_spec[MAXLEN]
Definition common.h:176
char receiver_cmd[MAXLEN]
Definition common.h:121
bool f_multiple_cmd_args
Definition common.h:139
char provider_cmd[MAXLEN]
Definition common.h:120
char out_spec[MAXLEN]
Definition common.h:169
char cmd[MAXLEN]
Definition common.h:122
char help_spec[MAXLEN]
Definition common.h:177

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 491 of file mem.c.

491 {
492 char tmp_str[MAXLEN];
493 int optind = 0;
494 if (optind < argc && !init->f_mapp_spec) {
495 menu->f_mapp_spec =
496 verify_spec_arg(menu->mapp_spec, argv[optind], init->mapp_msrc,
497 "~/menuapp/msrc", R_OK);
498 if (menu->f_mapp_spec)
499 optind++;
500 }
501 if (optind < argc && !menu->f_help_spec) {
502 menu->f_help_spec =
503 verify_spec_arg(menu->help_spec, argv[optind], init->mapp_help,
504 "~/menuapp/help", R_OK);
505 if (menu->f_help_spec)
506 optind++;
507 }
508 if (!menu->f_mapp_spec) {
509 menu->f_mapp_spec = verify_spec_arg(
510 menu->mapp_spec, "~/menuapp/msrc/main.m", nullptr, nullptr, R_OK);
511 if (!menu->f_mapp_spec) {
512 strnz__cpy(tmp_str, "menu cannot read description file ",
513 MAXLEN - 1);
514 strnz__cat(tmp_str, menu->mapp_spec, MAXLEN - 1);
515 abend(-1, tmp_str);
516 }
517 }
518 if (!menu->f_help_spec) {
519 menu->f_help_spec =
520 verify_spec_arg(menu->help_spec, "~/menuapp/help/menu.help",
521 nullptr, nullptr, R_OK);
522 if (!menu->f_help_spec) {
523 strnz__cpy(tmp_str, "menu cannot read help file ", MAXLEN - 1);
524 strnz__cat(tmp_str, menu->help_spec, MAXLEN - 1);
525 abend(-1, tmp_str);
526 }
527 }
528 return true;
529}
void abend(int ec, char *s)
Abnormal program termination.
Definition dwin.c:1204
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:566

References abend(), 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(), 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 539 of file mem.c.

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

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 754 of file mem.c.

754 {
755 char *e;
756 view = init->view;
757 view->lines = init->lines;
758 view->cols = init->cols;
759 view->begy = init->begy;
760 view->begx = init->begx;
761 view->f_ignore_case = init->f_ignore_case;
762 view->f_at_end_remove = init->f_at_end_remove;
763 view->f_squeeze = init->f_squeeze;
764 view->tab_stop = init->tab_stop;
765 view->f_ln = init->f_ln;
766 view->wrap = init->wrap;
767 view->h_shift = init->h_shift;
768 e = getenv("VIEW_HELP_FILE");
769 if (e && e[0] != '\0') {
770 strnz__cpy(view->help_spec, e, MAXLEN - 1);
771 }
772 view->f_help_spec =
773 verify_spec_arg(view->help_spec, view->help_spec, init->mapp_help,
774 "~/menuapp/help", R_OK);
775 if (!view->f_help_spec) {
776 strnz__cpy(view->help_spec, init->mapp_home, MAXLEN - 1);
777 strnz__cat(view->help_spec, "/help/", MAXLEN - 1);
778 strnz__cat(view->help_spec, VIEW_HELP_FILE, MAXLEN - 1);
779 }
780 strnz__cpy(view->provider_cmd, init->provider_cmd, MAXLEN - 1);
781 strnz__cpy(view->receiver_cmd, init->receiver_cmd, MAXLEN - 1);
782 strnz__cpy(view->cmd_all, init->cmd_all, MAXLEN - 1);
783 if (view->cmd[0] != '\0')
784 expand_tilde(view->cmd, MAXLEN - 1);
785 if (view->provider_cmd[0] != '\0')
786 expand_tilde(view->provider_cmd, MAXLEN - 1);
787 if (view->receiver_cmd[0] != '\0')
788 expand_tilde(view->receiver_cmd, MAXLEN - 1);
789 if (view->title[0] == '\0') {
790 if (init->title[0] != '\0') {
791 strnz__cpy(view->title, init->title, MAXLEN - 1);
792 } else {
793 if (view->provider_cmd[0] != '\0')
794 strnz__cpy(view->title, view->provider_cmd, MAXLEN - 1);
795 else {
796 if (view->argv != nullptr && view->argv[0] != nullptr &&
797 view->argv[0][0] != '\0') {
798 strnz__cpy(view->title, view->argv[0], MAXLEN - 1);
799 } else
800 strnz__cpy(view->title, "C-Menu View", MAXLEN - 1);
801 }
802 }
803 }
804 strip_quotes(view->title);
805 if (view->tab_stop == 0)
806 view->tab_stop = 4;
807 return true;
808}
#define VIEW_HELP_FILE
Definition common.h:35
int begx
Definition common.h:118
char cmd_all[MAXLEN]
Definition common.h:123
int cols
Definition common.h:116
int tab_stop
Definition common.h:181
char mapp_home[MAXLEN]
Definition common.h:147
bool f_squeeze
Definition common.h:137
int begy
Definition common.h:117
int h_shift
Definition common.h:182
bool wrap
Definition common.h:144
bool f_ln
Definition common.h:143
bool f_at_end_remove
Definition common.h:135
bool f_ignore_case
Definition common.h:133
int lines
Definition common.h:115

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 252 of file mem.c.

252 {
253 init->form = (Form *)calloc(1, sizeof(Form));
254 if (!init->form) {
255 abend(-1, "calloc form failed");
256 return nullptr;
257 }
258 init->form_cnt++;
259 form = init->form;
260 if (!init_form_files(init, argc, argv)) {
261 abend(-1, "init_form_files failed");
262 return nullptr;
263 }
264 strnz__cpy(form->brackets, init->brackets, 3);
265 strnz__cpy(form->fill_char, init->fill_char, MAXLEN - 1);
266 form->begy = begy;
267 form->begx = begx;
268 return init->form;
269}
bool init_form_files(Init *init, int argc, char **argv)
Initialize Form file specifications.
Definition mem.c:642
char fill_char[2]
Definition common.h:146
char brackets[3]
Definition common.h:145
Definition form.h:146

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

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 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 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->sio = (SIO *)calloc(1, sizeof(SIO));
83 if (!init->sio) {
84 Perror("calloc sio failed");
85 exit(EXIT_FAILURE);
86 }
87 init_cnt++;
88 return init;
89}
#define MAXARGS
Definition cm.h:50
char em1[MAXLEN]
Definition dwin.c:143
char em2[MAXLEN]
Definition dwin.c:144
char em0[MAXLEN]
Definition dwin.c:142
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition dwin.c:778
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:413
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:688
Gathers runtime information for C-Menu Menu, Form, Pick, and View components, used for passing common...
Definition common.h:113

References abend(), Init::argc, Init::argv, display_error(), em0, em1, em2, init_cnt, Perror(), Init::sio, and ssnprintf().

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 134 of file mem.c.

134 {
135 init->menu = (Menu *)calloc(1, sizeof(Menu));
136 if (!init->menu) {
137 abend(-1, "calloc menu failed");
138 return nullptr;
139 }
140 init->menu_cnt++;
141 menu = init->menu;
142 if (!init_menu_files(init, argc, argv)) {
143 abend(-1, "init_menu_files failed");
144 return nullptr;
145 }
146 menu->begy = begy;
147 menu->begx = begx;
148 return init->menu;
149}
bool init_menu_files(Init *init, int argc, char **argv)
Initialize Menu file specifications.
Definition mem.c:491
The Menu structure is the main data structure for the menu application, containing all the informatio...
Definition menu.h:105

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

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 186 of file mem.c.

186 {
187 init->pick = (Pick *)calloc(1, sizeof(Pick));
188 if (!init->pick) {
189 Perror("calloc pick failed");
190 return nullptr;
191 }
192 init->pick_cnt++;
193 pick = init->pick;
194 if (!init_pick_files(init, argc, argv)) {
195 abend(-1, "init_pick_files failed");
196 return nullptr;
197 }
198 pick->m_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
199 if (pick->m_object == nullptr) {
200 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
201 ssnprintf(em1, MAXLEN - 1,
202 "calloc pick->m_object = calloc(%d, %d) failed\n",
203 OBJ_MAXCNT + 1, sizeof(char *));
204 display_error(em0, em1, nullptr, nullptr);
205 abend(-1, "User terminated program");
206 }
207 pick->d_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
208 if (pick->d_object == nullptr) {
209 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
210 ssnprintf(em1, MAXLEN - 1,
211 "calloc pick->d_object = calloc(%d, %d) failed\n",
212 OBJ_MAXCNT + 1, sizeof(char *));
213 display_error(em0, em1, nullptr, nullptr);
214 abend(-1, "User terminated program");
215 }
216 pick->begy = begy;
217 pick->begx = begx;
218 return init->pick;
219}
bool init_pick_files(Init *init, int argc, char **argv)
Initialize Pick file specifications.
Definition mem.c:539
Pick data structure.
Definition pick.h:25

References abend(), Pick::begx, Pick::begy, Pick::d_object, display_error(), em0, em1, init_pick_files(), Pick::m_object, Perror(), Init::pick, pick, Init::pick_cnt, and ssnprintf().

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 299 of file mem.c.

299 {
300 init->view_cnt++;
301 init->view = (View *)calloc(1, sizeof(View));
302 if (!init->view) {
303 free(init->view);
304 ssnprintf(em0, MAXLEN - 1, "%s, line: %d, errno: %d", __FILE__,
305 __LINE__ - 1, errno);
306 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
307 ssnprintf(em2, MAXLEN - 1, "init->view = calloc(%d) failed\n",
308 sizeof(View));
309 display_error(em0, em1, em2, nullptr);
310 abend(-1, "calloc init->view failed");
311 return nullptr;
312 }
313 view = init->view;
314 view->argc = init->argc;
315 if (view->argc > 0) {
316 view->argv = calloc(view->argc + 1, sizeof(char *));
317 if (view->argv == nullptr) {
318 free(view->argv);
319 ssnprintf(em0, MAXLEN - 1, "%s, line: %d, errno: %d", __FILE__,
320 __LINE__ - 1, errno);
321 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
322 ssnprintf(em2, MAXLEN - 1, "view->argv = calloc(%d, %d) failed\n",
323 view->argc, sizeof(char *));
324 display_error(em0, em1, em2, nullptr);
325 abend(-1, "User terminated program");
326 return nullptr;
327 }
328 int s = 0;
329 int d = 0;
330 while (s < init->argc)
331 view->argv[d++] = strnz_dup(init->argv[s++], MAXLEN - 1);
332 view->argv[d] = nullptr;
333 }
334 if (!init_view_files(init)) {
335 abend(-1, "init_view_files failed");
336 return nullptr;
337 }
338 return view;
339}
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:647
bool init_view_files(Init *init)
Initialize View file specifications.
Definition mem.c:754
Definition view.h:61

References abend(), Init::argc, View::argc, Init::argv, View::argv, display_error(), em0, em1, em2, init_view_files(), ssnprintf(), strnz_dup(), 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 369 of file mem.c.

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

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: