+
+static void
+reg_print_categorical_encoding (FILE *fp, pspp_linreg_cache *c)
+{
+ int i;
+ size_t j;
+ struct pspp_linreg_coeff coeff;
+ union value *val;
+
+ fprintf (fp, "%s", reg_export_categorical_encode_1);
+
+ for (i = 1; i < c->n_indeps; i++) /* c->coeff[0] is the intercept. */
+ {
+ coeff = c->coeff[i];
+ if (coeff.v->type == ALPHA)
+ {
+ fprintf (fp, "struct pspp_reg_categorical_variable %s;\n\t", coeff.v->name);
+ }
+ }
+ for (i = 1; i < c->n_indeps; i++)
+ {
+ coeff = c->coeff[i];
+ if (coeff.v->type == ALPHA)
+ {
+ fprintf (fp, "%s.name = \"%s\";\n\t", coeff.v->name, coeff.v->name);
+ fprintf (fp, "%s.n_vals = %d;\n\t", coeff.v->name, coeff.v->obs_vals->n_categories);
+ fprintf (fp, "%s.values = {", coeff.v->name);
+ for (j = 0; j < coeff.v->obs_vals->n_categories - 1; j++)
+ {
+ val = cat_subscript_to_value ( (const size_t) j, coeff.v);
+ fprintf (fp, "\"%s\",\n\t\t", val->s);
+ }
+ val = cat_subscript_to_value ( (const size_t) j, coeff.v);
+ fprintf (fp, "\"%s\"};\n\n\t", val->s);
+ }
+ }
+}
+
+static void
+reg_print_depvars (FILE *fp, pspp_linreg_cache *c)
+{
+ int i;
+ struct pspp_linreg_coeff coeff;
+
+ fprintf (fp, "char *model_depvars[%d] = {", c->n_indeps);
+ for (i = 1; i < c->n_indeps; i++)
+ {
+ coeff = c->coeff[i];
+ fprintf (fp, "\"%s\",\n\t\t", coeff.v->name);
+ }
+ coeff = c->coeff[i];
+ fprintf (fp, "\"%s\"};\n\t", coeff.v->name);
+}
+static void
+reg_print_getvar (FILE *fp, pspp_linreg_cache *c)
+{
+ fprintf (fp, "static int\npspp_reg_getvar (char *v_name)\n{\n\t");
+ fprintf (fp, "int i;\n\tint n_vars = %d;\n\t",c->n_indeps);
+ reg_print_depvars (fp, c);
+ fprintf (fp, "for (i = 0; i < n_vars; i++)\n\t{\n\t\t");
+ fprintf (fp, "if (strcmp (v_name, model_depvars[i]) == 0)\n\t\t{\n\t\t\t");
+ fprintf (fp, "return i;\n\t\t}\n\t}\n}\n");
+}