zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
module.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
6 #include "zpmod.mdh"
7 #include "zpmod.pro"
8 #include "zpmod_builtins.h"
9 #include "zpmod_vendor_shims.h"
10 #include "zpmod_version.h"
11 
12 /* Declare builtin handlers implemented in other TUs */
13 int bin_zppathstat(char *nam, char **argv, Options ops, int func);
14 int bin_zpdirlist(char *nam, char **argv, Options ops, int func);
15 int bin_zpreadfile(char *nam, char **argv, Options ops, int func);
16 
17 /* Unified builtin table (static, like original) */
18 static struct builtin bintab[] = {
19 #ifdef ZPMOD_HAVE_SOURCE_STUDY
20  BUILTIN("custom_dot", 0, bin_custom_dot, 1, -1, 0, NULL, NULL),
21 #endif
22  BUILTIN("readarray", 0, bin_readarray, 1, 1, 0, "d:n:O:s:tu:C:c:h", NULL),
23  BUILTIN("zppathstat", 0, bin_zppathstat, 2, 2, 0, "Lf:", NULL),
24  BUILTIN("zpdirlist", 0, bin_zpdirlist, 2, 2, 0, "adf", NULL),
25  BUILTIN("zpreadfile", 0, bin_zpreadfile, 2, 2, 0, "md:0", NULL),
26  BUILTIN("zpmod", 0, bin_zpmod, 0, -1, 0, "hV", NULL),
27 };
28 
29 static struct features module_features = {
30  bintab, (int)(sizeof(bintab) / sizeof(*bintab)), NULL, 0, NULL, 0, NULL, 0,
31  0};
32 
34 int setup_(UNUSED(Module m)) {
35  extern void zp_setup_options_table(void);
37 #ifdef ZPMOD_HAVE_SOURCE_STUDY
38  extern void zp_source_setup_overrides(void);
40 #endif
41  return 0;
42 }
43 
45 int features_(Module m, char ***features) {
46  *features = featuresarray(m, &module_features);
47  return 0;
48 }
50 int enables_(Module m, int **enables) {
51  return handlefeatures(m, &module_features, enables);
52 }
54 int boot_(UNUSED(Module m)) { return 0; }
56 int cleanup_(Module m) { return setfeatureenables(m, &module_features, NULL); }
59 #ifdef ZPMOD_HAVE_SOURCE_STUDY
60  extern void zp_source_restore_overrides(void);
62 #endif
63  return 0;
64 }
int enables_(Module m, int **enables)
Enable/disable builtins as requested by the shell.
Definition: module.c:50
int bin_zpdirlist(char *nam, char **argv, Options ops, int func)
zpdirlist builtin entrypoint
Definition: fs_builtins.c:31
int features_(Module m, char ***features)
Provide feature list (builtins) to zsh.
Definition: module.c:45
int bin_zppathstat(char *nam, char **argv, Options ops, int func)
zppathstat builtin entrypoint
Definition: fs_builtins.c:15
int boot_(UNUSED(Module m))
Optional early boot hook (unused).
Definition: module.c:54
static struct features module_features
Definition: module.c:29
int finish_(UNUSED(Module m))
Finalize module: restore original source handlers.
Definition: module.c:58
static struct builtin bintab[]
Definition: module.c:18
int cleanup_(Module m)
Cleanup features when unloading.
Definition: module.c:56
int setup_(UNUSED(Module m))
Module setup: initialize option mapping and install source overrides.
Definition: module.c:34
int bin_zpreadfile(char *nam, char **argv, Options ops, int func)
zpreadfile builtin entrypoint
Definition: fs_builtins.c:45
void zp_setup_options_table(void)
Populate runtime option indices for the stable enum table.
Definition: options.c:37
int bin_readarray(char *nam, char **argv, Options ops, int func)
readarray builtin entrypoint
Definition: readarray.c:26
void zp_source_restore_overrides(void)
Definition: source.c:762
void zp_source_setup_overrides(void)
Definition: source.c:737
int bin_custom_dot(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
Replacement handler for '.
Definition: source.c:48
Module declaration header (mdh) for zpmod.
Prototype stub for zpmod when building out-of-tree.
#define UNUSED(x)
void * Module
int bin_zpmod(char *nam, char **argv, Options ops, int func)
int setfeatureenables(Module m, Features features, int **enables)
int handlefeatures(Module m, Features features, int **enables)
char ** featuresarray(Module m, Features features)
Local, non-invasive shims to suppress benign vendor header warnings.