From a74d1e1c9c1826b358eb1b812349262282918094 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 3 Jun 1998 14:54:31 +0000 Subject: Fix argument-merging. svn path=/trunk/; revision=1879 --- NEWS | 1 + design-notes.html | 10 +++-- fetchmail.c | 74 ++++++++++++++++++++++++++++++++++-- fetchmail.h | 1 - rcfile_y.y | 111 ------------------------------------------------------ 5 files changed, 78 insertions(+), 119 deletions(-) diff --git a/NEWS b/NEWS index 0035b9ef..971f0a26 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ fetchmail-4.4.9 (): * CompuServe RPA and idfile fixes from Rich Beerman . * Hajimu UMEMOTO patched the address-rewrite logic to deal with addresses of the form "John Smith (foo) " better. +* Command-line argument merging has been fixed. There are 278 people on fetchmail-friends and 216 on fetchmail-announce. diff --git a/design-notes.html b/design-notes.html index cb5d5e05..5e8721d7 100644 --- a/design-notes.html +++ b/design-notes.html @@ -10,7 +10,7 @@
Back to Fetchmail Home Page To Site Map -$Date: 1998/05/14 01:35:46 $ +$Date: 1998/06/03 14:54:27 $

Design Notes On Fetchmail

@@ -313,8 +313,7 @@ following minimum steps. the token to rcfile_l.
  • Go to rcfile_y.y. Add the token to the grammar. Don't - forget the %token declaration. Add proper - FLAG_FORCE and FLAG_MERGE actions. + forget the %token declaration.
  • Pick a long-form option name, and a one-letter short option if any are left. Go to options.c. Pick a new LA_ @@ -327,6 +326,9 @@ following minimum steps.
  • Add code to dump the option value in fetchmail.c:dump_params. +
  • Add proper FLAG_FORCE and FLAG_MERGE actions + in fetchmail.c's optmerge function. +
  • Document the option in fetchmail.man. This will require at least two changes; one to the collected table of options, and one full text description of the option. @@ -475,7 +477,7 @@ all shaped the design in one way or another.

    Back to Fetchmail Home Page To Site Map -$Date: 1998/05/14 01:35:46 $ +$Date: 1998/06/03 14:54:27 $

    Eric S. Raymond <esr@snark.thyrsus.com>
    diff --git a/fetchmail.c b/fetchmail.c index 47a3a63d..79563ab6 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -692,6 +692,71 @@ int main (int argc, char **argv) exit(successes ? PS_SUCCESS : querystatus); } +static void optmerge(struct query *h2, struct query *h1, int force) +/* merge two options records */ +{ + /* + * If force is off, modify h2 fields only when they're empty (treat h1 + * as defaults). If force is on, modify each h2 field whenever h1 + * is nonempty (treat h1 as an override). + */ + + if (!force) + { + append_str_list(&h2->server.localdomains, &h1->server.localdomains); + append_str_list(&h2->localnames, &h1->localnames); + append_str_list(&h2->mailboxes, &h1->mailboxes); + append_str_list(&h2->smtphunt, &h1->smtphunt); + } + +#define FLAG_MERGE(fld) if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld + FLAG_MERGE(server.via); + FLAG_MERGE(server.protocol); +#if INET6 + FLAG_MERGE(server.service); + FLAG_MERGE(server.netsec); +#else /* INET6 */ + FLAG_MERGE(server.port); +#endif /* INET6 */ + FLAG_MERGE(server.interval); + FLAG_MERGE(server.preauthenticate); + FLAG_MERGE(server.timeout); + FLAG_MERGE(server.envelope); + FLAG_MERGE(server.envskip); + FLAG_MERGE(server.qvirtual); + FLAG_MERGE(server.skip); + FLAG_MERGE(server.dns); + FLAG_MERGE(server.uidl); + +#ifdef linux + FLAG_MERGE(server.interface); + FLAG_MERGE(server.monitor); + FLAG_MERGE(server.interface_pair); +#endif /* linux */ + + FLAG_MERGE(remotename); + FLAG_MERGE(password); + FLAG_MERGE(mda); + FLAG_MERGE(smtpaddress); + FLAG_MERGE(antispam); + FLAG_MERGE(preconnect); + + FLAG_MERGE(keep); + FLAG_MERGE(flush); + FLAG_MERGE(fetchall); + FLAG_MERGE(rewrite); + FLAG_MERGE(forcecr); + FLAG_MERGE(stripcr); + FLAG_MERGE(pass8bits); + FLAG_MERGE(dropstatus); + FLAG_MERGE(mimedecode); + FLAG_MERGE(limit); + FLAG_MERGE(fetchlimit); + FLAG_MERGE(batchlimit); + FLAG_MERGE(expunge); +#undef FLAG_MERGE +} + static int load_params(int argc, char **argv, int optind) { int implicitmode, st; @@ -748,7 +813,7 @@ static int load_params(int argc, char **argv, int optind) if (querylist && strcmp(querylist->server.pollname, "defaults") == 0) { for (ctl = querylist->next; ctl; ctl = ctl->next) - optmerge(ctl, querylist); + optmerge(ctl, querylist, FALSE); querylist = querylist->next; } @@ -763,7 +828,10 @@ static int load_params(int argc, char **argv, int optind) if (configdump || (ctl->active && !(implicitmode && ctl->server.skip))) { /* merge in defaults */ - optmerge(ctl, &def_opts); + optmerge(ctl, &def_opts, FALSE); + + /* force command-line options */ + optmerge(ctl, &cmd_opts, TRUE); /* make sure we have a nonempty host list to forward to */ if (!ctl->smtphunt) @@ -1152,7 +1220,7 @@ void dump_params (struct runctl *runp, struct query *querylist, flag implicit) ctl->forcecr ? "en" : "dis", ctl->forcecr ? "on" : "off"); printf(" Interpretation of Content-Transfer-Encoding is %sabled (pass8bits %s).\n", - ctl->pass8bits ? "en" : "dis", + ctl->pass8bits ? "dis" : "en", ctl->pass8bits ? "on" : "off"); printf(" MIME decoding is %sabled (mimedecode %s).\n", ctl->mimedecode ? "en" : "dis", diff --git a/fetchmail.h b/fetchmail.h index e4792fb1..e57f4c32 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -370,7 +370,6 @@ int doETRN (struct query *); /* miscellanea */ struct query *hostalloc(struct query *); int parsecmdline (int, char **, struct runctl *, struct query *); -void optmerge(struct query *, struct query *); char *MD5Digest (unsigned char *); int POP3_auth_rpa(unsigned char *, unsigned char *, int socket); int daemonize(const char *, void (*)(int)); diff --git a/rcfile_y.y b/rcfile_y.y index 69a96db5..5c4f43b7 100644 --- a/rcfile_y.y +++ b/rcfile_y.y @@ -467,121 +467,10 @@ struct query *init; /* pointer to block containing initial values */ static void record_current(void) /* register current parameters and append to the host list */ { -#define FLAG_FORCE(fld) if (cmd_opts.fld) current.fld = cmd_opts.fld - FLAG_FORCE(server.localdomains); - FLAG_FORCE(localnames); - FLAG_FORCE(mailboxes); - FLAG_FORCE(smtphunt); - - FLAG_FORCE(server.via); - FLAG_FORCE(server.protocol); -#if INET6 - FLAG_FORCE(server.service); - FLAG_FORCE(server.netsec); -#else /* INET6 */ - FLAG_FORCE(server.port); -#endif /* INET6 */ - FLAG_FORCE(server.interval); - FLAG_FORCE(server.preauthenticate); - FLAG_FORCE(server.timeout); - FLAG_FORCE(server.envelope); - FLAG_FORCE(server.envskip); - FLAG_FORCE(server.qvirtual); - FLAG_FORCE(server.skip); - FLAG_FORCE(server.dns); - FLAG_FORCE(server.uidl); - -#ifdef linux - FLAG_FORCE(server.interface); - FLAG_FORCE(server.monitor); - FLAG_FORCE(server.interface_pair); -#endif /* linux */ - - FLAG_FORCE(remotename); - FLAG_FORCE(password); - FLAG_FORCE(mda); - FLAG_FORCE(smtpaddress); - FLAG_FORCE(antispam); - FLAG_FORCE(preconnect); - FLAG_FORCE(postconnect); - - FLAG_FORCE(keep); - FLAG_FORCE(flush); - FLAG_FORCE(fetchall); - FLAG_FORCE(rewrite); - FLAG_FORCE(forcecr); - FLAG_FORCE(stripcr); - FLAG_FORCE(pass8bits); - FLAG_FORCE(dropstatus); - FLAG_FORCE(mimedecode); - FLAG_FORCE(limit); - FLAG_FORCE(fetchlimit); - FLAG_FORCE(batchlimit); - FLAG_FORCE(expunge); - -#undef FLAG_FORCE - (void) hostalloc(¤t); - trailer = TRUE; } -void optmerge(struct query *h2, struct query *h1) -/* merge two options records; empty fields in h2 are filled in from h1 */ -{ - append_str_list(&h2->server.localdomains, &h1->server.localdomains); - append_str_list(&h2->localnames, &h1->localnames); - append_str_list(&h2->mailboxes, &h1->mailboxes); - append_str_list(&h2->smtphunt, &h1->smtphunt); - -#define FLAG_MERGE(fld) if (!h2->fld) h2->fld = h1->fld - FLAG_MERGE(server.via); - FLAG_MERGE(server.protocol); -#if INET6 - FLAG_MERGE(server.service); - FLAG_MERGE(server.netsec); -#else /* INET6 */ - FLAG_MERGE(server.port); -#endif /* INET6 */ - FLAG_MERGE(server.interval); - FLAG_MERGE(server.preauthenticate); - FLAG_MERGE(server.timeout); - FLAG_MERGE(server.envelope); - FLAG_MERGE(server.envskip); - FLAG_MERGE(server.qvirtual); - FLAG_MERGE(server.skip); - FLAG_MERGE(server.dns); - FLAG_MERGE(server.uidl); - -#ifdef linux - FLAG_MERGE(server.interface); - FLAG_MERGE(server.monitor); - FLAG_MERGE(server.interface_pair); -#endif /* linux */ - - FLAG_MERGE(remotename); - FLAG_MERGE(password); - FLAG_MERGE(mda); - FLAG_MERGE(smtpaddress); - FLAG_MERGE(antispam); - FLAG_MERGE(preconnect); - - FLAG_MERGE(keep); - FLAG_MERGE(flush); - FLAG_MERGE(fetchall); - FLAG_MERGE(rewrite); - FLAG_MERGE(forcecr); - FLAG_MERGE(stripcr); - FLAG_MERGE(pass8bits); - FLAG_MERGE(dropstatus); - FLAG_MERGE(mimedecode); - FLAG_MERGE(limit); - FLAG_MERGE(fetchlimit); - FLAG_MERGE(batchlimit); - FLAG_MERGE(expunge); -#undef FLAG_MERGE -} - /* easier to do this than cope with variations in where the library lives */ int yywrap(void) {return 1;} -- cgit v1.2.3