+
+static int
+compare_globals (const void *a, const void *b)
+{
+ const struct global *ga = a;
+ const struct global *gb = b;
+ return strcmp (ga->name, gb->name);
+}
+
+static void
+write_globals (void)
+{
+ int i;
+ qsort (globals, num_globals, sizeof (struct global), compare_globals);
+ for (i = 0; i < num_globals; ++i)
+ {
+ char const *type;
+
+ switch (globals[i].type)
+ {
+ case EMACS_INTEGER:
+ type = "EMACS_INT";
+ break;
+ case BOOLEAN:
+ type = "int";
+ break;
+ case LISP_OBJECT:
+ type = "Lisp_Object";
+ break;
+ default:
+ fatal ("not a recognized DEFVAR_", 0);
+ }
+
+ fprintf (outfile, " %s f_%s;\n", type, globals[i].name);
+ fprintf (outfile, "#define %s globals.f_%s\n",
+ globals[i].name, globals[i].name);
+ while (i + 1 < num_globals
+ && !strcmp (globals[i].name, globals[i + 1].name))
+ ++i;
+ }
+
+ fprintf (outfile, "};\n");
+ fprintf (outfile, "extern struct emacs_globals globals;\n");
+}
+