From 96068224350f214ff6bdea8c401eeb13750cc369 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 26 Apr 2020 21:02:54 -0400 Subject: Add -q to exit non-zero on early exit --- archive.c | 27 +++++++++++++++++++-------- bubger.1 | 5 ++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/archive.c b/archive.c index 6a3f612..a3b7f84 100644 --- a/archive.c +++ b/archive.c @@ -56,7 +56,16 @@ static void createDir(const char *path) { if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", path); } +static void createDirs(void) { + createDir("UID"); + createDir("attachment"); + createDir("message"); + createDir("thread"); +} + int main(int argc, char *argv[]) { + int exitStatus = 0; + const char *host = NULL; const char *port = "imaps"; const char *user = NULL; @@ -66,7 +75,7 @@ int main(int argc, char *argv[]) { const char *algo = "REFERENCES"; const char *search = "ALL"; - for (int opt; 0 < (opt = getopt(argc, argv, "C:a:h:m:p:s:t:u:vw:"));) { + for (int opt; 0 < (opt = getopt(argc, argv, "C:a:h:m:p:qs:t:u:vw:"));) { switch (opt) { break; case 'C': { int error = chdir(optarg); @@ -76,6 +85,7 @@ int main(int argc, char *argv[]) { break; case 'h': concatHead = optarg; break; case 'm': baseAddress = optarg; break; case 'p': port = optarg; + break; case 'q': exitStatus = EXIT_FAILURE; break; case 's': search = optarg; break; case 't': baseTitle = optarg; break; case 'u': baseURL = optarg; @@ -107,9 +117,6 @@ int main(int argc, char *argv[]) { if (!pass) errx(EX_CONFIG, ENV_PASSWORD " unset"); } - FILE *imapRead, *imap; - imapOpen(&imapRead, &imap, host, port); - enum { Ready, Login, @@ -130,6 +137,9 @@ int main(int argc, char *argv[]) { uint32_t uidNext = 0; struct List threads = {0}; struct Envelope *envelopes = NULL; + + FILE *imapRead, *imap; + imapOpen(&imapRead, &imap, host, port); for (struct Resp resp; resp = imapResp(imapRead), resp.resp != AtomBye;) { if (resp.resp == AtomNo || resp.resp == AtomBad) { errx(EX_CONFIG, "%s %s", Atoms[resp.resp], resp.text); @@ -170,6 +180,8 @@ int main(int argc, char *argv[]) { if (uidNext == prev) { fprintf(imap, "ayy LOGOUT\r\n"); state = Logout; + } else { + exitStatus = EXIT_SUCCESS; } } } @@ -187,10 +199,7 @@ int main(int argc, char *argv[]) { if (!resp.data.len) { errx(EX_TEMPFAIL, "no messages matching %s", search); } - createDir("UID"); - createDir("attachment"); - createDir("message"); - createDir("thread"); + createDirs(); threads = resp.data; resp.data = (struct List) {0}; @@ -237,4 +246,6 @@ int main(int argc, char *argv[]) { } fclose(imapRead); fclose(imap); + + return exitStatus; } diff --git a/bubger.1 b/bubger.1 index 07ae858..b626f6c 100644 --- a/bubger.1 +++ b/bubger.1 @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm -.Op Fl v +.Op Fl qv .Op Fl C Ar path .Op Fl a Ar algo .Op Fl h Ar head @@ -65,6 +65,9 @@ The default port is .Pq 993 . TLS without STARTTLS is assumed. . +.It Fl q +Exit non-zero if no changes are made. +. .It Fl s Ar search Limit threads to messages matching .Ar search . -- cgit 1.4.1 &id=c0b59823035efc136a82a96094d164a979d9b2e9&follow=1'>redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping 2015-08-12log: allow users to follow a fileJohn Keeping 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld 2015-08-12filters: apply HTML escapingLazaros Koromilas 2015-08-12git: update to v2.5.0Christian Hesse 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reicheltme catsh to 1shJune McEnroe Yes it's another rename because I felt like catsh was too long. 1sh is short and unique. 2019-06-28Set HISTSIZE in catshJune McEnroe 2019-06-28Unset iflag when exiting catshJune McEnroe It saves history! It's usable! 2019-06-24Consolidate catsh history documentationJune McEnroe 2019-06-19Set LESS=FRXJune McEnroe This is how git invokes less by default. I think I want this everywhere. This allows color, exits if the input fits on one screen, and doesn't clear the screen. 2019-06-16Alias date=ddateJune McEnroe Will I regret this? 2019-06-15Set sensitivity by slot in TF2June McEnroe 2019-06-15Add AcceptanceJune McEnroe 2019-06-07Add variables to bitJune McEnroe 2019-06-05Add A Closed and Common OrbitJune McEnroe 2019-06-02Add RebornJune McEnroe 2019-05-30Add bit to bin.7June McEnroe 2019-05-30Simplify and build bitJune McEnroe lex is a waste of time. 2019-05-29Add xx -p optionJune McEnroe 2019-05-27Add FrontierJune McEnroe 2019-05-27Break nicks with ZWNJJune McEnroe This should prevent bad wrapping. 2019-05-26Add DawnJune McEnroe 2019-05-20Declare vasprintf(3) for GNUJune McEnroe who the fuck is scraeming "#define _GNU_SOURCE" at my house. show yourself, coward. i will never #define _GNU_SOURCE 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe Their %-prefixed directives should probably be highlighted Macro. 2019-05-10Use val instead of suboptargJune McEnroe suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure? 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it. 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe