35 return (
unsigned char)a[1];
38 return (
unsigned char)a[0];
49 const char *target,
const char *body,
58 zwarnnam(nam,
"%s$ZI_REPORTS is not declared (zpmod not loaded?).",
64 Param val_pm = (Param)hn;
70 char *target_string = val_pm->u.str;
71 const int target_len = target_string ? (int)strlen(target_string) : 0;
72 const int new_len = target_len + body_len;
74 char *newbuf = (
char *)
zalloc((new_len + 1) *
sizeof(char));
80 memcpy(newbuf, target_string, (
size_t)target_len);
83 memcpy(newbuf + target_len, body, (
size_t)body_len);
85 newbuf[new_len] =
'\0';
90 val_pm->u.str = newbuf;
99 fprintf(stdout,
"%s Usage:\n",
zp_icon(
"📘 "));
100 fprintf(stdout,
" zpmod [--help|-h] [--version|-V]\n");
101 fprintf(stdout,
" zpmod report-append <plugin-id> <text>\n");
102 fprintf(stdout,
" zpmod source-study [-l]\n");
103 fprintf(stdout,
" zpmod dir-list [-a] [-d|-f] out_array dir\n");
104 fprintf(stdout,
" zpmod path-stat [-L] [-f fields] out_array in_array\n");
105 fprintf(stdout,
" zpmod path-warmup [-q] [--prune-missing] [--dry-run]\n");
106 fprintf(stdout,
" zpmod compaudit-cache [--rebuild] [--show] [--json]\n");
107 fprintf(stdout,
" zpmod rehash-diff\n");
108 fprintf(stdout,
" zpmod bundle-build --from DIR --out FILE [--max KB]\n");
109 fprintf(stdout,
" zpmod read-file [-m] [-d delim|-0] var file\n\n");
111 fprintf(stdout,
"%s Subcommands:\n",
zp_icon(
"🧰 "));
113 fprintf(stdout,
" %-14s %s\n",
"report-append",
114 "Append <text> to $ZI_REPORTS[<plugin-id>].");
115 fprintf(stdout,
" %-14s %s\n",
"source-study",
116 "Show sourced files with durations (ms).");
117 fprintf(stdout,
" %-14s %s\n",
"dir-list",
118 "List entries in directory into array.");
119 fprintf(stdout,
" %-14s %s\n",
"path-stat",
120 "Batch stat for input array into output array.");
121 fprintf(stdout,
" %-14s %s\n",
"path-warmup",
122 "Touch PATH dirs to warm kernel VFS caches.");
123 fprintf(stdout,
" %-14s %s\n\n",
"read-file",
124 "Read file into scalar or split into array.");
126 fprintf(stdout,
"%s Options:\n",
zp_icon(
"⚙️ "));
140 "report-append: missing plugin ID (e.g., z-shell/zbrowse). See -h.");
150 zwarnnam(nam,
"report-append: missing text to append. See -h.");
151 zfree(target, target_len);
154 body_len = (int)strlen(body);
157 zfree(target, target_len);
162 int bin_zpmod(
char *nam,
char **argv, Options ops,
int func) {
166 if (OPT_ISSET(ops,
'V') ||
168 (!strcmp(argv[0],
"--version") || !strcmp(argv[0],
"-V")))) {
169 fprintf(stdout,
"%szpmod %s (git: %s)\n",
zp_icon(
"🧩 "), ZPMOD_VERSION_STR,
170 ZPMOD_GIT_DESCRIBE_STR);
174 if (OPT_ISSET(ops,
'h')) {
179 zwarnnam(nam,
"missing subcommand. See -h.");
183 if (0 == strcmp(subcmd,
"report-append")) {
185 }
else if (0 == strcmp(subcmd,
"source-study")) {
187 }
else if (0 == strcmp(subcmd,
"source-hot")) {
189 }
else if (0 == strcmp(subcmd,
"path-warmup")) {
191 int prune_missing = 0;
193 while (*argv && argv[0][0] ==
'-') {
194 if (strcmp(argv[0],
"-q") == 0 || strcmp(argv[0],
"--quiet") == 0) {
199 if (strcmp(argv[0],
"--prune-missing") == 0) {
204 if (strcmp(argv[0],
"--dry-run") == 0) {
209 if (strcmp(argv[0],
"--") == 0) {
219 }
else if (0 == strcmp(subcmd,
"fpath-index")) {
221 }
else if (0 == strcmp(subcmd,
"compaudit-cache")) {
225 while (*argv && argv[0][0] ==
'-') {
226 if (!strcmp(argv[0],
"--rebuild")) {
231 if (!strcmp(argv[0],
"--show")) {
236 if (!strcmp(argv[0],
"--json")) {
241 if (!strcmp(argv[0],
"--")) {
248 }
else if (0 == strcmp(subcmd,
"rehash-diff")) {
250 }
else if (0 == strcmp(subcmd,
"bundle-build")) {
251 const char *from_dir = NULL;
252 const char *out_path = NULL;
255 if (!strcmp(argv[0],
"--from")) {
261 zwarnnam(nam,
"bundle-build: --from requires value");
265 if (!strcmp(argv[0],
"--out")) {
271 zwarnnam(nam,
"bundle-build: --out requires value");
275 if (!strcmp(argv[0],
"--max")) {
278 long v = strtol(argv[1], &end, 10);
279 if (*end ==
'\0' && v >= 0) {
282 zwarnnam(nam,
"bundle-build: invalid --max value: %s", argv[1]);
288 zwarnnam(nam,
"bundle-build: --max requires value");
292 if (!strcmp(argv[0],
"--")) {
301 }
else if (0 == strcmp(subcmd,
"dir-list")) {
303 }
else if (0 == strcmp(subcmd,
"path-stat")) {
305 }
else if (0 == strcmp(subcmd,
"read-file")) {
308 zwarnnam(nam,
"unknown subcommand: %s. See -h.", subcmd);
314 int report_count = 10;
315 int threshold_ms = 0;
316 int clear_history = 0;
318 if (strcmp(argv[0],
"--") == 0) {
322 if (strcmp(argv[0],
"-l") == 0) {
327 if (argv[0][0] ==
'-') {
328 zwarnnam(nam,
"source-study: unknown option: %s", argv[0]);
332 long val = strtol(argv[0], &endptr, 10);
333 if (*endptr ==
'\0' && val >= 0 && val <= INT_MAX) {
334 report_count = (int)val;
337 zwarnnam(nam,
"source-study: invalid report count: %s", argv[0]);
352 while (*argv && argv[0][0] ==
'-') {
353 if (!strcmp(argv[0],
"-a")) {
358 if (!strcmp(argv[0],
"-d")) {
363 if (!strcmp(argv[0],
"-f")) {
368 if (!strcmp(argv[0],
"--")) {
374 if (!argv[0] || !argv[1]) {
375 zwarnnam(nam,
"dir-list: usage: zpmod dir-list [-a] [-d|-f] out_array dir");
378 return zp_dirlist_core(nam, argv[0], argv[1], inc_all, only_dirs, only_files);
384 while (*argv && argv[0][0] ==
'-' && argv[0][1]) {
385 if (strcmp(argv[0],
"--") == 0) {
389 if (strcmp(argv[0],
"-L") == 0) {
394 if (argv[0][1] ==
'f') {
395 char **cursor = &argv[0];
408 if (!argv[0] || !argv[1]) {
410 "%spathstat: usage: zpmod path-stat [-L] [-f fields] out_array "
422 while (*argv && argv[0][0] ==
'-') {
423 if (strcmp(argv[0],
"--mmap") == 0) {
428 if (strcmp(argv[0],
"-0") == 0) {
434 if (strcmp(argv[0],
"--") == 0) {
438 if (argv[0][1] ==
'd') {
441 const char *a = argv[0] + 2;
443 if (a[0] ==
'\\' && a[1]) {
458 delim = (
unsigned char)a[1];
462 delim = (
unsigned char)a[0];
468 const char *a = argv[1];
486 delim = (
unsigned char)a[1];
493 delim = (
unsigned char)a[0];
498 zwarnnam(nam,
"read-file: -d requires delimiter");
503 if (!argv[0] || !argv[1]) {
506 "read-file: usage: zpmod read-file [-m|--mmap] [-0|-d delim] var file");
514 BUILTIN(
"zpmod", 0,
bin_zpmod, 0, -1, 0,
"hV", NULL),
int zp_compaudit_cache_core(char *nam, int rebuild, int show, int json)
const char * zp_icon(const char *s)
Return icon string if enabled, empty string otherwise.
int cmd_fpath_index(char *nam, char **argv)
Implements zpmod fpath-index with intelligent skip detection.
int zp_path_warmup_core(const char *nam, int quiet, int prune_missing, int dry_run)
Implements path-warmup functionality for executable discovery and path pruning.
int zp_readfile_core(char *nam, char *outname, char *path, int use_mmap, int split, int delim)
See zpmod_fs.h for contract.
int zp_dirlist_core(char *nam, char *outname, char *dir, int inc_all, int only_dirs, int only_files)
See zpmod_fs.h for contract.
int zp_pathstat_core(char *nam, char *outname, char *inname, int follow, char *fields)
See zpmod_fs.h for contract.
int zp_rehash_diff_core(char *nam)
int cmd_source_hot(char *nam, char **argv)
Implements zpmod source-hot.
int zp_source_study_core(const char *nam, int report_count, int threshold_ms, int clear_history)
int zp_take_opt_with_arg(char ***argvp, char opt, char **out_arg)
Consume a short option with required argument from argv.
char * zp_unmetafy_zalloc(const char *to_copy, int *new_len)
Duplicate and unmetafy a zsh string with zalloc; see header for details.
Module declaration header (mdh) for zpmod.
Prototype stub for zpmod when building out-of-tree.
int cmd_dirlist(char *nam, char **argv)
static int zp_append_report(const char *nam, const char *target, const char *body, int body_len)
int bin_zpmod(char *nam, char **argv, Options ops, int func)
static struct builtin self_builtins[]
static int cmd_report_append(char *nam, char **argv)
struct builtin * zp_get_self_builtins(size_t *count)
int cmd_source_study(char *nam, char **argv)
static int parse_delim(const char *a)
void zpmod_usage(void)
Print usage for the zpmod builtin.
int cmd_readfile(char *nam, char **argv)
int cmd_pathstat(char *nam, char **argv)
Startup bundle builder interface.
int zp_bundle_build_core(char *nam, const char *from_dir, const char *out_path, long max_kb)
Interface for cached compaudit security verdicts.
Optional terminal/locale detection for emoji support in messages.
Filesystem helpers used by builtins and zpmod subcommands.
void * zalloc(size_t size)
void zfree(void *ptr, size_t size)
void zwarnnam(const char *, const char *,...)
struct hashtable * HashTable
HashNode gethashnode2(HashTable, const char *)
struct hashnode * HashNode
Incremental PATH diff rehash entrypoint.
Public interfaces for source-study and source overrides.
Utility helpers shared across module components.
Local, non-invasive shims to suppress benign vendor header warnings.