C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
cm.h
Go to the documentation of this file.
1/** @file cm.h
2 * @brief Headder for C-Menu API library, libcm.so
3 * @author Bill Waller
4 * Copyright (c) 2025
5 * MIT License
6 * billxwaller@gmail.com
7 * @date 2026-02-09
8 */
9#pragma once
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#define _GNU_SOURCE
16#define _XOPEN_SOURCE_EXTENDED 1 /**< Enable wide character support */
17#define NCURSES_WIDECHAR 1 /**< Enable wide character support */
18#include "version.h"
19#include <argp.h>
20#ifdef UAL_UI
21// #include "../ui/ui_ncurses_internal.h"
22#include "ui_backend.h"
23#include <ncursesw/ncurses.h>
24#include <ncursesw/panel.h>
25#endif
26#ifdef NOTCURSES_UI
27#include "ui_backend.h"
28#include "ui_notcurses_internal.h"
29#include <notcurses/notcurses.h>
30#endif
31#include <pthread.h>
32#include <signal.h>
33#include <stdbool.h>
34#include <stddef.h>
35#include <stdlib.h>
36#include <time.h>
37#include <wait.h>
38#include <wchar.h>
39
40#ifdef __USE_GNU_GETTEXT
41#include <libintl.h>
42#define _(String) gettext(String)
43#define gettext_noop(String) String
44#define N_(String) gettext_noop(String)
45#else
46#define _(String) (String)
47#define N_(String) String
48#define textdomain(Domain)
49#define bindtextdomain(Package, Directory)
50#endif
51
52#if __STDC_VERSION__ < 202311L
53#define nullptr NULL
54#endif
55
56#define MAXWIN 30 /**< maximum number of windows that can be created */
57
58#ifdef UI_NCURSES
59extern SCREEN *screen;
60#endif
61extern FILE *tty_fp;
62#define MAX_ARGS 64 /**< maximum number of arguments for external commands */
63#define MAXLEN 256 /**< maximum length for strings and buffers */
64#define MAXARGS 64 /**< maximum number of arguments */
65#define SCR_COLS 1024 /**< maximum number of columns in the terminal screen */
66#define SCREEN_MAX_LINES 100
67#define Ctrl(c) ((c) & 0x1f)
68#include <stdio.h>
69
70typedef struct {
71 uint yyyy;
72 uint mm;
73 uint dd;
74} Date;
75
76typedef struct {
77 uint hh;
78 uint mm;
79 uint ss;
80} Time;
81
82#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
83
84/** @brief max macro evaluates two expressions, returning greatest result.
85 @details These macros use compound statements to create local scopes for the
86 temporary variables _x and _y, which store the values of x and y,
87 respectively. This ensures that if x or y have side effects (such as being
88 incremented), they will only be evaluated once when the macro is expanded.
89 The use of typeof allows the macro to work with any data type.
90 The line (void)(&_x == &_y) is a compile-time check to ensure that the
91 types of the arguments are compatible.
92 This implementation of the min and max macros provides a safer and
93 more robust way to determine the minimum and maximum values between two
94 expressions without risking unintended consequences from multiple
95 evaluations.
96 */
97#define max(a, b)
98 ({
99 __typeof__(a) _a = (a);
100 __typeof__(a) _b = (b);
101 _a > _b ? _a : _b;
102 })
103/** @brief min macro evaluates two expressions, returning least result */
104#define min(x, y)
105 ({
106 typeof(x) _x = (x);
107 typeof(x) _y = (y);
108 (void)(&_x == &_y);
109 _x < _y ? _x : _y;
110 })
111/**
112 */
113/** @brief MIN macro for compatibility with code that uses the same name,
114 while avoiding multiple evaluations of the arguments.
115 @details /usr/include/sys/param.h contains implementations of the MIN and MAX
116 macros, which are simple but can lead to issues with multiple evaluations of
117 the arguments if they have side effects. These macros provides a safer
118 alternative to param.h Here are the macros from /usr/include/sys/param.h. You
119 may comment out the macros defined herein and use the macros in param.h if
120 you prefer.
121 @code
122 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
123 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
124 @endcode
125 @note The following macro provides a safer alternative to param.h
126 */
127#define MAX(a, b)
128 ({
129 typeof(a) _a = (a);
130 typeof(y) _b = (b);
131 _a > _b ? _a : _b;
132 })
133/** @brief MAX macro for compatibility with code that uses the same name,
134 while avoiding multiple evaluations of the arguments.
135 @note The following macro provides a safer alternative to param.h
136 */
137#define MIN(x, y)
138 ({
139 typeof(x) _x = (x);
140 typeof(y) _y = (y);
141 (void)(&_x == &_y);
142 _x < _y ? _x : _y;
143 })
144/** @brief ABS macro for absolute value, which evaluates the expression once and
145 returns the absolute value.
146 @details This macro uses a compound statement to create a local scope for
147 the temporary variable _a, which stores the value of x. This ensures that if
148 x has side effects (such as being incremented), it will only be evaluated
149 once when the macro is expanded. The use of typeof allows the macro to work
150 with any data type that supports comparison with zero and negation.
151 */
152#define ABS(x)
153 ({
154 __typeof__(x) _a = (x);
155 _a < 0 ? -_a : _a;
156 })
157#define S_TOLOWER(c)
158 ({
159 int __c = (c);
160 (__c >= 'A' && __c <= 'Z') ? (__c + ('a' - 'A')) : __c;
161 })
162#define S_TOUPPER(c)
163 ({
164 int __c = (c);
165 (__c >= 'a' && __c <= 'z') ? (__c - ('a' - 'A')) : __c;
166 })
167
168/** to_uppercase(c) - convert a lowercase letter to uppercase */
169#define to_uppercase(c)
170 if (c >= 'a' && c <= 'z')
171 c -= ' '
172/** to_lowercase(c) - convert an uppercase letter to lowercase */
173#define to_lowercase(c)
174 if (c >= 'A' && c <= 'Z')
175 c += ' '
176/**
177 @brief Used for xterm256 color conversions
178 */
179
180typedef enum {
181 /** byte 0 - bits 0-7 Selection Flags*/
182 LF_HIDE = 0b00000001, /**< 1 Don't list hidden files */
183 LF_ICASE = 0b00000010, /**< 2 Ignore case in search */
184 LF_EXC_REGEX = 0b00000100, /**< 4 Exclude files matching regex */
185 LF_REGEX = 0b00001000, /**< 8 Include files matching regex */
186 LF_EXEC = 0b00010000, /**< 16 Execute command each file */
187 LF_USER = 0b00100000, /**< 32 Select User Name */
188 /** << 16 */
189 /** byte 1 - bits 8-15 */
190 LF_IXUSR = 0b00000001, /**< 1 Select Files with Execute Permission */
191 LF_IWUSR = 0b00000010, /**< 2 Select Files with Write Permission */
192 LF_IRUSR = 0b00000100, /**< 4 Select Files with Read Permission */
193 LF_ISGID = 0b00010000, /**< 16 Select Setgid Files */
194 LF_ISUID = 0b00100000, /**< 32 Select Setuid Files */
195} LFFlags;
196
197/** byte 2 - bits 16-23 File types*/
198typedef enum {
199 LF_FIFO = 0b00000001, /**< 1 named pipe */
200 LF_CHR = 0b00000010, /**< 2 character device */
201 LF_DIR = 0b00000100, /**< 4 directory */
202 LF_BLK = 0b00001000, /**< 8 block */
203 LF_REG = 0b00010000, /**< 16 regular file */
204 LF_LNK = 0b00100000, /**< 32 link */
205 LF_SOCK = 0b01000000, /**< 64 socket */
206 LF_UNKNOWN = 0b10000000 /**< 128 unknown */
207} LFTypes;
208
209typedef enum {
210 F_F0, // 0
211 F_FIFO, // 1
212 F_CHR, // 2
213 F_F1, // 3
214 F_DIR, // 4
215 F_F2, // 5
216 F_BLK, // 6
217 F_F3, // 7
218 F_REG, // 8
219 F_F4, // 9
220 F_LNK, // 10
221 F_F5, // 11
222 F_SOCK, // 12
223 F_F6, // 13
225} F_Type;
226
227// int const lf_type[][15] = {
228// {0, 0b00000001, 0b00000010, 0, 0b00000100, 0, 0b00001000, 0, 0b00010000, 0,
229// 0b00100000, 0,0b01000000, 0, 0b10000000}};
230
231/*
232 * dirent d_type to lf_type for reference
233------------------------ --------------------
234d_type binary dec lf_type binary dec ordinal
235--------- -------- --- ----------- -------- --- -------
236DT_FIFO: 00000001 1 LF_FIFO: 00000001 1 1
237DT_CHR: 00000010 2 LF_CHR: 00000010 2 2
238DT_DIR: 00000100 4 LF_DIR: 00000100 4 3
239DT_BLK: 00000110 6 LF_BLK: 00001000 8 4
240DT_REG: 00001000 8 LF_REG: 00010000 16 5
241DT_LNK: 00001010 10 LF_LNK: 00100000 32 6
242DT_SOCK: 00001100 12 LF_SOCK: 01000000 64 7
243DT_UNKNOWN: 00001110 14 LF_UNKNOWN: 10000000 128 8
244
245 */
246
247#define F_NO_STDERR 1
248
249/**
250 Include Exclude
251 ---------- ----------
252 LF_FIFO 1 0 00000001 7 11111110 named pipe
253 LF_CHR 2 1 00000010 6 11111101 character device
254 LF_DIR 4 2 00000100 5 11111011 directory
255 LF_BLK 8 3 00001000 4 11110111 block device
256 LF_REG 16 4 00010000 3 11101111 regular file
257 LF_LNK 32 5 00100000 2 11011111 link
258 LF_SOCK 64 6 01000000 1 10111111 socket
259 LF_UNKNOWN 128 7 10000000 0 01111111 unknown
260*/
261
262#define DEFAULTSHELL "/bin/bash"
263#define S_WCOK 0x1000 /**< write or create permitted */
264#define S_QUIET 0x2000 /**< quiet mode flag for file validation */
265
266/** @brief This macro registers the end_pgm function to be called when the
267 program exits.
268 @details It checks the return value of atexit() to ensure that the
269 registration was successful, and if not, it prints an error message and
270 exits with a failure status. Programs using libcm should call __atexit in
271 their main function to ensure that the end_pgm function is registered to be
272 called on program exit. This will help ensure that the terminal is properly
273 restored to its original state, even if the program encounters an error or
274 is terminated unexpectedly. */
275#define __atexit
276 {
277 int rc;
278 rc = atexit(end_pgm);
279 if (rc != 0) {
280 fprintf(stderr, "\nCannot set exit function\n");
281 exit(EXIT_FAILURE);
282 }
283 }
284
285extern UiChyron *wait_mk_chyron();
286extern bool wait_destroy(UiChyron *);
287extern bool waitpid_with_timeout(pid_t, uint);
288extern int wait_timeout;
289extern int fork_detach_execvp(char **);
290extern bool is_hex_str(char *, uint);
291extern bool unstr_hex_clr(char *, char *);
292
293extern bool f_debug; /**< a flag to indicate whether debug
294output should be printed, for debugging purposes */
295
296/**< see termios.h */
297extern struct termios shell_tioctl, program_tioctl;
298extern struct termios shell_in_tioctl, program_in_tioctl;
299extern struct termios shell_out_tioctl, program_out_tioctl;
300extern struct termios shell_err_tioctl, program_err_tioctl;
301
302extern bool f_have_shell_tioctl; /**< shell tioctl captured */
303extern bool f_have_program_tioctl; /**< program tioctl captured */
304extern bool f_program_open; /**< program mode is active */
305extern bool f_restore_screen; /**< whether to restore the screen */
306
307extern void dump_opts(); /**< dump options to stdout */
308
309extern void dump_opts_by_use(char *, char *); /**< dump options to stdout */
310extern bool capture_shell_tioctl();
311extern bool restore_shell_tioctl();
312extern bool capture_program_tioctl();
313extern bool restore_program_tioctl();
314extern bool mk_raw_tioctl(struct termios *);
315extern bool set_sane_tioctl(struct termios *);
316extern void win_resize(uint, uint, char *);
317extern void signal_handler(int);
318extern bool handle_signal(sig_atomic_t);
319extern volatile sig_atomic_t sig_received;
320extern void sig_prog_mode();
321extern void sig_dfl_mode();
322extern bool mk_dir(char *dir);
323extern int segmentation_fault();
324extern bool parse_local_timestamp(const char *, time_t *);
325extern char *format_local_timestamp(time_t, char *, size_t);
326extern char *get_local_timestamp();
327extern char *get_user_str(char *, size_t);
328extern char *get_ip_addresses(char *, uint);
329extern bool is_newer(char *, char *);
330
331#define KEY_ALTF0 0x138
332#define KEY_ALTF(n) (KEY_ALTF0 + (n)) /**< define alt function keys */
333
334extern uint n_lines; /**< number of lines in the terminal */
335extern uint n_cols; /**< number of columns in the terminal */
336// extern uint lines; current number of lines (may be less than n_lines if
337// the terminal is resized)
338// extern uint cols; current number of columns (may be less than n_cols
339// if the
340// terminal is resized) extern int begx;
341// beginning x coordinate of the terminal */
342// extern uint begy; beginning y coordinate of the terminal
343//
344#define MAXWIN 30 /**< maximum number of windows that can be created */
345typedef unsigned char uchar;
346
347extern void sig_prog_mode();
348extern void sig_shell_mode();
349extern char di_getch();
350extern uint enter_option();
351
352extern uint16_t win_attr; /**< Ncurses attributes for the current window, such as
353 color pair, bold, etc. */
354// extern bool win_pair; /**< Flag to indicate whether the current window is
355// part of a window pair */
356extern uint
357 mlines; /**< number of lines in the current window, which may be less than
358 the total number of lines in the terminal if the window is
359 resized or if multiple windows are being used. */
360extern uint
361 mcols; /**< number of columns in the current window, which may be less than
362 the total number of columns in the terminal if the window is
363 resized or if multiple windows are being used. */
364extern uint
365 mbegy; /**< beginning y coordinate of the current window, which can be used
366 to determine the position of the window on the terminal screen. */
367extern uint
368 mbegx; /**< beginning x coordinate of the current window, which can be used
369 to determine the position of the window on the terminal screen. */
370extern uint mg_action; /**< action in progress, which can be used to keep track
371 of the current state of the program and determine how
372 to respond to user input or other events. */
373extern uint mg_col; /**< window column, which can be used to determine the
374 current column position in the window for displaying text
375 or other content. */
376extern uint mg_line; /**< window line, which can be used to determine the current line
377 position in the window for displaying text or other content. */
378extern int stdin_fd; /**< the file descriptor for the terminal, for error messages */
379extern int stdout_fd; /**< the file descriptor for the terminal, for error messages */
380extern int stderr_fd; /**< the file descriptor for the terminal, for error messages
381 and other output */
382extern uint
383 dbgfd; /**< the file descriptor for debug output, for debugging purposes */
384extern uint src_line; /**< the line number of the source file being processed,
385 for error messages */
386extern char *src_name; /**< the name of the source file being processed, for
387 error messages */
388extern char fn[MAXLEN]; /**< function name for error messages */
389
390extern int exit_code; /**< the exit code for the program, for error messages and
391 other output */
392
393extern void win_del();
394extern void restore_wins();
395extern void win_init_attrs();
396extern void win_Toggle_Attrs();
398extern void init_stdscr();
399extern bool get_argp_doc_by_name(char *comment, const struct argp_option *, const char *);
400
401typedef struct {
402 char *s;
403 size_t l;
404} Arg;
405typedef struct {
406 Arg **v;
407 size_t n;
408} Argv;
409typedef struct {
410 char *s;
411 size_t l;
412} String;
413typedef struct {
414 wchar_t *s;
415 size_t l;
416} WCStr;
417/** simple macro to convert a character to uppercase */
418#define to_uppercase(c)
419 if (c >= 'a' && c <= 'z')
420 c -= ' '
421
422typedef struct {
423 uint flin;
424 uint fcol;
425 uint flen;
426 uint ff;
429} CmField;
430extern int a_toi(char *, bool *);
431extern bool chrep(char *, char, char);
432extern char *rep_substring(const char *, const char *, const char *) __attribute__((nonnull(1, 2, 3)));
433extern size_t strip_ansi(char *, char *);
434extern bool strip_quotes(char *);
435extern bool stripz_quotes(char *);
436extern int str_to_args(char **, char *, uint);
437extern int destroy_argv(uint argc, char **argv);
438extern bool str_to_bool(const char *);
439extern bool str_to_lower(char *);
440extern bool str_to_upper(char *);
441extern bool strnfill(char *, char, uint);
442extern bool str_subc(char *, char *, char, char *, uint);
443extern size_t strnz(char *, size_t);
444extern size_t strnlf(char *, size_t);
445extern char *strnz_dup(char *, size_t);
446extern size_t ssnprintf(char *, size_t, const char *, ...);
447size_t strnz__cpy(char *, const char *, size_t);
448size_t strnz__cat(char *, const char *, size_t);
449extern double str_to_double(char *);
450extern size_t string_cpy(String *, const String *);
451extern size_t string_cat(String *, const String *);
452extern size_t string_ncat(String *, const String *, size_t);
453extern size_t string_ncpy(String *, const String *, size_t);
454extern size_t trim(char *);
455extern size_t rtrim(char *);
456extern String to_string(const char *);
457extern String mk_string(size_t);
458extern String free_string(String);
459extern int fork_exec(char **);
460extern int full_screen_fork_exec(char **);
461extern int full_screen_shell(char *);
462extern int shell(char *);
463extern char errmsg[];
464extern void get_rfc3339_s(char *, size_t);
465extern void display_argv_error_msg(char *, char **);
466extern void user_end();
467extern unsigned long a_to_ul(const char *);
468extern size_t canonicalize_file_spec(char *);
469extern bool construct_file_spec(char *, char *, char *, char *, char *, uint);
470extern bool file_spec_path(char *, char *);
471extern bool file_spec_name(char *, char *);
472extern bool is_directory(const char *);
473extern bool is_symlink_to_dir(const char *);
474extern bool is_valid_regex(const char *);
475extern bool dir_name(char *, char *);
476extern bool base_name(char *, char *);
477extern bool expand_tilde(char *, uint);
478extern bool locate_file_in_path(char *, char *);
479extern bool normalize_file_spec(char *);
480extern bool trim_ext(char *, char *);
481extern bool trim_path(char *);
482extern bool verify_file(char *, uint);
483extern bool verify_file_q(char *, uint);
484extern bool verify_dir(char *, uint);
485extern bool verify_dir_q(char *, uint);
486extern bool verify_spec_arg(char *, char *, char *, char *, uint);
487extern char *fdname(int, char *);
488extern char *stdio_names(char *, char *);
489extern char *stdio_fdnames(char *, char *);
490extern char stdio_names_str[4096];
491extern void left_justify(char *s);
492extern void right_justify(char *, uint);
493
494extern bool is_valid_date(uint yyyy, uint mm, uint dd);
495extern bool is_valid_time(uint hh, uint mm, uint ss);
496extern void numeric(char *d, char *s);
497extern int cf_accept(UiSurface *, ss_t w, char *, uint, uint, uint);
498extern char *fill_field(char *, char *, char, uint);
499extern bool is_image_file(const char *filename);
500char *strerror__r(int errnum, char *buf, size_t buflen);
501
502#ifdef __cplusplus
503}
504#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]
volatile sig_atomic_t sig_received
Definition sig.c:32
size_t rtrim(char *)
Trims trailing spaces from string s in place.
Definition futil.c:308
bool handle_signal(sig_atomic_t)
void win_Toggle_Attrs()
uint mlines
uint mbegx
bool strnfill(char *, char, uint)
void sig_shell_mode()
void get_rfc3339_s(char *, size_t)
bool f_have_shell_tioctl
Definition scriou.c:24
bool waitpid_with_timeout(pid_t, uint)
void init_stdscr()
struct termios shell_out_tioctl program_out_tioctl
Definition scriou.c:36
char stdio_names_str[4096]
Definition futil.c:122
bool verify_dir_q(char *, uint)
uint dbgfd
@ F_REG
Definition cm.h:218
@ F_BLK
Definition cm.h:216
@ F_FIFO
Definition cm.h:211
@ F_F0
Definition cm.h:210
@ F_F3
Definition cm.h:217
@ F_SOCK
Definition cm.h:222
@ F_CHR
Definition cm.h:212
@ F_F5
Definition cm.h:221
@ F_F1
Definition cm.h:213
@ F_DIR
Definition cm.h:214
@ F_UNKNOWN
Definition cm.h:224
@ F_F2
Definition cm.h:215
@ F_F4
Definition cm.h:219
@ F_LNK
Definition cm.h:220
@ F_F6
Definition cm.h:223
#define KEY_ALTF0
Definition cm.h:331
uint n_lines
void restore_wins()
int stdout_fd
Definition ui_common.c:61
void dump_opts()
void win_del()
void win_resize(uint, uint, char *)
bool construct_file_spec(char *, char *, char *, char *, char *, uint)
struct termios shell_tioctl program_tioctl
Definition scriou.c:34
char * stdio_names(char *, char *)
Definition futil.c:1083
unsigned char uchar
Definition cm.h:345
String mk_string(size_t)
Create a String struct with a dynamically allocated string.
Definition futil.c:1550
uint mg_col
uint n_cols
bool verify_file_q(char *, uint)
char fn[MAXLEN]
Definition ui_common.c:45
void win_init_attrs()
struct termios shell_in_tioctl program_in_tioctl
Definition scriou.c:35
bool f_debug
uint mg_line
void dump_opts_by_use(char *, char *)
char errmsg[]
Definition futil.c:126
uint src_line
Definition ui_common.c:43
int wait_timeout
Definition futil.c:140
@ LF_EXC_REGEX
Definition cm.h:184
@ LF_HIDE
Definition cm.h:182
@ LF_ISUID
Definition cm.h:194
@ LF_IRUSR
Definition cm.h:192
@ LF_ICASE
Definition cm.h:183
@ LF_ISGID
Definition cm.h:193
@ LF_EXEC
Definition cm.h:186
@ LF_REGEX
Definition cm.h:185
@ LF_USER
Definition cm.h:187
@ LF_IXUSR
Definition cm.h:190
@ LF_IWUSR
Definition cm.h:191
bool f_restore_screen
@ LF_FIFO
Definition cm.h:199
@ LF_DIR
Definition cm.h:201
@ LF_UNKNOWN
Definition cm.h:206
@ LF_SOCK
Definition cm.h:205
@ LF_BLK
Definition cm.h:202
@ LF_LNK
Definition cm.h:204
@ LF_REG
Definition cm.h:203
@ LF_CHR
Definition cm.h:200
int exit_code
Definition ui_common.c:31
FILE * tty_fp
struct termios shell_err_tioctl program_err_tioctl
Definition scriou.c:37
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:104
uint16_t win_attr
Definition ui_common.c:34
int stdin_fd
Definition ui_common.c:61
bool f_program_open
uint mbegy
bool str_to_bool(const char *)
Converts String to boolean true or false.
Definition futil.c:960
uint mcols
#define __atexit
This macro registers the end_pgm function to be called when the program exits.
Definition cm.h:275
bool is_image_file(const char *filename)
char * src_name
Definition ui_common.c:44
char * fill_field(char *, char *, char, uint)
Definition futil.c:1714
uint mg_action
char * stdio_fdnames(char *, char *)
Definition futil.c:1108
void user_end()
UiChyron * wait_mk_chyron()
int display_curses_keys()
bool f_have_program_tioctl
Definition scriou.c:25
uint enter_option()
#define Ctrl(c)
Definition cm.h:67
int stderr_fd
Definition ui_common.c:61
void display_argv_error_msg(char *, char **)
bool wait_destroy(UiChyron *)
char * rep_substring(const char *, const char *, const char *) __attribute__((nonnull(1
Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
Definition futil.c:1449
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
struct termios shell_tioctl
Definition scriou.c:22
int fork_exec(char **)
Fork and exec a command.
Definition exec.c:122
int shell(char *)
Execute a shell command.
Definition exec.c:74
int full_screen_fork_exec(char **)
Execute a command in full screen mode.
Definition exec.c:45
int full_screen_shell(char *)
Execute a shell command in full screen mode.
Definition exec.c:58
int fork_detach_execvp(char **eargv)
Fork, set new session ID, close files, and execute detached command.
Definition detach.c:41
bool is_valid_date(uint yyyy, uint mm, uint dd)
Check if a given date is valid, including leap years.
Definition fields.c:612
void numeric(char *d, char *s)
Extract numeric characters from source string to destination string.
Definition fields.c:649
bool is_valid_time(uint hh, uint mm, uint ss)
Check if a given time is valid.
Definition fields.c:633
void right_justify(char *, uint)
Right justify string by removing trailing spaces and adding leadingspaces.
Definition fields.c:586
void left_justify(char *s)
Left justify string by removing leading spaces.
Definition fields.c:573
int init_form(Init *, int, char **, uint, uint)
Initialize form data structure and parse description file.
Definition form_engine.c:61
bool locate_file_in_path(char *, char *)
Locates a file in the system PATH.
Definition futil.c:1296
size_t canonicalize_file_spec(char *)
Removes quotes and trims at first space.
Definition futil.c:1350
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition whence.c:291
bool parse_local_timestamp(const char *, time_t *)
Parses an ISO 8601 timestamp string in local time and converts it to time_t.
Definition futil.c:250
bool trim_ext(char *, char *)
trims the file extension from "filename" and copies the result to "buf"
Definition futil.c:1035
bool stripz_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:723
size_t trim(char *)
Trims leading and trailing spaces from string s in place.
Definition futil.c:361
char * get_local_timestamp()
Returns the current local time as an ISO 8601 formatted string.
Definition futil.c:284
bool is_directory(const char *)
Checks if the given path is a directory.
Definition futil.c:1381
bool file_spec_path(char *, char *)
extracts the path component of a file specification
Definition futil.c:889
bool str_to_upper(char *)
Converts a string to uppercase.
Definition futil.c:496
bool dir_name(char *, char *)
Returns the directory name of a file specification.
Definition futil.c:1158
bool is_hex_str(char *, uint)
Validates that a string consists of exactly len hexadecimal digits.
Definition futil.c:197
double str_to_double(char *)
converts string to double
Definition futil.c:948
bool str_to_lower(char *)
Converts a string to lowercase.
Definition futil.c:482
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:599
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
bool strip_quotes(char *)
removes leading and trailing double quotes if present
Definition futil.c:710
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:412
bool is_valid_regex(const char *)
Checks if the given regular expression pattern is valid.
Definition futil.c:1409
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:989
char * strnz_dup(char *, size_t)
Allocates memory for and duplicates string s up to length l or until line feed or carriage return.
Definition futil.c:642
bool file_spec_name(char *, char *)
extracts the file name component of a file specification
Definition futil.c:916
char size_t strip_ansi(char *, char *)
Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
Definition futil.c:848
bool mk_dir(char *dir)
If directory doesn't exist, make it.
Definition futil.c:1329
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition whence.c:320
bool get_argp_doc_by_name(char *comment, const struct argp_option *, const char *)
Retrieves the documentation string for a given key name from an argp options array.
Definition futil.c:164
char * get_ip_addresses(char *, uint)
Retrieves the IP addresses of the local machine and formats them into a string.
Definition futil.c:324
bool is_symlink_to_dir(const char *)
Checks if the given path is a symbolic link to a directory.
Definition futil.c:1394
bool verify_file(char *, uint)
Verifies that the file specified by "in_spec" exists and is accessible with the permissions specified...
Definition futil.c:1249
size_t strnlf(char *, size_t)
terminates string with line feed
Definition futil.c:619
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:784
bool str_subc(char *, char *, char, char *, uint)
Replaces "ReplaceChr" in "s" with "Withstr" in "d" won't copy more than "l" bytes to "d" Replaces all...
Definition futil.c:680
char * strerror__r(int errnum, char *buf, size_t buflen)
A thread-safe alternative to strerror() that writes the error message corresponding to errnum into th...
Definition futil.c:748
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:468
bool chrep(char *, char, char)
Replaces all occurrences of old_chr in s with new_chr in place.
Definition futil.c:765
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1132
bool normalize_file_spec(char *)
replace backslashes with forward lashes
Definition futil.c:872
char * format_local_timestamp(time_t, char *, size_t)
Formats a time_t as an ISO 8601 string in local time.
Definition futil.c:273
bool is_newer(char *, char *)
Checks if the file specified by "fut" is newer than the file specified by "control".
Definition futil.c:148
char * fdname(int, char *)
Retrieves the file path associated with a given file descriptor.
Definition futil.c:1073
bool verify_dir(char *, uint)
Verifies that the directory specified by "spec" exists and is accessible with the permissions specifi...
Definition futil.c:1198
char * get_user_str(char *, size_t)
Retrieves the current user's name and UID, and formats it into a string.
Definition futil.c:297
bool trim_path(char *)
Trims trailing spaces and slashes from directory path in place.
Definition futil.c:1007
unsigned long a_to_ul(const char *)
Converts a string to an unsigned long long integer, with support for suffixes K, M,...
Definition futil.c:812
bool unstr_hex_clr(char *, char *)
Validates that a string is a hex color code in the format "#RRGGBB".
Definition futil.c:220
size_t string_cpy(String *, const String *)
Copy src String to dest String, allocating additional memory for dest String if necessary.
Definition futil.c:1584
String to_string(const char *)
String functions provide a simple string library to facilitate string manipulation in C,...
Definition futil.c:1530
size_t string_ncpy(String *, const String *, size_t)
copies up to n characters from src String to dest String, allocating additional memory for dest Strin...
Definition futil.c:1641
size_t string_cat(String *, const String *)
Concatenates src String to dest String, allocating additional memory for dest String if necessary.
Definition futil.c:1601
String free_string(String)
Free the dynamically allocated String.
Definition futil.c:1569
size_t string_ncat(String *, const String *, size_t)
Concatenates up to n characters from src String to dest String, allocating additional memory for dest...
Definition futil.c:1620
int segmentation_fault()
Function to intentionally cause a segmentation fault for testing purposes.
Definition futil.c:1666
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
bool verify_spec_arg(char *, char *, char *, char *, uint)
Verify file specification argument.
Definition mem.c:361
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
bool restore_program_tioctl()
restore_program_tioctl() - restore program terminal settings
Definition scriou.c:84
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition scriou.c:43
char di_getch()
get single character from terminal in raw mode
Definition scriou.c:158
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
Definition scriou.c:132
bool set_sane_tioctl(struct termios *)
set_sane_tioctl() - set terminal to sane settings for C-MENU
Definition scriou.c:99
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57
bool capture_program_tioctl()
capture_program_tioctl() - capture program terminal settings
Definition scriou.c:70
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:41
void signal_handler(int)
Signal handler for interrupt signals.
Definition sig.c:94
void sig_prog_mode()
Set up signal handlers for interrupt signals.
Definition sig.c:61
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.
uint mm
Definition cm.h:72
uint dd
Definition cm.h:73
uint yyyy
Definition cm.h:71
uint hh
Definition cm.h:77
uint mm
Definition cm.h:78
uint ss
Definition cm.h:79
char * s
Definition cm.h:402
size_t l
Definition cm.h:403
Arg ** v
Definition cm.h:406
size_t n
Definition cm.h:407
size_t l
Definition cm.h:411
char * s
Definition cm.h:410
size_t l
Definition cm.h:415
wchar_t * s
Definition cm.h:414
char fill_char
Definition cm.h:427
uint ff
Definition cm.h:426
uint flen
Definition cm.h:425
uint fcol
Definition cm.h:424
uint flin
Definition cm.h:423
bool cf_erase_remainder
Definition cm.h:428
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