Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with a non-zero exit status if a given mail does not exist #265

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blaze822.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ struct blaze822_seq_iter {
};

char *blaze822_seq_next(char *map, char *range, struct blaze822_seq_iter *iter);
long blaze822_loop(int, char **, void (*)(char *));
long blaze822_loop1(char *arg, void (*cb)(char *));
int blaze822_loop(int, char **, void (*)(char *));
int blaze822_loop1(char *arg, void (*cb)(char *));
char *blaze822_home_file(char *basename);

// filter.c
Expand Down
6 changes: 2 additions & 4 deletions maddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ main(int argc, char *argv[])
xpledge("stdio rpath", "");

if (argc == optind && isatty(0))
blaze822_loop1(":", addr);
return blaze822_loop1(":", addr);
else
blaze822_loop(argc-optind, argv+optind, addr);

return 0;
return blaze822_loop(argc-optind, argv+optind, addr);
}
7 changes: 5 additions & 2 deletions magrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,13 @@ main(int argc, char *argv[])
exit(2);
}

int ret;
if (argc == optind && isatty(0))
blaze822_loop1(":", magrep);
ret = blaze822_loop1(":", magrep);
else
blaze822_loop(argc-optind, argv+optind, magrep);
ret = blaze822_loop(argc-optind, argv+optind, magrep);
if (ret)
return 2;

if (cflag && !qflag && !mflag)
printf("%ld\n", matches);
Expand Down
4 changes: 1 addition & 3 deletions mdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ main(int argc, char *argv[])
if (argc == optind + 1 && isatty(0))
goto usage;
else
blaze822_loop(argc - 1 - optind, argv + optind, refile);

return 0;
return blaze822_loop(argc - 1 - optind, argv + optind, refile);
}

int c;
Expand Down
4 changes: 2 additions & 2 deletions mexport.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ main(int argc, char *argv[])
xpledge("stdio rpath", "");

if (argc == optind && isatty(0))
blaze822_loop1(":", export);
status |= blaze822_loop1(":", export);
else
blaze822_loop(argc-optind, argv+optind, export);
status |= blaze822_loop(argc-optind, argv+optind, export);

return status;
}
20 changes: 9 additions & 11 deletions mflag.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,29 @@ main(int argc, char *argv[])

if (vflag) {
if (argc == optind && !isatty(0)) {
blaze822_loop(0, 0, flag); // read from stdin
return 0;
return blaze822_loop(0, 0, flag); // read from stdin
}

args = calloc(argsalloc, sizeof (char *));
if (!args)
exit(-1);

int status;
if (argc == optind)
blaze822_loop1(".", add);
status = blaze822_loop1(".", add);
else
blaze822_loop(argc-optind, argv+optind, add);
status = blaze822_loop(argc-optind, argv+optind, add);

if (isatty(0))
blaze822_loop1(":", flag);
status |= blaze822_loop1(":", flag);
else
blaze822_loop(0, 0, flag);
status |= blaze822_loop(0, 0, flag);

return 0;
return status;
}

if (argc == optind && isatty(0))
blaze822_loop1(".", flag);
return blaze822_loop1(".", flag);
else
blaze822_loop(argc-optind, argv+optind, flag);

return 0;
return blaze822_loop(argc-optind, argv+optind, flag);
}
7 changes: 5 additions & 2 deletions mhdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,13 @@ main(int argc, char *argv[])

xpledge("stdio rpath", "");

int ret;
if (argc == optind && isatty(0))
blaze822_loop1(".", header);
ret = blaze822_loop1(".", header);
else
blaze822_loop(argc-optind, argv+optind, header);
ret = blaze822_loop(argc-optind, argv+optind, header);
if (ret)
return 2;

return status;
}
3 changes: 2 additions & 1 deletion minc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ main(int argc, char *argv[])
if (optind == argc) {
if (isatty(0))
goto usage;
blaze822_loop(0, 0, inc);
if (blaze822_loop(0, 0, inc))
return 1;
} else {
for (i = optind; i < argc; i++)
inc(argv[i]);
Expand Down
5 changes: 3 additions & 2 deletions mlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ main(int argc, char *argv[])
flagsum++;
}

int status = 0;
if (optind == argc) {
if (isatty(0))
goto usage;
blaze822_loop(0, 0, listarg);
status = blaze822_loop(0, 0, listarg);
} else {
for (i = optind; i < argc; i++)
listarg(argv[i]);
Expand All @@ -300,5 +301,5 @@ main(int argc, char *argv[])
tunseen, tflagged, tcount);
}

return 0;
return status;
}
13 changes: 8 additions & 5 deletions mpick.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static int need_thr;

static long kept;
static long num;
static long seen;

static struct expr *expr;
static long cur_idx;
Expand Down Expand Up @@ -1363,6 +1364,7 @@ collect(char *file)
struct mlist *ml;
char *f;

seen++;
f = xstrdup(file);
m = xcalloc(1, sizeof *m);
m = mailfile(m, f);
Expand Down Expand Up @@ -1409,6 +1411,7 @@ void
oneline(char *file)
{
struct mailinfo m = { 0 };
seen++;
m.index = num++;
(void) mailfile(&m, file);
if (expr && !eval(expr, &m))
Expand All @@ -1429,7 +1432,6 @@ oneline(char *file)
int
main(int argc, char *argv[])
{
long i;
int c;
int vflag;

Expand Down Expand Up @@ -1464,11 +1466,12 @@ main(int argc, char *argv[])

xpledge("stdio rpath wpath cpath proc exec", 0);

int status;
void (*cb)(char *) = need_thr ? collect : oneline;
if (argc == optind && isatty(0))
i = blaze822_loop1(":", cb);
status = blaze822_loop1(":", cb);
else
i = blaze822_loop(argc-optind, argv+optind, cb);
status = blaze822_loop(argc-optind, argv+optind, cb);

/* print and free last thread */
if (Tflag && thr)
Expand All @@ -1477,7 +1480,7 @@ main(int argc, char *argv[])
freeexpr(expr);

if (vflag)
fprintf(stderr, "%ld mails tested, %ld picked.\n", i, kept);
fprintf(stderr, "%ld mails tested, %ld picked.\n", seen, kept);

for (; files; files = fileq) {
fileq = files->next;
Expand All @@ -1488,5 +1491,5 @@ main(int argc, char *argv[])
free(files);
}

return 0;
return status;
}
17 changes: 9 additions & 8 deletions mscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static int cols;
static wchar_t replacement = L'?';
static char *cur;
static long seen;

static char *aliases[32];
static int alias_idx;
Expand Down Expand Up @@ -306,6 +307,7 @@ print_human(intmax_t i, int w)
void
oneline(char *file)
{
seen++;
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
Expand Down Expand Up @@ -559,10 +561,9 @@ main(int argc, char *argv[])

if (nflag) {
if (argc == optind && isatty(0))
blaze822_loop1(":", numline);
return blaze822_loop1(":", numline);
else
blaze822_loop(argc-optind, argv+optind, numline);
return 0;
return blaze822_loop(argc-optind, argv+optind, numline);
}

now = time(0);
Expand Down Expand Up @@ -622,17 +623,17 @@ main(int argc, char *argv[])
fflag = v;
}

long i;
int status;
if (argc == optind && isatty(0))
i = blaze822_loop1(":", oneline);
status = blaze822_loop1(":", oneline);
else
i = blaze822_loop(argc-optind, argv+optind, oneline);
status = blaze822_loop(argc-optind, argv+optind, oneline);

if (pager_pid > 0)
pipeclose(pager_pid);

if (vflag)
fprintf(stderr, "%ld mails scanned\n", i);
fprintf(stderr, "%ld mails scanned\n", seen);

return 0;
return status;
}
6 changes: 2 additions & 4 deletions msed.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ main(int argc, char *argv[])
optind++;

if (argc == optind && isatty(0))
blaze822_loop1(".", sed);
return blaze822_loop1(".", sed);
else
blaze822_loop(argc-optind, argv+optind, sed);

return 0;
return blaze822_loop(argc-optind, argv+optind, sed);
}
10 changes: 4 additions & 6 deletions mseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,11 @@ main(int argc, char *argv[])

xpledge("stdio rpath wpath cpath", "");

if (cflag)
blaze822_loop1(cflag, overridecur);
if (cflag && blaze822_loop1(cflag, overridecur))
return 1;

if (Cflag) {
blaze822_loop1(Cflag, setcur);
return 0;
}
if (Cflag)
return blaze822_loop1(Cflag, setcur);

if (Sflag && optind != argc) {
fprintf(stderr, "error: -S/-A doesn't take arguments.\n");
Expand Down
21 changes: 11 additions & 10 deletions mshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,13 @@ extract_cb(char *file)
blaze822_walk_mime(msg, 0, extract_mime);
}

void
int
extract(char *file, int argc, char **argv, int use_stdout)
{
extract_argc = argc;
extract_argv = argv;
extract_stdout = use_stdout;
blaze822_loop1(file, extract_cb);
return blaze822_loop1(file, extract_cb);
}

static char *newcur;
Expand Down Expand Up @@ -832,21 +832,22 @@ main(int argc, char *argv[])
}
}

int status = 0;
if (xflag) { // extract
xpledge("stdio rpath wpath cpath", NULL);
extract(xflag, argc-optind, argv+optind, 0);
status = extract(xflag, argc-optind, argv+optind, 0);
} else if (Oflag) { // extract to stdout
xpledge("stdio rpath", NULL);
extract(Oflag, argc-optind, argv+optind, 1);
status = extract(Oflag, argc-optind, argv+optind, 1);
} else if (tflag) { // list
xpledge("stdio rpath", NULL);
if (argc == optind && isatty(0))
blaze822_loop1(".", list);
status = blaze822_loop1(".", list);
else
blaze822_loop(argc-optind, argv+optind, list);
status = blaze822_loop(argc-optind, argv+optind, list);
} else if (Rflag) { // render for reply
xpledge("stdio rpath", NULL);
blaze822_loop(argc-optind, argv+optind, reply);
status = blaze822_loop(argc-optind, argv+optind, reply);
} else { // show
/* XXX pledge: still r/w on the whole file-system + fork/exec */
if (!(qflag || rflag || Fflag)) {
Expand All @@ -857,9 +858,9 @@ main(int argc, char *argv[])
filters = blaze822(f);
}
if (argc == optind && isatty(0))
blaze822_loop1(".", show);
status = blaze822_loop1(".", show);
else
blaze822_loop(argc-optind, argv+optind, show);
status = blaze822_loop(argc-optind, argv+optind, show);
if (!nflag) // don't set cur
if (newcur)
blaze822_seq_setcur(newcur);
Expand All @@ -875,5 +876,5 @@ main(int argc, char *argv[])
return 1;
}

return 0;
return status;
}
7 changes: 4 additions & 3 deletions msort.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,11 @@ main(int argc, char *argv[])
if (!mails)
exit(-1);

int status;
if (argc == optind && isatty(0))
blaze822_loop1(":", add);
status = blaze822_loop1(":", add);
else
blaze822_loop(argc-optind, argv+optind, add);
status = blaze822_loop(argc-optind, argv+optind, add);

qsort(mails, idx, sizeof (struct mail), order);

Expand All @@ -337,5 +338,5 @@ main(int argc, char *argv[])
for (i = 0; i < idx; i++)
printf("%s\n", mails[i].file);

return 0;
return status;
}
Loading