zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
options.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 #include "zpmod.mdh"
11 #include "zpmod.pro"
12 #include "zpmod_compat.h"
13 #include <stddef.h>
14 
15 static int zp_opt_for_zsh_version[64] = {0};
16 
18  const char *name;
19  int enum_val;
20 };
21 
22 /*
23  * Mapping from zpmod-stable option enums to zsh option names.
24  * Keep this list terminated with a NULL name sentinel.
25  */
26 static struct zp_option_name zp_options[] = {
27  /* Only map the options we actually use from C code. */
28  {"function_argzero", FUNCTIONARGZERO__},
29  {"path_dirs", PATHDIRS__},
30  {"posix_builtins", POSIXBUILTINS__},
31  {"shin_stdin", SHINSTDIN__},
32  {"source_trace", SOURCETRACE__},
33  /* Sentinel terminator (required) */
34  {NULL, 0}};
35 
38  for (int i = 0; zp_options[i].name != NULL; ++i) {
39  int e = zp_options[i].enum_val;
40  if (e < 0 || e >= (int)(sizeof(zp_opt_for_zsh_version) /
41  sizeof(zp_opt_for_zsh_version[0]))) {
42  continue;
43  }
44  int optno = optlookup(zp_options[i].name);
45  if (optno >= 0) {
46  zp_opt_for_zsh_version[e] = optno;
47  }
48  }
49 }
50 
52 int zp_conv_opt(int zp_opt_num) {
53  if (zp_opt_num < 0 || zp_opt_num >= ZP_OPT_COUNT__) {
54  return 0;
55  }
56  return zp_opt_for_zsh_version[zp_opt_num];
57 }
static struct zp_option_name zp_options[]
Definition: options.c:26
int zp_conv_opt(int zp_opt_num)
Convert a stable option enum to a runtime option index (sign-preserving).
Definition: options.c:52
void zp_setup_options_table(void)
Populate runtime option indices for the stable enum table.
Definition: options.c:37
static int zp_opt_for_zsh_version[64]
Definition: options.c:15
int enum_val
Definition: options.c:19
const char * name
Definition: options.c:18
Module declaration header (mdh) for zpmod.
Prototype stub for zpmod when building out-of-tree.
@ ZP_OPT_COUNT__
Definition: zpmod_compat.h:21
@ SOURCETRACE__
Definition: zpmod_compat.h:20
@ POSIXBUILTINS__
Definition: zpmod_compat.h:18
@ PATHDIRS__
Definition: zpmod_compat.h:17
@ FUNCTIONARGZERO__
Definition: zpmod_compat.h:16
@ SHINSTDIN__
Definition: zpmod_compat.h:19
int optlookup(const char *name)