Created function open_form() to open form file or fallback to default
[mmh] / sbr / utils.c
index 8aba5b6..64df443 100644 (file)
@@ -12,6 +12,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #include <errno.h>
 
 /*
@@ -184,3 +185,19 @@ app_msgarg(struct msgs_array *msgs, char *cp)
                msgs->msgs = mh_xrealloc(msgs->msgs, (msgs->max+=MAXMSGS)*sizeof(*msgs->msgs));
        msgs->msgs[msgs->size++] = cp;
 }
+
+/* Open a form or components file */
+int
+open_form(char **form, char *def)
+{
+       int in;
+       if (*form) {
+               if ((in = open (etcpath (*form), O_RDONLY)) == NOTOK)
+                       adios (*form, "unable to open form file");
+       } else {
+               if ((in = open (etcpath (def), O_RDONLY)) == NOTOK)
+                       adios (def, "unable to open default components file");
+               *form = def;
+       }
+       return in;
+}