]>
diplodocus.org Git - nmh/blob - sbr/fmt_new.c
1 /* fmt_new.c -- read format file/string and normalize
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
13 static char *formats
= 0;
18 static void normalize (char *);
22 * Get new format string
26 new_fs (char *form
, char *format
, 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);
42 if (read (fileno(fp
), formats
, (int) st
.st_size
) != st
.st_size
)
43 adios (form
, "error reading format file");
45 formats
[st
.st_size
] = '\0';
49 formats
= getcpy (format
? format
: default_fs
);
52 normalize (formats
); /* expand escapes */
66 * Expand escapes in format strings
74 for (dp
= cp
; *cp
; cp
++) {