summary refs log tree commit diff
path: root/src/var.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-10-11 22:36:28 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-10-11 22:36:28 +0800
commitf6e3b2f8a59922405f42c8bc283e0f5546c25d0e (patch)
tree6f8a59c3b8f836292fda23c77b1c95eefeae9cc4 /src/var.c
parent[PARSER] Report substition errors at expansion time (diff)
downloaddash-f6e3b2f8a59922405f42c8bc283e0f5546c25d0e.tar.gz
dash-f6e3b2f8a59922405f42c8bc283e0f5546c25d0e.zip
[ARITH] Add assignment and intmax_t support
This patch adds assignment operator support in arithmetic expansions.  It
also changes the type used to intmax_t.
Diffstat (limited to 'src/var.c')
-rw-r--r--src/var.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/var.c b/src/var.c
index 501a279..17d3637 100644
--- a/src/var.c
+++ b/src/var.c
@@ -202,6 +202,21 @@ setvar(const char *name, const char *val, int flags)
 	INTON;
 }
 
+/*
+ * Set the given integer as the value of a variable.  The flags argument is
+ * ored with the flags of the variable.
+ */
+
+intmax_t setvarint(const char *name, intmax_t val)
+{
+	int len = max_int_length(sizeof(val));
+	char buf[len];
+
+	fmtstr(buf, len, "%jd", val);
+	setvar(name, buf, 0);
+	return val;
+}
+
 
 
 /*
@@ -293,6 +308,11 @@ lookupvar(const char *name)
 	return NULL;
 }
 
+intmax_t lookupvarint(const char *name)
+{
+	return atomax(lookupvar(name) ?: nullstr, 0);
+}
+
 
 
 /*