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

Initnew_init (int argc, char **argv)
 Create and initialize Init structure.
Initdestroy_init (Init *init)
 Destroy Init structure.
Menunew_menu (Init *init, int argc, char **argv, int begy, int begx)
 Create and initialize Menu structure.
Menudestroy_menu (Init *init)
 Destroy Menu structure.
Picknew_pick (Init *init, int argc, char **argv, int begy, int begx)
 Create and initialize Pick structure.
Pickdestroy_pick (Init *init)
 Destroy Pick structure.
Formnew_form (Init *init, int argc, char **argv, int begy, int begx)
 Create and initialize Form structure.
Formdestroy_form (Init *init)
 Destroy Form structure.
Viewnew_view (Init *init)
 Create and initialize View structure.
Viewdestroy_view (Init *init)
 Destroy View structure.
bool verify_spec_arg (char *spec, char *org_spec, char *dir, char *alt_dir, int mode)
 Verify file specification argument.
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_form_files (Init *init, int argc, char **argv)
 Initialize Form file specifications.
bool init_view_files (Init *init)
 Initialize View file specifications.

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

276 {
277 int i;
278
279 if (!init->form)
280 return nullptr;
281 for (i = 0; i < FIELD_MAXCNT; i++) {
282 if (init->form->field[i])
283 free(init->form->field[i]);
284 init->form->field[i] = nullptr;
285 }
286 for (i = 0; i < FIELD_MAXCNT; i++) {
287 if (init->form->text[i])
288 free(init->form->text[i]);
289 init->form->text[i] = nullptr;
290 }
291 free(init->form);
292 init->form = nullptr;
293 init->form_cnt--;
294 return init->form;
295}
#define FIELD_MAXCNT
Definition form.h:19
Init * init
Definition common.h:183

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

105 {
106 if (!init)
107 return nullptr;
108 if (init->sio) {
109 free(init->sio);
110 init->sio = nullptr;
111 }
112 if (init->menu) {
113 init->menu = destroy_menu(init);
114 init->menu = nullptr;
115 }
116 if (init->view) {
117 init->view = destroy_view(init);
118 init->view = nullptr;
119 }
120 if (init->form) {
121 init->form = destroy_form(init);
122 init->form = nullptr;
123 }
124 if (init->pick) {
125 init->pick = destroy_pick(init);
126 init->pick = nullptr;
127 }
128 destroy_argv(init->argc, init->argv);
129 if (init->argv != nullptr)
130 free(init->argv);
131 if (init != nullptr) {
132 free(init);
133 init = nullptr;
134 }
135 init_cnt--;
136 return init;
137}
int init_cnt
Definition mem.c:43
void destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:230
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:346
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:169
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:276
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:230

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

Here is the call graph for this function:

◆ destroy_menu()

Menu * destroy_menu ( Init * init)

Destroy Menu structure.

Parameters
initstructure
Returns
nullptr

Definition at line 169 of file mem.c.

169 {
170 menu = init->menu;
171 for (menu->line_idx = 0; menu->line_idx < menu->item_count;
172 menu->line_idx++) {
173 if (menu->line[menu->line_idx]) {
174 if (menu->line[menu->line_idx]->raw_text != nullptr)
175 free(menu->line[menu->line_idx]->raw_text);
176 if (menu->line[menu->line_idx]->command_str != nullptr)
177 free(menu->line[menu->line_idx]->command_str);
178 if (menu->line[menu->line_idx]->choice_text != nullptr)
179 free(menu->line[menu->line_idx]->choice_text);
180 free(menu->line[menu->line_idx]);
181 menu->line[menu->line_idx] = nullptr;
182 }
183 }
184 free(init->menu);
185 init->menu = nullptr;
186 menu = nullptr;
187 init->menu_cnt--;
188 return init->menu;
189}
Menu * menu
Definition mem.c:45

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

230 {
231 if (!init->pick)
232 return nullptr;
233
234 for (pick->obj_idx = 0; pick->obj_idx < pick->obj_cnt; pick->obj_idx++)
235 if (pick->object[pick->obj_idx] != nullptr)
236 free(pick->object[pick->obj_idx]);
237 free(pick->object);
238 free(pick);
239 init->pick = nullptr;
240 init->pick_cnt--;
241 return init->pick;
242}
Pick * pick
Definition mem.c:46

References Pick::obj_cnt, Pick::obj_idx, Pick::object, Init::pick, pick, and Init::pick_cnt.

Referenced by destroy_init(), init_pick(), 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 346 of file mem.c.

346 {
347 view = init->view;
348 if (!view)
349 return nullptr;
350 if (view->ln_tbl) {
351 free(view->ln_tbl);
352 view->ln_tbl = nullptr;
353 }
354 if (view->ln_win) {
355 delwin(view->ln_win);
356 view->ln_win = nullptr;
357 }
358 if (view->cmdln_win) {
359 delwin(view->cmdln_win);
360 view->cmdln_win = nullptr;
361 }
362 delwin(view->cmdln_win);
363 if (view->box) {
364 delwin(view->box);
365 view->box = nullptr;
366 }
367 delwin(view->box);
368 if (view->pad) {
369 delwin(view->pad);
370 view->pad = nullptr;
371 }
372 delwin(view->pad);
373 destroy_argv(view->argc, view->argv);
374 free(view->argv);
375 free(view);
376 init->view = nullptr;
377 view = nullptr;
378 init->view_cnt--;
379 return init->view;
380}
View * view
Definition mem.c:48

References View::argc, View::argv, View::box, View::cmdln_win, destroy_argv(), View::ln_tbl, View::ln_win, View::pad, Init::view, view, and Init::view_cnt.

Referenced by destroy_init(), 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
Note
Positional args: [pick desc], [in_file], [out_file], [help_file]

Definition at line 651 of file mem.c.

651 {
652 char tmp_str[MAXLEN];
653 int optind = 0;
654 form->f_mapp_spec =
655 verify_spec_arg(form->mapp_spec, init->mapp_spec, init->mapp_msrc,
656 "~/menuapp/msrc", R_OK);
657 form->f_in_spec = verify_spec_arg(form->in_spec, init->in_spec,
658 init->mapp_data, "~/menuapp/data", R_OK);
659 form->f_out_spec =
660 verify_spec_arg(form->out_spec, init->out_spec, init->mapp_data,
661 "~/menuapp/data", W_OK | S_QUIET);
662 if (init->provider_cmd[0] != '\0') {
663 form->f_provider_cmd =
664 verify_spec_arg(form->provider_cmd, init->provider_cmd,
665 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
666 }
667 if (init->cmd[0] != '\0') {
668 form->f_cmd = verify_spec_arg(form->cmd, init->cmd, "~/menuapp/bin",
669 "$PATH", X_OK | S_QUIET);
670 }
671 if (init->receiver_cmd[0] != '\0') {
672 form->f_receiver_cmd =
673 verify_spec_arg(form->receiver_cmd, init->receiver_cmd,
674 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
675 }
676 form->f_help_spec =
677 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
678 "~/menuapp/help", R_OK);
679 if (optind < argc && !form->f_mapp_spec) {
680 form->f_mapp_spec =
681 verify_spec_arg(form->mapp_spec, argv[optind], init->mapp_msrc,
682 "~/menuapp/msrc", R_OK);
683 if (form->f_mapp_spec)
684 optind++;
685 }
686 if (optind < argc && !form->f_in_spec) {
687 form->f_in_spec =
688 verify_spec_arg(form->in_spec, argv[optind], init->mapp_data,
689 "~/menuapp/data", R_OK);
690 if (form->f_in_spec)
691 optind++;
692 }
693 if (optind < argc && !form->f_out_spec) {
694 form->f_out_spec =
695 verify_spec_arg(form->out_spec, argv[optind], init->mapp_data,
696 "~/menuapp/data", W_OK | S_QUIET);
697 if (form->f_out_spec)
698 optind++;
699 }
700 if (optind < argc && !form->f_provider_cmd) {
701 if (argv[optind][0] != '\0') {
702 form->f_provider_cmd =
703 verify_spec_arg(form->provider_cmd, argv[optind],
704 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
705 if (!form->f_provider_cmd) {
706 base_name(tmp_str, argv[optind]);
707 form->f_provider_cmd =
708 locate_file_in_path(form->provider_cmd, tmp_str);
709 }
710 }
711 optind++;
712 }
713 if (optind < argc && !form->f_cmd) {
714 if (argv[optind][0] != '\0') {
715 form->f_cmd =
716 verify_spec_arg(form->cmd, argv[optind], "~/menuapp/bin",
717 nullptr, X_OK | S_QUIET);
718 if (!form->f_cmd) {
719 base_name(tmp_str, argv[optind]);
720 form->f_cmd = locate_file_in_path(form->cmd, tmp_str);
721 }
722 }
723 optind++;
724 }
725 if (optind < argc && !form->f_receiver_cmd) {
726 if (argv[optind][0] != '\0') {
727 form->f_receiver_cmd =
728 verify_spec_arg(form->receiver_cmd, argv[optind],
729 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
730 if (!form->f_receiver_cmd) {
731 base_name(tmp_str, argv[optind]);
732 form->f_receiver_cmd =
733 locate_file_in_path(form->receiver_cmd, tmp_str);
734 }
735 }
736 optind++;
737 }
738 if (optind < argc && !form->f_help_spec) {
739 form->f_help_spec =
740 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
741 "~/menuapp/help", R_OK);
742 if (form->f_help_spec)
743 optind++;
744 }
745 form->f_erase_remainder = init->f_erase_remainder;
746 if (form->title[0] == '\0' && init->title[0] != '\0') {
747 strip_quotes(init->title);
748 strnz__cpy(form->title, init->title, MAXLEN - 1);
749 }
750 return true;
751}
Form * form
Definition mem.c:47
#define S_QUIET
Definition cm.h:191
#define MAXLEN
Definition curskeys.c:15
bool locate_file_in_path(char *, char *)
Locates a file in the system PATH.
Definition futil.c:964
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:278
bool strip_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:463
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:800
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
Definition mem.c:393

References base_name(), Form::cmd, Init::cmd, 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_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
Note
Positional args: [menu desc], [help file]

Definition at line 506 of file mem.c.

506 {
507 char tmp_str[MAXLEN];
508 int optind = 0;
509 if (optind < argc && !init->f_mapp_spec) {
510 menu->f_mapp_spec =
511 verify_spec_arg(menu->mapp_spec, argv[optind], init->mapp_msrc,
512 "~/menuapp/msrc", R_OK);
513 if (menu->f_mapp_spec)
514 optind++;
515 }
516 if (optind < argc && !menu->f_help_spec) {
517 menu->f_help_spec =
518 verify_spec_arg(menu->help_spec, argv[optind], init->mapp_help,
519 "~/menuapp/help", R_OK);
520 if (menu->f_help_spec)
521 optind++;
522 }
523 if (!menu->f_mapp_spec) {
524 menu->f_mapp_spec = verify_spec_arg(
525 menu->mapp_spec, "~/menuapp/msrc/main.m", nullptr, nullptr, R_OK);
526 if (!menu->f_mapp_spec) {
527 strnz__cpy(tmp_str, "menu cannot read description file ",
528 MAXLEN - 1);
529 strnz__cat(tmp_str, menu->mapp_spec, MAXLEN - 1);
530 abend(-1, tmp_str);
531 }
532 }
533 if (!menu->f_help_spec) {
534 menu->f_help_spec =
535 verify_spec_arg(menu->help_spec, "~/menuapp/help/menu.help",
536 nullptr, nullptr, R_OK);
537 if (!menu->f_help_spec) {
538 strnz__cpy(tmp_str, "menu cannot read help file ", MAXLEN - 1);
539 strnz__cat(tmp_str, menu->help_spec, MAXLEN - 1);
540 abend(-1, tmp_str);
541 }
542 }
543 return true;
544}
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1336
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:307

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
Note
Positional args: [pick desc], [in_file], [out_file], [help_file]

Definition at line 554 of file mem.c.

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

References base_name(), Init::cmd, Pick::cmd, 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, 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, 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
Note
Positional args: pick desc, in_file, out_file, help_file

Definition at line 756 of file mem.c.

756 {
757 char *e;
758 view = init->view;
759 view->lines = init->lines;
760 view->cols = init->cols;
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->f_ln = init->f_ln;
765 e = getenv("VIEW_HELP_FILE");
766 if (e && e[0] != '\0') {
767 strnz__cpy(view->help_spec, e, MAXLEN - 1);
768 }
769 view->f_help_spec =
770 verify_spec_arg(view->help_spec, view->help_spec, init->mapp_help,
771 "~/menuapp/help", R_OK);
772 if (!view->f_help_spec) {
773 strnz__cpy(view->help_spec, init->mapp_home, MAXLEN - 1);
774 strnz__cat(view->help_spec, "/help/", MAXLEN - 1);
775 strnz__cat(view->help_spec, VIEW_HELP_FILE, MAXLEN - 1);
776 }
777 strnz__cpy(view->provider_cmd, init->provider_cmd, MAXLEN - 1);
778 strnz__cpy(view->receiver_cmd, init->receiver_cmd, MAXLEN - 1);
779 strnz__cpy(view->cmd_all, init->cmd_all, MAXLEN - 1);
780 if (view->title[0] == '\0') {
781 if (init->title[0] != '\0') {
782 strnz__cpy(view->title, init->title, MAXLEN - 1);
783 } else {
784 if (view->provider_cmd[0] != '\0')
785 strnz__cpy(view->title, view->provider_cmd, MAXLEN - 1);
786 else {
787 if (view->argv[0] != nullptr && view->argv[0][0] != '\0')
788 strnz__cpy(view->title, view->argv[0], MAXLEN - 1);
789 else
790 strnz__cpy(view->title, "C-Menu View", MAXLEN - 1);
791 }
792 }
793 }
794 strip_quotes(view->title);
795 if (view->tab_stop == 0)
796 view->tab_stop = 4;
797 return true;
798}
#define VIEW_HELP_FILE
Definition common.h:37

References View::argv, Init::cmd_all, View::cmd_all, Init::cols, View::cols, 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, 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(), View::tab_stop, Init::title, View::title, verify_spec_arg(), Init::view, and view.

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,
int begy,
int 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 253 of file mem.c.

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

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(), and popup_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.

Note
calloc initializes all fields to zero/nullptr
Parameters
argc,argv- arguments 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
Note
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 70 of file mem.c.

70 {
71 int i = 0;
72 Init *init = calloc(1, sizeof(Init));
73 if (init == nullptr) {
74 abend(-1, "calloc init failed");
75 return nullptr;
76 }
77 init->argv = calloc(MAXARGS + 1, sizeof(char *));
78 if (init->argv == nullptr) {
79 ssnprintf(em0, MAXLEN - 1, "%s, line: %d, errno: %d", __FILE__,
80 __LINE__ - 4, errno);
81 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
82 ssnprintf(em2, MAXLEN - 1, "view->argv = calloc(%d, %d) failed\n",
83 (MAXARGS + 1), sizeof(char *));
84 display_error(em0, em1, em2, nullptr);
85 exit(EXIT_FAILURE);
86 }
87 init->argc = argc;
88 for (i = 0; i < init->argc; i++)
89 init->argv[i] = argv[i];
90 init->argv[i] = nullptr;
91
92 init->sio = (SIO *)calloc(1, sizeof(SIO));
93 if (!init->sio) {
94 Perror("calloc sio failed");
95 exit(EXIT_FAILURE);
96 }
97 init_cnt++;
98 return init;
99}
#define MAXARGS
Definition cm.h:30
char em1[MAXLEN]
Definition dwin.c:134
char em0[MAXLEN]
Definition dwin.c:133
char em2[MAXLEN]
Definition dwin.c:135
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1115
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1059
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:156
Gathers runtime information for C-Menu Menu, Form, Pick, and View components, used for passing common...
Definition common.h:104
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:651

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,
int begy,
int 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 148 of file mem.c.

148 {
149 init->menu = (Menu *)calloc(1, sizeof(Menu));
150 if (!init->menu) {
151 abend(-1, "calloc menu failed");
152 return nullptr;
153 }
154 init->menu_cnt++;
155 menu = init->menu;
156 if (!init_menu_files(init, argc, argv)) {
157 abend(-1, "init_menu_files failed");
158 return nullptr;
159 }
160 menu->begy = begy;
161 menu->begx = begx;
162 return init->menu;
163}
bool init_menu_files(Init *, int, char **)
Initialize Menu file specifications.
Definition mem.c:506
The Menu structure is the main data structure for the menu application, containing all the informatio...
Definition menu.h:81

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,
int begy,
int 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 200 of file mem.c.

200 {
201 init->pick = (Pick *)calloc(1, sizeof(Pick));
202 if (!init->pick) {
203 Perror("calloc pick failed");
204 return nullptr;
205 }
206 init->pick_cnt++;
207 pick = init->pick;
208 if (!init_pick_files(init, argc, argv)) {
209 abend(-1, "init_pick_files failed");
210 return nullptr;
211 }
212 pick->object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
213 if (pick->object == nullptr) {
214 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
215 ssnprintf(em1, MAXLEN - 1,
216 "calloc pick->object = calloc(%d, %d) failed\n",
217 OBJ_MAXCNT + 1, sizeof(char *));
218 display_error(em0, em1, nullptr, nullptr);
219 abend(-1, "User terminated program");
220 }
221 pick->begy = begy;
222 pick->begx = begx;
223 return init->pick;
224}
#define OBJ_MAXCNT
Definition pick.h:17
bool init_pick_files(Init *, int, char **)
Initialize Pick file specifications.
Definition mem.c:554
Pick data structure.
Definition pick.h:25

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

Referenced by init_pick(), and popup_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 300 of file mem.c.

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

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(), 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,
int 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
Note
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 393 of file mem.c.

394 {
395 bool f_dir = false;
396 bool f_spec = false;
397 bool f_quote = true;
398 char *s1;
399 char *s2;
400 char s1_s[MAXLEN];
401 char s2_s[MAXLEN];
402 char file_name[MAXLEN];
403 char try_spec[MAXLEN];
404 char idio_spec[MAXLEN];
405
406 if (!org_spec[0])
407 return false;
408 idio_spec[0] = '\0';
409 strnz__cpy(try_spec, org_spec, MAXLEN - 1);
410 f_quote = stripz_quotes(try_spec);
411 s1 = strtok(try_spec, " \t\n");
412 strnz__cpy(s1_s, s1, MAXLEN - 1);
413 s2 = strtok(nullptr, "\n");
414 strnz__cpy(s2_s, s2, MAXLEN - 1);
415 strnz__cpy(file_name, s1, MAXLEN - 1);
416 strnz__cpy(try_spec, file_name, MAXLEN - 1);
417 canonicalize_file_spec(try_spec);
418 if (try_spec[0]) {
419 expand_tilde(try_spec, MAXLEN - 1);
420 if (try_spec[0] == '/') {
421 f_spec = verify_file(try_spec, mode);
422 if (f_quote)
424 strnz__cpy(spec, org_spec, MAXLEN - 1);
425 else
426 strnz__cpy(spec, try_spec, MAXLEN - 1);
427 return f_spec;
428 } else {
429 if (!f_dir && dir[0]) {
430 if (strcmp(dir, "$PATH") == 0) {
431 strnz__cpy(try_spec, file_name, MAXLEN - 1);
432 f_spec = locate_file_in_path(try_spec, file_name);
433 } else {
434 strnz__cpy(try_spec, dir, MAXLEN - 1);
435 expand_tilde(try_spec, MAXLEN - 1);
436 f_dir = verify_dir(try_spec, mode);
437 if (f_dir) {
438 strnz__cat(try_spec, "/", MAXLEN - 1);
439 strnz__cat(try_spec, file_name, MAXLEN - 1);
440 strnz__cpy(idio_spec, try_spec, MAXLEN - 1);
441 if (mode & S_WCOK)
442 f_spec = true;
443 else
444 f_spec = verify_file(idio_spec, mode | S_QUIET);
445 }
446 }
447 }
448 if (!f_spec && alt_dir && alt_dir[0] != '\0') {
449 if (strcmp(alt_dir, "$PATH") == 0) {
450 strnz__cpy(try_spec, file_name, MAXLEN - 1);
451 f_spec = locate_file_in_path(try_spec, file_name);
452 } else {
453 strnz__cpy(try_spec, alt_dir, MAXLEN - 1);
454 expand_tilde(try_spec, MAXLEN - 1);
455 f_dir = verify_dir(try_spec, mode);
456 if (f_dir) {
457 strnz__cat(try_spec, "/", MAXLEN - 1);
458 strnz__cat(try_spec, file_name, MAXLEN - 1);
459 if (mode & S_WCOK)
460 f_spec = true;
461 else
462 f_spec = verify_file(try_spec, mode | S_QUIET);
463 }
464 }
465 }
466 if (!f_spec) {
467 strnz__cpy(try_spec, ".", MAXLEN - 1);
468 strnz__cat(try_spec, "/", MAXLEN - 1);
469 strnz__cat(try_spec, file_name, MAXLEN - 1);
470 f_spec = verify_file(try_spec, mode | S_QUIET);
471 }
472 if (!f_spec && mode == W_OK) {
473 strnz__cpy(try_spec, idio_spec, MAXLEN - 1);
474 FILE *fp = fopen(try_spec, "a");
475 if (fp) {
476 fclose(fp);
477 f_spec = true;
478 }
479 }
480 if (f_quote)
482 strnz__cpy(spec, org_spec, MAXLEN - 1);
483 else if (f_spec)
484 strnz__cpy(spec, try_spec, MAXLEN - 1);
485 if (try_spec[0] == '\0' && idio_spec[0] != '\0')
486 strnz__cpy(spec, idio_spec, MAXLEN - 1);
487 else
488 strnz__cpy(spec, try_spec, MAXLEN - 1);
489 if (s2_s[0] != '\0') {
490 strnz__cat(spec, " ", MAXLEN - 1);
491 strnz__cat(spec, s2_s, MAXLEN - 1);
492 }
493 return f_spec;
494 }
495 }
496 return false;
497}
#define S_WCOK
Definition cm.h:190
char * file_name[MAXLEN+1]
Definition whence.c:25
size_t canonicalize_file_spec(char *)
Removes quotes and trims at first space.
Definition futil.c:1315
bool stripz_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:478
bool verify_file(char *, int)
Verifies that the file specified by "in_spec" exists and is accessible with the permissions specified...
Definition futil.c:917
bool expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
Definition futil.c:709
bool verify_dir(char *, int)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:866

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(), and init_view_files().

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