X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffmt_new.c;h=9fd34c8e1b4350782be1164cbb544ab81469f4fb;hp=6cdcfcc7075db5fcb09d9e48066c4973eedcdb4c;hb=f51956be123db66b00138f80464d06f030dbb88d;hpb=84c6039eb7226c0ba0a8f708205e33d10950d2ae diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index 6cdcfcc..9fd34c8 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -21,7 +21,7 @@ static void normalize(char *); ** Copy first available format string, store in static memory and normalize it. */ char * -new_fs(char *form, char *format, char *def_form, char *default_fs) +new_fs(char *form, char *def_form) { struct stat st; register FILE *fp; @@ -31,38 +31,39 @@ new_fs(char *form, char *format, char *def_form, char *default_fs) } 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"); - } - 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 if (def_form) { - if ((fp = fopen(etcpath(def_form), "r")) == NULL) { - adios(def_form, "unable to open format file"); + 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); } - 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); - - } else { - formats = getcpy(default_fs); } normalize(formats); /* expand escapes */