+
+/* If there are any hacks in the system-wide defaults that are not in
+ the ~/.xscreensaver file, add the new ones to the end of the list.
+ This does *not* actually save the file.
+ */
+static void
+merge_system_screenhacks (saver_preferences *p,
+ screenhack **system_list, int system_count)
+{
+ /* Yeah yeah, this is an N^2 operation, but I don't have hashtables handy,
+ so fuck it. */
+
+ int made_space = 0;
+ int i;
+ for (i = 0; i < system_count; i++)
+ {
+ int j;
+ Bool matched_p = False;
+
+ for (j = 0; j < p->screenhacks_count; j++)
+ {
+ char *name;
+ if (!system_list[i]->name)
+ system_list[i]->name = make_hack_name (system_list[i]->command);
+
+ name = p->screenhacks[j]->name;
+ if (!name)
+ name = make_hack_name (p->screenhacks[j]->command);
+
+ matched_p = !strcasecmp (name, system_list[i]->name);
+
+ if (name != p->screenhacks[j]->name)
+ free (name);
+
+ if (matched_p)
+ break;
+ }
+
+ if (!matched_p)
+ {
+ /* We have an entry in the system-wide list that is not in the
+ user's .xscreensaver file. Add it to the end.
+ Note that p->screenhacks is a single malloc block, not a
+ linked list, so we have to realloc it.
+ */
+ screenhack *oh = system_list[i];
+ screenhack *nh = (screenhack *) malloc (sizeof(screenhack));
+
+ if (made_space == 0)
+ {
+ made_space = 10;
+ p->screenhacks = (screenhack **)
+ realloc (p->screenhacks,
+ (p->screenhacks_count + made_space + 1)
+ * sizeof(screenhack));
+ if (!p->screenhacks) abort();
+ }
+
+ nh->enabled_p = oh->enabled_p;
+ nh->visual = oh->visual ? strdup(oh->visual) : 0;
+ nh->name = oh->name ? strdup(oh->name) : 0;
+ nh->command = oh->command ? strdup(oh->command) : 0;
+
+ p->screenhacks[p->screenhacks_count++] = nh;
+ p->screenhacks[p->screenhacks_count] = 0;
+ made_space--;
+
+#if 0
+ fprintf (stderr, "%s: noticed new hack: %s\n", blurb(),
+ (nh->name ? nh->name : make_hack_name (nh->command)));
+#endif
+ }
+ }
+}
+
+