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.
14 static char *formats = NULL;
19 static void normalize(char *);
23 ** Copy first available format string, store in static memory and normalize it.
26 new_fs(char *form, char *def_form)
37 formats = getcpy(form+1);
39 if ((fp = fopen(etcpath(form), "r")) == NULL) {
40 adios(form, "unable to open format file");
42 if (fstat(fileno(fp), &st) == -1) {
43 adios(form, "unable to stat format file");
45 formats = mh_xmalloc((size_t) st.st_size + 1);
46 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
47 adios(form, "error reading format file");
49 formats[st.st_size] = '\0';
52 } else if (def_form) {
53 if (*def_form == '=') {
54 formats = getcpy(def_form+1);
56 if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
57 adios(def_form, "unable to open format file");
59 if (fstat(fileno(fp), &st) == -1) {
60 adios(def_form, "unable to stat format file");
62 formats = mh_xmalloc((size_t) st.st_size + 1);
63 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
64 adios(def_form, "error reading format file");
66 formats[st.st_size] = '\0';
70 normalize(formats); /* expand escapes */
77 ** Expand escapes in format strings
84 for (dp = cp; *cp; cp++) {