-static char *
-reformat_hack(const char *hack)
-{
- int i;
- const char *in = hack;
- int indent = 13;
- char *h2 = (char *) malloc(strlen(in) + indent + 2);
- char *out = h2;
-
- while (isspace(*in)) in++; /* skip whitespace */
- while (*in && !isspace(*in) && *in != ':')
- *out++ = *in++; /* snarf first token */
- while (isspace(*in)) in++; /* skip whitespace */
-
- if (*in == ':')
- *out++ = *in++; /* copy colon */
- else
- {
- in = hack;
- out = h2; /* reset to beginning */
- }
-
- *out = 0;
-
- while (isspace(*in)) in++; /* skip whitespace */
- for (i = strlen(h2); i < indent; i++) /* indent */
- *out++ = ' ';
-
- while (*in) *out++ = *in++; /* copy rest of line */
- *out = 0;
-
- return h2;
-}
-
-
-static void
-get_screenhacks (saver_info *si)
-{
- saver_preferences *p = &si->prefs;
- int i = 0;
- int hacks_size = 60;
- int size;
- char *d;
-
- d = get_string_resource ("monoPrograms", "MonoPrograms");
- if (d && !*d) { free(d); d = 0; }
- if (!d)
- d = get_string_resource ("colorPrograms", "ColorPrograms");
- if (d && !*d) { free(d); d = 0; }
-
- if (d)
- {
- fprintf (stderr,
- "%s: the `monoPrograms' and `colorPrograms' resources are obsolete;\n\
- see the manual for details.\n", blurb());
- free(d);
- }
-
- d = get_string_resource ("programs", "Programs");
-
- size = d ? strlen (d) : 0;
- p->screenhacks = (char **) malloc (sizeof (char *) * hacks_size);
- p->screenhacks_count = 0;
-
- while (i < size)
- {
- int end, start = i;
- if (d[i] == ' ' || d[i] == '\t' || d[i] == '\n' || d[i] == 0)
- {
- i++;
- continue;
- }
- if (hacks_size <= p->screenhacks_count)
- p->screenhacks = (char **) realloc (p->screenhacks,
- (hacks_size = hacks_size * 2) *
- sizeof (char *));
- p->screenhacks [p->screenhacks_count++] = d + i;
- while (d[i] != 0 && d[i] != '\n')
- i++;
- end = i;
- while (i > start && (d[i-1] == ' ' || d[i-1] == '\t'))
- i--;
- d[i] = 0;
- i = end + 1;
- }
-
- /* shrink all whitespace to one space, for the benefit of the "demo"
- mode display. We only do this when we can easily tell that the
- whitespace is not significant (no shell metachars).
- */
- for (i = 0; i < p->screenhacks_count; i++)
- {
- char *s = p->screenhacks [i];
- char *s2;
- int L = strlen (s);
- int j, k;
- for (j = 0; j < L; j++)
- {
- switch (s[j])
- {
- case '\'': case '"': case '`': case '\\':
- goto DONE;
- case '\t':
- s[j] = ' ';
- case ' ':
- k = 0;
- for (s2 = s+j+1; *s2 == ' ' || *s2 == '\t'; s2++)
- k++;
- if (k > 0)
- {
- for (s2 = s+j+1; s2[k]; s2++)
- *s2 = s2[k];
- *s2 = 0;
- }
- break;
- }
- }
- DONE:
- p->screenhacks[i] = reformat_hack(s); /* mallocs */
- }
-
- if (p->screenhacks_count)
- {
- /* Shrink down the screenhacks array to be only as big as it needs to.
- This doesn't really matter at all. */
- p->screenhacks = (char **)
- realloc (p->screenhacks, ((p->screenhacks_count + 1) *
- sizeof(char *)));
- p->screenhacks [p->screenhacks_count] = 0;
- }
- else
- {
- free (p->screenhacks);
- p->screenhacks = 0;
- }
-}