/*
-** Copy format string (selected by precedence) and store in static memory.
-** Normalize it.
+** Copy first available format string, store in static memory and normalize it.
*/
char *
-new_fs(char *form, char *format, char *default_fs)
+new_fs(char *form, char *def_form)
{
struct stat st;
register FILE *fp;
}
if (form) {
- if ((fp = fopen(etcpath(form), "r")) == NULL) {
- adios(form, "unable to open format file");
+ if (*form == '=') {
+ formats = getcpy(form+1);
+ } else {
+ if ((fp = fopen(etcpath(form), "r")) == NULL) {
+ adios(form, "unable to open format file");
+ }
+ if (fstat(fileno(fp), &st) == -1) {
+ adios(form, "unable to stat format file");
+ }
+ formats = mh_xmalloc((size_t) st.st_size + 1);
+ if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
+ adios(form, "error reading format file");
+ }
+ formats[st.st_size] = '\0';
+ fclose(fp);
}
- if (fstat(fileno(fp), &st) == -1) {
- adios(form, "unable to stat format file");
+ } else if (def_form) {
+ if (*def_form == '=') {
+ formats = getcpy(def_form+1);
+ } else {
+ if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
+ adios(def_form, "unable to open format file");
+ }
+ if (fstat(fileno(fp), &st) == -1) {
+ adios(def_form, "unable to stat format file");
+ }
+ formats = mh_xmalloc((size_t) st.st_size + 1);
+ if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
+ adios(def_form, "error reading format file");
+ }
+ formats[st.st_size] = '\0';
+ fclose(fp);
}
- formats = mh_xmalloc((size_t) st.st_size + 1);
- if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
- adios(form, "error reading format file");
- }
- formats[st.st_size] = '\0';
- fclose(fp);
-
- } else if (format) {
- formats = getcpy(format);
-
- } else {
- formats = getcpy(default_fs);
}
normalize(formats); /* expand escapes */