commit: 3a97f0953c995b29f8ad75b2ddc3ae32e2fd1272
parent 1e64470ce8647c3eaa7deb34ecab81fed45b1be6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 1 Jan 2026 21:40:31 +0100
cmd/test: Use `enum token` to store token information instead of `int`
Diffstat:
| M | cmd/test.c | 41 | ++++++++++++++++++++--------------------- |
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/cmd/test.c b/cmd/test.c
@@ -117,7 +117,7 @@ enum token
static const struct t_op
{
char op_text[2];
- short op_num;
+ enum token tok;
} ops1[] =
{
{"=", STREQ},
@@ -421,7 +421,7 @@ filstat(char *nm, enum token mode)
}
}
-static int
+static enum token
find_op_1char(const struct t_op *op, const struct t_op *end, const char *s)
{
char c;
@@ -429,24 +429,24 @@ find_op_1char(const struct t_op *op, const struct t_op *end, const char *s)
c = s[0];
while(op != end)
{
- if(c == *op->op_text) return op->op_num;
+ if(c == *op->op_text) return op->tok;
op++;
}
return OPERAND;
}
-static int
+static enum token
find_op_2char(const struct t_op *op, const struct t_op *end, const char *s)
{
while(op != end)
{
- if(s[0] == op->op_text[0] && s[1] == op->op_text[1]) return op->op_num;
+ if(s[0] == op->op_text[0] && s[1] == op->op_text[1]) return op->tok;
op++;
}
return OPERAND;
}
-static int
+static enum token
find_op(const char *s)
{
if(s[0] == '\0')
@@ -465,17 +465,16 @@ find_op(const char *s)
static enum token
t_lex(char *s)
{
- int num;
+ enum token tok;
- if(s == NULL)
- {
- return EOI;
- }
- num = find_op(s);
- if(((TOKEN_TYPE(num) == UNOP || TOKEN_TYPE(num) == BUNOP) && isunopoperand()) ||
- (num == LPAREN && islparenoperand()) || (num == RPAREN && isrparenoperand()))
+ if(s == NULL) return EOI;
+
+ tok = find_op(s);
+ if(((TOKEN_TYPE(tok) == UNOP || TOKEN_TYPE(tok) == BUNOP) && isunopoperand()) ||
+ (tok == LPAREN && islparenoperand()) || (tok == RPAREN && isrparenoperand()))
return OPERAND;
- return num;
+
+ return tok;
}
static int
@@ -483,28 +482,28 @@ isunopoperand(void)
{
char *s;
char *t;
- int num;
+ enum token tok;
if(nargc == 1) return 1;
s = *(t_wp + 1);
if(nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0;
t = *(t_wp + 2);
- num = find_op(s);
- return TOKEN_TYPE(num) == BINOP && (parenlevel == 0 || t[0] != ')' || t[1] != '\0');
+ tok = find_op(s);
+ return TOKEN_TYPE(tok) == BINOP && (parenlevel == 0 || t[0] != ')' || t[1] != '\0');
}
static int
islparenoperand(void)
{
char *s;
- int num;
+ enum token tok;
if(nargc == 1) return 1;
s = *(t_wp + 1);
if(nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0;
if(nargc != 3) return 0;
- num = find_op(s);
- return TOKEN_TYPE(num) == BINOP;
+ tok = find_op(s);
+ return TOKEN_TYPE(tok) == BINOP;
}
static int