From: Philipp Takacs <philipp@bureaucracy.de>
Date: Thu, 5 Nov 2015 21:48:34 +0000 (+0100)
Subject: handle hghsel lowsel and numsel in (un)set_selected
X-Git-Tag: mmh-0.3~63
X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=1492dd50aa1043da58809ca0fec18cb6ab9937bc;p=mmh

handle hghsel lowsel and numsel in (un)set_selected

Now you can use this funkitions without taking care
of this values.

Thanks c_14 for reporting this bug.
---

diff --git a/sbr/folder_addmsg.c b/sbr/folder_addmsg.c
index 4cc8d6c6..e14c7099 100644
--- a/sbr/folder_addmsg.c
+++ b/sbr/folder_addmsg.c
@@ -87,20 +87,6 @@ folder_addmsg(struct msgs **mpp, char *msgfile, int selected,
 		/* should we set the SELECTED bit? */
 		if (selected) {
 			set_selected(mp, msgnum);
-
-			/* check if highest or lowest selected */
-			if (mp->numsel == 0) {
-				mp->lowsel = msgnum;
-				mp->hghsel = msgnum;
-			} else {
-				if (msgnum < mp->lowsel)
-					mp->lowsel = msgnum;
-				if (msgnum > mp->hghsel)
-					mp->hghsel = msgnum;
-			}
-
-			/* increment number selected */
-			mp->numsel++;
 		}
 
 		/*
diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c
index 8e5fd0a2..31658838 100644
--- a/sbr/folder_delmsgs.c
+++ b/sbr/folder_delmsgs.c
@@ -28,7 +28,6 @@ folder_delmsgs(struct msgs *mp, int hook)
 
 		/* unselect message */
 		unset_selected(mp, msgnum);
-		mp->numsel--;
 
 		snprintf(msgpath, sizeof (msgpath), "%s/%d",
 				mp->foldpath, msgnum);
diff --git a/sbr/m_convert.c b/sbr/m_convert.c
index f113366c..0a475681 100644
--- a/sbr/m_convert.c
+++ b/sbr/m_convert.c
@@ -44,13 +44,6 @@ addtosel(struct msgs *mp, int msg)
 		return;  /* dont select twice */
 	}
 	set_selected(mp, msg);
-	mp->numsel++;
-	if (mp->lowsel == 0 || msg < mp->lowsel) {
-		mp->lowsel = msg;
-	}
-	if (msg > mp->hghsel) {
-		mp->hghsel = msg;
-	}
 }
 
 int
diff --git a/sbr/seq_msgstats.c b/sbr/seq_msgstats.c
index eb483b7b..6b89d705 100644
--- a/sbr/seq_msgstats.c
+++ b/sbr/seq_msgstats.c
@@ -99,6 +99,13 @@ set_selected(struct msgs *mp, int msgnum)
 {
 	assert_msg_range(mp, msgnum);
 	mp->msgstats[msgnum - mp->lowoff] |= SELECTED;
+	if (mp->lowsel == 0 || msgnum < mp->lowsel) {
+		mp->lowsel = msgnum;
+	}
+	if (msgnum > mp->hghsel) {
+		mp->hghsel = msgnum;
+	}
+	mp->numsel++;
 }
 
 void
@@ -120,6 +127,9 @@ unset_selected(struct msgs *mp, int msgnum)
 {
 	assert_msg_range(mp, msgnum);
 	mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED;
+	if (mp->numsel > 0) {
+		mp->numsel--;
+	}
 }
 
 void
diff --git a/uip/pick.c b/uip/pick.c
index 984d80bd..2d2bd650 100644
--- a/uip/pick.c
+++ b/uip/pick.c
@@ -274,7 +274,6 @@ main(int argc, char **argv)
 			} else {
 				/* if it doesn't match, then unselect it */
 				unset_selected(mp, msgnum);
-				mp->numsel--;
 			}
 			if (fp)
 				fclose(fp);