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/** Without #define _GNU_SOURCE you may get errors like
14 locale_t undefined in time.h */
15#define _GNU_SOURCE
16#define _XOPEN_SOURCE_EXTENDED 1
17#define NCURSES_WIDECHAR 1
18#include <ncursesw/ncurses.h>
19
20#include <cm.h>
21#include <form.h>
22#include <menu.h>
23#include <pick.h>
24#include <view.h>
25
26#include <stddef.h>
27#define USE_PAD TRUE
28#define MIN_COLS 40
29
30#define MAX_WIDE_LEN 1024
31#define COLOR_LEN 8
32#define PICK_MAX_ARG_LEN 256
33#define MAX_PICK_OBJS 1024
34#define ACCEPT_PROMPT_CHAR '_'
35
36#define MENU_HELP_FILE "menu.help"
37#define FORM_HELP_FILE "form.help"
38#define PICK_HELP_FILE "pick.help"
39#define VIEW_HELP_FILE "view.help"
40#define VIEW_PRT_FILE "prtout"
41#define DEFAULTEDITOR "vi"
42
43#define MINITRC ".minitrc"
44#define ABOUT ".about"
45#define MAPP_DIR "~/menuapp"
46#define PRINTCMD "lp -c -s"
47#define MAXOPTS 50
48#define EIGHT 8
49#define F_VIEW 0x01
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
75enum Caller { VIEW, FORM, PICK, MENU };
76
77/** @brief option types */
78enum OptType {
83};
84
85/** @brief option groups */
94};
95
96typedef Menu Menu;
97typedef Form Form;
98typedef Pick Pick;
99typedef View View;
100
101/**
102 * @struct Init
103 * @brief Gathers runtime information for C-Menu Menu, Form, Pick, and View
104 * components, used for passing common data and state during initialization and
105 * processing of these componentsi.
106 */
107typedef struct {
108 SIO *sio;
109 int lines; /**< number of lines for window size */
110 int cols; /**< number of columns for window size */
111 int begy; /**< screen line upper left corner of window */
112 int begx; /**< screen column upper left corner of window */
113
114 char provider_cmd[MAXLEN]; /**< command provides input */
115 char receiver_cmd[MAXLEN]; /**< command receives output */
116 char cmd[MAXLEN]; /**< command to execute in foreground, e.g. an editor */
117 char cmd_all[MAXLEN]; /**< View - command to execute at start of program */
118 char parent_cmd[MAXLEN]; /**< command to be executed by parent */
119 char prompt_str[MAXLEN]; /**< prompt string for chyron */
120 int prompt_type; /**< View - prompt type for chyron, e.g. 0=short, 1=long,
121 2=none */
122 char chyron_s[MAXLEN]; /**< chyron string */
123 char title[MAXLEN]; /**< display on top line of box window */
124 int argc; /**< command line arguments count */
125 char **argv; /**< command line arguments vector */
126 int optind; /**< getopt pointer to non-option arguments in argv */
127 bool f_ignore_case; /**< View - ignore case in search */
128 bool f_at_end_remove; /**< obsolete, unneeded */
129 bool f_strip_ansi; /**< strip ansi escape sequences when writing buffer */
130 bool f_squeeze; /**< View - print one line for each group of blank lines
131 */
132 bool f_multiple_cmd_args; /**< View - put multiple arguments in a single
133 string */
134 bool f_erase_remainder; /**< Form - erase remainder of field on enter */
135 bool f_ln; /**< View - show line numbers */
136 char brackets[3]; /**< Form - left and right enclosing characters */
137 char fill_char[2]; /**< Form - fill character for fields */
138 char mapp_home[MAXLEN]; /**< home directory */
139 char mapp_data[MAXLEN]; /**< data directory */
140 char mapp_help[MAXLEN]; /**< help directory */
141 char mapp_msrc[MAXLEN]; /**< source directory */
142 char mapp_user[MAXLEN]; /**< user directory */
143
144 bool f_mapp_home; /**< flag - mapp_home verified */
145 bool f_mapp_data; /**< flag - mapp_data verified */
146 bool f_mapp_spec; /**< flag - mapp_spec verified */
147 bool f_mapp_help; /**< flag - mapp_help verified */
148 bool f_mapp_msrc; /**< flag - mapp_msrc verified */
149 bool f_mapp_user; /**< flag - mapp_user verified */
150 // file flags
151 bool f_mapp_desc; /**< flag - mapp_desc verified */
152 bool f_provider_cmd; /**< flag - provider_cmd verified */
153 bool f_receiver_cmd; /**< flag - receiver_cmd verified */
154 bool f_cmd; /**< flag - cmd verified */
155 bool f_cmd_all; /**< flag - cmd_all verified */
156 bool f_title; /**< flag - title verified */
157 bool f_help_spec; /**< flag - help_spec verified */
158 char in_spec[MAXLEN]; /**< input file spec */
159 char out_spec[MAXLEN]; /**< output file spec */
160 bool f_in_spec; /**< in_spec verified */
161 bool f_out_spec; /**< out_spec verified */
162 char editor[MAXLEN]; /**< default editor */
163 char menuapp[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
164 char minitrc[MAXLEN]; /**< main configuration file, e.g. cmenu/.minitrc */
165 char about_fn[MAXLEN]; /**< about information file, e.g. cmenu/.about */
166 char mapp_spec[MAXLEN]; /**< description file */
167 char help_spec[MAXLEN]; /**< help file */
168 // Pick
169 int select_max; /**< Pick maximum number of selections */
170 // View
171 int tab_stop; /**< View - number of spapaces per tab */
172 Menu *menu; /**< menu data structure */
173 int menu_cnt; /**< number of menu data structures allocated */
174 Form *form; /**< form data structure */
175 int form_cnt; /**< number of form data structures allocated */
176 Pick *pick; /**< pick data structure */
177 int pick_cnt; /**< number of pick data structures allocated */
178 View *view; /**< view data structure */
179 int view_cnt; /**< number of view data structures allocated */
180} Init;
181
182extern Init *init;
183
185
186extern Init *init;
187extern int init_cnt; /** number of Init data structures allocated */
188extern char minitrc[MAXLEN];
189extern void mapp_initialization(Init *, int, char **);
190extern Init *new_init(int, char **);
191extern View *new_view(Init *);
192extern Form *new_form(Init *, int, char **, int, int);
193extern Pick *new_pick(Init *, int, char **, int, int);
194extern Menu *new_menu(Init *, int, char **, int, int);
195extern int popup_menu(Init *, int, char **, int, int);
196extern int popup_form(Init *, int, char **, int, int);
197extern int popup_pick(Init *, int, char **, int, int);
198extern int popup_view(Init *, int, char **, int, int, int, int);
199extern int popup_ckeys();
200extern Menu *destroy_menu(Init *init);
201extern Pick *destroy_pick(Init *init);
202extern Form *destroy_form(Init *init);
203extern View *destroy_view(Init *init);
204extern Init *destroy_init(Init *init);
205extern int parse_opt_args(Init *, int, char **);
206extern void zero_opt_args(Init *);
207extern int write_config(Init *);
208extern bool derive_file_spec(char *, char *, char *);
209extern bool init_menu_files(Init *, int, char **);
210extern unsigned int menu_engine(Init *);
211extern unsigned int parse_menu_description(Init *);
212extern int init_form(Init *, int, char **, int, int);
213extern int init_pick(Init *, int, char **, int, int);
214extern int open_pick_win(Init *);
215extern int pick_engine(Init *);
216extern int view_file(Init *);
217extern int init_view_full_screen(Init *);
218extern int init_view_boxwin(Init *, char *);
219extern int view_init_input(View *, char *);
220extern int cmd_processor(Init *);
221#endif
int cmd_processor(Init *)
Init * init
Definition common.h:186
OptType
option types
Definition common.h:78
@ OT_INT
Definition common.h:80
@ OT_BOOL
Definition common.h:81
@ OT_HEX
Definition common.h:82
@ OT_STRING
Definition common.h:79
Caller
Definition common.h:75
@ FORM
Definition common.h:75
@ MENU
Definition common.h:75
@ VIEW
Definition common.h:75
@ PICK
Definition common.h:75
int popup_form(Init *, int, char **, int, int)
Definition popups.c:34
OptGroup
option groups
Definition common.h:86
@ OG_FILES
Definition common.h:87
@ OG_DIRS
Definition common.h:88
@ OG_SPECS
Definition common.h:89
@ OG_MISC
Definition common.h:90
@ OG_FLAGS
Definition common.h:92
@ OG_PARMS
Definition common.h:91
@ OG_COL
Definition common.h:93
int popup_menu(Init *, int, char **, int, int)
Definition popups.c:8
int popup_view(Init *, int, char **, int, int, int, int)
Definition popups.c:47
int parse_opt_args(Init *, int, char **)
Definition init.c:393
int popup_pick(Init *, int, char **, int, int)
Definition popups.c:21
@ IC_MENU
Definition common.h:184
@ IC_VIEW
Definition common.h:184
@ IC_FORM
Definition common.h:184
@ IC_PICK
Definition common.h:184
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:403
#define KEY_ALTLEFT
Definition cm.h:406
#define KEY_ALTDOWN
Definition cm.h:407
#define KEY_ALTHOME
Definition cm.h:400
#define KEY_ALTPGDN
Definition cm.h:404
#define KEY_ALTRIGHT
Definition cm.h:408
#define KEY_ALTDEL
Definition cm.h:402
#define KEY_ALTUP
Definition cm.h:405
#define KEY_ALTPGUP
Definition cm.h:401
#define KEY_ALTF(n)
Definition cm.h:346
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:194
#define KEY_ALTINS
Definition cm.h:399
#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:114
char em1[MAXLEN]
Definition dwin.c:133
int win_ptr
Definition dwin.c:121
char em0[MAXLEN]
Definition dwin.c:132
WINDOW * win_box[MAXWIN]
Definition dwin.c:115
char em2[MAXLEN]
Definition dwin.c:134
int win_new(int, int, int, int, char *, int)
Create a new window with optional box and title.
Definition dwin.c:783
WINDOW * win_del()
Delete the current window and its associated box window.
Definition dwin.c:902
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1110
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1054
int init_form(Init *, int, char **, int, int)
Initialize form data structure and parse description file.
Definition form_engine.c:59
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:269
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:298
bool derive_file_spec(char *, char *, char *)
Derive full file specification from directory and file name.
Definition init.c:821
int write_config(Init *)
Write the current configuration to a file specified in init->minitrc.
Definition init.c:723
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:324
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:408
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
Definition init_view.c:40
int init_view_boxwin(Init *, char *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:123
int view_init_input(View *, char *)
Initialize the input for a C-Menu View.
Definition init_view.c:223
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:346
Form * new_form(Init *, int, char **, int, int)
Create and initialize Form structure.
Definition mem.c:253
bool init_menu_files(Init *, int, char **)
Initialize Menu file specifications.
Definition mem.c:486
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:276
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:300
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:230
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:37
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:59
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:123
char mapp_data[MAXLEN]
Definition common.h:139
char minitrc[MAXLEN]
Definition common.h:164
bool f_out_spec
Definition common.h:161
char mapp_help[MAXLEN]
Definition common.h:140
int begx
Definition common.h:112
bool f_title
Definition common.h:156
char chyron_s[MAXLEN]
Definition common.h:122
SIO * sio
Definition common.h:108
int pick_cnt
Definition common.h:177
bool f_cmd_all
Definition common.h:155
Form * form
Definition common.h:174
char in_spec[MAXLEN]
Definition common.h:158
char cmd_all[MAXLEN]
Definition common.h:117
bool f_mapp_help
Definition common.h:147
bool f_mapp_msrc
Definition common.h:148
int argc
Definition common.h:124
char fill_char[2]
Definition common.h:137
bool f_cmd
Definition common.h:154
int prompt_type
Definition common.h:120
char about_fn[MAXLEN]
Definition common.h:165
char mapp_msrc[MAXLEN]
Definition common.h:141
int cols
Definition common.h:110
int menu_cnt
Definition common.h:173
int tab_stop
Definition common.h:171
bool f_mapp_home
Definition common.h:144
bool f_erase_remainder
Definition common.h:134
bool f_mapp_data
Definition common.h:145
bool f_mapp_desc
Definition common.h:151
char mapp_home[MAXLEN]
Definition common.h:138
bool f_mapp_user
Definition common.h:149
char prompt_str[MAXLEN]
Definition common.h:119
bool f_squeeze
Definition common.h:130
int begy
Definition common.h:111
char parent_cmd[MAXLEN]
Definition common.h:118
char mapp_spec[MAXLEN]
Definition common.h:166
char receiver_cmd[MAXLEN]
Definition common.h:115
bool f_multiple_cmd_args
Definition common.h:132
int select_max
Definition common.h:169
bool f_ln
Definition common.h:135
bool f_mapp_spec
Definition common.h:146
char provider_cmd[MAXLEN]
Definition common.h:114
char out_spec[MAXLEN]
Definition common.h:159
bool f_strip_ansi
Definition common.h:129
View * view
Definition common.h:178
Menu * menu
Definition common.h:172
bool f_at_end_remove
Definition common.h:128
int view_cnt
Definition common.h:179
char brackets[3]
Definition common.h:136
bool f_ignore_case
Definition common.h:127
char ** argv
Definition common.h:125
int lines
Definition common.h:109
char mapp_user[MAXLEN]
Definition common.h:142
char cmd[MAXLEN]
Definition common.h:116
int optind
Definition common.h:126
bool f_help_spec
Definition common.h:157
bool f_receiver_cmd
Definition common.h:153
bool f_provider_cmd
Definition common.h:152
int form_cnt
Definition common.h:175
char help_spec[MAXLEN]
Definition common.h:167
char editor[MAXLEN]
Definition common.h:162
Pick * pick
Definition common.h:176
bool f_in_spec
Definition common.h:160
char menuapp[MAXLEN]
Definition common.h:163