From: David Levine Date: Fri, 12 Oct 2012 02:48:42 +0000 (-0500) Subject: Added -noall/-all switches to sortm(1). X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=a6f717992d5588898c37711aa1895dbb11016e1c;p=mmh Added -noall/-all switches to sortm(1). --- diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 9550117..fcc99a7 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -24,6 +24,9 @@ NEW FEATURES (pseudo)random bytes and uses microsecond-resolution time. - Added -clobber switch to mhstore(1) to control overwriting of existing files. +- Added -noall/-all switches to sortm(1). sortm -noall requires + a messages argument. + ---------------------------- OBSOLETE/DEPRECATED FEATURES diff --git a/man/sortm.man b/man/sortm.man index 47dcee3..dd24014 100644 --- a/man/sortm.man +++ b/man/sortm.man @@ -10,6 +10,7 @@ sortm \- sort messages .B sortm .RI [ +folder ] .RI [ msgs ] +.RB [ \-all | \-noall ] .RB [ \-datefield .IR field ] .RB [ \-textfield @@ -27,6 +28,21 @@ sortm \- sort messages sorts the specified messages in the named folder according to the chronological order of the \*(lqDate:\*(rq field of each message. .PP +If no messages are specified, the default is all messages in the folder. +However, if no messages are specified and the +.B \-noall +switch is enabled, then +.B sortm +reports that as an error and exits with non-zero status. +.B \-noall +is most useful in the user's profile, to avoid inadvertant sorting of +an entire folder. The +.B \-all +switch can then be used on the command line to disable it. Of course, +a message specification of +.I all +can be used in any case. +.PP The .B \-verbose switch directs @@ -104,7 +120,8 @@ folder(1) .SH DEFAULTS .nf .RB ` +folder "' defaults to the current folder" -.RB ` msgs"' defaults to all" +.RB ` msgs"' defaults to all without -noall, no default with -noall" +.RB ` \-all ' .RB ` \-datefield "' defaults to date" .RB ` \-notextfield ' .RB ` \-noverbose ' diff --git a/test/folder/test-sortm b/test/folder/test-sortm index daee94b..0e33154 100755 --- a/test/folder/test-sortm +++ b/test/folder/test-sortm @@ -22,7 +22,7 @@ actual=$MH_TEST_DIR/$$.actual cd $MH_TEST_DIR # check -help -cat >$expected <"$expected" <$actual 2>&1 -check $expected $actual +sortm -help >"$actual" 2>&1 +check "$expected" "$actual" # check -version case `sortm -version` in @@ -45,7 +46,7 @@ case `sortm -version` in failed=`expr ${failed:-0} + 1`;; esac -cat > $MH_TEST_DIR/Mail/inbox/11 <$MH_TEST_DIR/Mail/inbox/11 < To: Some User Date: Fri, 29 Sep 2006 00:00:01 @@ -55,7 +56,7 @@ Subject: Re: common subject This is message number 11 EOF -cat > $MH_TEST_DIR/Mail/inbox/12 <$MH_TEST_DIR/Mail/inbox/12 < To: Some User Date: Thu, 28 Sep 2006 23:59:59 @@ -66,7 +67,7 @@ This is message number 12 EOF # check with no options -cat >$expected <"$expected" <> 2 09/29 Test1 Testing message 1<> 3 09/29 Test2 Testing message 2<> @@ -82,11 +83,11 @@ cat >$expected < $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check +folder -cat >$expected <"$expected" <> 2+ 09/29 Test1 Testing message 1<> 3 09/29 Test2 Testing message 2<> @@ -101,14 +102,13 @@ cat >$expected <> EOF -refile first +inbox -folder -pack > /dev/null +refile first +inbox; folder -pack >/dev/null sortm +inbox -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -verbose -cat >$expected <"$expected" <> EOF -refile first +inbox -folder -pack > /dev/null -sortm -verbose >$actual -scan >> $actual -check $expected $actual +refile first +inbox; folder -pack >/dev/null +sortm -verbose >"$actual" +scan >>"$actual" +check "$expected" "$actual" # check -noverbose -cat >$expected <"$expected" <> 2+ 09/29 Test1 Testing message 1<> 3 09/29 Test2 Testing message 2<> @@ -158,14 +157,13 @@ cat >$expected <> EOF -refile first +inbox -folder -pack > /dev/null -sortm -verbose -noverbose >$actual -scan >> $actual -check $expected $actual +refile first +inbox; folder -pack >/dev/null +sortm -verbose -noverbose >"$actual" +scan >>"$actual" +check "$expected" "$actual" # check msgs -cat >$expected <"$expected" <> 2 09/29 Test2 Testing message 2<> 3 09/29 Test3 Testing message 3<> @@ -180,14 +178,13 @@ cat >$expected <> EOF -refile first +inbox -folder -pack > /dev/null +refile first +inbox; folder -pack >/dev/null sortm first last -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -datefield -cat >$expected <"$expected" <> 2 09/29 Test2 Testing message 2<> 3 09/29 Test3 Testing message 3<> @@ -203,11 +200,11 @@ cat >$expected < $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -textfield subject (datefield major, subjects grouped) -cat >$expected <"$expected" <> 2 09/29 Test11 Re: common subject<> 3 09/29 Test2 Testing message 2<> @@ -223,11 +220,11 @@ cat >$expected < $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -nolimit -cat >$expected <"$expected" <> 2 09/29 Test11 Re: common subject<> 3 09/29 Test2 Testing message 2<> @@ -243,11 +240,11 @@ cat >$expected < $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -textfield subject -limit 0 (subject sort) -cat >$expected <"$expected" <> 2 09/28 Test12 common subject<> 3 09/29 Test1 Testing message 1<> @@ -262,13 +259,13 @@ cat >$expected <> EOF -refile 2-7 +inbox; refile 1 +inbox; folder -pa last >/dev/null +refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null sortm -textfield subject -limit 0 -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -textfield -limit 0 (text sort) -cat >$expected <"$expected" <> 2 09/29 Test11 Re: common subject<> 3 09/28 Test12 common subject<> @@ -283,13 +280,13 @@ cat >$expected <> EOF -refile 2-7 +inbox; refile 1 +inbox; folder -pa last >/dev/null +refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null sortm -textfield from -limit 0 -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -textfield with finite -limit that doesn't cover message 13 -cat > $MH_TEST_DIR/Mail/inbox/13 <$MH_TEST_DIR/Mail/inbox/13 < To: Some User Date: Tue, 31 Oct 2006 23:59:59 @@ -298,7 +295,7 @@ Subject: Re: common subject This is message number 13 EOF -cat >$expected <"$expected" <> 2 09/29 Test11 Re: common subject<> 3 09/29 Test5 Testing message 5<> @@ -314,13 +311,13 @@ cat >$expected <> EOF -refile 2-7 +inbox; refile 1 +inbox; folder -pa last >/dev/null +refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null sortm -textfield subject -limit 10 -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -textfield with finite -limit that does cover message 13 -cat >$expected <"$expected" <> 2 09/29 Test11 Re: common subject<> 3 10/31 Test13 Re: common subject<> @@ -336,13 +333,13 @@ cat >$expected <> EOF -refile 2-7 +inbox; refile 1 +inbox; folder -pa last >/dev/null +refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null sortm -textfield subject -limit 60 -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" # check -notextfield -cat >$expected <"$expected" <> 2 09/29 Test10 Testing message 10<> 3 09/29 Test5 Testing message 5<> @@ -358,9 +355,35 @@ cat >$expected <> EOF -refile 2-7 +inbox; refile 1 +inbox; folder -pa last >/dev/null +refile 2-7 +inbox; refile 1 +inbox; folder -pack last >/dev/null sortm -textfield subject -limit 60 -notextfield -scan > $actual -check $expected $actual +scan >"$actual" +check "$expected" "$actual" -exit $failed +# check -noall +run_test 'sortm -noall' 'sortm: must specify messages to sort with -noall' + +# check -all +cat >"$expected" <> + 2+ 09/29 Test10 Testing message 10<> + 3 09/29 Test5 Testing message 5<> + 4 09/29 Test6 Testing message 6<> + 5 09/29 Test7 Testing message 7<> + 6 09/29 Test8 Testing message 8<> + 7 09/29 Test9 Testing message 9<> + 8 09/29 Test1 Testing message 1<> + 9 09/29 Test2 Testing message 2<> + 10 09/29 Test3 Testing message 3<> + 11 09/29 Test4 Testing message 4<> + 12 09/29 Test11 Re: common subject<> + 13 10/31 Test13 Re: common subject<> +EOF + +refile first +inbox; folder -pack >/dev/null +sortm -noall -all +scan >"$actual" +check "$expected" "$actual" + + +exit ${failed:-0} diff --git a/uip/sortm.c b/uip/sortm.c index a1fcf5d..d2486ee 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -28,9 +28,13 @@ static struct swit switches[] = { { "verbose", 0 }, #define NVERBSW 7 { "noverbose", 0 }, -#define VERSIONSW 8 +#define ALLMSGS 8 + { "all", 0 }, +#define NALLMSGS 9 + { "noall", 0 }, +#define VERSIONSW 10 { "version", 0 }, -#define HELPSW 9 +#define HELPSW 11 { "help", 0 }, { NULL, 0 } }; @@ -48,6 +52,7 @@ char *subjsort = (char *) 0; /* sort on subject if != 0 */ time_t datelimit = 0; int submajor = 0; /* if true, sort on subject-major */ int verbose; +int allmsgs = 1; /* This keeps compiler happy on calls to qsort */ typedef int (*qsort_comp) (const void *, const void *); @@ -153,6 +158,13 @@ main (int argc, char **argv) case NVERBSW: verbose = 0; continue; + + case ALLMSGS: + allmsgs = 1; + continue; + case NALLMSGS: + allmsgs = 0; + continue; } } if (*cp == '+' || *cp == '@') { @@ -166,8 +178,13 @@ main (int argc, char **argv) if (!context_find ("path")) free (path ("./", TFOLDER)); - if (!msgs.size) - app_msgarg(&msgs, "all"); + if (!msgs.size) { + if (allmsgs) { + app_msgarg(&msgs, "all"); + } else { + adios (NULL, "must specify messages to sort with -noall"); + } + } if (!datesw) datesw = "date"; if (!folder)