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 *format, char *def_form, char *default_fs)
34 if ((fp = fopen(etcpath(form), "r")) == NULL) {
35 adios(form, "unable to open format file");
37 if (fstat(fileno(fp), &st) == -1) {
38 adios(form, "unable to stat format file");
40 formats = mh_xmalloc((size_t) st.st_size + 1);
41 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
42 adios(form, "error reading format file");
44 formats[st.st_size] = '\0';
48 formats = getcpy(format);
50 } else if (def_form) {
51 if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
52 adios(def_form, "unable to open format file");
54 if (fstat(fileno(fp), &st) == -1) {
55 adios(def_form, "unable to stat format file");
57 formats = mh_xmalloc((size_t) st.st_size + 1);
58 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
59 adios(def_form, "error reading format file");
61 formats[st.st_size] = '\0';
65 formats = getcpy(default_fs);
67 normalize(formats); /* expand escapes */
74 ** Expand escapes in format strings
81 for (dp = cp; *cp; cp++) {