+static void fix_name(char *name)
+{
+ unsigned int i, j;
+
+ for (i = j = 0; name[i]; i++) {
+ if (isalnum(name[i]) || name[i] == '_')
+ name[j++] = toupper(name[i]);
+ }
+ name[j] = '\0';
+}
+
+static void handle_idem(struct manifest *m, struct score *score)
+{
+ struct file_error *e;
+
+ list_for_each(&score->per_file_errors, e, list) {
+ char *name, *q, *tmpname;
+ FILE *out;
+ unsigned int i;
+
+ /* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */
+ if (strstarts(e->file->name, m->basename)
+ || strlen(e->file->name) != strlen(m->basename) + 2)
+ name = talloc_asprintf(score, "CCAN_%s_H", m->basename);
+ else
+ name = talloc_asprintf(score, "CCAN_%s_%s_H",
+ m->basename, e->file->name);
+ fix_name(name);
+
+ q = talloc_asprintf(score,
+ "Should I wrap %s in #ifndef/#define %s for you?",
+ e->file->name, name);
+ if (!ask(q))
+ continue;
+
+ tmpname = maybe_temp_file(score, ".h", false, e->file->name);
+ out = fopen(tmpname, "w");
+ if (!out)
+ err(1, "Opening %s", tmpname);
+ if (fprintf(out, "#ifndef %s\n#define %s\n", name, name) < 0)
+ err(1, "Writing %s", tmpname);
+
+ for (i = 0; i < e->file->num_lines; i++)
+ if (fprintf(out, "%s\n", e->file->lines[i]) < 0)
+ err(1, "Writing %s", tmpname);
+
+ if (fprintf(out, "#endif /* %s */\n", name) < 0)
+ err(1, "Writing %s", tmpname);
+
+ if (fclose(out) != 0)
+ err(1, "Closing %s", tmpname);
+
+ if (!move_file(tmpname, e->file->fullname))
+ err(1, "Moving %s to %s", tmpname, e->file->fullname);
+ }
+}
+
+static bool check_idem(struct ccan_file *f, struct score *score)