about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-03-03 17:37:13 -0500
committerJune McEnroe <june@causal.agency>2021-03-03 17:37:13 -0500
commitd8b2df1479e8c73080be859c3b0d7b7d2b02bf0e (patch)
treef4a659afb2434d0287363b12c32f65afc0612b69
parentOutput updated paths (diff)
downloadbubger-d8b2df1479e8c73080be859c3b0d7b7d2b02bf0e.tar.gz
bubger-d8b2df1479e8c73080be859c3b0d7b7d2b02bf0e.zip
Add -t flag to truncate stdout before writing paths
-rw-r--r--archive.c15
-rw-r--r--bubger.118
2 files changed, 25 insertions, 8 deletions
diff --git a/archive.c b/archive.c
index 1ef4f33..91c6118 100644
--- a/archive.c
+++ b/archive.c
@@ -82,6 +82,7 @@ static void createDirs(void) {
 
 int main(int argc, char *argv[]) {
 	int exitStatus = 0;
+	bool truncate = false;
 
 	const char *host = NULL;
 	const char *port = "imaps";
@@ -95,7 +96,7 @@ int main(int argc, char *argv[]) {
 
 	for (
 		int opt;
-		0 < (opt = getopt(argc, argv, "C:H:S:a:h:im:p:qs:t:u:vw:y:"));
+		0 < (opt = getopt(argc, argv, "C:H:S:T:a:h:im:p:qs:tu:vw:y:"));
 	) {
 		switch (opt) {
 			break; case 'C': {
@@ -104,6 +105,7 @@ int main(int argc, char *argv[]) {
 			}
 			break; case 'H': concatHead = optarg;
 			break; case 'S': search = optarg;
+			break; case 'T': baseTitle = optarg;
 			break; case 'a': algo = optarg;
 			break; case 'h': host = optarg;
 			break; case 'i': idle = true;
@@ -111,7 +113,7 @@ int main(int argc, char *argv[]) {
 			break; case 'p': port = optarg;
 			break; case 'q': quiet = true; exitStatus = EXIT_FAILURE;
 			break; case 's': baseSubscribe = optarg;
-			break; case 't': baseTitle = optarg;
+			break; case 't': truncate = true;
 			break; case 'u': baseURL = optarg;
 			break; case 'v': imapVerbose = true;
 			break; case 'w': passPath = optarg;
@@ -177,7 +179,13 @@ int main(int argc, char *argv[]) {
 	for (; resp = respOk(imapResp(&imap)), resp.tag != login; respFree(resp));
 	respFree(resp);
 
-examine:;
+examine:
+	if (truncate) {
+		int error = ftruncate(STDOUT_FILENO, 0);
+		if (error) warn("ftruncate");
+		rewind(stdout);
+	}
+
 	uint32_t uidNext = 0;
 	uint32_t uidValidity = 0;
 	enum Atom examine = atom("examine");
@@ -259,6 +267,7 @@ concat:;
 
 	concatThreads(threads, envelopes);
 	concatIndex(threads, envelopes);
+	fflush(stdout);
 	uidWrite("UIDNEXT", uidNext);
 
 	for (size_t i = 0; i < threads.len; ++i) {
diff --git a/bubger.1 b/bubger.1
index 80392bb..56bf658 100644
--- a/bubger.1
+++ b/bubger.1
@@ -8,16 +8,16 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl iqv
+.Op Fl iqtv
 .Op Fl C Ar path
 .Op Fl H Ar head
 .Op Fl S Ar search
+.Op Fl T Ar title
 .Op Fl a Ar algo
 .Op Fl h Ar host
 .Op Fl m Ar addr
 .Op Fl p Ar port
 .Op Fl s Ar url
-.Op Fl t Ar title
 .Op Fl u Ar base
 .Op Fl w Ar file
 .Op Fl y Ar css
@@ -58,6 +58,10 @@ Limit threads to messages matching
 The default search is
 .Sy ALL .
 .
+.It Fl T Ar title
+Set the title for the index HTML page and Atom feed.
+The default title is the mailbox name.
+.
 .It Fl a Ar algo
 Set the threading algorithm to one of
 .Sy ORDEREDSUBJECT
@@ -110,9 +114,13 @@ link of
 .Ar url
 to the index page navigation.
 .
-.It Fl t Ar title
-Set the title for the index HTML page and Atom feed.
-The default title is the mailbox name.
+.It Fl t
+Attempt to truncate standard output
+before writing the list of updated files.
+With
+.Fl i ,
+truncate before each time
+files are updated.
 .
 .It Fl u Ar base
 Set the base URL for links in Atom feeds.