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.
** 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 **);
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 *);
/*
-** 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;
} 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);
}
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)
char *folder = NULL, *msg = NULL, buf[BUFSIZ];
char drft[BUFSIZ], **argp, **arguments;
struct msgs *mp = NULL;
+ char *nfs;
+
#ifdef LOCALE
setlocale(LC_ALL, "");
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);
}
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)
/*
** 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);
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 */
#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);
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;
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;
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 =
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);
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 */
/*
** 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