chiark / gitweb /
show title
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 19 Oct 2008 18:25:34 +0000 (19:25 +0100)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 19 Oct 2008 18:25:34 +0000 (19:25 +0100)
view.c

diff --git a/view.c b/view.c
index a395c8c..36b85b5 100644 (file)
--- a/view.c
+++ b/view.c
@@ -25,11 +25,44 @@ static struct stat input_stab;
 static const char *input_filename;
 static int pause_updates;
 
+#define TITLE_MAX 100
+static char title[TITLE_MAX+1];
+
 static void read_input(void) {
-  int r;
+  int r, last_readlink_r, last_readlink_errno=0;
+  char symlink_check[sizeof(title)];
+
+  last_readlink_r= -2;
   
-  if (input_f) fclose(input_f);
-  input_f= fopen(input_filename, "rb");  if (!input_f) diee("input file");
+  for (;;) {
+    r= readlink(input_filename, symlink_check, TITLE_MAX);
+    assert(r<=TITLE_MAX);
+    assert(r!=-2);
+
+    if (r>=0) symlink_check[r]= 0;
+    else symlink_check[0]= 0;
+
+    if (r == last_readlink_r &&
+       (r<0
+        ? (errno==last_readlink_errno)
+        : !strcmp(symlink_check, title))) {
+      assert(input_f);
+      if (r<0) {
+       if (last_readlink_errno==EINVAL)
+         snprintf(title,sizeof(title),"%s",input_filename);
+       else
+         snprintf(title,sizeof(title),"? %s",strerror(last_readlink_errno));
+      }
+      break;
+    }
+    
+    strcpy(title, symlink_check);
+    last_readlink_r= r;
+    last_readlink_errno= errno;
+
+    if (input_f) fclose(input_f);
+    input_f= fopen(input_filename, "rb");  if (!input_f) diee("input file");
+  }
 
   if (fstat(fileno(input_f), &input_stab)) diee("fstat input file");
 
@@ -255,7 +288,8 @@ static void display_conformation(void) {
     drawtriangles(&dmwhite);
     printf("shown, %d/%d triangles cut\n", ncut, ntris);
   }
-  
+
+  XA( XStoreName(display,window,title) );
   XA( XSetWindowBackgroundPixmap(display,window,pixmap) );
   XA( XClearWindow(display,window) );
   currentbuffer= !currentbuffer;