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 <ncursesw/ncurses.h>
17
18#include <cm.h>
19#include <form.h>
20#include <menu.h>
21#include <pick.h>
22#include <view.h>
23
24#include <stddef.h>
25#define USE_PAD TRUE
26#define MIN_COLS 40
27
28#define MAX_WIDE_LEN 1024
29#define COLOR_LEN 8
30#define PICK_MAX_ARG_LEN 256
31#define MAX_PICK_OBJS 1024
32#define ACCEPT_PROMPT_CHAR '_'
33
34#define MENU_HELP_FILE "menu.help"
35#define FORM_HELP_FILE "form.help"
36#define PICK_HELP_FILE "pick.help"
37#define VIEW_HELP_FILE "view.help"
38#define VIEW_PRT_FILE "prtout"
39#define DEFAULTEDITOR "vi"
40
41#define MINITRC ".minitrc"
42#define ABOUT ".about"
43#define MAPP_DIR "~/menuapp"
44#define PRINTCMD "lp -c -s"
45#define MAXOPTS 50
46#define EIGHT 8
47#define P_READ 0
48#define P_WRITE 1
49#define TRUE 1
50
51#define new_cmenu()
52 __end_pgm;
53 int main(int argc, char **argv) {
55 capture_shell_tioctl();
56 Init *init = new_init(argc, argv);
57 SIO *sio = init->sio;
58 mapp_initialization(init);
59 open_curses(sio);
60 sig_prog_mode();
61 capture_curses_tioctl();
62 win_init_attrs();
63
64#define destroy_cmenu()
65 destroy_init(init);
66 win_del();
67 curs_set(1);
68 destroy_curses();
69 return 0;
70 }
71
72typedef enum { VIEW, FORM, PICK, MENU } Caller;
73
74/** @brief option types */
75typedef enum {
80} OptType;
81
82/** @brief option groups */
83typedef enum {
91} OptGroup;
92
93typedef Menu Menu;
94typedef Form Form;
95typedef Pick Pick;
96typedef View View;
97
98/**
99 * @struct Init
100 * @brief Gathers runtime information for C-Menu Menu, Form, Pick, and View
101 * components, used for passing common data and state during initialization and
102 * processing of these componentsi.
103 */
104typedef struct {
105 SIO *sio;
106 int lines; /**< number of lines for window size */
107 int cols; /**< number of columns for window size */
108 int begy; /**< screen line upper left corner of window */
109 int begx; /**< screen column upper left corner of window */
110
111 char provider_cmd[MAXLEN]; /**< command provides input */
112 char receiver_cmd[MAXLEN]; /**< command receives output */
113 char cmd[MAXLEN]; /**< command to execute in foreground, e.g. an editor */
114 char cmd_all[MAXLEN]; /**< View - command to execute at start of program */
115 char parent_cmd[MAXLEN]; /**< command to be executed by parent */
116 char prompt_str[MAXLEN]; /**< prompt string for chyron */
117 int prompt_type; /**< View - prompt type for chyron, e.g. 0=short, 1=long,
118 2=none */
119 char chyron_s[MAXLEN]; /**< chyron string */
120 char title[MAXLEN]; /**< display on top line of box window */
121 int argc; /**< command line arguments count */
122 char **argv; /**< command line arguments vector */
123 int optind; /**< getopt pointer to non-option arguments in argv */
124 bool f_ignore_case; /**< View - ignore case in search */
125 bool f_at_end_remove; /**< obsolete, unneeded */
126 bool f_strip_ansi; /**< strip ansi escape sequences when writing buffer */
127 bool f_squeeze; /**< View - print one line for each group of blank lines
128 */
129 bool f_multiple_cmd_args; /**< View - put multiple arguments in a single
130 string */
131 bool f_erase_remainder; /**< Form - erase remainder of field on enter */
132 bool f_ln; /**< View - show line numbers */
133 char brackets[3]; /**< Form - left and right enclosing characters */
134 char fill_char[2]; /**< Form - fill character for fields */
135 char mapp_home[MAXLEN]; /**< home directory */
136 char mapp_data[MAXLEN]; /**< data directory */
137 char mapp_help[MAXLEN]; /**< help directory */
138 char mapp_msrc[MAXLEN]; /**< source directory */
139 char mapp_user[MAXLEN]; /**< user directory */
140
141 bool f_mapp_home; /**< flag - mapp_home verified */
142 bool f_mapp_data; /**< flag - mapp_data verified */
143 bool f_mapp_spec; /**< flag - mapp_spec verified */
144 bool f_mapp_help; /**< flag - mapp_help verified */
145 bool f_mapp_msrc; /**< flag - mapp_msrc verified */
146 bool f_mapp_user; /**< flag - mapp_user verified */
147 // file flags
148 bool f_mapp_desc; /**< flag - mapp_desc verified */
149 bool f_provider_cmd; /**< flag - provider_cmd verified */
150 bool f_receiver_cmd; /**< flag - receiver_cmd verified */
151 bool f_cmd; /**< flag - cmd verified */
152 bool f_cmd_all; /**< flag - cmd_all verified */
153 bool f_title; /**< flag - title verified */
154 bool f_help_spec; /**< flag - help_spec verified */
155 char in_spec[MAXLEN]; /**< input file spec */
156 char out_spec[MAXLEN]; /**< output file spec */
157 bool f_in_spec; /**< in_spec verified */
158 bool f_out_spec; /**< out_spec verified */
159 char editor[MAXLEN]; /**< default editor */
160 char menuapp[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
161 char minitrc[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
162 char about_fn[MAXLEN]; /**< about information file, e.g. cmenu/.about */
163 char mapp_spec[MAXLEN]; /**< description file */
164 char help_spec[MAXLEN]; /**< help file */
165 // Pick
166 int select_max; /**< Pick maximum number of selections */
167 // View
168 int tab_stop; /**< View - number of spapaces per tab */
169 Menu *menu; /**< menu data structure */
170 int menu_cnt; /**< number of menu data structures allocated */
171 Form *form; /**< form data structure */
172 int form_cnt; /**< number of form data structures allocated */
173 Pick *pick; /**< pick data structure */
174 int pick_cnt; /**< number of pick data structures allocated */
175 View *view; /**< view data structure */
176 int view_cnt; /**< number of view data structures allocated */
177} Init;
178
179extern Init *init;
180extern int init_cnt; /** number of Init data structures allocated */
181extern char minitrc[MAXLEN];
182extern void mapp_initialization(Init *, int, char **);
183extern Init *new_init(int, char **);
184extern View *new_view(Init *);
185extern Form *new_form(Init *, int, char **, int, int);
186extern Pick *new_pick(Init *, int, char **, int, int);
187extern Menu *new_menu(Init *, int, char **, int, int);
188extern int popup_menu(Init *, int, char **, int, int);
189extern int popup_form(Init *, int, char **, int, int);
190extern int popup_pick(Init *, int, char **, int, int);
191extern int popup_view(Init *, int, char **, int, int, int, int);
192extern int popup_ckeys();
193extern Menu *destroy_menu(Init *init);
194extern Pick *destroy_pick(Init *init);
195extern Form *destroy_form(Init *init);
196extern View *destroy_view(Init *init);
197extern Init *destroy_init(Init *init);
198extern int parse_opt_args(Init *, int, char **);
199extern void zero_opt_args(Init *);
200extern int write_config(Init *);
201extern bool derive_file_spec(char *, char *, char *);
202extern bool init_menu_files(Init *, int, char **);
203extern unsigned int menu_engine(Init *);
204extern unsigned int parse_menu_description(Init *);
205extern int init_form(Init *, int, char **, int, int);
206extern int init_pick(Init *, int, char **, int, int);
207extern int open_pick_win(Init *);
208extern int pick_engine(Init *);
209extern int cmd_processor(Init *);
210extern int view_file(Init *);
211extern int init_view_full_screen(Init *);
212extern int init_view_boxwin(Init *, char *);
213extern int view_init_input(View *, char *);
214extern void view_calc_full_screen_dimensions(Init *);
215extern void view_full_screen_resize(Init *);
216extern void view_calc_win_dimensions(Init *, char *title);
217extern void view_win_resize(Init *, char *);
218#endif
int cmd_processor(Init *)
@ OT_INT
Definition common.h:77
@ OT_BOOL
Definition common.h:78
@ OT_HEX
Definition common.h:79
@ OT_STRING
Definition common.h:76
Init * init
Definition init.c:74
@ FORM
Definition common.h:72
@ MENU
Definition common.h:72
@ VIEW
Definition common.h:72
@ PICK
Definition common.h:72
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
Definition popups.c:113
@ OG_FILES
Definition common.h:84
@ OG_DIRS
Definition common.h:85
@ OG_SPECS
Definition common.h:86
@ OG_MISC
Definition common.h:87
@ OG_FLAGS
Definition common.h:89
@ OG_PARMS
Definition common.h:88
@ OG_COL
Definition common.h:90
int popup_menu(Init *, int, char **, int, int)
instantiate a menu popup window
Definition popups.c:53
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
Definition popups.c:146
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:43
volatile sig_atomic_t sig_received
Definition sig.c:31
bool handle_signal(sig_atomic_t)
#define KEY_ALTEND
Definition cm.h:460
#define KEY_ALTLEFT
Definition cm.h:463
#define KEY_ALTDOWN
Definition cm.h:464
#define KEY_ALTHOME
Definition cm.h:457
#define KEY_ALTPGDN
Definition cm.h:461
#define KEY_ALTRIGHT
Definition cm.h:465
#define KEY_ALTDEL
Definition cm.h:459
#define KEY_ALTUP
Definition cm.h:462
#define KEY_ALTPGUP
Definition cm.h:458
#define KEY_ALTF(n)
Definition cm.h:403
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:230
#define KEY_ALTINS
Definition cm.h:456
#define TRUE
Definition iloan.c:19
int popup_ckeys()
Display Curses Keys Responds to curses keys and mouse events, displaying the key code and description...
Definition curskeys.c:23
#define KSTRLEN
Definition curskeys.c:14
#define MAXLEN
Definition curskeys.c:15
WINDOW * win_win[MAXWIN]
Definition dwin.c:122
char em1[MAXLEN]
Definition dwin.c:142
int win_ptr
Definition dwin.c:130
char em0[MAXLEN]
Definition dwin.c:141
WINDOW * win_box[MAXWIN]
Definition dwin.c:124
char em2[MAXLEN]
Definition dwin.c:143
void view_win_resize(Init *, char *)
Resize the current window and its box, and update the title.
Definition init_view.c:265
int box_new(int, int, int, int, char *, bool)
Create a new window with optional box and title.
Definition dwin.c:745
void view_full_screen_resize(Init *)
Resize the full screen view and its components.
Definition init_view.c:115
WINDOW * win_del()
Delete the current window and its associated box window.
Definition dwin.c:893
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1162
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1102
int init_form(Init *, int, char **, int, int)
Initialize form data structure and parse description file.
Definition form_engine.c:60
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:435
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:464
int parse_opt_args(Init *, int, char **)
Parse command-line options and set Init struct values accordingly.
Definition init.c:427
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
Definition init.c:907
int write_config(Init *)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:797
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:328
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:442
void view_calc_win_dimensions(Init *, char *title)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:367
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
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:140
int view_init_input(View *, char *)
Initialize the input for a C-Menu View.
Definition init_view.c:443
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:359
Form * new_form(Init *, int, char **, int, int)
Create and initialize Form structure.
Definition mem.c:266
bool init_menu_files(Init *, int, char **)
Initialize Menu file specifications.
Definition mem.c:528
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
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:169
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:289
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:313
Pick * new_pick(Init *, int, char **, int, int)
Create and initialize Pick structure.
Definition mem.c:200
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:105
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:239
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:60
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.
char title[MAXLEN]
Definition common.h:120
char mapp_data[MAXLEN]
Definition common.h:136
char minitrc[MAXLEN]
Definition common.h:161
bool f_out_spec
Definition common.h:158
char mapp_help[MAXLEN]
Definition common.h:137
int begx
Definition common.h:109
bool f_title
Definition common.h:153
char chyron_s[MAXLEN]
Definition common.h:119
SIO * sio
Definition common.h:105
int pick_cnt
Definition common.h:174
bool f_cmd_all
Definition common.h:152
Form * form
Definition common.h:171
char in_spec[MAXLEN]
Definition common.h:155
char cmd_all[MAXLEN]
Definition common.h:114
bool f_mapp_help
Definition common.h:144
bool f_mapp_msrc
Definition common.h:145
int argc
Definition common.h:121
char fill_char[2]
Definition common.h:134
bool f_cmd
Definition common.h:151
int prompt_type
Definition common.h:117
char about_fn[MAXLEN]
Definition common.h:162
char mapp_msrc[MAXLEN]
Definition common.h:138
int cols
Definition common.h:107
int menu_cnt
Definition common.h:170
int tab_stop
Definition common.h:168
bool f_mapp_home
Definition common.h:141
bool f_erase_remainder
Definition common.h:131
bool f_mapp_data
Definition common.h:142
bool f_mapp_desc
Definition common.h:148
char mapp_home[MAXLEN]
Definition common.h:135
bool f_mapp_user
Definition common.h:146
char prompt_str[MAXLEN]
Definition common.h:116
bool f_squeeze
Definition common.h:127
int begy
Definition common.h:108
char parent_cmd[MAXLEN]
Definition common.h:115
char mapp_spec[MAXLEN]
Definition common.h:163
char receiver_cmd[MAXLEN]
Definition common.h:112
bool f_multiple_cmd_args
Definition common.h:129
int select_max
Definition common.h:166
bool f_ln
Definition common.h:132
bool f_mapp_spec
Definition common.h:143
char provider_cmd[MAXLEN]
Definition common.h:111
char out_spec[MAXLEN]
Definition common.h:156
bool f_strip_ansi
Definition common.h:126
View * view
Definition common.h:175
Menu * menu
Definition common.h:169
bool f_at_end_remove
Definition common.h:125
int view_cnt
Definition common.h:176
char brackets[3]
Definition common.h:133
bool f_ignore_case
Definition common.h:124
char ** argv
Definition common.h:122
int lines
Definition common.h:106
char mapp_user[MAXLEN]
Definition common.h:139
char cmd[MAXLEN]
Definition common.h:113
int optind
Definition common.h:123
bool f_help_spec
Definition common.h:154
bool f_receiver_cmd
Definition common.h:150
bool f_provider_cmd
Definition common.h:149
int form_cnt
Definition common.h:172
char help_spec[MAXLEN]
Definition common.h:164
char editor[MAXLEN]
Definition common.h:159
Pick * pick
Definition common.h:173
bool f_in_spec
Definition common.h:157
char menuapp[MAXLEN]
Definition common.h:160