X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2Fiostextclient.m;h=f1f3ad7aed9686638388e7171184c8c0d9bd8857;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=646436c323fcbcb1bb026353b0225e0ca4558291;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;p=xscreensaver diff --git a/OSX/iostextclient.m b/OSX/iostextclient.m index 646436c3..f1f3ad7a 100644 --- a/OSX/iostextclient.m +++ b/OSX/iostextclient.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2012 Jamie Zawinski +/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -31,6 +31,7 @@ struct text_data { char *literal, *url; int columns; + int max_lines; char *buf; int buf_size; char *fp; @@ -38,15 +39,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) { @@ -289,7 +281,7 @@ copy_rss_field (const char *s) s += 9; char *e = strstr (s, "]]"); if (e) *e = 0; - int L = strlen (s); + unsigned long L = strlen (s); char *s2 = (char *) malloc (L+1); memcpy (s2, s, L+1); return s2; @@ -316,10 +308,10 @@ pick_rss_field (const char *a, const char *b, const char *c, const char *d) char *b2 = copy_rss_field (b); char *c2 = copy_rss_field (c); char *d2 = copy_rss_field (d); - int al = a2 ? strlen(a2) : 0; - int bl = b2 ? strlen(b2) : 0; - int cl = c2 ? strlen(c2) : 0; - int dl = d2 ? strlen(d2) : 0; + unsigned long al = a2 ? strlen(a2) : 0; + unsigned long bl = b2 ? strlen(b2) : 0; + unsigned long cl = c2 ? strlen(c2) : 0; + unsigned long dl = d2 ? strlen(d2) : 0; char *ret = 0; if (al > bl && al > cl && al > dl) ret = a2; @@ -401,10 +393,12 @@ strip_rss (char *rss) static void -wrap_text (char *body, int columns) +wrap_text (char *body, int columns, int max_lines) { int col = 0, last_col = 0; char *last_space = 0; + int lines = 0; + if (! body) return; for (char *p = body; *p; p++) { if (*p == '\r' || *p == '\n' || *p == ' ' || *p == '\t') { if (col > columns && last_space) { @@ -418,6 +412,12 @@ wrap_text (char *body, int columns) col = 0; last_col = 0; last_space = 0; + lines++; + if (max_lines && lines >= max_lines) + { + *p = 0; + break; + } } else { col++; } @@ -425,6 +425,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, 0); +} + + + static void strip_backslashes (char *s) { @@ -462,7 +479,7 @@ url_string (const char *url) // Only search the first 1/2 K of the document while determining type. - int L = [body length]; + unsigned long L = [body length]; if (L > 512) L = 512; NSString *head = [[[body substringToIndex: L] stringByTrimmingCharactersInSet: @@ -535,7 +552,7 @@ textclient_getc (text_data *d) abort(); } if (d->columns > 10) - wrap_text (d->buf, d->columns); + wrap_text (d->buf, d->columns, d->max_lines); d->fp = d->buf; } @@ -553,4 +570,16 @@ 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, + int max_lines) +{ + d->columns = char_w; + d->max_lines = max_lines; + rewrap_text (d->buf, d->columns); +} + #endif /* USE_IPHONE -- whole file */