+/*-----------------------------------------------------------------.
+| Try to open file NAME with mode MODE, and print an error message |
+| if fails. |
+`-----------------------------------------------------------------*/
+
+static FILE *
+xfopen (const char *name, const char *mode)
+{
+ FILE *ptr;
+
+ ptr = fopen (name, mode);
+ if (!ptr)
+ error (2, errno, _("cannot open file `%s'"), name);
+
+ return ptr;
+}
+
+/*-------------------------------------------------------------.
+| Try to close file PTR, and print an error message if fails. |
+`-------------------------------------------------------------*/
+
+static int
+xfclose (FILE *ptr)
+{
+ int result;
+
+ if (ptr == NULL)
+ return 0;
+
+ result = fclose (ptr);
+ if (result == EOF)
+ error (2, errno, _("cannot close file"));
+
+ return result;
+}
+
+/*--------------------------------------------------.
+| Save the content of the obstack OBS in FILENAME. |
+`--------------------------------------------------*/
+
+static void
+obstack_save (struct obstack *obs, const char *filename)
+{
+ FILE *out = xfopen (filename, "w");
+ size_t size = obstack_object_size (obs);
+ fwrite (obstack_finish (obs), 1, size, out);
+ xfclose (out);
+}
+
+
+static const char *
+skeleton_find (const char *envvar, const char *skeleton)
+{
+ const char *res = getenv (envvar);
+
+#ifdef MSDOS
+ const char *cp;
+
+ /* File doesn't exist in current directory; try in INIT directory. */
+ if (!res && (cp = getenv ("INIT")))
+ {
+ res = XMALLOC (char, strlen (cp) + strlen (skeleton) + 2);
+ sprintf (res, "%s%c%s", cp, '/', skeleton);
+ }
+#endif /* !MSDOS */
+
+ if (!res)
+ res = skeleton;
+
+ return res;
+}
+
+\f
+/*-----------------------------------------------------------------.
+| Open the input file. Look for the skeletons. Find the names of |
+| the output files. Prepare the obstacks. |
+`-----------------------------------------------------------------*/