From http://www.jwz.org/xscreensaver/xscreensaver-5.18.tar.gz
[xscreensaver] / OSX / iostextclient.m
index 646436c323fcbcb1bb026353b0225e0ca4558291..09c6298561b41493cb9faf8f7b5503f80c16510f 100644 (file)
@@ -38,15 +38,6 @@ struct text_data {
 };
 
 
-void
-textclient_reshape (text_data *d,
-                    int pix_w, int pix_h,
-                    int char_w, int char_h)
-{
-  d->columns = char_w;
-}
-
-
 text_data *
 textclient_open (Display *dpy)
 {
@@ -405,6 +396,7 @@ wrap_text (char *body, int columns)
 {
   int col = 0, last_col = 0;
   char *last_space = 0;
+  if (! body) return;
   for (char *p = body; *p; p++) {
     if (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t') {
       if (col > columns && last_space) {
@@ -425,6 +417,23 @@ wrap_text (char *body, int columns)
 }
 
 
+static void
+rewrap_text (char *body, int columns)
+{
+  if (! body) return;
+  for (char *p = body; *p; p++) {
+    if (*p == '\n') {
+      if (p[1] == '\n')
+        p++;
+      else
+        *p = ' ';
+    }
+  }
+  wrap_text (body, columns);
+}
+
+
+
 static void
 strip_backslashes (char *s)
 {
@@ -553,4 +562,14 @@ textclient_putc (text_data *d, XKeyEvent *k)
   return False;
 }
 
+
+void
+textclient_reshape (text_data *d,
+                    int pix_w, int pix_h,
+                    int char_w, int char_h)
+{
+  d->columns = char_w;
+  rewrap_text (d->buf, d->columns);
+}
+
 #endif /* USE_IPHONE -- whole file */