From: markus schnalke Date: Thu, 9 Feb 2012 18:31:44 +0000 (+0100) Subject: Augmented new_fs() with an additional argument for a default form. X-Git-Tag: mmh-thesis-end~331 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=a0b824f146a18ad99633addede9e81a470d4cb59;hp=2d48b455c303a807041c35e4248955f8bec59eeb Augmented new_fs() with an additional argument for a default form. This balances the arguments: user-form, user-string, def-form, def-string. In comp.c I've already replaced open_form() with new_fs(). forw.c and dist.c are to follow. --- diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 38e2793..713c89b 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -88,5 +88,5 @@ struct format { ** prototypes */ struct format *fmt_scan(struct format *, char *, int, int *); -char *new_fs(char *, char *, char *); +char *new_fs(char *, char *, char *, char *); int fmt_compile(char *, struct format **); diff --git a/h/prototypes.h b/h/prototypes.h index 00768e5..01c6a59 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -80,7 +80,7 @@ void m_unknown(FILE *); int makedir(char *); char *nmh_getpass(const char *); char *norm_charmap(char *); -char *new_fs(char *, char *, char *); +char *new_fs(char *, char *, char *, char *); int peekc(FILE *ib); int pidwait(pid_t, int); int pidstatus(int, FILE *, char *); diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index 9d81874..6cdcfcc 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -18,11 +18,10 @@ static void normalize(char *); /* -** 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 *format, char *def_form, char *default_fs) { struct stat st; register FILE *fp; @@ -48,6 +47,20 @@ new_fs(char *form, char *format, char *default_fs) } 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 (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); } diff --git a/uip/ap.c b/uip/ap.c index e444cd8..a4e2189 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -124,7 +124,7 @@ main(int argc, char **argv) adios(NULL, "usage: %s [switches] addrs ...", invo_name); /* get new format string */ - nfs = new_fs(form, format, FORMAT); + nfs = new_fs(form, format, NULL, FORMAT); if (width == 0) { if ((width = sc_width()) < WIDTH / 2) diff --git a/uip/comp.c b/uip/comp.c index ce76cd8..6508ba6 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -43,6 +43,8 @@ main(int argc, char **argv) char *folder = NULL, *msg = NULL, buf[BUFSIZ]; char drft[BUFSIZ], **argp, **arguments; struct msgs *mp = NULL; + char *nfs; + #ifdef LOCALE setlocale(LC_ALL, ""); @@ -162,14 +164,14 @@ main(int argc, char **argv) close(out); } else { - in = open_form(&form, components); - + nfs = new_fs(form, NULL, components, NULL); strncpy(drft, m_draft(seq_beyond), sizeof(drft)); if ((out = creat(drft, m_gmprot())) == NOTOK) { adios(drft, "unable to create"); } - cpydata(in, out, form, drft); - close(in); + if (write(out, nfs, strlen(nfs)) != strlen(nfs)) { + adios(drft, "error writing"); + } close(out); } diff --git a/uip/dp.c b/uip/dp.c index d5f0c59..a9940d3 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -114,7 +114,7 @@ main(int argc, char **argv) adios(NULL, "usage: %s [switches] dates ...", invo_name); /* get new format string */ - nfs = new_fs(form, format, FORMAT); + nfs = new_fs(form, format, NULL, FORMAT); if (width == 0) { if ((width = sc_width()) < WIDTH / 2) diff --git a/uip/fmtdump.c b/uip/fmtdump.c index d948a06..75ac4c2 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -102,7 +102,7 @@ main(int argc, char **argv) /* ** Get new format string. Must be before chdir(). */ - nfs = new_fs(form, format, FORMAT); + nfs = new_fs(form, format, NULL, FORMAT); ncomps = fmt_compile(nfs, &fmt); fmt_dump(fmt); diff --git a/uip/forw.c b/uip/forw.c index b84632b..feb60f9 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -304,7 +304,7 @@ build_form(char *form, char *digest, int volume, int issue) char *cp = NULL; /* Get new format string */ - nfs = new_fs(form, NULL, NULL); + nfs = new_fs(form, NULL, NULL, NULL); fmtsize = strlen(nfs) + 256; /* Compile format string */ diff --git a/uip/inc.c b/uip/inc.c index 587bd84..762a858 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -373,7 +373,7 @@ main(int argc, char **argv) #endif /* MHE */ /* Get new format string */ - nfs = new_fs(form, format, FORMAT); + nfs = new_fs(form, format, NULL, FORMAT); if (noisy) { printf("Incorporating new mail into %s...\n\n", folder); diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 15360ea..218d38d 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -659,7 +659,7 @@ evalvar(struct mcomp *c1) if (ptos(name, &cp)) return 1; - nfs = new_fs(NULL, NULL, cp); + nfs = new_fs(NULL, NULL, NULL, cp); c1->c_nfs = getcpy(nfs); c1->c_flags |= FORMAT; return 0; @@ -668,7 +668,7 @@ evalvar(struct mcomp *c1) if (!mh_strcasecmp(name, "decode")) { char *nfs; - nfs = new_fs(NULL, NULL, "%(decode{text})"); + nfs = new_fs(NULL, NULL, NULL, "%(decode{text})"); c1->c_nfs = getcpy(nfs); c1->c_flags |= FORMAT; return 0; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 338455f..9adb5d4 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -171,7 +171,7 @@ rcvdistout(FILE *inb, char *form, char *addrs) adios(drft, "unable to create"); /* get new format string */ - cp = new_fs(form ? form : rcvdistcomps, NULL, NULL); + cp = new_fs(form ? form : rcvdistcomps, NULL, NULL, NULL); format_len = strlen(cp); ncomps = fmt_compile(cp, &fmt) + 1; if (!(nxtbuf = compbuffers = diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 86066ed..99ae680 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -292,7 +292,7 @@ header_fd(void) rewind(stdin); /* get new format string */ - nfs = new_fs(form, format, SCANFMT); + nfs = new_fs(form, format, NULL, SCANFMT); scan(stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0); if (newline) write(fd, "\n\r", 2); diff --git a/uip/repl.c b/uip/repl.c index 4e2c18a..5943857 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -424,7 +424,7 @@ replout(FILE *inb, char *msg, char *drft, struct msgs *mp, umask(mask); /* get new format string */ - cp = new_fs(form, NULL, NULL); + cp = new_fs(form, NULL, NULL, NULL); format_len = strlen(cp); /* compile format string */ diff --git a/uip/scan.c b/uip/scan.c index d228c71..f8e2e11 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -133,7 +133,7 @@ main(int argc, char **argv) /* ** Get new format string. Must be before chdir(). */ - nfs = new_fs(form, format, FORMAT); + nfs = new_fs(form, format, NULL, FORMAT); /* ** We are scanning a maildrop file