+static void
+flip_images (m_state *state)
+{
+ XImage *im = XGetImage (state->dpy, state->images, 0, 0,
+ state->image_width, state->image_height,
+ ~0L, (state->xgwa.depth > 1 ? ZPixmap : XYPixmap));
+ int x, y, i;
+ int w = state->image_width / CHAR_COLS;
+ unsigned long *row = (unsigned long *) malloc (sizeof(*row) * w);
+
+ for (y = 0; y < state->image_height; y++)
+ for (i = 0; i < CHAR_COLS; i++)
+ {
+ for (x = 0; x < w; x++)
+ row[x] = XGetPixel (im, (i * w) + x, y);
+ for (x = 0; x < w; x++)
+ XPutPixel (im, (i * w) + x, y, row[w - x - 1]);
+ }
+
+ XPutImage (state->dpy, state->images, state->draw_gc, im, 0, 0, 0, 0,
+ state->image_width, state->image_height);
+ XDestroyImage (im);
+ free (row);
+}
+
+
+static void
+init_spinners (m_state *state)
+{
+ int i = state->nspinners;
+ int x, y;
+ m_cell *cell;
+
+ for (y = 0; y < state->grid_height; y++)
+ for (x = 0; x < state->grid_width; x++)
+ {
+ cell = &state->cells[state->grid_width * y + x];
+ cell->spinner = 0;
+ }
+
+ while (--i > 0)
+ {
+ x = random() % state->grid_width;
+ y = random() % state->grid_height;
+ cell = &state->cells[state->grid_width * y + x];
+ cell->spinner = 1;
+ }
+}
+
+
+static void
+init_trace (m_state *state)
+{
+ char *s = get_string_resource ("tracePhone", "TracePhone");
+ char *s2, *s3;
+ int i;
+ if (!s)
+ goto FAIL;
+
+ state->tracing = (char *) malloc (strlen (s) + 1);
+ s3 = state->tracing;
+
+ for (s2 = s; *s2; s2++)
+ if (*s2 >= '0' && *s2 <= '9')
+ *s3++ = *s2;
+ *s3 = 0;
+
+ if (s3 == (char *) state->tracing)
+ goto FAIL;
+
+ for (i = 0; i < strlen(state->tracing); i++)
+ state->tracing[i] = -state->tracing[i];
+ state->nglyphs = 10;
+ flip_images (state);
+
+ return;
+
+ FAIL:
+ fprintf (stderr, "%s: bad phone number: \"%s\".\n",
+ progname, s ? s : "(null)");
+
+ if (s) free (s);
+ if (state->tracing) free (state->tracing);
+ state->tracing = 0;
+ state->trace_p = False;
+}
+
+