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:186

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:221
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_cmd_processor(), 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 delwin(view->ln_win);
351 delwin(view->win);
352 free(view->ln_tbl);
353 destroy_argv(view->argc, view->argv);
354 free(view->argv);
355 free(view);
356 init->view = nullptr;
357 view = nullptr;
358 init->view_cnt--;
359 return init->view;
360}
View * view
Definition mem.c:48

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

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

631 {
632 char tmp_str[MAXLEN];
633 int optind = 0;
634 form->f_mapp_spec =
635 verify_spec_arg(form->mapp_spec, init->mapp_spec, init->mapp_msrc,
636 "~/menuapp/msrc", R_OK);
637 form->f_in_spec = verify_spec_arg(form->in_spec, init->in_spec,
638 init->mapp_data, "~/menuapp/data", R_OK);
639 form->f_out_spec =
640 verify_spec_arg(form->out_spec, init->out_spec, init->mapp_data,
641 "~/menuapp/data", W_OK | S_QUIET);
642 if (init->provider_cmd[0] != '\0') {
643 form->f_provider_cmd =
644 verify_spec_arg(form->provider_cmd, init->provider_cmd,
645 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
646 }
647 if (init->cmd[0] != '\0') {
648 form->f_cmd = verify_spec_arg(form->cmd, init->cmd, "~/menuapp/bin",
649 "$PATH", X_OK | S_QUIET);
650 }
651 if (init->receiver_cmd[0] != '\0') {
652 form->f_receiver_cmd =
653 verify_spec_arg(form->receiver_cmd, init->receiver_cmd,
654 "~/menuapp/bin", "$PATH", X_OK | S_QUIET);
655 }
656 form->f_help_spec =
657 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
658 "~/menuapp/help", R_OK);
659 if (optind < argc && !form->f_mapp_spec) {
660 form->f_mapp_spec =
661 verify_spec_arg(form->mapp_spec, argv[optind], init->mapp_msrc,
662 "~/menuapp/msrc", R_OK);
663 if (form->f_mapp_spec)
664 optind++;
665 }
666 if (optind < argc && !form->f_in_spec) {
667 form->f_in_spec =
668 verify_spec_arg(form->in_spec, argv[optind], init->mapp_data,
669 "~/menuapp/data", R_OK);
670 if (form->f_in_spec)
671 optind++;
672 }
673 if (optind < argc && !form->f_out_spec) {
674 form->f_out_spec =
675 verify_spec_arg(form->out_spec, argv[optind], init->mapp_data,
676 "~/menuapp/data", W_OK | S_QUIET);
677 if (form->f_out_spec)
678 optind++;
679 }
680 if (optind < argc && !form->f_provider_cmd) {
681 if (argv[optind][0] != '\0') {
682 form->f_provider_cmd =
683 verify_spec_arg(form->provider_cmd, argv[optind],
684 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
685 if (!form->f_provider_cmd) {
686 base_name(tmp_str, argv[optind]);
687 form->f_provider_cmd =
688 locate_file_in_path(form->provider_cmd, tmp_str);
689 }
690 }
691 optind++;
692 }
693 if (optind < argc && !form->f_cmd) {
694 if (argv[optind][0] != '\0') {
695 form->f_cmd =
696 verify_spec_arg(form->cmd, argv[optind], "~/menuapp/bin",
697 nullptr, X_OK | S_QUIET);
698 if (!form->f_cmd) {
699 base_name(tmp_str, argv[optind]);
700 form->f_cmd = locate_file_in_path(form->cmd, tmp_str);
701 }
702 }
703 optind++;
704 }
705 if (optind < argc && !form->f_receiver_cmd) {
706 if (argv[optind][0] != '\0') {
707 form->f_receiver_cmd =
708 verify_spec_arg(form->receiver_cmd, argv[optind],
709 "~/menuapp/bin", nullptr, X_OK | S_QUIET);
710 if (!form->f_receiver_cmd) {
711 base_name(tmp_str, argv[optind]);
712 form->f_receiver_cmd =
713 locate_file_in_path(form->receiver_cmd, tmp_str);
714 }
715 }
716 optind++;
717 }
718 if (optind < argc && !form->f_help_spec) {
719 form->f_help_spec =
720 verify_spec_arg(form->help_spec, init->help_spec, init->mapp_help,
721 "~/menuapp/help", R_OK);
722 if (form->f_help_spec)
723 optind++;
724 }
725 form->f_erase_remainder = init->f_erase_remainder;
726 if (form->title[0] == '\0' && init->title[0] != '\0') {
727 strip_quotes(init->title);
728 strnz__cpy(form->title, init->title, MAXLEN - 1);
729 }
730 return true;
731}
Form * form
Definition mem.c:47
#define S_QUIET
Definition cm.h:183
#define MAXLEN
Definition curskeys.c:15
bool locate_file_in_path(char *, char *)
Locates a file in the system PATH.
Definition futil.c:939
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
bool strip_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:454
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:775
bool verify_spec_arg(char *, char *, char *, char *, int)
Verify file specification argument.
Definition mem.c:373

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

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

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

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

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

736 {
737 char *e;
738 view = init->view;
739 view->lines = init->lines;
740 view->cols = init->cols;
741 view->f_ignore_case = init->f_ignore_case;
742 view->f_at_end_remove = init->f_at_end_remove;
743 view->f_squeeze = init->f_squeeze;
744 view->f_ln = init->f_ln;
745 e = getenv("VIEW_HELP_FILE");
746 if (e && e[0] != '\0') {
747 strnz__cpy(view->help_spec, e, MAXLEN - 1);
748 }
749 view->f_help_spec =
750 verify_spec_arg(view->help_spec, view->help_spec, init->mapp_help,
751 "~/menuapp/help", R_OK);
752 if (!view->f_help_spec) {
753 strnz__cpy(view->help_spec, init->mapp_home, MAXLEN - 1);
754 strnz__cat(view->help_spec, "/help/", MAXLEN - 1);
755 strnz__cat(view->help_spec, VIEW_HELP_FILE, MAXLEN - 1);
756 }
757 strnz__cpy(view->provider_cmd, init->provider_cmd, MAXLEN - 1);
758 strnz__cpy(view->receiver_cmd, init->receiver_cmd, MAXLEN - 1);
759 strnz__cpy(view->cmd_all, init->cmd_all, MAXLEN - 1);
760 if (view->title[0] == '\0') {
761 if (init->title[0] != '\0') {
762 strnz__cpy(view->title, init->title, MAXLEN - 1);
763 } else {
764 if (view->provider_cmd[0] != '\0')
765 strnz__cpy(view->title, view->provider_cmd, MAXLEN - 1);
766 else {
767 if (view->argv[0] != nullptr && view->argv[0][0] != '\0')
768 strnz__cpy(view->title, view->argv[0], MAXLEN - 1);
769 else
770 strnz__cpy(view->title, "C-Menu View", MAXLEN - 1);
771 }
772 }
773 }
774 strip_quotes(view->title);
775 if (view->tab_stop == 0)
776 view->tab_stop = 4;
777 return true;
778}
#define VIEW_HELP_FILE
Definition common.h:39

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:631
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:133
char em0[MAXLEN]
Definition dwin.c:132
char em2[MAXLEN]
Definition dwin.c:134
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1110
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1054
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:147
Gathers runtime information for C-Menu Menu, Form, Pick, and View components, used for passing common...
Definition common.h:107
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:626

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:486
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(), menu_cmd_processor(), 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:534
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:379
bool init_view_files(Init *)
Initialize View file specifications.
Definition mem.c:736
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 373 of file mem.c.

374 {
375 bool f_dir = false;
376 bool f_spec = false;
377 bool f_quote = true;
378 char *s1;
379 char *s2;
380 char s1_s[MAXLEN];
381 char s2_s[MAXLEN];
382 char file_name[MAXLEN];
383 char try_spec[MAXLEN];
384 char idio_spec[MAXLEN];
385
386 if (!org_spec[0])
387 return false;
388 idio_spec[0] = '\0';
389 strnz__cpy(try_spec, org_spec, MAXLEN - 1);
390 f_quote = stripz_quotes(try_spec);
391 s1 = strtok(try_spec, " \t\n");
392 strnz__cpy(s1_s, s1, MAXLEN - 1);
393 s2 = strtok(nullptr, "\n");
394 strnz__cpy(s2_s, s2, MAXLEN - 1);
395 strnz__cpy(file_name, s1, MAXLEN - 1);
396 strnz__cpy(try_spec, file_name, MAXLEN - 1);
397 canonicalize_file_spec(try_spec);
398 if (try_spec[0]) {
399 expand_tilde(try_spec, MAXLEN - 1);
400 if (try_spec[0] == '/') {
401 f_spec = verify_file(try_spec, mode);
402 if (f_quote)
404 strnz__cpy(spec, org_spec, MAXLEN - 1);
405 else
406 strnz__cpy(spec, try_spec, MAXLEN - 1);
407 return f_spec;
408 } else {
409 if (!f_dir && dir[0]) {
410 if (strcmp(dir, "$PATH") == 0) {
411 strnz__cpy(try_spec, file_name, MAXLEN - 1);
412 f_spec = locate_file_in_path(try_spec, file_name);
413 } else {
414 strnz__cpy(try_spec, dir, MAXLEN - 1);
415 expand_tilde(try_spec, MAXLEN - 1);
416 f_dir = verify_dir(try_spec, mode);
417 if (f_dir) {
418 strnz__cat(try_spec, "/", MAXLEN - 1);
419 strnz__cat(try_spec, file_name, MAXLEN - 1);
420 strnz__cpy(idio_spec, try_spec, MAXLEN - 1);
421 if (mode & S_WCOK)
422 f_spec = true;
423 else
424 f_spec = verify_file(idio_spec, mode | S_QUIET);
425 }
426 }
427 }
428 if (!f_spec && alt_dir && alt_dir[0] != '\0') {
429 if (strcmp(alt_dir, "$PATH") == 0) {
430 strnz__cpy(try_spec, file_name, MAXLEN - 1);
431 f_spec = locate_file_in_path(try_spec, file_name);
432 } else {
433 strnz__cpy(try_spec, alt_dir, MAXLEN - 1);
434 expand_tilde(try_spec, MAXLEN - 1);
435 f_dir = verify_dir(try_spec, mode);
436 if (f_dir) {
437 strnz__cat(try_spec, "/", MAXLEN - 1);
438 strnz__cat(try_spec, file_name, MAXLEN - 1);
439 if (mode & S_WCOK)
440 f_spec = true;
441 else
442 f_spec = verify_file(try_spec, mode | S_QUIET);
443 }
444 }
445 }
446 if (!f_spec) {
447 strnz__cpy(try_spec, ".", MAXLEN - 1);
448 strnz__cat(try_spec, "/", MAXLEN - 1);
449 strnz__cat(try_spec, file_name, MAXLEN - 1);
450 f_spec = verify_file(try_spec, mode | S_QUIET);
451 }
452 if (!f_spec && mode == W_OK) {
453 strnz__cpy(try_spec, idio_spec, MAXLEN - 1);
454 FILE *fp = fopen(try_spec, "a");
455 if (fp) {
456 fclose(fp);
457 f_spec = true;
458 }
459 }
460 if (f_quote)
462 strnz__cpy(spec, org_spec, MAXLEN - 1);
463 else if (f_spec)
464 strnz__cpy(spec, try_spec, MAXLEN - 1);
465 if (try_spec[0] == '\0' && idio_spec[0] != '\0')
466 strnz__cpy(spec, idio_spec, MAXLEN - 1);
467 else
468 strnz__cpy(spec, try_spec, MAXLEN - 1);
469 if (s2_s[0] != '\0') {
470 strnz__cat(spec, " ", MAXLEN - 1);
471 strnz__cat(spec, s2_s, MAXLEN - 1);
472 }
473 return f_spec;
474 }
475 }
476 return false;
477}
#define S_WCOK
Definition cm.h:182
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:1216
bool stripz_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:469
bool verify_file(char *, int)
Verifies that the file specified by "in_spec" exists and is accessible with the permissions specified...
Definition futil.c:892
bool expand_tilde(char *, int)
Replace Leading Tilde With Home Directory.
Definition futil.c:684
bool verify_dir(char *, int)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:841

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: