summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ChangeLog1
-rw-r--r--src/var.c54
-rw-r--r--src/var.h2
3 files changed, 19 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index f3c7701..1f7120f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2010-05-25  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Fix poplocalvar leak.
+	* Move unsetvar functionality into setvareq.
 
 2010-05-24  Herbert Xu <herbert@gondor.apana.org.au>
 
diff --git a/src/var.c b/src/var.c
index fc6d367..12f2f6c 100644
--- a/src/var.c
+++ b/src/var.c
@@ -266,10 +266,22 @@ setvareq(char *s, int flags)
 		if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
 			ckfree(vp->text);
 
+		if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) |
+		     (vp->flags & VSTRFIXED)) == VUNSET) {
+			*vpp = vp->next;
+			ckfree(vp);
+out_free:
+			if ((flags & (VTEXTFIXED|VSTACK|VNOSAVE)) == VNOSAVE)
+				ckfree(s);
+			return;
+		}
+
 		flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET);
 	} else {
 		if (flags & VNOSET)
 			return;
+		if ((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) == VUNSET)
+			goto out_free;
 		/* not found */
 		vp = ckmalloc(sizeof (*vp));
 		vp->next = *vpp;
@@ -588,7 +600,6 @@ unsetcmd(int argc, char **argv)
 	char **ap;
 	int i;
 	int flag = 0;
-	int ret = 0;
 
 	while ((i = nextopt("vf")) != '\0') {
 		flag = i;
@@ -596,15 +607,13 @@ unsetcmd(int argc, char **argv)
 
 	for (ap = argptr; *ap ; ap++) {
 		if (flag != 'f') {
-			i = unsetvar(*ap);
-			ret |= i;
-			if (!(i & 2))
-				continue;
+			unsetvar(*ap);
+			continue;
 		}
 		if (flag != 'v')
 			unsetfunc(*ap);
 	}
-	return ret & 1;
+	return 0;
 }
 
 
@@ -612,38 +621,9 @@ unsetcmd(int argc, char **argv)
  * Unset the specified variable.
  */
 
-int
-unsetvar(const char *s)
+void unsetvar(const char *s)
 {
-	struct var **vpp;
-	struct var *vp;
-	int retval;
-
-	vpp = findvar(hashvar(s), s);
-	vp = *vpp;
-	retval = 2;
-	if (vp) {
-		int flags = vp->flags;
-
-		retval = 1;
-		if (flags & VREADONLY)
-			goto out;
-		if ((flags & VSTRFIXED) == 0) {
-			INTOFF;
-			if ((flags & (VTEXTFIXED|VSTACK)) == 0)
-				ckfree(vp->text);
-			*vpp = vp->next;
-			ckfree(vp);
-			INTON;
-		} else if (!(flags & VUNSET)) {
-			setvar(s, 0, 0);
-			vp->flags &= ~VEXPORT;
-		}
-		retval = 0;
-	}
-
-out:
-	return retval;
+	setvar(s, 0, 0);
 }
 
 
diff --git a/src/var.h b/src/var.h
index 32b0dde..2bb82b1 100644
--- a/src/var.h
+++ b/src/var.h
@@ -142,7 +142,7 @@ int localcmd(int, char **);
 void pushlocalvars(void);
 void poplocalvars(void);
 int unsetcmd(int, char **);
-int unsetvar(const char *);
+void unsetvar(const char *);
 int varcmp(const char *, const char *);
 
 static inline int varequal(const char *a, const char *b) {
54c0d48e3f9f3b0a3ea4b5c71cbd6b332df5&follow=1'>Move color selection to format.cJune McEnroe 2018-09-13Fix len for format->split at end of stringJune McEnroe 2018-09-13Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe I have no idea why I did this. 2018-09-13Rewrite UI againJune McEnroe The persistent topic is gone and the status line is now at the top. The status formatting still needs to be reworked. I also want to try showing the nick in the input window so it really looks like your next message. 2018-09-12Add note about C-oJune McEnroe Why are there so few well usable ctrl key bindings? 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe Ridiculous. 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe