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#pragma once
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#define _GNU_SOURCE
17// #define _XOPEN_SOURCE_EXTENDED 1
18#define NCURSES_WIDECHAR 1
19#include "cm.h"
20#include <form.h>
21#include <menu.h>
22#include <pick.h>
23#include <view.h>
24
25#include <stddef.h>
26#define USE_PAD TRUE
27#define MIN_COLS 40
28
29#define MAX_WIDE_LEN 1024
30#define COLOR_LEN 8
31#define PICK_MAX_ARG_LEN 256
32#define MAX_PICK_OBJS 1024
33#define ACCEPT_PROMPT_CHAR '_'
34
35#define MENU_HELP_FILE "menu.help"
36#define FORM_HELP_FILE "form.help"
37#define PICK_HELP_FILE "pick.help"
38#define VIEW_HELP_FILE "view.help"
39#define VIEW_PRT_FILE "prtout"
40#define DEFAULTEDITOR "vi"
41
42#define MAX_VIEWS 10
43#define MAX_FORMS 10
44#define MAX_MENUS 10
45#define MAX_PICKS 10
46
47#define MINITRC ".minitrc"
48#define ABOUT ".about"
49#define MAPP_DIR "~/menuapp"
50#define PRINTCMD "lp -c -s"
51#define MAXOPTS 50
52#define EIGHT 8
53#define P_READ 0
54#define P_WRITE 1
55#define TRUE 1
56
57#define new_cmenu()
58 __end_pgm;
59 int main(int argc, char **argv) {
61 capture_shell_tioctl();
62 Init *init = new_init(argc, argv);
63 SIO *sio = init->sio;
64 mapp_initialization(init);
65 ui_init(sio);
66 sig_prog_mode();
67 capture_curses_tioctl();
68 win_init_attrs();
69
70#define destroy_cmenu()
71 destroy_init(init);
72 win_del();
73 curs_set(1);
74 destroy_curses();
75 return 0;
76 }
77
78typedef enum {
83} Caller;
84
85/** @brief option types */
86typedef enum {
91} OptType;
92
93/** @brief option groups */
94typedef enum {
102} OptGroup;
103
104typedef Menu Menu;
105typedef Form Form;
106typedef Pick Pick;
107typedef View View;
108
109/**
110 * @struct Init
111 * @brief Gathers runtime information for C-Menu Menu, Form, Pick, and View
112 * components, used for passing common data and state during initialization and
113 * processing of these componentsi.
114 */
115typedef struct
116{
117 SIO *sio;
118 int lines; /**< number of lines for window size */
119 int cols; /**< number of columns for window size */
120 int begy; /**< screen line upper left corner of window */
121 int begx; /**< screen column upper left corner of window */
122
123 char provider_cmd[MAXLEN]; /**< command provides input */
124 char receiver_cmd[MAXLEN]; /**< command receives output */
125 char cmd[MAXLEN]; /**< command to execute in foreground, e.g. an editor */
126 char cmd_all[MAXLEN]; /**< View - command to execute at start of program */
127 char parent_cmd[MAXLEN]; /**< command to be executed by parent */
128 char prompt_str[MAXLEN]; /**< prompt string for chyron */
129 int prompt_type; /**< View - prompt type for chyron, e.g. 0=short, 1=long,
130 2=none */
131 char chyron_s[MAXLEN]; /**< chyron string */
132 char title[MAXLEN]; /**< display on top line of box window */
133 int argc; /**< command line arguments count */
134 char **argv; /**< command line arguments vector */
135 int optind; /**< getopt pointer to non-option arguments in argv */
136 bool f_ignore_case; /**< View - ignore case in search */
137 bool p_view_files; /**< Pick - View Pick Files */
138 bool f_at_end_remove; /**< obsolete, unneeded */
139 bool f_strip_ansi; /**< strip ansi escape sequences when writing buffer */
140 bool f_squeeze; /**< View - print one line for each group of blank lines
141 */
142 bool f_multiple_cmd_args; /**< View - put multiple arguments in a single
143 string */
144 bool f_erase_remainder; /**< Form - erase remainder of field on enter */
145 bool f_read_theme; /**< Pick - read and process theme */
146 bool f_ln; /**< View - show line numbers */
147 bool wrap; /**< View - wrap lines */
148 char brackets[3]; /**< Form - left and right enclosing characters */
149 char fill_char[2]; /**< Form - fill character for fields */
150 char mapp_home[MAXLEN]; /**< home directory */
151 char mapp_data[MAXLEN]; /**< data directory */
152 char mapp_help[MAXLEN]; /**< help directory */
153 char mapp_msrc[MAXLEN]; /**< source directory */
154 char mapp_user[MAXLEN]; /**< user directory */
155 char mapp_theme[MAXLEN]; /**< default theme file */
156
157 bool f_mapp_home; /**< flag - mapp_home verified */
158 bool f_mapp_data; /**< flag - mapp_data verified */
159 bool f_mapp_spec; /**< flag - mapp_spec verified */
160 bool f_mapp_help; /**< flag - mapp_help verified */
161 bool f_mapp_msrc; /**< flag - mapp_msrc verified */
162 bool f_mapp_user; /**< flag - mapp_user verified */
163 // file flags
164 bool f_mapp_desc; /**< flag - mapp_desc verified */
165 bool f_provider_cmd; /**< flag - provider_cmd verified */
166 bool f_receiver_cmd; /**< flag - receiver_cmd verified */
167 bool f_cmd; /**< flag - cmd verified */
168 bool f_cmd_all; /**< flag - cmd_all verified */
169 bool f_title; /**< flag - title verified */
170 bool f_help_spec; /**< flag - help_spec verified */
171 char in_spec[MAXLEN]; /**< input file spec */
172 char out_spec[MAXLEN]; /**< output file spec */
173 bool f_in_spec; /**< in_spec verified */
174 bool f_out_spec; /**< out_spec verified */
175 char editor[MAXLEN]; /**< default editor */
176 char menuapp[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
177 char minitrc[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
178 char about_fn[MAXLEN]; /**< about information file, e.g. cmenu/.about */
179 char mapp_spec[MAXLEN]; /**< description file */
180 char help_spec[MAXLEN]; /**< help file */
181 char log_file_spec[MAXLEN]; /**< log file spec */
182 uint timeout_secs; /**< timeout seconds for user input */
183 UiLogLevel min_log_level;
184 int select_max; /**< Pick maximum number of selections */
185 int tab_stop; /**< View - number of spapaces per tab */
186 int h_shift; /**< View - horizontal scroll shift width */
187 Menu *menu; /**< menu data structure */
188 int menu_cnt; /**< number of menu data structures allocated */
189 Form *form; /**< form data structure */
190 int form_cnt; /**< number of form data structures allocated */
191 Pick *pick; /**< pick data structure */
192 int pick_cnt; /**< number of pick data structures allocated */
193 View *view; /**< view data structure */
194 int view_cnt; /**< number of view data structures allocated */
195} Init;
196
197// extern Init *init;
198extern int init_cnt; /** number of Init data structures allocated */
199extern char minitrc[MAXLEN];
200extern void mapp_initialization(Init *, int, char **);
201extern Init *new_init(int, char **);
202extern View *new_view(Init *);
203extern Form *new_form(Init *, int, char **, uint, uint);
204extern Pick *new_pick(Init *, int, char **, uint, uint);
205extern Menu *new_menu(Init *, int, char **, uint, uint);
206extern int popup_menu(Init *, int, char **, uint, uint);
207extern int popup_form(Init *, int, char **, uint, uint);
208extern int popup_pick(Init *, int, char **, uint, uint);
209extern int popup_view(Init *, int, char **, uint, uint, uint, uint);
210extern int popup_ckeys();
211extern Menu *destroy_menu(Init *init);
212extern Pick *destroy_pick(Init *init);
213extern Form *destroy_form(Init *init);
214extern View *destroy_view(Init *init);
215extern Init *destroy_init(Init *init);
216extern int parse_opt_args(Init *, int, char **);
217extern void zero_opt_args(Init *);
218extern int write_config(Init *);
219extern bool derive_file_spec(char *, char *, char *);
220extern unsigned int menu_engine(Init *);
221extern unsigned int parse_menu_description(Init *);
222extern int init_form(Init *, int, char **, uint, uint);
223extern int init_pick(Init *, int, char **, uint, uint);
224extern int open_pick_win(Init *);
225extern int pick_engine(Init *);
226extern int cmd_processor(Init *);
227extern int view_file(Init *);
228extern int init_view_full_screen(Init *);
229extern int init_view_boxwin(Init *);
230extern int view_init_input(Init *, char *);
231extern void view_calc_full_screen_dimensions(Init *);
232extern void view_full_screen_resize(Init *);
233extern void view_calc_boxwin_dimensions(Init *);
234extern void view_boxwin_resize(Init *);
235extern int process_config_file(char *, Init *);
236extern void initialize_line_table(View *);
237extern void page_next(View *);
238extern int view_cmd_processor(Init *);
239extern int pad_refresh(View *);
240extern void build_prompt(View *); // View build prompt
241extern int display_prompt(View *, char *); // view display prompt
242extern ViewStack view_stack;
243extern bool view_stack_init(ViewStack *, size_t);
244extern bool view_stack_push(ViewStack *, View);
245extern bool view_stack_pop(ViewStack *, View *);
246extern bool view_stack_peek(const ViewStack *, View *);
247extern void view_stack_free(ViewStack *);
248extern int view_cmd_processor(Init *);
249extern void destroy_view_win(Init *);
250extern void destroy_line_table(View *);
251void cmenu_shutdown(Init *init);
252void cmenu_abend(Init *init, int ec, char *s);
253
254#ifdef __cplusplus
255}
256#endif
int cmd_processor(Init *)
int open_pick_win(Init *)
bool view_stack_peek(const ViewStack *, View *)
@ OT_INT
Definition common.h:88
@ OT_BOOL
Definition common.h:89
@ OT_HEX
Definition common.h:90
@ OT_STRING
Definition common.h:87
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:80
@ MENU
Definition common.h:82
@ VIEW
Definition common.h:79
@ PICK
Definition common.h:81
@ OG_FILES
Definition common.h:95
@ OG_DIRS
Definition common.h:96
@ OG_SPECS
Definition common.h:97
@ OG_MISC
Definition common.h:98
@ OG_FLAGS
Definition common.h:100
@ OG_PARMS
Definition common.h:99
@ OG_COL
Definition common.h:101
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
int pick_engine(Init *)
char minitrc[MAXLEN]
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:104
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:275
#define Ctrl(c)
Definition cm.h:67
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:884
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:666
int click_x
Definition ui_common.c:30
int ui_curs_set(int visibility)
Set the visibility of the cursor.
Definition ui_ncurses.c:840
int click_y
Definition ui_common.c:29
int ui_wclrtoeol(UiSurface *s, ss_t w)
Clear to the end of the line in a surface window.
#define UIKEY_DC
#define UIKEY_BACKSPACE
#define UIKEY_LEFT
#define UIKEY_F09
#define UIKEY_IC
#define UIKEY_END
#define UIKEY_BUTTON1
#define UIKEY_RIGHT
#define UIKEY_HOME
#define UIKEY_ENTER
int ui_get_event(UiSurface *s, ss_t w, UiChyron *chyron, UiEvent *ev, int timeout_ms)
Read input events.
int ui_mvwaddstr(UiSurface *s, ss_t w, uint y, uint x, const char *text)
Draw a text string at a specific position in a surface window.
int init_cnt
Definition mem.c:28
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:111
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:198
ViewStack view_stack
Definition init_view.c:32
#define TRUE
Definition iloan.c:31
int popup_ckeys()
Definition curskeys.c:31
#define MAXLEN
Definition curskeys.c:15
void cmenu_shutdown(Init *init)
Definition menu.c:88
void cmenu_abend(Init *init, int ec, char *s)
Definition menu.c:94
int cf_accept(UiSurface *sfc, ss_t 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:694
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:622
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
Definition init.c:1436
int write_config(Init *init)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:1160
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:498
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:637
void view_calc_boxwin_dimensions(Init *)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:215
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:162
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:128
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:299
Pick * new_pick(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Pick structure.
Definition mem.c:178
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:337
Menu * new_menu(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Menu structure.
Definition mem.c:126
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:147
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:267
View * new_view(Init *init)
Create and initialize View structure.
Definition mem.c:291
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:91
Form * new_form(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Form structure.
Definition mem.c:244
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:217
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:68
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 page_next(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:132
char mapp_data[MAXLEN]
Definition common.h:151
char minitrc[MAXLEN]
Definition common.h:177
bool f_out_spec
Definition common.h:174
char mapp_help[MAXLEN]
Definition common.h:152
int begx
Definition common.h:121
bool f_title
Definition common.h:169
char chyron_s[MAXLEN]
Definition common.h:131
SIO * sio
Definition common.h:117
int pick_cnt
Definition common.h:192
bool f_cmd_all
Definition common.h:168
Form * form
Definition common.h:189
char in_spec[MAXLEN]
Definition common.h:171
char log_file_spec[MAXLEN]
Definition common.h:181
UiLogLevel min_log_level
Definition common.h:183
char cmd_all[MAXLEN]
Definition common.h:126
bool f_mapp_help
Definition common.h:160
bool f_mapp_msrc
Definition common.h:161
int argc
Definition common.h:133
char fill_char[2]
Definition common.h:149
bool f_cmd
Definition common.h:167
int prompt_type
Definition common.h:129
char about_fn[MAXLEN]
Definition common.h:178
char mapp_msrc[MAXLEN]
Definition common.h:153
int cols
Definition common.h:119
int menu_cnt
Definition common.h:188
int tab_stop
Definition common.h:185
bool f_mapp_home
Definition common.h:157
bool f_erase_remainder
Definition common.h:144
bool f_mapp_data
Definition common.h:158
bool f_read_theme
Definition common.h:145
bool f_mapp_desc
Definition common.h:164
char mapp_home[MAXLEN]
Definition common.h:150
bool f_mapp_user
Definition common.h:162
char prompt_str[MAXLEN]
Definition common.h:128
bool f_squeeze
Definition common.h:140
int begy
Definition common.h:120
char parent_cmd[MAXLEN]
Definition common.h:127
char mapp_spec[MAXLEN]
Definition common.h:179
char receiver_cmd[MAXLEN]
Definition common.h:124
int h_shift
Definition common.h:186
bool wrap
Definition common.h:147
bool f_multiple_cmd_args
Definition common.h:142
int select_max
Definition common.h:184
bool f_ln
Definition common.h:146
bool f_mapp_spec
Definition common.h:159
char provider_cmd[MAXLEN]
Definition common.h:123
char out_spec[MAXLEN]
Definition common.h:172
bool f_strip_ansi
Definition common.h:139
View * view
Definition common.h:193
bool p_view_files
Definition common.h:137
Menu * menu
Definition common.h:187
bool f_at_end_remove
Definition common.h:138
int view_cnt
Definition common.h:194
char brackets[3]
Definition common.h:148
bool f_ignore_case
Definition common.h:136
char ** argv
Definition common.h:134
int lines
Definition common.h:118
char mapp_user[MAXLEN]
Definition common.h:154
char cmd[MAXLEN]
Definition common.h:125
char mapp_theme[MAXLEN]
Definition common.h:155
uint timeout_secs
Definition common.h:182
int optind
Definition common.h:135
bool f_help_spec
Definition common.h:170
bool f_receiver_cmd
Definition common.h:166
bool f_provider_cmd
Definition common.h:165
int form_cnt
Definition common.h:190
char help_spec[MAXLEN]
Definition common.h:180
char editor[MAXLEN]
Definition common.h:175
Pick * pick
Definition common.h:191
bool f_in_spec
Definition common.h:173
char menuapp[MAXLEN]
Definition common.h:176