jcs
/subtext
/amendments
/352
main: Hook up binkp thread, handle malloc failure, allow blanker disabling
jcs made amendment 352 over 2 years ago
--- main.c	Sun Feb  5 11:13:11 2023
+++ main.c	Thu Mar  2 07:59:17 2023
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020-2022 joshua stein <jcs@jcs.org>
+ * Copyright (c) 2020-2023 joshua stein <jcs@jcs.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -18,6 +18,7 @@
 #include <string.h>
 
 #include "subtext.h"
+#include "binkp.h"
 #include "console.h"
 #include "db.h"
 #include "focusable.h"
@@ -37,6 +38,7 @@ struct db *db = NULL;
 bool blanker_on = false;
 unsigned long blanker_last_blank = 0;
 WindowPtr blanker_win = NULL;
+struct binkp_connection *binkpc = NULL;
 
 bool handle_menu(long menu_id);
 void handle_exit(void);
@@ -117,7 +119,9 @@ main(void)
 		telnet_init();
 	if (db->config.modem_port)
 		serial_init();
-	
+	if (db->config.binkp_hostname[0])
+		uthread_add(binkp_process, NULL);
+		
 	blanker_last_blank = Time;
 
 	while (!quitting) {
@@ -143,7 +147,6 @@ main(void)
 					strlcpy(last_daily_job, today, sizeof(last_daily_job));
 				}
 			}
-			
 			continue;
 		}
 		
@@ -268,6 +271,8 @@ handle_exit(void)
 			focusables[n]->atexit(focusables[n]);
 	}
 	
+	binkp_atexit();
+	
 	if (db->config.telnet_port)
 		telnet_atexit();
 	if (db->config.modem_port)
@@ -314,8 +319,10 @@ handle_menu(long menu_id)
 				 * nfocusables and focusables array will probably be
 				 * modified as each focusable quits
 				 */
-				tfocusables = xcalloc(sizeof(Ptr), tnfocusables,
-				  "focusables quit");
+				tfocusables = xcalloc(sizeof(Ptr), tnfocusables);
+				if (tfocusables == NULL)
+					ExitToShell();
+					
 				memcpy(tfocusables, focusables,
 				  sizeof(Ptr) * tnfocusables);
 			
@@ -386,6 +393,9 @@ handle_menu(long menu_id)
 void
 blanker_idle(void)
 {
+	if (db->config.blanker_idle_seconds == 0)
+		return;
+		
 	if (!blanker_on && !nsessions &&
 	  (Time - blanker_last_blank > db->config.blanker_idle_seconds)) {
 		HideMenuBar();