C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
cm.h File Reference

Headder for C-Menu API library, libcm.so. More...

#include "version.h"
#include <argp.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#include <wait.h>
#include <wchar.h>
#include <stdio.h>
Include dependency graph for cm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Arg
struct  Argv
struct  CmField
struct  Date
struct  String
struct  Time
struct  WCStr

Macros

#define _(String)
#define __atexit
 This macro registers the end_pgm function to be called when the program exits.
#define _GNU_SOURCE
#define _XOPEN_SOURCE_EXTENDED   1
#define ABS(x)
 ABS macro for absolute value, which evaluates the expression once and returns the absolute value.
#define bindtextdomain(Package, Directory)
#define Ctrl(c)
#define DEFAULTSHELL   "/bin/bash"
#define DIV_ROUND_UP(n, d)
#define F_NO_STDERR   1
#define KEY_ALTF(n)
#define KEY_ALTF0   0x138
#define MAX(a, b)
 MIN macro for compatibility with code that uses the same name, while avoiding multiple evaluations of the arguments.
#define max(a, b)
 max macro evaluates two expressions, returning greatest result.
#define MAX_ARGS   64
#define MAXARGS   64
#define MAXLEN   256
#define MAXWIN   30
#define MAXWIN   30
#define MIN(x, y)
 MAX macro for compatibility with code that uses the same name, while avoiding multiple evaluations of the arguments.
#define min(x, y)
 min macro evaluates two expressions, returning least result
#define N_(String)
#define NCURSES_WIDECHAR   1
#define nullptr   NULL
#define S_QUIET   0x2000
#define S_TOLOWER(c)
#define S_TOUPPER(c)
#define S_WCOK   0x1000
#define SCR_COLS   1024
#define SCREEN_MAX_LINES   100
#define textdomain(Domain)
#define to_lowercase(c)
#define to_uppercase(c)
#define to_uppercase(c)

Typedefs

typedef unsigned char uchar

Enumerations

enum  F_Type {
  F_F0 , F_FIFO , F_CHR , F_F1 ,
  F_DIR , F_F2 , F_BLK , F_F3 ,
  F_REG , F_F4 , F_LNK , F_F5 ,
  F_SOCK , F_F6 , F_UNKNOWN
}
enum  LFFlags {
  LF_HIDE = 0b00000001 , LF_ICASE = 0b00000010 , LF_EXC_REGEX = 0b00000100 , LF_REGEX = 0b00001000 ,
  LF_EXEC = 0b00010000 , LF_USER = 0b00100000 , LF_IXUSR = 0b00000001 , LF_IWUSR = 0b00000010 ,
  LF_IRUSR = 0b00000100 , LF_ISGID = 0b00010000 , LF_ISUID = 0b00100000
}
 Used for xterm256 color conversions. More...
enum  LFTypes {
  LF_FIFO = 0b00000001 , LF_CHR = 0b00000010 , LF_DIR = 0b00000100 , LF_BLK = 0b00001000 ,
  LF_REG = 0b00010000 , LF_LNK = 0b00100000 , LF_SOCK = 0b01000000 , LF_UNKNOWN = 0b10000000
}

Functions

unsigned long a_to_ul (const char *)
 Converts a string to an unsigned long long integer, with support for suffixes K, M, and G for kilobytes, megabytes, and gigabytes respectively.
int a_toi (char *, bool *)
 a safer alternative to atoi() for converting ASCII strings to integers.
bool base_name (char *, char *)
 Returns the base name of a file specification.
size_t canonicalize_file_spec (char *)
 Removes quotes and trims at first space.
bool capture_program_tioctl ()
 capture_program_tioctl() - capture program terminal settings
bool capture_shell_tioctl ()
 capture_shell_tioctl() - capture shell terminal settings
int cf_accept (UiSurface *, ss_t w, char *, uint, uint, uint)
 Accepts input for a field in a C-Menu window.
bool chrep (char *, char, char)
 Replaces all occurrences of old_chr in s with new_chr in place.
bool construct_file_spec (char *, char *, char *, char *, char *, uint)
int destroy_argv (uint argc, char **argv)
 Deallocates memory allocated for argument strings in argv.
char di_getch ()
 get single character from terminal in raw mode
bool dir_name (char *, char *)
 Returns the directory name of a file specification.
void display_argv_error_msg (char *, char **)
int display_curses_keys ()
void dump_opts ()
void dump_opts_by_use (char *, char *)
uint enter_option ()
bool expand_tilde (char *, uint)
 Replaces "~/" in string with the user's home directory.
char * fdname (int, char *)
 Retrieves the file path associated with a given file descriptor.
bool file_spec_name (char *, char *)
 extracts the file name component of a file specification
bool file_spec_path (char *, char *)
 extracts the path component of a file specification
char * fill_field (char *, char *, char, uint)
int fork_detach_execvp (char **)
 Fork, set new session ID, close files, and execute detached command.
int fork_exec (char **)
 Fork and exec a command.
char * format_local_timestamp (time_t, char *, size_t)
 Formats a time_t as an ISO 8601 string in local time.
String free_string (String)
 Free the dynamically allocated String.
int full_screen_fork_exec (char **)
 Execute a command in full screen mode.
int full_screen_shell (char *)
 Execute a shell command in full screen mode.
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.
char * get_ip_addresses (char *, uint)
 Retrieves the IP addresses of the local machine and formats them into a string.
char * get_local_timestamp ()
 Returns the current local time as an ISO 8601 formatted string.
void get_rfc3339_s (char *, size_t)
char * get_user_str (char *, size_t)
 Retrieves the current user's name and UID, and formats it into a string.
bool handle_signal (sig_atomic_t)
void init_stdscr ()
bool is_directory (const char *)
 Checks if the given path is a directory.
bool is_hex_str (char *, uint)
 Validates that a string consists of exactly len hexadecimal digits.
bool is_image_file (const char *filename)
bool is_newer (char *, char *)
 Checks if the file specified by "fut" is newer than the file specified by "control".
bool is_symlink_to_dir (const char *)
 Checks if the given path is a symbolic link to a directory.
bool is_valid_date (uint yyyy, uint mm, uint dd)
 Check if a given date is valid, including leap years.
bool is_valid_regex (const char *)
 Checks if the given regular expression pattern is valid.
bool is_valid_time (uint hh, uint mm, uint ss)
 Check if a given time is valid.
void left_justify (char *s)
 Left justify string by removing leading spaces.
bool locate_file_in_path (char *, char *)
 Locates a file in the system PATH.
bool mk_dir (char *dir)
 If directory doesn't exist, make it.
bool mk_raw_tioctl (struct termios *)
 mk_raw_tioctl() - set terminal to raw mode
String mk_string (size_t)
 Create a String struct with a dynamically allocated string.
bool normalize_file_spec (char *)
 replace backslashes with forward lashes
void numeric (char *d, char *s)
 Extract numeric characters from source string to destination string.
bool parse_local_timestamp (const char *, time_t *)
 Parses an ISO 8601 timestamp string in local time and converts it to time_t.
char * rep_substring (const char *, const char *, const char *) __attribute__((nonnull(1
 Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
bool restore_program_tioctl ()
 restore_program_tioctl() - restore program terminal settings
bool restore_shell_tioctl ()
 restore_shell_tioctl() - restore shell terminal settings
void restore_wins ()
void right_justify (char *, uint)
 Right justify string by removing trailing spaces and adding leadingspaces.
size_t rtrim (char *)
 Trims trailing spaces from string s in place.
int segmentation_fault ()
 Function to intentionally cause a segmentation fault for testing purposes.
bool set_sane_tioctl (struct termios *)
 set_sane_tioctl() - set terminal to sane settings for C-MENU
int shell (char *)
 Execute a shell command.
void sig_dfl_mode ()
 Set signal handlers to default behavior.
void sig_prog_mode ()
 Set up signal handlers for interrupt signals.
void sig_shell_mode ()
void signal_handler (int)
 Signal handler for interrupt signals.
size_t ssnprintf (char *, size_t, const char *,...)
 ssnprintf was designed to be a safer alternative to snprintf.
char * stdio_fdnames (char *, char *)
char * stdio_names (char *, char *)
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 occurrences of a character in a string with another string, copying the result to a destination buffer.
int str_to_args (char **, char *, uint)
 Converts a string into an array of argument strings.
bool str_to_bool (const char *)
 Converts String to boolean true or false.
double str_to_double (char *)
 converts string to double
bool str_to_lower (char *)
 Converts a string to lowercase.
bool str_to_upper (char *)
 Converts a string to uppercase.
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 the provided buffer.
size_t string_cat (String *, const String *)
 Concatenates src String to dest String, allocating additional memory for dest String if necessary.
size_t string_cpy (String *, const String *)
 Copy src String to dest String, allocating additional memory for dest String if necessary.
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 String if necessary.
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 String if necessary
char size_t strip_ansi (char *, char *)
 Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
bool strip_quotes (char *)
 removes leading and trailing double quotes if present
bool stripz_quotes (char *)
 removes leading and trailing double quotes if present
bool strnfill (char *, char, uint)
size_t strnlf (char *, size_t)
 terminates string with line feed
size_t strnz (char *, size_t)
 terminates string at New Line, Carriage Return, or max_len
size_t strnz__cat (char *, const char *, size_t)
 safer alternative to strncat
size_t strnz__cpy (char *, const char *, size_t)
 safer alternative to strncpy
char * strnz_dup (char *, size_t)
 Allocates memory for and duplicates string s up to length l or until line feed or carriage return.
String to_string (const char *)
 String functions provide a simple string library to facilitate string manipulation in C, allowing developers to easily create, copy, concatenate, and free strings without having to manage memory manually.
size_t trim (char *)
 Trims leading and trailing spaces from string s in place.
bool trim_ext (char *, char *)
 trims the file extension from "filename" and copies the result to "buf"
bool trim_path (char *)
 Trims trailing spaces and slashes from directory path in place.
bool unstr_hex_clr (char *, char *)
 Validates that a string is a hex color code in the format "#RRGGBB".
void user_end ()
bool verify_dir (char *, uint)
 Verifies that the directory specified by "spec" exists and is accessible with the permissions specified by "imode".
bool verify_dir_q (char *, uint)
bool verify_file (char *, uint)
 Verifies that the file specified by "in_spec" exists and is accessible with the permissions specified by "imode".
bool verify_file_q (char *, uint)
bool verify_spec_arg (char *, char *, char *, char *, uint)
 Verify file specification argument.
bool wait_destroy (UiChyron *)
UiChyron * wait_mk_chyron ()
bool waitpid_with_timeout (pid_t, uint)
void win_del ()
void win_init_attrs ()
void win_resize (uint, uint, char *)
void win_Toggle_Attrs ()

Variables

uint dbgfd
char errmsg []
int exit_code
bool f_debug
bool f_have_program_tioctl = false
bool f_have_shell_tioctl = false
bool f_program_open
bool f_restore_screen
char fn [MAXLEN]
uint mbegx
uint mbegy
uint mcols
uint mg_action
uint mg_col
uint mg_line
uint mlines
uint n_cols
uint n_lines
struct termios shell_err_tioctl program_err_tioctl
struct termios shell_in_tioctl program_in_tioctl
struct termios shell_out_tioctl program_out_tioctl
struct termios shell_tioctl program_tioctl
volatile sig_atomic_t sig_received = 0
uint src_line
char * src_name
int stderr_fd
int stdin_fd
char stdio_names_str [4096]
int stdout_fd
FILE * tty_fp
int wait_timeout
uint16_t win_attr

Detailed Description

Headder for C-Menu API library, libcm.so.

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file cm.h.

Macro Definition Documentation

◆ _

#define _ ( String)
Value:
Definition cm.h:409

Definition at line 46 of file cm.h.

◆ __atexit

#define __atexit
Value:
{ \
int rc; \
rc = atexit(end_pgm); \
if (rc != 0) { \
fprintf(stderr, "\nCannot set exit function\n"); \
exit(EXIT_FAILURE); \
} \
}

This macro registers the end_pgm function to be called when the program exits.

It checks the return value of atexit() to ensure that the registration was successful, and if not, it prints an error message and exits with a failure status. Programs using libcm should call __atexit in their main function to ensure that the end_pgm function is registered to be called on program exit. This will help ensure that the terminal is properly restored to its original state, even if the program encounters an error or is terminated unexpectedly.

Definition at line 275 of file cm.h.

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 }

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 15 of file cm.h.

◆ _XOPEN_SOURCE_EXTENDED

#define _XOPEN_SOURCE_EXTENDED   1

Enable wide character support

Definition at line 16 of file cm.h.

◆ ABS

#define ABS ( x)
Value:
({ \
__typeof__(x) _a = (x); \
_a < 0 ? -_a : _a; \
})

ABS macro for absolute value, which evaluates the expression once and returns the absolute value.

This macro uses a compound statement to create a local scope for the temporary variable _a, which stores the value of x. This ensures that if x has side effects (such as being incremented), it will only be evaluated once when the macro is expanded. The use of typeof allows the macro to work with any data type that supports comparison with zero and negation.

Definition at line 152 of file cm.h.

152#define ABS(x) \
153 ({ \
154 __typeof__(x) _a = (x); \
155 _a < 0 ? -_a : _a; \
156 })

◆ bindtextdomain

#define bindtextdomain ( Package,
Directory )

Definition at line 49 of file cm.h.

◆ Ctrl

#define Ctrl ( c)
Value:
((c) & 0x1f)

Definition at line 67 of file cm.h.

◆ DEFAULTSHELL

#define DEFAULTSHELL   "/bin/bash"
              Include     Exclude
             ----------  ----------

LF_FIFO 1 0 00000001 7 11111110 named pipe LF_CHR 2 1 00000010 6 11111101 character device LF_DIR 4 2 00000100 5 11111011 directory LF_BLK 8 3 00001000 4 11110111 block device LF_REG 16 4 00010000 3 11101111 regular file LF_LNK 32 5 00100000 2 11011111 link LF_SOCK 64 6 01000000 1 10111111 socket LF_UNKNOWN 128 7 10000000 0 01111111 unknown

Definition at line 262 of file cm.h.

◆ DIV_ROUND_UP

#define DIV_ROUND_UP ( n,
d )
Value:
(((n) + (d) - 1) / (d))

Definition at line 82 of file cm.h.

◆ F_NO_STDERR

#define F_NO_STDERR   1

Definition at line 247 of file cm.h.

◆ KEY_ALTF

#define KEY_ALTF ( n)
Value:
(KEY_ALTF0 + (n))
#define KEY_ALTF0
Definition cm.h:331

define alt function keys

Definition at line 332 of file cm.h.

◆ KEY_ALTF0

#define KEY_ALTF0   0x138

Definition at line 331 of file cm.h.

◆ MAX

#define MAX ( a,
b )
Value:
({ \
typeof(a) _a = (a); \
typeof(y) _b = (b); \
_a > _b ? _a : _b; \
})

MIN macro for compatibility with code that uses the same name, while avoiding multiple evaluations of the arguments.

/usr/include/sys/param.h contains implementations of the MIN and MAX macros, which are simple but can lead to issues with multiple evaluations of the arguments if they have side effects. These macros provides a safer alternative to param.h Here are the macros from /usr/include/sys/param.h. You may comment out the macros defined herein and use the macros in param.h if you prefer.

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
Note
The following macro provides a safer alternative to param.h

Definition at line 127 of file cm.h.

127#define MAX(a, b) \
128 ({ \
129 typeof(a) _a = (a); \
130 typeof(y) _b = (b); \
131 _a > _b ? _a : _b; \
132 })

◆ max

#define max ( a,
b )
Value:
({ \
__typeof__(a) _a = (a); \
__typeof__(a) _b = (b); \
_a > _b ? _a : _b; \
})

max macro evaluates two expressions, returning greatest result.

These macros use compound statements to create local scopes for the temporary variables _x and _y, which store the values of x and y, respectively. This ensures that if x or y have side effects (such as being incremented), they will only be evaluated once when the macro is expanded. The use of typeof allows the macro to work with any data type. The line (void)(&_x == &_y) is a compile-time check to ensure that the types of the arguments are compatible. This implementation of the min and max macros provides a safer and more robust way to determine the minimum and maximum values between two expressions without risking unintended consequences from multiple evaluations.

Definition at line 97 of file cm.h.

97#define max(a, b) \
98 ({ \
99 __typeof__(a) _a = (a); \
100 __typeof__(a) _b = (b); \
101 _a > _b ? _a : _b; \
102 })

◆ MAX_ARGS

#define MAX_ARGS   64

maximum number of arguments for external commands

Definition at line 62 of file cm.h.

◆ MAXARGS

#define MAXARGS   64

maximum number of arguments

Definition at line 64 of file cm.h.

◆ MAXLEN

#define MAXLEN   256

maximum length for strings and buffers

Definition at line 63 of file cm.h.

◆ MAXWIN [1/2]

#define MAXWIN   30

maximum number of windows that can be created

Definition at line 56 of file cm.h.

◆ MAXWIN [2/2]

#define MAXWIN   30

maximum number of windows that can be created

Definition at line 56 of file cm.h.

◆ MIN

#define MIN ( x,
y )
Value:
({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void)(&_x == &_y); \
_x < _y ? _x : _y; \
})

MAX macro for compatibility with code that uses the same name, while avoiding multiple evaluations of the arguments.

Note
The following macro provides a safer alternative to param.h

Definition at line 137 of file cm.h.

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 })

◆ min

#define min ( x,
y )
Value:
({ \
typeof(x) _x = (x); \
typeof(x) _y = (y); \
(void)(&_x == &_y); \
_x < _y ? _x : _y; \
})

min macro evaluates two expressions, returning least result

Definition at line 104 of file cm.h.

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 })

◆ N_

#define N_ ( String)
Value:

Definition at line 47 of file cm.h.

◆ NCURSES_WIDECHAR

#define NCURSES_WIDECHAR   1

Enable wide character support

Definition at line 17 of file cm.h.

◆ nullptr

#define nullptr   NULL

Definition at line 53 of file cm.h.

◆ S_QUIET

#define S_QUIET   0x2000

quiet mode flag for file validation

Definition at line 264 of file cm.h.

◆ S_TOLOWER

#define S_TOLOWER ( c)
Value:
({ \
int __c = (c); \
(__c >= 'A' && __c <= 'Z') ? (__c + ('a' - 'A')) : __c; \
})

Definition at line 157 of file cm.h.

157#define S_TOLOWER(c) \
158 ({ \
159 int __c = (c); \
160 (__c >= 'A' && __c <= 'Z') ? (__c + ('a' - 'A')) : __c; \
161 })

◆ S_TOUPPER

#define S_TOUPPER ( c)
Value:
({ \
int __c = (c); \
(__c >= 'a' && __c <= 'z') ? (__c - ('a' - 'A')) : __c; \
})

Definition at line 162 of file cm.h.

162#define S_TOUPPER(c) \
163 ({ \
164 int __c = (c); \
165 (__c >= 'a' && __c <= 'z') ? (__c - ('a' - 'A')) : __c; \
166 })

◆ S_WCOK

#define S_WCOK   0x1000

write or create permitted

Definition at line 263 of file cm.h.

◆ SCR_COLS

#define SCR_COLS   1024

maximum number of columns in the terminal screen

Definition at line 65 of file cm.h.

◆ SCREEN_MAX_LINES

#define SCREEN_MAX_LINES   100

Definition at line 66 of file cm.h.

◆ textdomain

#define textdomain ( Domain)

Definition at line 48 of file cm.h.

◆ to_lowercase

#define to_lowercase ( c)
Value:
if (c >= 'A' && c <= 'Z') \
c += ' '

to_lowercase(c) - convert an uppercase letter to lowercase

Definition at line 173 of file cm.h.

173#define to_lowercase(c) \
174 if (c >= 'A' && c <= 'Z') \
175 c += ' '

◆ to_uppercase [1/2]

#define to_uppercase ( c)
Value:
if (c >= 'a' && c <= 'z') \
c -= ' '

to_uppercase(c) - convert a lowercase letter to uppercase

simple macro to convert a character to uppercase

Definition at line 169 of file cm.h.

169#define to_uppercase(c) \
170 if (c >= 'a' && c <= 'z') \
171 c -= ' '

◆ to_uppercase [2/2]

#define to_uppercase ( c)
Value:
if (c >= 'a' && c <= 'z') \
c -= ' '

to_uppercase(c) - convert a lowercase letter to uppercase

simple macro to convert a character to uppercase

Definition at line 169 of file cm.h.

169#define to_uppercase(c) \
170 if (c >= 'a' && c <= 'z') \
171 c -= ' '

Typedef Documentation

◆ uchar

typedef unsigned char uchar

Definition at line 345 of file cm.h.

Enumeration Type Documentation

◆ F_Type

enum F_Type
Enumerator
F_F0 
F_FIFO 
F_CHR 
F_F1 
F_DIR 
F_F2 
F_BLK 
F_F3 
F_REG 
F_F4 
F_LNK 
F_F5 
F_SOCK 
F_F6 
F_UNKNOWN 

Definition at line 209 of file cm.h.

209 {
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
224 F_UNKNOWN, // 14
225} F_Type;
F_Type
Definition cm.h:209
@ 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

◆ LFFlags

enum LFFlags

Used for xterm256 color conversions.

Enumerator
LF_HIDE 

byte 0 - bits 0-7 Selection Flags 1 Don't list hidden files

LF_ICASE 

2 Ignore case in search

LF_EXC_REGEX 

4 Exclude files matching regex

LF_REGEX 

8 Include files matching regex

LF_EXEC 

16 Execute command each file

LF_USER 

32 Select User Name

LF_IXUSR 

<< 16 byte 1 - bits 8-15 1 Select Files with Execute Permission

LF_IWUSR 

2 Select Files with Write Permission

LF_IRUSR 

4 Select Files with Read Permission

LF_ISGID 

16 Select Setgid Files

LF_ISUID 

32 Select Setuid Files

Definition at line 180 of file cm.h.

180 {
182 LF_HIDE = 0b00000001,
183 LF_ICASE = 0b00000010,
184 LF_EXC_REGEX = 0b00000100,
185 LF_REGEX = 0b00001000,
186 LF_EXEC = 0b00010000,
187 LF_USER = 0b00100000,
190 LF_IXUSR = 0b00000001,
191 LF_IWUSR = 0b00000010,
192 LF_IRUSR = 0b00000100,
193 LF_ISGID = 0b00010000,
194 LF_ISUID = 0b00100000,
195} LFFlags;
LFFlags
Used for xterm256 color conversions.
Definition cm.h:180
@ 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

◆ LFTypes

enum LFTypes

byte 2 - bits 16-23 File types

Enumerator
LF_FIFO 

1 named pipe

LF_CHR 

2 character device

LF_DIR 

4 directory

LF_BLK 

8 block

LF_REG 

16 regular file

LF_LNK 

32 link

LF_SOCK 

64 socket

LF_UNKNOWN 

128 unknown

Definition at line 198 of file cm.h.

198 {
199 LF_FIFO = 0b00000001,
200 LF_CHR = 0b00000010,
201 LF_DIR = 0b00000100,
202 LF_BLK = 0b00001000,
203 LF_REG = 0b00010000,
204 LF_LNK = 0b00100000,
205 LF_SOCK = 0b01000000,
206 LF_UNKNOWN = 0b10000000
207} LFTypes;
LFTypes
Definition cm.h:198
@ LF_FIFO
Definition cm.h:199
@ LF_UNKNOWN
Definition cm.h:206
@ LF_SOCK
Definition cm.h:205
@ LF_BLK
Definition cm.h:202
@ LF_CHR
Definition cm.h:200
#define LF_DIR
Definition futil.c:44
#define LF_REG
Definition futil.c:45
#define LF_LNK
Definition futil.c:43

Function Documentation

◆ cf_accept()

int cf_accept ( UiSurface * sfc,
ss_t w,
char * accept_s,
uint flin,
uint fcol,
uint flen )
extern

Accepts input for a field in a C-Menu window.

Parameters
UiSurface*sfc The surface to accept input from
winThe window to accept input from
accept_sThe string to accept input into
flinThe line number of the field
fcolThe column number of the field
flenThe length of the field
Returns
The key pressed to exit the field (UIKEY_ENTER, UIKEY_F09, etc.)

< Enter accepts the field and moves to the next field if f_erase_remainder is set, it will clear the remaining characters above and after the current cursor location

UIKEY_IC toggles insert mode

UIKEY_DC deletes character at cursor

UIKEY_HOME moves cursor to start of field

UIKEY_BACKSPACE deletes character before cursor

UIKEY_LEFT moves cursor left one character

UIKEY_RIGHT moves cursor right one character

Handles mouse events for field editing

Definition at line 41 of file cm_fields.c.

41 {
42 bool f_insert = false;
43 int in_key = 0;
44 char *s, *d;
45 char *fstart;
46 UiEvent event;
47
48 click_x = click_y = -1;
49 char *p = fstart = accept_s;
50 char *fend = fstart + flen;
51 int x = fcol;
52 char *str_end = p + strlen(p);
53 while (1) {
54 if (in_key == 0) {
55 ui_mvwaddstr(sfc, w, flin, fcol, accept_s);
56 ui_wclrtoeol(sfc, w);
57 ui_cursor_move(sfc, w, flin, x);
58 ui_render();
59 in_key = ui_get_event(sfc, w, NULL, &event, -1);
60 }
61 ui_curs_set(0);
62 switch (in_key) {
63 case UIKEY_F09:
64 in_key = UIKEY_F09;
65 return (in_key);
66 case '\t':
67 case UIKEY_END:
68 case Ctrl('e'):
69 while (*p != '\0')
70 p++;
71 x = fcol + (p - fstart);
72 in_key = 0;
73 continue;
77 case '\n':
78 case UIKEY_ENTER:
80 *p = '\0';
81 in_key = UIKEY_ENTER;
82 return (in_key);
84 case UIKEY_IC:
85 f_insert = !f_insert;
86 in_key = 0;
87 continue;
89 case UIKEY_DC:
90 s = p + 1;
91 d = p;
92 while (*s != '\0')
93 *d++ = *s++;
94 *d = '\0';
95 str_end = d;
96 f_insert = false;
97 in_key = 0;
98 continue;
100 case UIKEY_HOME:
101 case Ctrl('a'):
102 p = fstart;
103 x = fcol;
104 in_key = 0;
105 continue;
107 case UIKEY_BACKSPACE:
108 if (p > fstart) {
109 p--;
110 x--;
111 }
112 s = p + 1;
113 d = p;
114 while (*s != '\0')
115 *d++ = *s++;
116 *d = '\0';
117 str_end = d;
118 in_key = 0;
119 continue;
121 case UIKEY_LEFT:
122 if (p > fstart) {
123 p--;
124 x--;
125 }
126 in_key = 0;
127 continue;
129 case UIKEY_RIGHT:
130 if (p < fend && p < str_end) {
131 p++;
132 x++;
133 }
134 in_key = 0;
135 continue;
137 case UIKEY_BUTTON1:
138 x = click_x;
139 flin = click_y;
140 fstart = accept_s;
141 fend = fstart + flen;
142 str_end = fstart + strlen(fstart);
143 p = fstart + (x - fcol);
144 if (p > str_end)
145 x -= p - str_end;
146 p = min(p, str_end);
147 in_key = 0;
148 continue;
149 default:
150 if (p >= fend) {
151 in_key = 0;
152 continue;
153 }
154 if (in_key < ' ' || in_key > '~') {
155 in_key = 0;
156 continue;
157 }
158 if (f_insert) {
159 if (str_end < fend) {
160 s = str_end - 1;
161 d = str_end;
162 while (s >= p)
163 *d-- = *s--;
164 *p++ = in_key;
165 str_end++;
166 x++;
167 }
168 } else {
169 if (p < fend) {
170 if (p < str_end) {
171 if (p == accept_s && in_key == ' ') {
172 d = accept_s;
173 s = accept_s + 1;
174 while (*s != '\0')
175 *d++ = *s++;
176 *d = '\0';
177 in_key = 0;
178 continue;
179 }
180 *p++ = in_key;
181 x++;
182 } else if (p == str_end) {
183 *p++ = in_key;
184 *p = '\0';
185 str_end = p;
186 x++;
187 }
188 }
189 }
190 in_key = 0;
191 continue;
192 }
193 }
194}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:104
#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.
bool f_erase_remainder
Structure to hold field information for C-Menu.
Definition cm_fields.c:30

References click_x, click_y, f_erase_remainder, ui_curs_set(), ui_cursor_move(), ui_get_event(), ui_mvwaddstr(), ui_render(), and ui_wclrtoeol().

Referenced by get_cmd_arg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_file_spec()

bool construct_file_spec ( char * ,
char * ,
char * ,
char * ,
char * ,
uint  )
extern

◆ display_argv_error_msg()

void display_argv_error_msg ( char * ,
char **  )
extern

◆ display_curses_keys()

int display_curses_keys ( )
extern

◆ dump_opts()

void dump_opts ( )
extern

dump options to stdout

◆ dump_opts_by_use()

void dump_opts_by_use ( char * ,
char *  )
extern

dump options to stdout

◆ enter_option()

uint enter_option ( )
extern

◆ fill_field()

char * fill_field ( char * accept_s,
char * display_s,
char fill_char,
uint flen )
extern

Definition at line 1714 of file futil.c.

1715 {
1716 char *s = accept_s;
1717 char *d = display_s;
1718 char *e = d + flen;
1719 while (*s != '\0' && d < e)
1720 *d++ = *s++;
1721 while (d < e)
1722 *d++ = fill_char;
1723 *d = '\0';
1724 return display_s;

◆ get_rfc3339_s()

void get_rfc3339_s ( char * ,
size_t  )
extern

◆ handle_signal()

bool handle_signal ( sig_atomic_t )
extern

Referenced by ui_get_event().

Here is the caller graph for this function:

◆ init_stdscr()

void init_stdscr ( )
extern

◆ is_image_file()

bool is_image_file ( const char * filename)
extern

◆ mk_string()

String mk_string ( size_t l)
extern

Create a String struct with a dynamically allocated string.

Parameters
llength of string to create including null terminator
Returns
String struct

The returned String struct contains a dynamically allocated string of he specified length

Note
the caller is responsible for calling free_string to free the allocated memory.

Definition at line 1550 of file futil.c.

1551 {
1552 if (l == 0) {
1553 String str;
1554 str.l = 0;
1555 str.s = nullptr;
1556 return str;
1557 }
1558 String str;
1559 str.l = l + 1;
1560 str.s = (char *)malloc(str.l);
1561 str.s[0] = '\0';
1562 return str;
size_t l
Definition cm.h:411
char * s
Definition cm.h:410

References String::l, and String::s.

◆ rep_substring()

char * rep_substring ( const char * org_s,
const char * tgt_s,
const char * rep_s )
extern

Replace all occurrences of "tgt_s" in "org_s" with "rep_s".

Parameters
org_s- original string
tgt_s- target substring to replace
rep_s- replacement substring
Returns
A pointer to the newly allocated string with replacements or a copy of the replacement string if original string is the same as target string This is a special case that allows for replacing the entire original string. If any parameter is nullptr, the function returns nullptr. If "tgt_s" is not found in "org_s", the function returns a copy of "org_s". If target substring is not found the function returns a copy of the original string.
Note
allocates memory for the return value, so the caller is responsible for freeing this memory when it is no longer needed to avoid memory leaks. Does not modify the original string "org_s".
Assumes that "tgt_s" and "rep_s" are null-terminated strings. If they are not, the behavior is undefined.
Does not perform any bounds checking on the input strings, so it is the caller's responsibility to ensure that they are valid and that the resulting string does not exceed available memory.
Uses the standard library functions strlen, strstr, malloc, and strcpy, which may have their own limitations and behaviors that the caller should be aware of.
Does not handle overlapping occurrences of "tgt_s" in "org_s". If "tgt_s" can overlap with itself in "org_s", the behavior may be unexpected. The caller should ensure that "tgt_s" does not contain overlapping patterns to avoid this issue.
Does not handle cases where "tgt_s" is a substring of "rep_s", which could lead to unintended consequences if "tgt_s" appears in "rep_s". The caller should ensure that "tgt_s" and "rep_s" are distinct to avoid this issue.

Definition at line 1449 of file futil.c.

1450 {
1451 if (*org_s == '\0' || *tgt_s == '\0' || *rep_s == '\0')
1452 return nullptr;
1453 if (strstr(org_s, tgt_s) == nullptr)
1454 return strdup(org_s);
1455 if (strstr(rep_s, tgt_s) != nullptr)
1456 return nullptr;
1457 if (tgt_s == rep_s || tgt_s == org_s || rep_s == org_s)
1458 return strdup(org_s);
1459 if (strcmp(org_s, tgt_s) == 0)
1460 return strdup(rep_s);
1461 char *out_s, *ip, *tmp;
1462 uint tgt_l = strlen(tgt_s);
1463 uint rep_l = strlen(rep_s);
1464 uint head_l;
1465 uint n = 0;
1466 ip = (char *)org_s;
1467 while ((tmp = strstr(ip, tgt_s)) != nullptr) {
1468 n++;
1469 ip = tmp + tgt_l;
1470 }
1471 out_s = malloc(strlen(org_s) + (rep_l - tgt_l) * n + 1);
1472 if (!out_s) {
1473 return nullptr;
1474 }
1475 tmp = out_s;
1476 ip = (char *)org_s;
1477 while (n--) {
1478 char *p = strstr(ip, tgt_s);
1479 head_l = p - ip;
1480 strnz__cpy(tmp, ip, head_l);
1481 tmp += head_l;
1482 strnz__cpy(tmp, rep_s, MAXLEN - 1);
1483 tmp += rep_l;
1484 ip += head_l + tgt_l;
1485 }
1486 strnz__cpy(tmp, ip, MAXLEN - 1);
1487 return out_s;
#define MAXLEN
Definition curskeys.c:15
size_t strnz__cpy(char *d, const char *s, size_t max_len)
safer alternative to strncpy
Definition futil.c:518

References strnz__cpy().

Referenced by exec_objects(), expand_tilde(), and form_exec_receiver().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_wins()

void restore_wins ( )
extern

◆ rtrim()

size_t rtrim ( char * s)
extern

Trims trailing spaces from string s in place.

Parameters
s- string to trim
Returns
length of trimmed string

Definition at line 308 of file futil.c.

308 {
309 if (s == nullptr || *s == '\0')
310 return (size_t)0;
311 char *p = s + strlen(s) - 1;
312 while (p >= s && *p == ' ')
313 p--;
314 *(p + 1) = '\0';
315 return (size_t)(p - s + 1);
316}

Referenced by fmt_line(), and picker().

Here is the caller graph for this function:

◆ sig_shell_mode()

void sig_shell_mode ( )
extern

◆ stdio_fdnames()

char * stdio_fdnames ( char * stdio_str,
char * id )
extern

Definition at line 1108 of file futil.c.

1109 {
1110 if (!stdio_str)
1111 return nullptr;
1112 char buf[MAXLEN] = {'\0'};
1113 char buf0[MAXLEN] = {'\0'};
1114 ssnprintf(buf, MAXLEN - 1, "%s: ", id);
1115 strnz__cpy(stdio_str, buf, MAXLEN - 1);
1116 for (int i = 0; i < 16; i++) {
1117 if (fdname(i, buf0) != nullptr) {
1118 ssnprintf(buf, 4095, " fd%d=%s", i, buf0);
1119 strnz__cat(stdio_str, buf, MAXLEN - 1);
1120 strnz__cat(stdio_str, ",", MAXLEN - 1);
1121 }
1122 }
1123 return stdio_str;
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
size_t strnz__cat(char *d, const char *s, size_t max_len)
safer alternative to strncat
Definition futil.c:549
char * fdname(int fd, char *out_path)
Retrieves the file path associated with a given file descriptor.
Definition futil.c:1073

References fdname(), ssnprintf(), strnz__cat(), and strnz__cpy().

Referenced by form_process(), init_pick(), and view_init_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stdio_names()

char * stdio_names ( char * stdio_str,
char * id )
extern

Definition at line 1083 of file futil.c.

1084 {
1085 if (!stdio_str)
1086 return nullptr;
1087 char buf[MAXLEN] = {'\0'};
1088 char err_str[MAXLEN] = {'\0'};
1089 errno = 0;
1090 ssnprintf(buf, MAXLEN - 1, "%s - ", id);
1091 strnz__cpy(stdio_str, buf, MAXLEN - 1);
1092 strnz__cat(stdio_str, ttyname(0), MAXLEN - 1);
1093 strnz__cat(stdio_str, ", ", MAXLEN - 1);
1094 if (errno)
1095 ssnprintf(err_str, MAXLEN - 1, "Error fd %d: %s\n", 0, strerror(errno));
1096
1097 strnz__cat(stdio_str, ttyname(1), MAXLEN - 1);
1098 strnz__cat(stdio_str, ", ", MAXLEN - 1);
1099 if (errno)
1100 ssnprintf(err_str, MAXLEN - 1, _("Error fd %d: %s\n"), 1, strerror(errno));
1101
1102 strnz__cat(stdio_str, ttyname(2), MAXLEN - 1);
1103 strnz__cat(stdio_str, ", ", MAXLEN - 1);
1104 if (errno)
1105 ssnprintf(err_str, MAXLEN - 1, _("Error fd %d: %s\n"), 2, strerror(errno));
1106
1107 return stdio_str;
#define _(String)
Definition amort.c:23

References ssnprintf(), strnz__cat(), and strnz__cpy().

Referenced by fork_exec(), and menu_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_bool()

bool str_to_bool ( const char * s)
extern

Converts String to boolean true or false.

Parameters
s- string to convert
Returns
boolean true or false

Definition at line 960 of file futil.c.

961 {
962 if (s == nullptr || *s == '\0')
963 return false;
964 switch (s[0]) {
965 case 't':
966 case 'T':
967 case 'y':
968 case 'Y':
969 case '1':
970 return true;
971 case 'o':
972 case 'O':
973 switch (s[1]) {
974 case 'n':
975 case 'N':
976 return true;
977 default:
978 break;
979 }
980 default:
981 break;
982 }
983 return false;

Referenced by process_config_file().

Here is the caller graph for this function:

◆ strnfill()

bool strnfill ( char * ,
char ,
uint  )
extern

◆ user_end()

void user_end ( )
extern

◆ verify_dir_q()

bool verify_dir_q ( char * ,
uint  )
extern

◆ verify_file_q()

bool verify_file_q ( char * ,
uint  )
extern

◆ wait_destroy()

bool wait_destroy ( UiChyron * )
extern

◆ wait_mk_chyron()

UiChyron * wait_mk_chyron ( )
extern

◆ waitpid_with_timeout()

bool waitpid_with_timeout ( pid_t ,
uint  )
extern

◆ win_del()

void win_del ( )
extern

◆ win_init_attrs()

void win_init_attrs ( )
extern

◆ win_resize()

void win_resize ( uint ,
uint ,
char *  )
extern

◆ win_Toggle_Attrs()

void win_Toggle_Attrs ( )
extern

Variable Documentation

◆ dbgfd

uint dbgfd
extern

the file descriptor for debug output, for debugging purposes

◆ errmsg

char errmsg
extern

Global variables for error reporting

Definition at line 126 of file futil.c.

◆ exit_code

int exit_code
extern

the exit code for the program, for error messages and other output

Definition at line 31 of file ui_common.c.

◆ f_debug

bool f_debug
extern

a flag to indicate whether debug output should be printed, for debugging purposes see termios.h

◆ f_have_program_tioctl

bool f_have_program_tioctl = false
extern

program tioctl captured

Definition at line 25 of file scriou.c.

Referenced by capture_program_tioctl(), and restore_program_tioctl().

◆ f_have_shell_tioctl

bool f_have_shell_tioctl = false
extern

shell tioctl captured

Definition at line 24 of file scriou.c.

Referenced by capture_shell_tioctl(), and restore_shell_tioctl().

◆ f_program_open

bool f_program_open
extern

program mode is active

◆ f_restore_screen

bool f_restore_screen
extern

whether to restore the screen

◆ fn

char fn
extern

function name for error messages

Definition at line 45 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ mbegx

uint mbegx
extern

beginning x coordinate of the current window, which can be used to determine the position of the window on the terminal screen.

◆ mbegy

uint mbegy
extern

beginning y coordinate of the current window, which can be used to determine the position of the window on the terminal screen.

◆ mcols

uint mcols
extern

number of columns in the current window, which may be less than the total number of columns in the terminal if the window is resized or if multiple windows are being used.

◆ mg_action

uint mg_action
extern

action in progress, which can be used to keep track of the current state of the program and determine how to respond to user input or other events.

◆ mg_col

uint mg_col
extern

window column, which can be used to determine the current column position in the window for displaying text or other content.

◆ mg_line

uint mg_line
extern

window line, which can be used to determine the current line position in the window for displaying text or other content.

◆ mlines

uint mlines
extern

number of lines in the current window, which may be less than the total number of lines in the terminal if the window is resized or if multiple windows are being used.

◆ n_cols

uint n_cols
extern

number of columns in the terminal

◆ n_lines

uint n_lines
extern

number of lines in the terminal

◆ program_err_tioctl

struct termios shell_err_tioctl program_err_tioctl
extern

Definition at line 37 of file scriou.c.

Referenced by capture_program_tioctl(), and restore_program_tioctl().

◆ program_in_tioctl

struct termios shell_in_tioctl program_in_tioctl
extern

Definition at line 35 of file scriou.c.

Referenced by capture_program_tioctl(), and restore_program_tioctl().

◆ program_out_tioctl

struct termios shell_out_tioctl program_out_tioctl
extern

Definition at line 36 of file scriou.c.

Referenced by capture_program_tioctl(), and restore_program_tioctl().

◆ program_tioctl

struct termios shell_tioctl program_tioctl
extern

Definition at line 34 of file scriou.c.

◆ sig_received

volatile sig_atomic_t sig_received = 0
extern

Definition at line 32 of file sig.c.

Referenced by handle_signal(), signal_handler(), and ui_get_event().

◆ src_line

uint src_line
extern

the line number of the source file being processed, for error messages

Definition at line 43 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ src_name

char * src_name
extern

the name of the source file being processed, for error messages

Definition at line 44 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ stderr_fd

int stderr_fd
extern

the file descriptor for the terminal, for error messages and other output

Definition at line 61 of file ui_common.c.

◆ stdin_fd

int stdin_fd
extern

the file descriptor for the terminal, for error messages

Definition at line 61 of file ui_common.c.

◆ stdio_names_str

char stdio_names_str
extern

Definition at line 122 of file futil.c.

Referenced by fork_exec(), form_process(), init_pick(), menu_cmd_processor(), and view_init_input().

◆ stdout_fd

int stdout_fd
extern

the file descriptor for the terminal, for error messages

Definition at line 61 of file ui_common.c.

◆ tty_fp

FILE* tty_fp
extern

◆ wait_timeout

int wait_timeout
extern

Definition at line 140 of file futil.c.

◆ win_attr

uint16_t win_attr
extern

Ncurses attributes for the current window, such as color pair, bold, etc.

Definition at line 34 of file ui_common.c.