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, int begy, int 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, int begy, int begx)
 Create and initialize Menu structure.
Picknew_pick (Init *init, int argc, char **argv, int begy, int 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, int 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 286 of file mem.c.

286 {
287 int i;
288
289 if (!init->form)
290 return nullptr;
291 for (i = 0; i < FIELD_MAXCNT; i++) {
292 if (init->form->field[i])
293 free(init->form->field[i]);
294 init->form->field[i] = nullptr;
295 }
296 for (i = 0; i < FIELD_MAXCNT; i++) {
297 if (init->form->text[i])
298 free(init->form->text[i]);
299 init->form->text[i] = nullptr;
300 }
301 free(init->form);
302 init->form = nullptr;
303 init->form_cnt--;
304 return init->form;
305}
#define FIELD_MAXCNT
Definition form.h:19
Form * form
Definition common.h:184
int form_cnt
Definition common.h:185
Text * text[FIELD_MAXCNT]
Definition form.h:338
Field * field[FIELD_MAXCNT]
Definition form.h:351

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

106 {
107 if (!init)
108 return nullptr;
109 if (init->sio) {
110 free(init->sio);
111 init->sio = nullptr;
112 }
113 if (init->menu) {
114 init->menu = destroy_menu(init);
115 init->menu = nullptr;
116 }
117 if (init->form) {
118 init->form = destroy_form(init);
119 init->form = nullptr;
120 }
121 if (init->pick) {
122 init->pick = destroy_pick(init);
123 init->pick = nullptr;
124 }
125 init->argc = destroy_argv(init->argc, init->argv);
126 if (init->argv != nullptr)
127 free(init->argv);
128 if (init != nullptr) {
129 free(init);
130 init = nullptr;
131 }
132 init_cnt--;
133 return init;
134}
int init_cnt
Definition mem.c:44
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:494
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:166
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:286
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:236
SIO * sio
Definition common.h:114
int argc
Definition common.h:130
Menu * menu
Definition common.h:182
char ** argv
Definition common.h:131
Pick * pick
Definition common.h:186

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

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

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

236 {
237 if (!init->pick)
238 return nullptr;
239
240 for (pick->m_idx = 0; pick->m_idx < OBJ_MAXCNT; pick->m_idx++) {
241 if (pick->m_object[pick->m_idx] != nullptr)
242 free(pick->m_object[pick->m_idx]);
243 // if (pick->d_object[pick->d_idx] != nullptr)
244 // free(pick->d_object[pick->d_idx]);
245 }
246 free(pick->m_object);
247 free(pick->d_object);
248 free(pick);
249 init->pick = nullptr;
250 init->pick_cnt--;
251 return init->pick;
252}
#define OBJ_MAXCNT
Definition pick.h:17
Pick * pick
Definition mem.c:47
int pick_cnt
Definition common.h:187

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

356 {
357 view = init->view;
358 if (!view)
359 return nullptr;
360 view->argc = destroy_argv(view->argc, view->argv);
361 free(view->argv);
362 free(view);
363 init->view = nullptr;
364 view = nullptr;
365 init->view_cnt--;
366 return init->view;
367}
View * view
Definition mem.c:49
View * view
Definition common.h:188
int view_cnt
Definition common.h:189

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

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

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

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

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

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

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

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

765 {
766 char *e;
767 view = init->view;
768 view->lines = init->lines;
769 view->cols = init->cols;
770 view->begy = init->begy;
771 view->begx = init->begx;
772 view->f_ignore_case = init->f_ignore_case;
773 view->f_at_end_remove = init->f_at_end_remove;
774 view->f_squeeze = init->f_squeeze;
775 view->tab_stop = init->tab_stop;
776 view->f_ln = init->f_ln;
777 view->h_shift = init->h_shift;
778 e = getenv("VIEW_HELP_FILE");
779 if (e && e[0] != '\0') {
780 strnz__cpy(view->help_spec, e, MAXLEN - 1);
781 }
782 view->f_help_spec =
783 verify_spec_arg(view->help_spec, view->help_spec, init->mapp_help,
784 "~/menuapp/help", R_OK);
785 if (!view->f_help_spec) {
786 strnz__cpy(view->help_spec, init->mapp_home, MAXLEN - 1);
787 strnz__cat(view->help_spec, "/help/", MAXLEN - 1);
788 strnz__cat(view->help_spec, VIEW_HELP_FILE, MAXLEN - 1);
789 }
790 strnz__cpy(view->provider_cmd, init->provider_cmd, MAXLEN - 1);
791 strnz__cpy(view->receiver_cmd, init->receiver_cmd, MAXLEN - 1);
792 strnz__cpy(view->cmd_all, init->cmd_all, MAXLEN - 1);
793 if (view->cmd[0] != '\0')
794 expand_tilde(view->cmd, MAXLEN - 1);
795 if (view->provider_cmd[0] != '\0')
796 expand_tilde(view->provider_cmd, MAXLEN - 1);
797 if (view->receiver_cmd[0] != '\0')
798 expand_tilde(view->receiver_cmd, MAXLEN - 1);
799 if (view->title[0] == '\0') {
800 if (init->title[0] != '\0') {
801 strnz__cpy(view->title, init->title, MAXLEN - 1);
802 } else {
803 if (view->provider_cmd[0] != '\0')
804 strnz__cpy(view->title, view->provider_cmd, MAXLEN - 1);
805 else {
806 if (view->argv != nullptr && view->argv[0] != nullptr &&
807 view->argv[0][0] != '\0') {
808 strnz__cpy(view->title, view->argv[0], MAXLEN - 1);
809 } else
810 strnz__cpy(view->title, "C-Menu View", MAXLEN - 1);
811 }
812 }
813 }
814 strip_quotes(view->title);
815 if (view->tab_stop == 0)
816 view->tab_stop = 4;
817 return true;
818}
#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:180
char mapp_home[MAXLEN]
Definition common.h:146
bool f_squeeze
Definition common.h:137
int begy
Definition common.h:117
int h_shift
Definition common.h:181
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, 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 263 of file mem.c.

263 {
264 init->form = (Form *)calloc(1, sizeof(Form));
265 if (!init->form) {
266 abend(-1, "calloc form failed");
267 return nullptr;
268 }
269 init->form_cnt++;
270 form = init->form;
271 if (!init_form_files(init, argc, argv)) {
272 abend(-1, "init_form_files failed");
273 return nullptr;
274 }
275 strnz__cpy(form->brackets, init->brackets, 3);
276 strnz__cpy(form->fill_char, init->fill_char, MAXLEN - 1);
277 form->begy = begy;
278 form->begx = begx;
279 return init->form;
280}
bool init_form_files(Init *, int, char **)
Initialize Form file specifications.
Definition mem.c:653
char fill_char[4]
Definition common.h:145
char brackets[3]
Definition common.h:144
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().

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

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

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

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

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

197 {
198 init->pick = (Pick *)calloc(1, sizeof(Pick));
199 if (!init->pick) {
200 Perror("calloc pick failed");
201 return nullptr;
202 }
203 init->pick_cnt++;
204 pick = init->pick;
205 if (!init_pick_files(init, argc, argv)) {
206 abend(-1, "init_pick_files failed");
207 return nullptr;
208 }
209 pick->m_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
210 if (pick->m_object == nullptr) {
211 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
212 ssnprintf(em1, MAXLEN - 1,
213 "calloc pick->m_object = calloc(%d, %d) failed\n",
214 OBJ_MAXCNT + 1, sizeof(char *));
215 display_error(em0, em1, nullptr, nullptr);
216 abend(-1, "User terminated program");
217 }
218 pick->d_object = calloc(OBJ_MAXCNT + 1, sizeof(char *));
219 if (pick->d_object == nullptr) {
220 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
221 ssnprintf(em1, MAXLEN - 1,
222 "calloc pick->d_object = calloc(%d, %d) failed\n",
223 OBJ_MAXCNT + 1, sizeof(char *));
224 display_error(em0, em1, nullptr, nullptr);
225 abend(-1, "User terminated program");
226 }
227 pick->begy = begy;
228 pick->begx = begx;
229 return init->pick;
230}
bool init_pick_files(Init *, int, char **)
Initialize Pick file specifications.
Definition mem.c:550
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 310 of file mem.c.

310 {
311 init->view_cnt++;
312 init->view = (View *)calloc(1, sizeof(View));
313 if (!init->view) {
314 free(init->view);
315 ssnprintf(em0, MAXLEN - 1, "%s, line: %d, errno: %d", __FILE__,
316 __LINE__ - 1, errno);
317 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
318 ssnprintf(em2, MAXLEN - 1, "init->view = calloc(%d) failed\n",
319 sizeof(View));
320 display_error(em0, em1, em2, nullptr);
321 abend(-1, "calloc init->view failed");
322 return nullptr;
323 }
324 view = init->view;
325 view->argc = init->argc;
326 if (view->argc > 0) {
327 view->argv = calloc(view->argc + 1, sizeof(char *));
328 if (view->argv == nullptr) {
329 free(view->argv);
330 ssnprintf(em0, MAXLEN - 1, "%s, line: %d, errno: %d", __FILE__,
331 __LINE__ - 1, errno);
332 ssnprintf(em1, MAXLEN - 1, "%s", strerror(errno));
333 ssnprintf(em2, MAXLEN - 1, "view->argv = calloc(%d, %d) failed\n",
334 view->argc, sizeof(char *));
335 display_error(em0, em1, em2, nullptr);
336 abend(-1, "User terminated program");
337 return nullptr;
338 }
339 int s = 0;
340 int d = 0;
341 while (s < init->argc)
342 view->argv[d++] = strnz_dup(init->argv[s++], MAXLEN - 1);
343 view->argv[d] = nullptr;
344 }
345 if (!init_view_files(init)) {
346 abend(-1, "init_view_files failed");
347 return nullptr;
348 }
349 return view;
350}
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:654
bool init_view_files(Init *)
Initialize View file specifications.
Definition mem.c:765
Definition view.h:42

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,
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

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

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

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: