-/* xscreensaver, Copyright (c) 2012 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
char *literal, *url;
int columns;
+ int max_lines;
char *buf;
int buf_size;
char *fp;
};
-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)
{
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;
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;
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) {
col = 0;
last_col = 0;
last_space = 0;
+ lines++;
+ if (max_lines && lines >= max_lines)
+ {
+ *p = 0;
+ break;
+ }
} else {
col++;
}
}
+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)
{
// 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:
abort();
}
if (d->columns > 10)
- wrap_text (d->buf, d->columns);
+ wrap_text (d->buf, d->columns, d->max_lines);
d->fp = d->buf;
}
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 */