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.
15 static char *formats = NULL;
20 static void normalize(char *);
24 ** Copy first available format string, store in static memory and normalize it.
27 new_fs(char *form, char *def_form)
38 formats = getcpy(form+1);
40 if ((fp = fopen(etcpath(form), "r")) == NULL) {
41 adios(EX_IOERR, form, "unable to open format file");
43 if (fstat(fileno(fp), &st) == -1) {
44 adios(EX_IOERR, form, "unable to stat format file");
46 formats = mh_xmalloc((size_t) st.st_size + 1);
47 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
48 adios(EX_IOERR, form, "error reading format file");
50 formats[st.st_size] = '\0';
53 } else if (def_form) {
54 if (*def_form == '=') {
55 formats = getcpy(def_form+1);
57 if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
58 adios(EX_IOERR, def_form, "unable to open format file");
60 if (fstat(fileno(fp), &st) == -1) {
61 adios(EX_IOERR, def_form, "unable to stat format file");
63 formats = mh_xmalloc((size_t) st.st_size + 1);
64 if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
65 adios(EX_IOERR, def_form, "error reading format file");
67 formats[st.st_size] = '\0';
71 normalize(formats); /* expand escapes */
78 ** Expand escapes in format strings
85 for (dp = cp; *cp; cp++) {