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 open_curses(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 char brackets[3]; /**< Form - left and right enclosing characters */
145 char fill_char[4]; /**< Form - fill character for fields */
146 char mapp_home[MAXLEN]; /**< home directory */
147 char mapp_data[MAXLEN]; /**< data directory */
148 char mapp_help[MAXLEN]; /**< help directory */
149 char mapp_msrc[MAXLEN]; /**< source directory */
150 char mapp_user[MAXLEN]; /**< user directory */
151 char mapp_theme[MAXLEN]; /**< default theme file */
152
153 bool f_mapp_home; /**< flag - mapp_home verified */
154 bool f_mapp_data; /**< flag - mapp_data verified */
155 bool f_mapp_spec; /**< flag - mapp_spec verified */
156 bool f_mapp_help; /**< flag - mapp_help verified */
157 bool f_mapp_msrc; /**< flag - mapp_msrc verified */
158 bool f_mapp_user; /**< flag - mapp_user verified */
159 // file flags
160 bool f_mapp_desc; /**< flag - mapp_desc verified */
161 bool f_provider_cmd; /**< flag - provider_cmd verified */
162 bool f_receiver_cmd; /**< flag - receiver_cmd verified */
163 bool f_cmd; /**< flag - cmd verified */
164 bool f_cmd_all; /**< flag - cmd_all verified */
165 bool f_title; /**< flag - title verified */
166 bool f_help_spec; /**< flag - help_spec verified */
167 char in_spec[MAXLEN]; /**< input file spec */
168 char out_spec[MAXLEN]; /**< output file spec */
169 bool f_in_spec; /**< in_spec verified */
170 bool f_out_spec; /**< out_spec verified */
171 char editor[MAXLEN]; /**< default editor */
172 char menuapp[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
173 char minitrc[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
174 char about_fn[MAXLEN]; /**< about information file, e.g. cmenu/.about */
175 char mapp_spec[MAXLEN]; /**< description file */
176 char help_spec[MAXLEN]; /**< help file */
177 // Pick
178 int select_max; /**< Pick maximum number of selections */
179 // View
180 int tab_stop; /**< View - number of spapaces per tab */
181 int h_shift; /**< View - horizontal scroll shift width */
182 Menu *menu; /**< menu data structure */
183 int menu_cnt; /**< number of menu data structures allocated */
184 Form *form; /**< form data structure */
185 int form_cnt; /**< number of form data structures allocated */
186 Pick *pick; /**< pick data structure */
187 int pick_cnt; /**< number of pick data structures allocated */
188 View *view; /**< view data structure */
189 int view_cnt; /**< number of view data structures allocated */
190} Init;
191
192// extern Init *init;
193extern int init_cnt; /** number of Init data structures allocated */
194extern char minitrc[MAXLEN];
195extern void mapp_initialization(Init *, int, char **);
196extern Init *new_init(int, char **);
197extern View *new_view(Init *);
198extern Form *new_form(Init *, int, char **, int, int);
199extern Pick *new_pick(Init *, int, char **, int, int);
200extern Menu *new_menu(Init *, int, char **, int, int);
201extern int popup_menu(Init *, int, char **, int, int);
202extern int popup_form(Init *, int, char **, int, int);
203extern int popup_pick(Init *, int, char **, int, int);
204extern int popup_view(Init *, int, char **, int, int, int, int);
205extern int popup_ckeys();
206extern Menu *destroy_menu(Init *init);
207extern Pick *destroy_pick(Init *init);
208extern Form *destroy_form(Init *init);
209extern View *destroy_view(Init *init);
210extern Init *destroy_init(Init *init);
211extern int parse_opt_args(Init *, int, char **);
212extern void zero_opt_args(Init *);
213extern int write_config(Init *);
214extern bool derive_file_spec(char *, char *, char *);
215extern bool init_menu_files(Init *, int, char **);
216extern unsigned int menu_engine(Init *);
217extern unsigned int parse_menu_description(Init *);
218extern int init_form(Init *, int, char **, int, int);
219extern int init_pick(Init *, int, char **, int, int);
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_local_colors(SIO *);
233extern void initialize_line_table(View *);
234extern void next_page(View *);
235extern int view_cmd_processor(Init *);
236extern int pad_refresh(View *);
237extern void build_prompt(View *); // View build prompt
238extern int display_prompt(View *, char *); // view display prompt
239extern ViewStack view_stack;
240extern bool view_stack_init(ViewStack *, size_t);
241extern bool view_stack_push(ViewStack *, View);
242extern bool view_stack_pop(ViewStack *, View *);
243extern bool view_stack_peek(const ViewStack *, View *);
244extern void view_stack_free(ViewStack *);
245extern int view_cmd_processor(Init *);
246extern void destroy_view_win(Init *);
247extern void destroy_line_table(View *);
248#endif
int cmd_processor(Init *)
@ 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_ckeys()
Display Curses Keys Responds to curses keys and mouse events, displaying the key code and description...
Definition curskeys.c:23
int process_config_file(char *, Init *)
Definition init.c:631
@ FORM
Definition common.h:77
@ MENU
Definition common.h:79
@ VIEW
Definition common.h:76
@ PICK
Definition common.h:78
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
Definition popups.c:112
@ 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
void destroy_view_win(Init *)
Definition init_view.c:318
int popup_menu(Init *, int, char **, int, int)
instantiate a menu popup window
Definition popups.c:53
ViewStack view_stack
Definition init_view.c:34
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
Definition popups.c:144
int popup_pick(Init *, int, char **, int, int)
instantiate a pick popup window
Definition popups.c:83
char minitrc[MAXLEN]
int init_cnt
Definition mem.c:44
void destroy_line_table(View *)
int click_x
Definition dwin.c:81
int click_y
Definition dwin.c:80
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:89
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:297
#define Ctrl(c)
Definition cm.h:52
#define TRUE
Definition iloan.c:19
#define FALSE
Definition iloan.c:18
#define MAXLEN
Definition curskeys.c:15
int cf_accept(WINDOW *win, char *accept_s, int flin, int fcol, int flen)
Accepts input for a field in a C-Menu window.
Definition cm_fields.c:51
bool f_erase_remainder
Definition cm_fields.c:39
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:140
void view_boxwin_resize(Init *)
Resize the current window and its box.
Definition init_view.c:346
int vgetch(WINDOW *, int)
Wrapper for wgetch that handles signals and mouse events, and accepts a single character answer.
Definition dwin.c:2258
void initialize_local_colors(SIO *)
Initialize local color variables and color pairs based on SIO settings.
Definition dwin.c:320
int init_form(Init *, int, char **, int, int)
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:559
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
Definition init.c:1306
int write_config(Init *)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:1049
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:441
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:574
void view_calc_boxwin_dimensions(Init *)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:362
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
Definition init_view.c:49
int init_view_boxwin(Init *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:194
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:159
int view_init_input(Init *, char *)
Initialize the input for the C-Menu View.
Definition init_view.c:447
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:356
Form * new_form(Init *, int, char **, int, int)
Create and initialize Form structure.
Definition mem.c:263
bool init_menu_files(Init *, int, char **)
Initialize Menu file specifications.
Definition mem.c:502
Init * new_init(int, char **)
Create and initialize Init structure.
Definition mem.c:71
Menu * new_menu(Init *, int, char **, int, int)
Create and initialize Menu structure.
Definition mem.c:145
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:166
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:286
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:310
Pick * new_pick(Init *, int, char **, int, int)
Create and initialize Pick structure.
Definition mem.c:197
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:106
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:236
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:38
unsigned int parse_menu_description(Init *)
Parse menu description file and create Menu.
int init_pick(Init *, int, char **, int, int)
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.
bool view_stack_pop(ViewStack *, View *)
Pop Item from View Stack.
bool view_stack_peek(const ViewStack *, View *)
Peek at Top Item of View Stack.
void view_stack_free(ViewStack *)
Free View Stack.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
bool view_stack_init(ViewStack *, size_t)
Initialize View Stack.
void build_prompt(View *)
Build Prompt String.
bool view_stack_push(ViewStack *, View)
Push Item onto View Stack.
void initialize_line_table(View *)
Initialize 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:147
char minitrc[MAXLEN]
Definition common.h:173
bool f_out_spec
Definition common.h:170
char mapp_help[MAXLEN]
Definition common.h:148
int begx
Definition common.h:118
bool f_title
Definition common.h:165
char chyron_s[MAXLEN]
Definition common.h:128
SIO * sio
Definition common.h:114
int pick_cnt
Definition common.h:187
bool f_cmd_all
Definition common.h:164
Form * form
Definition common.h:184
char in_spec[MAXLEN]
Definition common.h:167
char cmd_all[MAXLEN]
Definition common.h:123
bool f_mapp_help
Definition common.h:156
bool f_mapp_msrc
Definition common.h:157
int argc
Definition common.h:130
bool f_cmd
Definition common.h:163
int prompt_type
Definition common.h:126
char about_fn[MAXLEN]
Definition common.h:174
char mapp_msrc[MAXLEN]
Definition common.h:149
int cols
Definition common.h:116
int menu_cnt
Definition common.h:183
int tab_stop
Definition common.h:180
bool f_mapp_home
Definition common.h:153
bool f_erase_remainder
Definition common.h:141
bool f_mapp_data
Definition common.h:154
bool f_read_theme
Definition common.h:142
bool f_mapp_desc
Definition common.h:160
char mapp_home[MAXLEN]
Definition common.h:146
bool f_mapp_user
Definition common.h:158
char prompt_str[MAXLEN]
Definition common.h:125
char fill_char[4]
Definition common.h:145
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:175
char receiver_cmd[MAXLEN]
Definition common.h:121
int h_shift
Definition common.h:181
bool f_multiple_cmd_args
Definition common.h:139
int select_max
Definition common.h:178
bool f_ln
Definition common.h:143
bool f_mapp_spec
Definition common.h:155
char provider_cmd[MAXLEN]
Definition common.h:120
char out_spec[MAXLEN]
Definition common.h:168
bool f_strip_ansi
Definition common.h:136
View * view
Definition common.h:188
bool p_view_files
Definition common.h:134
Menu * menu
Definition common.h:182
bool f_at_end_remove
Definition common.h:135
int view_cnt
Definition common.h:189
char brackets[3]
Definition common.h:144
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:150
char cmd[MAXLEN]
Definition common.h:122
char mapp_theme[MAXLEN]
Definition common.h:151
int optind
Definition common.h:132
bool f_help_spec
Definition common.h:166
bool f_receiver_cmd
Definition common.h:162
bool f_provider_cmd
Definition common.h:161
int form_cnt
Definition common.h:185
char help_spec[MAXLEN]
Definition common.h:176
char editor[MAXLEN]
Definition common.h:171
Pick * pick
Definition common.h:186
bool f_in_spec
Definition common.h:169
char menuapp[MAXLEN]
Definition common.h:172