aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-31 19:42:30 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-31 19:42:30 +0200
commit9e02ec69f18c186b5a23775aeb771965f259fb76 (patch)
tree829dd9444f2dcb259e3b4cc0867c45b35fe58aa7
parent2fc528e8ec81a7094229c3eec02a63d30a19e1a1 (diff)
downloadmblaze-9e02ec69f18c186b5a23775aeb771965f259fb76.tar.gz
mscan: add -n to only print message number
-rw-r--r--man/mscan.14
-rw-r--r--mscan.c39
2 files changed, 40 insertions, 3 deletions
diff --git a/man/mscan.1 b/man/mscan.1
index f780985..6582622 100644
--- a/man/mscan.1
+++ b/man/mscan.1
@@ -6,6 +6,7 @@
.Nd print a one line per message mail listing
.Sh SYNOPSIS
.Nm
+.Op Fl n
.Op Fl I
.Ar msgs\ ...
.Sh DESCRIPTION
@@ -33,6 +34,9 @@ and the subject of the message.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl n
+Only print message numbers
+(or file names, if the message is not in the current sequence).
.It Fl I
Force ISO date output.
Use twice to force ISO date and time output.
diff --git a/mscan.c b/mscan.c
index 91ec422..0b10dd7 100644
--- a/mscan.c
+++ b/mscan.c
@@ -26,6 +26,7 @@ static char *aliases[32];
static int alias_idx;
static int Iflag;
+static int nflag;
static int curyear;
static int curyday;
@@ -70,12 +71,35 @@ itsme(char *v)
return 0;
}
+static int init;
+
+void
+numline(char *file)
+{
+ if (!init) {
+ // delay loading of the seq until we need to scan the first
+ // file, in case someone in the pipe updated the map before
+ char *seq = blaze822_seq_open(0);
+ blaze822_seq_load(seq);
+ cur = blaze822_seq_cur();
+ init = 1;
+ }
+
+ while (*file == ' ' || *file == '\t')
+ file++;
+
+ long lineno = blaze822_seq_find(file);
+ if (lineno)
+ printf("%ld\n", lineno);
+ else
+ printf("%s\n", file);
+}
+
void
oneline(char *file)
{
int metawidth = 38;
- static int init;
if (!init) {
// delay loading of the seq until we need to scan the first
// file, in case someone in the pipe updated the map before
@@ -217,14 +241,23 @@ int
main(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "I")) != -1)
+ while ((c = getopt(argc, argv, "In")) != -1)
switch(c) {
case 'I': Iflag++; break;
+ case 'n': nflag = 1; break;
default:
- fprintf(stderr, "Usage: mscan [-I] [msgs...]\n");
+ fprintf(stderr, "Usage: mscan [-n] [-I] [msgs...]\n");
exit(1);
}
+ if (nflag) {
+ if (argc == optind && isatty(0))
+ blaze822_loop1(":", numline);
+ else
+ blaze822_loop(argc-optind, argv+optind, numline);
+ return 0;
+ }
+
time_t now = time(0);
struct tm *tm = localtime(&now);
curyear = tm->tm_year;