]> git.plutz.net Git - gladerunner/commitdiff
read arbitrarily long command lines + embedded line breaks
authorPaul Hänsch <paul@plutz.net>
Mon, 13 Jul 2026 15:48:38 +0000 (17:48 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 13 Jul 2026 15:48:38 +0000 (17:48 +0200)
glade1.c
glade1.glade

index 712c86dd9c8b6fa72c6cfd3352f39aeb4d374305..de2a1987330c5df59df62eb9bdf38f9fda77affb 100644 (file)
--- a/glade1.c
+++ b/glade1.c
@@ -109,12 +109,23 @@ void a_command(char *cli) {
 
 gboolean idle_readline(gpointer d) {
   // GtkBuilder *bld = GTK_BUILDER(d);
-  static char buf[128];
-  int len;
-
-  if ( (len = read(0, &buf, 127)) > 0 ) {
-    buf[len] = 0;
+  static size_t s = 128;
+  static char *buf = NULL;
+  static int len = 0; int l;
+  if (!buf) buf = malloc(s);
+
+  l = read(0, buf + len, s - len);
+  while ( l > 0 ) {
+    len += l;
+    if ( buf[len - 1] == '\n' && (len < 2 || buf[len - 2] != '\\') ) break;
+    else if (len >= 2) buf[--len - 1] = '\n';
+    if ( len == s - 1 ) buf = realloc(buf, s+=128);
+    l = read(0, buf + len, s - len);
+  }
+  if ( l > 0 ) {
+    buf[len - 1] = 0;
     a_command(buf);
+    len = 0;
   }
   return 1;
 }
index a09f50d6d1baeb20ae9d2f79d135bf9e6973feeb..de6da826fbc69b7228622a8c6bc347dc05de223d 100644 (file)
@@ -9,11 +9,8 @@
   <object class="GtkWindow" id="win1">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
-    <property name="modal">True</property>
     <property name="window-position">mouse</property>
     <property name="icon-name">applications-science</property>
-    <property name="skip-taskbar-hint">True</property>
-    <property name="skip-pager-hint">True</property>
     <signal name="destroy" handler="app_quit" swapped="no"/>
     <child>
       <object class="GtkBox">