2 ** fmt_new.c -- read format file/string and normalize
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
12 static char *formats = NULL;
17 static void normalize(char *);
21 ** Copy first available format string, store in static memory and normalize it.
24 new_fs(char *form, char *def_form)
35 formats = getcpy(form+1);
37 if ((fp = fopen(etcpath(form), "r")) == NULL) {
38 adios(form, "unable to open format file");
40 if (fstat(fileno(fp), &st) == -1) {
41 adios(form, "unable to stat format file");
43 formats = mh_xmalloc((size_t) st.st_size + 1);
44 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
45 adios(form, "error reading format file");
47 formats[st.st_size] = '\0';
50 } else if (def_form) {
51 if (*def_form == '=') {
52 formats = getcpy(def_form+1);
54 if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
55 adios(def_form, "unable to open format file");
57 if (fstat(fileno(fp), &st) == -1) {
58 adios(def_form, "unable to stat format file");
60 formats = mh_xmalloc((size_t) st.st_size + 1);
61 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
62 adios(def_form, "error reading format file");
64 formats[st.st_size] = '\0';
68 normalize(formats); /* expand escapes */
75 ** Expand escapes in format strings
82 for (dp = cp; *cp; cp++) {