C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
menu.c
Go to the documentation of this file.
1/** @file menu.c
2 @brief Command line start-up for C-Menu components
3 @author Bill Waller
4 Copyright (c) 2025
5 MIT License
6 billxwaller@gmail.com
7 @date 2026-02-09
8 */
9
10#include <common.h>
11#include <string.h>
12
13/** @brief This function is responsible for cleaning up the terminal state and
14 exiting the program.
15 @details This function is typically registered to be called when the program
16 exits, ensuring that the terminal is properly restored to its original state,
17 even if the program encounters an error or is terminated unexpectedly. The
18 end_pgm function performs the following actions:
19 1. It calls win_del() to delete any windows that may have been created
20 during the program's execution.
21 2. It calls destroy_curses() to clean up the ncurses library and restore the
22 terminal to its normal state.
23 3. It calls restore_shell_tioctl() to restore the terminal's input/output
24 settings to their original state.
25 4. Finally, it calls exit(EXIT_FAILURE) to terminate the program with a
26 failure status, indicating that the program has encountered an error or is
27 exiting due to an unexpected condition. By defining this function and
28 registering it to be called on program exit, you can help ensure that the
29 terminal is properly cleaned up and restored, preventing any issues with the
30 terminal state after the program has exited. */
31static void end_pgm(void) {
32 curs_set(1);
36 init = nullptr;
39 close(cmenu_log_fd);
40 exit(EXIT_SUCCESS);
41}
42
43int main(int argc, char **argv) {
44 int rc;
45 char pgm_name[MAXLEN];
47 init = new_init(argc, argv);
48 SIO *sio = init->sio;
50 rc = atexit(end_pgm);
51 if (rc != 0) {
52 fprintf(stderr, "\nCannot set exit function\n");
53 exit(EXIT_FAILURE);
54 }
59 base_name(pgm_name, argv[0]);
60 if (!strcmp(pgm_name, "menu")) {
61 new_menu(init, init->argc, init->argv, LINES / 14, COLS / 14);
64 } else if (!strcmp(pgm_name, "form")) {
65 init_form(init, init->argc, init->argv, LINES / 14, COLS / 14);
66 } else if (!strcmp(pgm_name, "pick")) {
68 } else if (!strcmp(pgm_name, "view")) {
70 if (init->lines > 0 || init->cols > 0) {
73 }
74 } else if (!init_view_full_screen(init)) {
76 }
77 } else if (!strcmp(pgm_name, "ckeys"))
79 // end_pgm();
80}
Init * init
Definition init.c:74
int cmenu_log_fd
Definition futil.c:48
#define nullptr
Definition cm.h:25
Menu * menu
Definition mem.c:45
View * view
Definition mem.c:48
int popup_ckeys()
Display Curses Keys Responds to curses keys and mouse events, displaying the key code and description...
Definition curskeys.c:23
#define MAXLEN
Definition curskeys.c:15
int main(int argc, char **argv)
Definition amort.c:34
bool open_curses(SIO *)
Initialize NCurses and color settings.
Definition dwin.c:192
void win_init_attrs()
Initialize window attributes.
Definition dwin.c:176
WINDOW * win_del()
Delete the current window and its associated box window.
Definition dwin.c:893
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:540
int init_form(Init *, int, char **, int, int)
Initialize form data structure and parse description file.
Definition form_engine.c:60
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:984
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:328
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
Definition init_view.c:45
int init_view_boxwin(Init *, char *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:172
Init * new_init(int, char **)
Create and initialize Init structure.
Definition mem.c:70
Menu * new_menu(Init *, int, char **, int, int)
Create and initialize Menu structure.
Definition mem.c:148
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:313
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:105
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:38
int init_pick(Init *, int, char **, int, int)
Initializes pick structure and opens pick input file or pipe.
Definition pick_engine.c:60
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition scriou.c:43
bool capture_curses_tioctl()
capture_curses_tioctl() - capture curses terminal settings
Definition scriou.c:68
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42
void sig_prog_mode()
Set up signal handlers for interrupt signals.
Definition sig.c:62
int view_file(Init *)
Start view.
char title[MAXLEN]
Definition common.h:120
SIO * sio
Definition common.h:105
int argc
Definition common.h:121
int cols
Definition common.h:107
Menu * menu
Definition common.h:169
char ** argv
Definition common.h:122
int lines
Definition common.h:106