C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/** @file common.h
2 @brief Headder for C-Menu Menu, Form, Pick, and View components
3 @author Bill Waller
4 Copyright (c) 2025
5 MIT License
6 billxwaller@gmail.com
7 @date 2026-02-09
8 */
9
10#ifndef _COMMON_H
11#define _COMMON_H 1
12
13#define _GNU_SOURCE
14// #define _XOPEN_SOURCE_EXTENDED 1
15#define NCURSES_WIDECHAR 1
16#include "cm.h"
17#include <form.h>
18#include <menu.h>
19#include <pick.h>
20#include <view.h>
21
22#include <stddef.h>
23#define USE_PAD TRUE
24#define MIN_COLS 40
25
26#define MAX_WIDE_LEN 1024
27#define COLOR_LEN 8
28#define PICK_MAX_ARG_LEN 256
29#define MAX_PICK_OBJS 1024
30#define ACCEPT_PROMPT_CHAR '_'
31
32#define MENU_HELP_FILE "menu.help"
33#define FORM_HELP_FILE "form.help"
34#define PICK_HELP_FILE "pick.help"
35#define VIEW_HELP_FILE "view.help"
36#define VIEW_PRT_FILE "prtout"
37#define DEFAULTEDITOR "vi"
38
39#define MAX_VIEWS 10
40#define MAX_FORMS 10
41#define MAX_MENUS 10
42#define MAX_PICKS 10
43
44#define MINITRC ".minitrc"
45#define ABOUT ".about"
46#define MAPP_DIR "~/menuapp"
47#define PRINTCMD "lp -c -s"
48#define MAXOPTS 50
49#define EIGHT 8
50#define P_READ 0
51#define P_WRITE 1
52#define TRUE 1
53
54#define new_cmenu()
55 __end_pgm;
56 int main(int argc, char **argv) {
58 capture_shell_tioctl();
59 Init *init = new_init(argc, argv);
60 SIO *sio = init->sio;
61 mapp_initialization(init);
62 ui_init(sio);
63 sig_prog_mode();
64 capture_curses_tioctl();
65 win_init_attrs();
66
67#define destroy_cmenu()
68 destroy_init(init);
69 win_del();
70 curs_set(1);
71 destroy_curses();
72 return 0;
73 }
74
75typedef enum {
80} Caller;
81
82/** @brief option types */
83typedef enum {
88} OptType;
89
90/** @brief option groups */
91typedef enum {
99} OptGroup;
100
101typedef Menu Menu;
102typedef Form Form;
103typedef Pick Pick;
104typedef View View;
105
106/**
107 * @struct Init
108 * @brief Gathers runtime information for C-Menu Menu, Form, Pick, and View
109 * components, used for passing common data and state during initialization and
110 * processing of these componentsi.
111 */
112typedef struct
113{
114 SIO *sio;
115 int lines; /**< number of lines for window size */
116 int cols; /**< number of columns for window size */
117 int begy; /**< screen line upper left corner of window */
118 int begx; /**< screen column upper left corner of window */
119
120 char provider_cmd[MAXLEN]; /**< command provides input */
121 char receiver_cmd[MAXLEN]; /**< command receives output */
122 char cmd[MAXLEN]; /**< command to execute in foreground, e.g. an editor */
123 char cmd_all[MAXLEN]; /**< View - command to execute at start of program */
124 char parent_cmd[MAXLEN]; /**< command to be executed by parent */
125 char prompt_str[MAXLEN]; /**< prompt string for chyron */
126 int prompt_type; /**< View - prompt type for chyron, e.g. 0=short, 1=long,
127 2=none */
128 char chyron_s[MAXLEN]; /**< chyron string */
129 char title[MAXLEN]; /**< display on top line of box window */
130 int argc; /**< command line arguments count */
131 char **argv; /**< command line arguments vector */
132 int optind; /**< getopt pointer to non-option arguments in argv */
133 bool f_ignore_case; /**< View - ignore case in search */
134 bool p_view_files; /**< Pick - View Pick Files */
135 bool f_at_end_remove; /**< obsolete, unneeded */
136 bool f_strip_ansi; /**< strip ansi escape sequences when writing buffer */
137 bool f_squeeze; /**< View - print one line for each group of blank lines
138 */
139 bool f_multiple_cmd_args; /**< View - put multiple arguments in a single
140 string */
141 bool f_erase_remainder; /**< Form - erase remainder of field on enter */
142 bool f_read_theme; /**< Pick - read and process theme */
143 bool f_ln; /**< View - show line numbers */
144 bool wrap; /**< View - wrap lines */
145 char brackets[3]; /**< Form - left and right enclosing characters */
146 char fill_char[2]; /**< Form - fill character for fields */
147 char mapp_home[MAXLEN]; /**< home directory */
148 char mapp_data[MAXLEN]; /**< data directory */
149 char mapp_help[MAXLEN]; /**< help directory */
150 char mapp_msrc[MAXLEN]; /**< source directory */
151 char mapp_user[MAXLEN]; /**< user directory */
152 char mapp_theme[MAXLEN]; /**< default theme file */
153
154 bool f_mapp_home; /**< flag - mapp_home verified */
155 bool f_mapp_data; /**< flag - mapp_data verified */
156 bool f_mapp_spec; /**< flag - mapp_spec verified */
157 bool f_mapp_help; /**< flag - mapp_help verified */
158 bool f_mapp_msrc; /**< flag - mapp_msrc verified */
159 bool f_mapp_user; /**< flag - mapp_user verified */
160 // file flags
161 bool f_mapp_desc; /**< flag - mapp_desc verified */
162 bool f_provider_cmd; /**< flag - provider_cmd verified */
163 bool f_receiver_cmd; /**< flag - receiver_cmd verified */
164 bool f_cmd; /**< flag - cmd verified */
165 bool f_cmd_all; /**< flag - cmd_all verified */
166 bool f_title; /**< flag - title verified */
167 bool f_help_spec; /**< flag - help_spec verified */
168 char in_spec[MAXLEN]; /**< input file spec */
169 char out_spec[MAXLEN]; /**< output file spec */
170 bool f_in_spec; /**< in_spec verified */
171 bool f_out_spec; /**< out_spec verified */
172 char editor[MAXLEN]; /**< default editor */
173 char menuapp[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
174 char minitrc[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
175 char about_fn[MAXLEN]; /**< about information file, e.g. cmenu/.about */
176 char mapp_spec[MAXLEN]; /**< description file */
177 char help_spec[MAXLEN]; /**< help file */
178 // Pick
179 int select_max; /**< Pick maximum number of selections */
180 // View
181 int tab_stop; /**< View - number of spapaces per tab */
182 int h_shift; /**< View - horizontal scroll shift width */
183 Menu *menu; /**< menu data structure */
184 int menu_cnt; /**< number of menu data structures allocated */
185 Form *form; /**< form data structure */
186 int form_cnt; /**< number of form data structures allocated */
187 Pick *pick; /**< pick data structure */
188 int pick_cnt; /**< number of pick data structures allocated */
189 View *view; /**< view data structure */
190 int view_cnt; /**< number of view data structures allocated */
191} Init;
192
193// extern Init *init;
194extern int init_cnt; /** number of Init data structures allocated */
195extern char minitrc[MAXLEN];
196extern void mapp_initialization(Init *, int, char **);
197extern Init *new_init(int, char **);
198extern View *new_view(Init *);
199extern Form *new_form(Init *, int, char **, uint, uint);
200extern Pick *new_pick(Init *, int, char **, uint, uint);
201extern Menu *new_menu(Init *, int, char **, uint, uint);
202extern int popup_menu(Init *, int, char **, uint, uint);
203extern int popup_form(Init *, int, char **, uint, uint);
204extern int popup_pick(Init *, int, char **, uint, uint);
205extern int popup_view(Init *, int, char **, uint, uint, uint, uint);
206extern int popup_ckeys();
207extern Menu *destroy_menu(Init *init);
208extern Pick *destroy_pick(Init *init);
209extern Form *destroy_form(Init *init);
210extern View *destroy_view(Init *init);
211extern Init *destroy_init(Init *init);
212extern int parse_opt_args(Init *, int, char **);
213extern void zero_opt_args(Init *);
214extern int write_config(Init *);
215extern bool derive_file_spec(char *, char *, char *);
216extern unsigned int menu_engine(Init *);
217extern unsigned int parse_menu_description(Init *);
218extern int init_form(Init *, int, char **, uint, uint);
219extern int init_pick(Init *, int, char **, uint, uint);
220extern int open_pick_win(Init *);
221extern int pick_engine(Init *);
222extern int cmd_processor(Init *);
223extern int view_file(Init *);
224extern int init_view_full_screen(Init *);
225extern int init_view_boxwin(Init *);
226extern int view_init_input(Init *, char *);
227extern void view_calc_full_screen_dimensions(Init *);
228extern void view_full_screen_resize(Init *);
229extern void view_calc_boxwin_dimensions(Init *);
230extern void view_boxwin_resize(Init *);
231extern int process_config_file(char *, Init *);
232extern void initialize_line_table(View *);
233extern void next_page(View *);
234extern int view_cmd_processor(Init *);
235extern int pad_refresh(View *);
236extern void build_prompt(View *); // View build prompt
237extern int display_prompt(View *, char *); // view display prompt
238extern ViewStack view_stack;
239extern bool view_stack_init(ViewStack *, size_t);
240extern bool view_stack_push(ViewStack *, View);
241extern bool view_stack_pop(ViewStack *, View *);
242extern bool view_stack_peek(const ViewStack *, View *);
243extern void view_stack_free(ViewStack *);
244extern int view_cmd_processor(Init *);
245extern void destroy_view_win(Init *);
246extern void destroy_line_table(View *);
247#endif
int cmd_processor(Init *)
bool view_stack_peek(const ViewStack *, View *)
@ OT_INT
Definition common.h:85
@ OT_BOOL
Definition common.h:86
@ OT_HEX
Definition common.h:87
@ OT_STRING
Definition common.h:84
int popup_form(Init *, int, char **, uint, uint)
instantiate a form popup window
Definition popups.c:113
bool view_stack_push(ViewStack *, View)
int popup_menu(Init *, int, char **, uint, uint)
instantiate a menu popup window
Definition popups.c:53
void view_stack_free(ViewStack *)
@ FORM
Definition common.h:77
@ MENU
Definition common.h:79
@ VIEW
Definition common.h:76
@ PICK
Definition common.h:78
@ OG_FILES
Definition common.h:92
@ OG_DIRS
Definition common.h:93
@ OG_SPECS
Definition common.h:94
@ OG_MISC
Definition common.h:95
@ OG_FLAGS
Definition common.h:97
@ OG_PARMS
Definition common.h:96
@ OG_COL
Definition common.h:98
bool view_stack_pop(ViewStack *, View *)
int popup_pick(Init *, int, char **, uint, uint)
instantiate a pick popup window
Definition popups.c:83
bool view_stack_init(ViewStack *, size_t)
void destroy_view_win(Init *)
int popup_view(Init *, int, char **, uint, uint, uint, uint)
instantiate a view popup window
Definition popups.c:145
char minitrc[MAXLEN]
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:339
#define Ctrl(c)
Definition cm.h:54
void ui_render()
Definition ui_ncurses.c:800
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:727
int ui_mvwaddstr(UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_get_event(UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
Wait for an input event on target (or stdscr if NULL).
int ui_wclrtoeol(UiSurface *s, uint w)
int ui_curs_set(int visibility)
Definition ui_ncurses.c:737
#define KEY_F09
#define KEY_RIGHT
#define KEY_DC
#define KEY_BACKSPACE
#define KEY_END
#define KEY_ENTER
#define KEY_MOUSE
#define KEY_IC
#define KEY_LEFT
#define KEY_HOME
int init_cnt
Definition mem.c:28
ViewStack view_stack
Definition init_view.c:32
#define TRUE
Definition iloan.c:19
int popup_ckeys()
Definition curskeys.c:31
#define MAXLEN
Definition curskeys.c:15
int cf_accept(UiSurface *sfc, uint w, char *accept_s, uint flin, uint fcol, uint flen)
Accepts input for a field in a C-Menu window.
Definition cm_fields.c:41
bool f_erase_remainder
Structure to hold field information for C-Menu.
Definition cm_fields.c:30
int process_config_file(char *, Init *)
Definition init.c:663
int click_x
Definition dwin.c:45
int click_y
Definition dwin.c:44
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:97
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:178
int init_form(Init *, int, char **, uint, uint)
Initialize form data structure and parse description file.
Definition form_engine.c:61
int parse_opt_args(Init *, int, char **)
Parse command-line options and set Init struct values accordingly.
Definition init.c:591
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
Definition init.c:1367
int write_config(Init *init)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:1103
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:474
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:606
void view_calc_boxwin_dimensions(Init *)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:195
int init_view_full_screen(Init *init)
Initialize C-Menu View in full screen mode.
Definition init_view.c:47
int init_view_boxwin(Init *init)
Initialize the C-Menu View in box window mode.
Definition init_view.c:147
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:113
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:279
Pick * new_pick(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Pick structure.
Definition mem.c:186
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:345
Menu * new_menu(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Menu structure.
Definition mem.c:134
Init * new_init(int argc, char **argv)
Create and initialize Init structure.
Definition mem.c:60
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:155
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:275
View * new_view(Init *init)
Create and initialize View structure.
Definition mem.c:299
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:95
Form * new_form(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Form structure.
Definition mem.c:252
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:225
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:36
unsigned int parse_menu_description(Init *)
Parse menu description file and create Menu.
int init_pick(Init *, int, char **, uint, uint)
Initializes pick structure and opens pick input file or pipe.
Definition pick_engine.c:66
int pick_engine(Init *)
Initializes pick interface, calculates window size and position, and enters picker loop.
int open_pick_win(Init *)
Initializes the pick window based on the parameters specified in the Pick structure.
int view_file(Init *)
Start view.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
void build_prompt(View *)
Build Prompt String.
void initialize_line_table(View *)
Initialize Line Table.
void destroy_line_table(View *)
Destroy Line Table.
void next_page(View *)
Advance to Next Page.
int pad_refresh(View *)
Refresh Pad and Line Number Window.
int display_prompt(View *, char *)
Display Command Line Prompt.
char title[MAXLEN]
Definition common.h:129
char mapp_data[MAXLEN]
Definition common.h:148
char minitrc[MAXLEN]
Definition common.h:174
bool f_out_spec
Definition common.h:171
char mapp_help[MAXLEN]
Definition common.h:149
int begx
Definition common.h:118
bool f_title
Definition common.h:166
char chyron_s[MAXLEN]
Definition common.h:128
SIO * sio
Definition common.h:114
int pick_cnt
Definition common.h:188
bool f_cmd_all
Definition common.h:165
Form * form
Definition common.h:185
char in_spec[MAXLEN]
Definition common.h:168
char cmd_all[MAXLEN]
Definition common.h:123
bool f_mapp_help
Definition common.h:157
bool f_mapp_msrc
Definition common.h:158
int argc
Definition common.h:130
char fill_char[2]
Definition common.h:146
bool f_cmd
Definition common.h:164
int prompt_type
Definition common.h:126
char about_fn[MAXLEN]
Definition common.h:175
char mapp_msrc[MAXLEN]
Definition common.h:150
int cols
Definition common.h:116
int menu_cnt
Definition common.h:184
int tab_stop
Definition common.h:181
bool f_mapp_home
Definition common.h:154
bool f_erase_remainder
Definition common.h:141
bool f_mapp_data
Definition common.h:155
bool f_read_theme
Definition common.h:142
bool f_mapp_desc
Definition common.h:161
char mapp_home[MAXLEN]
Definition common.h:147
bool f_mapp_user
Definition common.h:159
char prompt_str[MAXLEN]
Definition common.h:125
bool f_squeeze
Definition common.h:137
int begy
Definition common.h:117
char parent_cmd[MAXLEN]
Definition common.h:124
char mapp_spec[MAXLEN]
Definition common.h:176
char receiver_cmd[MAXLEN]
Definition common.h:121
int h_shift
Definition common.h:182
bool wrap
Definition common.h:144
bool f_multiple_cmd_args
Definition common.h:139
int select_max
Definition common.h:179
bool f_ln
Definition common.h:143
bool f_mapp_spec
Definition common.h:156
char provider_cmd[MAXLEN]
Definition common.h:120
char out_spec[MAXLEN]
Definition common.h:169
bool f_strip_ansi
Definition common.h:136
View * view
Definition common.h:189
bool p_view_files
Definition common.h:134
Menu * menu
Definition common.h:183
bool f_at_end_remove
Definition common.h:135
int view_cnt
Definition common.h:190
char brackets[3]
Definition common.h:145
bool f_ignore_case
Definition common.h:133
char ** argv
Definition common.h:131
int lines
Definition common.h:115
char mapp_user[MAXLEN]
Definition common.h:151
char cmd[MAXLEN]
Definition common.h:122
char mapp_theme[MAXLEN]
Definition common.h:152
int optind
Definition common.h:132
bool f_help_spec
Definition common.h:167
bool f_receiver_cmd
Definition common.h:163
bool f_provider_cmd
Definition common.h:162
int form_cnt
Definition common.h:186
char help_spec[MAXLEN]
Definition common.h:177
char editor[MAXLEN]
Definition common.h:172
Pick * pick
Definition common.h:187
bool f_in_spec
Definition common.h:170
char menuapp[MAXLEN]
Definition common.h:173