summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 12:52:38 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 12:52:38 -0600
commite569552eb9766bc663871b6f3cb203a77e83503c (patch)
treea3bd6f994a6c61aae2430e51de762880b002be03 /src
parent5d830cb1c04da59553d3af848340162a7be9fa58 (diff)
downloadzash-e569552eb9766bc663871b6f3cb203a77e83503c.tar.gz
C23: constexpr internal linkage, naming and trailing commas; clangd at C23
A constexpr at file scope has external linkage, so the CSI offsets and CSI_MAX_CALLS now say static. The naming check gets the C23 spellings wrap the check itself: typed constants keep the macro case, and a local static constexpr table keeps the variable case. .clangd says -std=c23, which it still did not, so the editor could not read constexpr at all.
Diffstat (limited to 'src')
-rw-r--r--src/arith.c2
-rw-r--r--src/ast.h36
-rw-r--r--src/complete.c3
-rw-r--r--src/exec.c17
-rw-r--r--src/exec.h5
-rw-r--r--src/expand.c6
-rw-r--r--src/mvsfmt.c30
-rw-r--r--src/parser.c6
-rw-r--r--src/pattern.c8
-rw-r--r--src/redir.c6
-rw-r--r--src/sys.h4
-rw-r--r--src/test.c7
12 files changed, 70 insertions, 60 deletions
diff --git a/src/arith.c b/src/arith.c
index 24016a7..b1e7fb0 100644
--- a/src/arith.c
+++ b/src/arith.c
@@ -193,7 +193,7 @@ typedef enum binop {
OP_BXOR,
OP_BOR,
OP_LAND,
- OP_LOR
+ OP_LOR,
} binop;
/**
diff --git a/src/ast.h b/src/ast.h
index 3f11633..c49228e 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -61,7 +61,7 @@ typedef enum param_op {
PS_TRIML, /**< `${x#w}` */
PS_TRIMLL, /**< `${x##w}` */
PS_TRIMR, /**< `${x%w}` */
- PS_TRIMRR /**< `${x%%w}` */
+ PS_TRIMRR, /**< `${x%%w}` */
} param_op;
/**
@@ -99,7 +99,7 @@ typedef enum redir_op {
R_RDWR, /**< <> */
R_DUPIN, /**< <& */
R_DUPOUT, /**< >& */
- R_HERE /**< << and <<- */
+ R_HERE, /**< << and <<- */
} redir_op;
/**
@@ -142,7 +142,7 @@ typedef enum node_kind {
N_FUNC,
N_ARITH, /**< (( expression )) */
N_COND, /**< [[ expression ]] */
- N_TIME /**< time pipeline */
+ N_TIME, /**< time pipeline */
} node_kind;
/**
@@ -154,27 +154,27 @@ typedef enum cond_kind {
CN_NOT, /**< ! left */
CN_UNARY, /**< -op a */
CN_BINARY, /**< a op b */
- CN_STRING /**< a: true if not empty */
+ CN_STRING, /**< a: true if not empty */
} cond_kind;
/**
* @brief Binary operators of `[[ ]]`.
*/
typedef enum cond_op {
- CO_MATCH, /**< `=`, `==`: a matches the pattern b */
- CO_NOMATCH, /**< `!=`: a does not match the pattern b */
- CO_REGEX, /**< `=~`: a matches the extended regular expression b */
- CO_LESS, /**< `<`: a sorts before b */
- CO_GREATER, /**< `>`: a sorts after b */
- CO_EQ, /**< `-eq` (operands are arithmetic expressions) */
- CO_NE, /**< `-ne` */
- CO_LT, /**< `-lt` */
- CO_LE, /**< `-le` */
- CO_GT, /**< `-gt` */
- CO_GE, /**< `-ge` */
- CO_NEWER, /**< `-nt` */
- CO_OLDER, /**< `-ot` */
- CO_SAMEFILE /**< `-ef` */
+ CO_MATCH, /**< `=`, `==`: a matches the pattern b */
+ CO_NOMATCH, /**< `!=`: a does not match the pattern b */
+ CO_REGEX, /**< `=~`: a matches the extended regular expression b */
+ CO_LESS, /**< `<`: a sorts before b */
+ CO_GREATER, /**< `>`: a sorts after b */
+ CO_EQ, /**< `-eq` (operands are arithmetic expressions) */
+ CO_NE, /**< `-ne` */
+ CO_LT, /**< `-lt` */
+ CO_LE, /**< `-le` */
+ CO_GT, /**< `-gt` */
+ CO_GE, /**< `-ge` */
+ CO_NEWER, /**< `-nt` */
+ CO_OLDER, /**< `-ot` */
+ CO_SAMEFILE, /**< `-ef` */
} cond_op;
/**
diff --git a/src/complete.c b/src/complete.c
index d2e68ef..029dcef 100644
--- a/src/complete.c
+++ b/src/complete.c
@@ -428,7 +428,8 @@ void complete_line(const char *line, size_t cursor, completion *out) {
c.count = k;
}
*out = (completion){
- c.list, c.count, start, word_quoted, word_quoted ? quote : 0, mvs};
+ c.list, c.count, start, word_quoted, word_quoted ? quote : 0, mvs,
+ };
arena_release(&scratch, mark);
}
diff --git a/src/exec.c b/src/exec.c
index fbc46ba..c0267a8 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -215,10 +215,14 @@ static int eval_time(const node *n, unsigned flags) {
getrusage(RUSAGE_SELF, &s1);
getrusage(RUSAGE_CHILDREN, &c1);
bool posix = n->u.time.posix;
- long long self[2] = {tv_diff(s0.ru_utime, s1.ru_utime),
- tv_diff(s0.ru_stime, s1.ru_stime)};
- long long kids[2] = {tv_diff(c0.ru_utime, c1.ru_utime),
- tv_diff(c0.ru_stime, c1.ru_stime)};
+ long long self[2] = {
+ tv_diff(s0.ru_utime, s1.ru_utime),
+ tv_diff(s0.ru_stime, s1.ru_stime),
+ };
+ long long kids[2] = {
+ tv_diff(c0.ru_utime, c1.ru_utime),
+ tv_diff(c0.ru_stime, c1.ru_stime),
+ };
static const char *const label[2] = {"user", "sys"};
out_flush(&out1);
put_time("real", tv_diff(t0, t1), posix);
@@ -877,7 +881,10 @@ static void assign_temp(const simple_cmd *sc) {
*/
static bool tag_prefix_begin(const simple_cmd *sc, tag_mode saved[3]) {
static const char *const name[3] = {
- "_TAG_REDIR_IN=", "_TAG_REDIR_OUT=", "_TAG_REDIR_ERR="};
+ "_TAG_REDIR_IN=",
+ "_TAG_REDIR_OUT=",
+ "_TAG_REDIR_ERR=",
+ };
bool any = false;
memcpy(saved, tag_redir, sizeof tag_redir);
for (int i = 0; i < sc->nassign; i++) {
diff --git a/src/exec.h b/src/exec.h
index 7b058d0..54f5b3e 100644
--- a/src/exec.h
+++ b/src/exec.h
@@ -37,7 +37,7 @@ typedef enum skip_type {
SKIP_NONE,
SKIP_BREAK,
SKIP_CONTINUE,
- SKIP_RETURN
+ SKIP_RETURN,
} skip_type;
extern skip_type skip_kind; /**< a break/continue/return is in progress */
@@ -61,8 +61,7 @@ void exec_init(void);
*/
enum {
BI_SPECIAL = 1u << 0, /**< POSIX special builtin */
- BI_PURE = 1u << 1, /**< only writes to out1/out2: safe to run in the
- shell in place of a subshell */
+ BI_PURE = 1u << 1,
};
/**
diff --git a/src/expand.c b/src/expand.c
index 943d2bf..e81f5c2 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -23,9 +23,9 @@
* @brief What an expansion is producing.
*/
typedef enum xmode {
- X_FIELDS, /**< command arguments: split and glob */
- X_SINGLE, /**< one string, quotes removed */
- X_PATTERN /**< one string, quoted characters backslash-escaped */
+ X_FIELDS, /**< command arguments: split and glob */
+ X_SINGLE, /**< one string, quotes removed */
+ X_PATTERN, /**< one string, quoted characters backslash-escaped */
} xmode;
/**
diff --git a/src/mvsfmt.c b/src/mvsfmt.c
index dc268b0..a182e1f 100644
--- a/src/mvsfmt.c
+++ b/src/mvsfmt.c
@@ -138,15 +138,15 @@ static void put32(unsigned char *p, uint32_t v) {
* | 152 | 2 | CSINUMEN | number of field names |
* | 154 | 8 | CSIFLDNM | field names |
*/
-constexpr unsigned CSIFILTK = 0; /**< +0, length of the filter key */
-constexpr unsigned CSIDTYPS = 132; /**< entry types to return */
-constexpr unsigned CSIRESUM = 149; /**< Y: return error information */
-constexpr unsigned CSIS1CAT = 150; /**< Y: search one catalog only */
-constexpr unsigned CSINUMEN = 152; /**< number of field names */
-constexpr unsigned CSIFLDNM = 154; /**< field names, 8 each */
+static constexpr unsigned CSIFILTK = 0; /**< +0, length of the filter key */
+static constexpr unsigned CSIDTYPS = 132; /**< entry types to return */
+static constexpr unsigned CSIRESUM = 149; /**< Y: return error information */
+static constexpr unsigned CSIS1CAT = 150; /**< Y: search one catalog only */
+static constexpr unsigned CSINUMEN = 152; /**< number of field names */
+static constexpr unsigned CSIFLDNM = 154; /**< field names, 8 each */
/* Return work area, the first field of it (see csi_parse()). */
-constexpr unsigned CSIREQLN = 4; /**< length of the entry that failed */
+static constexpr unsigned CSIREQLN = 4; /**< length of the entry that failed */
/*
* Return work area: CSIUSRLN +0 (4, set by the caller), CSIREQLN +4,
@@ -156,12 +156,12 @@ constexpr unsigned CSIREQLN = 4; /**< length of the entry that failed */
* X'40') or, with halfword lengths, CSITOTLN (2) counting itself, two
* reserved bytes, one length per field and the fields.
*/
-constexpr unsigned CSIUSDLN = 8; /**< bytes of return information used */
-constexpr unsigned CSI_FIRST = 14; /**< offset of the first entry */
-constexpr unsigned CSIE_NAME = 2; /**< name, within an entry */
-constexpr unsigned CSIE_FIXED = 46; /**< bytes before the lengths */
-constexpr unsigned CSIE_RETINFO = 50; /**< bytes of an entry with return info */
-constexpr unsigned char CSIENTER = 0x40; /**< CSIEFLAG: error, return info follows */
+static constexpr unsigned CSIUSDLN = 8; /**< bytes of return information used */
+static constexpr unsigned CSI_FIRST = 14; /**< offset of the first entry */
+static constexpr unsigned CSIE_NAME = 2; /**< name, within an entry */
+static constexpr unsigned CSIE_FIXED = 46; /**< bytes before the lengths */
+static constexpr unsigned CSIE_RETINFO = 50; /**< bytes of an entry with return info */
+static constexpr unsigned char CSIENTER = 0x40; /**< CSIEFLAG: error, return info follows */
#define EB_ZERO 0xf0 /* CSIETYPE of a catalog entry, EBCDIC '0' */
#define EB_Y 0xe8 /* EBCDIC 'Y' */
@@ -299,7 +299,7 @@ bool csi_parse(const unsigned char *work, size_t worklen, mvs_name_fn *fn,
* at -- and a broad filter on a big catalog is the one way this feature
* can put real work on catalog management.
*/
-constexpr int CSI_MAX_CALLS = 3; /**< searches before giving up */
+static constexpr int CSI_MAX_CALLS = 3; /**< searches before giving up */
/**
* @brief Search the catalog: build the criteria, call, decode, and
@@ -362,7 +362,7 @@ bool pds_parse_block(const unsigned char *blk, mvs_name_fn *fn, void *arg,
return false;
const unsigned char *e = blk + off;
static const unsigned char last[8] = {0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff};
+ 0xff, 0xff, 0xff, 0xff,};
if (!memcmp(e, last, 8)) {
*end = true;
return true;
diff --git a/src/parser.c b/src/parser.c
index 28ea5b6..0677b37 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -32,7 +32,7 @@ typedef enum tok_kind {
T_RP,
T_DSEMI,
T_WORD,
- T_REDIR
+ T_REDIR,
} tok_kind;
/**
@@ -59,7 +59,7 @@ typedef enum keyword {
KW_FUNCTION,
KW_TIME,
KW_DLBRACKET, /**< [[ */
- KW_DRBRACKET /**< ]] */
+ KW_DRBRACKET, /**< ]] */
} keyword;
/**
@@ -186,7 +186,7 @@ typedef enum lex_mode {
M_BRACE, /**< the word in ${x:-word}: ends at } */
M_BRACE_DQ, /**< the same, inside double quotes */
M_ARITH, /**< $(( ... )): ends at )) */
- M_HERE /**< here-document body: ends at end of input */
+ M_HERE, /**< here-document body: ends at end of input */
} lex_mode;
static void read_parts(pbuild *b, lex_mode mode, bool litq);
diff --git a/src/pattern.c b/src/pattern.c
index a60f643..0dabc15 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -30,9 +30,11 @@ static int index_in(const char *set, unsigned char c) {
* alphabet. Any other range is by character code.
*/
static bool in_range(unsigned char lo, unsigned char hi, unsigned char c) {
- static const char *const sets[] = {"abcdefghijklmnopqrstuvwxyz",
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
- "0123456789"};
+ static const char *const sets[] = {
+ "abcdefghijklmnopqrstuvwxyz",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ "0123456789",
+ };
for (size_t i = 0; i < ARRAY_LEN(sets); i++) {
int a = index_in(sets[i], lo);
int b = index_in(sets[i], hi);
diff --git a/src/redir.c b/src/redir.c
index f49e818..b6d4da6 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -38,9 +38,9 @@
*/
typedef enum resolved {
RK_ERROR,
- RK_FD, /**< a newly opened descriptor, to be closed after use */
- RK_DUP, /**< an existing descriptor number */
- RK_CLOSE /**< n>&- */
+ RK_FD, /**< a newly opened descriptor, to be closed after use */
+ RK_DUP, /**< an existing descriptor number */
+ RK_CLOSE, /**< n>&- */
} resolved;
/**
diff --git a/src/sys.h b/src/sys.h
index 7c9e9cf..0389a2e 100644
--- a/src/sys.h
+++ b/src/sys.h
@@ -76,7 +76,7 @@ const char *sys_strsignal(int sig);
typedef enum tag_mode {
TAG_UNSET, /**< variable not set: the default behaviour */
TAG_TXT, /**< treat or tag as text */
- TAG_BIN /**< treat or tag as binary */
+ TAG_BIN, /**< treat or tag as binary */
} tag_mode;
/**
@@ -126,7 +126,7 @@ typedef enum sys_info_kind {
SI_SYSPLEX, /**< sysplex name */
SI_RELEASE, /**< z/OS version and release, "03.02" */
SI_ASID, /**< address space ID of the shell, 4 hex digits */
- SI_JOBNAME /**< job name of the shell's address space */
+ SI_JOBNAME, /**< job name of the shell's address space */
} sys_info_kind;
const char *sys_info(sys_info_kind kind);
diff --git a/src/test.c b/src/test.c
index 232b307..01a903c 100644
--- a/src/test.c
+++ b/src/test.c
@@ -34,9 +34,10 @@ static int remaining(const test_state *t) {
* @brief Is this a binary operator of `test` (`=`, `-eq`, `-nt` ...)?
*/
static bool is_binary_op(const char *s) {
- static const char *const ops[] = {"=", "==", "!=", "<", ">",
- "-eq", "-ne", "-lt", "-le", "-gt",
- "-ge", "-nt", "-ot", "-ef"};
+ static const char *const ops[] = {
+ "=", "==", "!=", "<", ">", "-eq", "-ne",
+ "-lt", "-le", "-gt", "-ge", "-nt", "-ot", "-ef",
+ };
for (size_t i = 0; i < ARRAY_LEN(ops); i++) {
if (!strcmp(s, ops[i]))
return true;