|
|
1.1 root 1: [ MH-patches - Tue Jul 18 00:47:38 1989 - WP patches to MH - /mtr ]
2:
3:
4: Here are patches to MH 6.5 to allow send/whom to expand names into addresses.
5:
6: The user specifies a name by bracketing a WhitePages query between
7: '<<' and '>>' using fred's whois syntax, e.g.,
8:
9: To: << rose -org nyser >>
10:
11: At the "What now?" prompt, the user can say "whom" to have the
12: names expanded into addresses. Alternately, the "send" option can
13: be used as well. For each query appearing between '<<' and '>>',
14: fred will be asked to perform a white pages resolution. All
15: matches are printed and the user is asked to select one. If one is
16: not selected, the user remains with fred, to make more queries,
17: until eventually one is selected (or the user exits fred to abort
18: the expansion process).
19:
20: Note that expansion can occur only if whom/send is invoked
21: interactively. If you use push, then the expansion will fail
22: because fred will be unable to query you to select/confirm the
23: right entry to use for the substitution.
24:
25: To enable these patches, add "options WP" to your MH config file,
26: run mhconfig, apply the patches, and then do "make" from the
27: top-level. Note that this code has only been tested with
28:
29: #undef BERK
30:
31: in effect. I believe that it should work okay, but since I don't
32: run with BERK defined, I have no way of knowing.
33:
34: /mtr
35: diff -c sbr/*addrsbr.c
36: diff -c uip/_post.c uip/post.c
37: diff -c uip/*whom.c
38: diff -c uip/*whatnowsbr.c
39: diff -c zotnet/mf/*mf.c
40: *** sbr/:addrsbr.c Mon Oct 30 17:22:49 1989
41: --- sbr/addrsbr.c Sat Nov 4 22:18:39 1989
42: ***************
43: *** 103,108 ****
44: --- 103,117 ----
45:
46: char *getusr ();
47:
48: +
49: + #ifdef WP
50: + int do_wp = 0;
51: +
52: + #ifdef BERK
53: + char *wp_expand ();
54: + #endif
55: + #endif
56: +
57: /* */
58:
59: char *getname (addrs)
60: ***************
61: *** 171,176 ****
62: --- 180,214 ----
63: while ( (c = *addrs++) == ',' || isspace(c))
64: ;
65:
66: + #ifdef WP
67: + if (do_wp && c == '<' && *addrs == '<') {
68: + register char *cp,
69: + *dp,
70: + *ep;
71: +
72: + if (cp = index (++addrs, '>')) {
73: + *++cp = NULL;
74: + if (dp = wp_expand (addrs, NULLCP)) {
75: + *(addrs - 1) = NULL;
76: + ep = concat (saved_addr, dp, cp, NULLCP);
77: + addrs = ep + strlen (saved_addr);
78: + while ((c = *addrs++) == ',' || isspace (c))
79: + continue;
80: + free (saved_addr);
81: + saved_addr = ep;
82: + free (dp);
83: + }
84: + else {
85: + err = "unable to expand WhitePages query";
86: + (void) strcpy (adrtext, addrs);
87: + addrs = cp;
88: + goto out;
89: + }
90: +
91: + }
92: + }
93: + #endif
94: +
95: *nxtout = *adrcopy = '\0';
96: while (state != EOA) {
97: *adrcopy++ = c;
98: ***************
99: *** 267,280 ****
100: * addr points to where we should start scanning next time.
101: */
102: *(nxtout-1) = *(adrcopy-1) = '\0';
103: if (*adr && !err) {
104: adr_ptr = addrs-1;
105: - return adrtext;
106: } else {
107: free (saved_addr);
108: adr_ptr = NULL;
109: - return NULL;
110: }
111: #else not BERK
112: register struct adrx *ap;
113:
114: --- 305,320 ----
115: * addr points to where we should start scanning next time.
116: */
117: *(nxtout-1) = *(adrcopy-1) = '\0';
118: + #ifdef WP
119: + out: ;
120: + #endif
121: if (*adr && !err) {
122: adr_ptr = addrs-1;
123: } else {
124: free (saved_addr);
125: adr_ptr = NULL;
126: }
127: + return adrtext;
128: #else not BERK
129: register struct adrx *ap;
130:
131: ***************
132: *** 825,827 ****
133: --- 865,1013 ----
134:
135: return 0;
136: }
137: +
138: + /* */
139: +
140: + #ifdef WP
141: + #include <signal.h>
142: +
143: +
144: + static char *fredproc = NULL;
145: +
146: +
147: + char *wp_expand (query, error)
148: + char *query,
149: + *error;
150: + {
151: + register int cc,
152: + i,
153: + vecp;
154: + int (*istat) (), (*qstat) (), (*pstat) ();
155: + register char *bp,
156: + *cp;
157: + char *ep,
158: + buffer[BUFSIZ],
159: + fds[10],
160: + *vec[10];
161: + static int child_id = NOTOK,
162: + pdi[2],
163: + pdo[2];
164: +
165: + if (error)
166: + (void) strcpy (error, "unable to expand WhitePages query: ");
167: +
168: + if (child_id == NOTOK || kill (child_id, 0) == NOTOK) {
169: + if (!isatty (fileno (stdout))) {
170: + if (error)
171: + (void) strcat (error, "not a tty");
172: + return NULLCP;
173: + }
174: +
175: + if (fredproc == NULL && (fredproc = m_find ("fredproc")) == NULL)
176: + fredproc = "fred";
177: +
178: + if (pipe (pdi) == NOTOK) {
179: + if (error)
180: + (void) strcat (error, "unable to pipe");
181: +
182: + return NULLCP;
183: + }
184: +
185: + if (pipe (pdo) == NOTOK) {
186: + if (error)
187: + (void) strcat (error, "unable to pipe");
188: +
189: + losing: ;
190: + (void) close (pdi[0]);
191: + (void) close (pdi[1]);
192: + return NULLCP;
193: + }
194: +
195: + for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
196: + sleep (5);
197: +
198: + switch (child_id) {
199: + case NOTOK:
200: + if (error)
201: + (void) strcat (error, "unable to fork");
202: +
203: + (void) close (pdo[0]);
204: + (void) close (pdo[1]);
205: + goto losing;
206: +
207: + case OK:
208: + (void) close (pdi[0]);
209: + (void) close (pdo[1]);
210: + (void) sprintf (fds, "%d %d", pdo[0], pdi[1]);
211: + vecp = 0;
212: + vec[vecp++] = r1bindex (fredproc, '/');
213: + vec[vecp++] = "-q";
214: + vec[vecp++] = fds;
215: + vec[vecp] = NULL;
216: + execvp (fredproc, vec);
217: + _exit (-1); /* NOTREACHED */
218: +
219: + default:
220: + (void) close (pdi[1]);
221: + (void) close (pdo[0]);
222: + break;
223: + }
224: + }
225: +
226: + istat = signal (SIGINT, SIG_IGN);
227: + qstat = signal (SIGQUIT, SIG_IGN);
228: +
229: + pstat = signal (SIGPIPE, SIG_IGN);
230: +
231: + (void) sprintf (buffer, "%s\n", query);
232: + cc = write (pdo[1], buffer, i = strlen (buffer));
233: +
234: + (void) signal (SIGPIPE, pstat);
235: +
236: + if (cc != i) {
237: + if (error)
238: + (void) strcat (error, "write to pipe failed");
239: +
240: + lost_child: ;
241: + (void) kill (child_id, SIGTERM);
242: + (void) close (pdi[0]);
243: + (void) close (pdo[1]);
244: +
245: + child_id = NOTOK;
246: + return NULLCP;
247: + }
248: +
249: + for (ep = (bp = buffer) + sizeof buffer - 1;
250: + (i = read (pdi[0], bp, ep - bp)) > 0; ) {
251: + for (cp = bp + i; bp < cp; bp++)
252: + if (*bp == '\n')
253: + break;
254: + if (bp < cp)
255: + break;
256: + }
257: +
258: + (void) signal (SIGINT, istat);
259: + (void) signal (SIGQUIT, qstat);
260: +
261: + if (i == NOTOK) {
262: + if (error)
263: + (void) strcat (error, "read from pipe failed");
264: + goto lost_child;
265: + }
266: + if (i == 0) {
267: + if (error)
268: + (void) sprintf (error + strlen (error), "%s exited prematurely",
269: + fredproc);
270: + goto lost_child;
271: + }
272: + *bp = NULL;
273: +
274: + if (error)
275: + if (bp != buffer)
276: + error[0] = NULL;
277: + else
278: + (void) strcpy (error, "unable to expand WhitePages query");
279: +
280: + return (*buffer ? getcpy (buffer) : NULLCP);
281: + }
282: + #endif
283: *** uip/_post.c Mon Oct 30 17:22:54 1989
284: --- uip/post.c Tue Aug 8 20:28:58 1989
285: ***************
286: *** 91,97 ****
287: #define NWATCSW 17
288: "nowatch", 0,
289:
290: ! #define WHOMSW 18 /* interface from whom */
291: "whom", -4,
292:
293: #define WIDTHSW 19
294: --- 91,97 ----
295: #define NWATCSW 17
296: "nowatch", 0,
297:
298: ! #define WHOMSW 18 /* interface from whom */
299: "whom", -4,
300:
301: #define WIDTHSW 19
302: ***************
303: *** 122,127 ****
304: --- 122,130 ----
305: #define SNOOPSW 29
306: "snoop", -5,
307:
308: + #define FILLSW 30
309: + "fill-in file", -7,
310: +
311: NULL, NULL
312: };
313:
314: ***************
315: *** 284,289 ****
316: --- 287,298 ----
317: static int encryptsw = 0; /* encrypt it */
318:
319:
320: + #ifdef WP
321: + extern int do_wp; /* fill-in white pages queries */
322: + #endif
323: + static char *fill_in = NULLCP;
324: +
325: +
326: long lseek (), time ();
327:
328: /* MAIN */
329: ***************
330: *** 486,491 ****
331: --- 495,507 ----
332: snoop++;
333: continue;
334: #endif SENDMTS
335: +
336: + case FILLSW:
337: + #ifdef WP
338: + if (!(fill_in = *argp++) || *fill_in == '-')
339: + adios (NULLCP, "missing argument to %s", argp[-2]);
340: + #endif
341: + continue;
342: }
343: if (msg)
344: adios (NULLCP, "only one message at a time!");
345: ***************
346: *** 494,499 ****
347: --- 510,518 ----
348: }
349:
350: (void) alias (AliasFile);
351: + #ifdef WP
352: + do_wp++;
353: + #endif
354:
355: /* */
356:
357: ***************
358: *** 534,540 ****
359: else
360: #endif MHMTS
361: if (whomsw) {
362: ! if ((out = fopen ("/dev/null", "w")) == NULL)
363: adios ("/dev/null", "unable to open");
364: }
365: else {
366: --- 553,559 ----
367: else
368: #endif MHMTS
369: if (whomsw) {
370: ! if ((out = fopen (fill_in ? fill_in : "/dev/null", "w")) == NULL)
371: adios ("/dev/null", "unable to open");
372: }
373: else {
374: ***************
375: *** 575,581 ****
376: case BODY:
377: case BODYEOF:
378: finish_headers (out);
379: ! if (whomsw)
380: break;
381: fprintf (out, "\n%s", buf);
382: while (state == BODY) {
383: --- 594,600 ----
384: case BODY:
385: case BODYEOF:
386: finish_headers (out);
387: ! if (whomsw && !fill_in)
388: break;
389: fprintf (out, "\n%s", buf);
390: while (state == BODY) {
391: ***************
392: *** 699,709 ****
393: }
394:
395: hdr = &hdrtab[i];
396: ! if (hdr -> flags & HIGN)
397: return;
398: if (hdr -> flags & HBAD) {
399: ! advise (NULLCP, "illegal header line -- %s:", name);
400: ! badmsg++;
401: return;
402: }
403: msgflags |= (hdr -> set & ~(MVIS | MINV));
404: --- 718,735 ----
405: }
406:
407: hdr = &hdrtab[i];
408: ! if (hdr -> flags & HIGN) {
409: ! if (fill_in)
410: ! fprintf (out, "%s: %s", name, str);
411: return;
412: + }
413: if (hdr -> flags & HBAD) {
414: ! if (fill_in)
415: ! fprintf (out, "%s: %s", name, str);
416: ! else {
417: ! advise (NULLCP, "illegal header line -- %s:", name);
418: ! badmsg++;
419: ! }
420: return;
421: }
422: msgflags |= (hdr -> set & ~(MVIS | MINV));
423: ***************
424: *** 711,716 ****
425: --- 737,747 ----
426: if (hdr -> flags & HSUB)
427: subject = subject ? add (str, add ("\t", subject)) : getcpy (str);
428: if (hdr -> flags & HFCC) {
429: + if (fill_in) {
430: + fprintf (out, "%s: %s", name, str);
431: + return;
432: + }
433: +
434: if (cp = rindex (str, '\n'))
435: *cp = NULL;
436: for (cp = pp = str; cp = index (pp, ','); pp = cp) {
437: ***************
438: *** 759,765 ****
439:
440: nameoutput = linepos = 0;
441: (void) sprintf (namep, "%s%s",
442: ! (hdr -> flags & HMNG) ? "Original-" : "", name);
443:
444: for (grp = 0, mp = tmpaddrs.m_next; mp; mp = np)
445: if (mp -> m_nohost) { /* also used to test (hdr -> flags & HTRY) */
446: --- 790,797 ----
447:
448: nameoutput = linepos = 0;
449: (void) sprintf (namep, "%s%s",
450: ! !fill_in && (hdr -> flags & HMNG) ? "Original-" : "",
451: ! name);
452:
453: for (grp = 0, mp = tmpaddrs.m_next; mp; mp = np)
454: if (mp -> m_nohost) { /* also used to test (hdr -> flags & HTRY) */
455: ***************
456: *** 810,817 ****
457: advise (NULLCP, "%s: field does not allow groups", name);
458: badmsg++;
459: }
460: ! if (linepos)
461: (void) putc ('\n', out);
462: }
463:
464: /* */
465: --- 842,852 ----
466: advise (NULLCP, "%s: field does not allow groups", name);
467: badmsg++;
468: }
469: ! if (linepos) {
470: ! if (fill_in && grp > 0)
471: ! (void) putc (';', out);
472: (void) putc ('\n', out);
473: + }
474: }
475:
476: /* */
477: ***************
478: *** 942,948 ****
479:
480: if (mp -> m_mbox == NULL || ((flags & HTRY) && !insert (mp)))
481: return 0;
482: ! if ((flags & HBCC) || mp -> m_ingrp)
483: return 1;
484:
485: if (!nameoutput) {
486: --- 977,983 ----
487:
488: if (mp -> m_mbox == NULL || ((flags & HTRY) && !insert (mp)))
489: return 0;
490: ! if (!fill_in && ((flags & HBCC) || mp -> m_ingrp))
491: return 1;
492:
493: if (!nameoutput) {
494: ***************
495: *** 953,959 ****
496: if (*aka && mp -> m_type != UUCPHOST && !mp -> m_pers)
497: mp -> m_pers = getcpy (aka);
498: if (format) {
499: ! if (mp -> m_gname)
500: (void) sprintf (cp = buffer, "%s;", mp -> m_gname);
501: else
502: cp = adrformat (mp);
503: --- 988,994 ----
504: if (*aka && mp -> m_type != UUCPHOST && !mp -> m_pers)
505: mp -> m_pers = getcpy (aka);
506: if (format) {
507: ! if (mp -> m_gname && !fill_in)
508: (void) sprintf (cp = buffer, "%s;", mp -> m_gname);
509: else
510: cp = adrformat (mp);
511: ***************
512: *** 987,1004 ****
513: int len;
514: char *cp;
515:
516: ! if (flags & HBCC)
517: return;
518:
519: if (!nameoutput) {
520: fprintf (out, "%s: ", name);
521: linepos += (nameoutput = strlen (name) + 2);
522: }
523:
524: ! cp = concat (group, ";", NULLCP);
525: len = strlen (cp);
526:
527: ! if (linepos != nameoutput)
528: if (len + linepos + 2 > outputlinelen) {
529: fprintf (out, ",\n%*s", nameoutput, "");
530: linepos = nameoutput;
531: --- 1022,1041 ----
532: int len;
533: char *cp;
534:
535: ! if (!fill_in && (flags & HBCC))
536: return;
537:
538: if (!nameoutput) {
539: fprintf (out, "%s: ", name);
540: linepos += (nameoutput = strlen (name) + 2);
541: + if (fill_in)
542: + linepos -= strlen (group);
543: }
544:
545: ! cp = fill_in ? group : concat (group, ";", NULLCP);
546: len = strlen (cp);
547:
548: ! if (linepos > nameoutput)
549: if (len + linepos + 2 > outputlinelen) {
550: fprintf (out, ",\n%*s", nameoutput, "");
551: linepos = nameoutput;
552: *** uip/_whom.c Mon Oct 30 17:22:52 1989
553: --- uip/whom.c Mon Jul 17 09:22:31 1989
554: ***************
555: *** 35,40 ****
556: --- 35,43 ----
557: #define SNOOPSW 10
558: "snoop", -5,
559:
560: + #define FILLSW 11
561: + "fill-in file", -7,
562: +
563: NULL, NULL
564: };
565:
566: ***************
567: *** 125,130 ****
568: --- 128,134 ----
569: case ALIASW:
570: case CLIESW:
571: case SERVSW:
572: + case FILLSW:
573: vec[vecp++] = --cp;
574: if (!(cp = *argp++) || *cp == '-')
575: adios (NULLCP, "missing argument to %s", argp[-2]);
576: *** uip/_whatnowsbr.c Mon Oct 30 17:22:57 1989
577: --- uip/whatnowsbr.c Mon Jul 17 12:04:19 1989
578: ***************
579: *** 758,764 ****
580: --- 758,773 ----
581: int pid;
582: register int vecp;
583: char *vec[MAXARGS];
584: + #ifdef WP
585: + char *cp,
586: + draft[BUFSIZ],
587: + backup[BUFSIZ];
588: + #endif
589:
590: + #ifdef WP
591: + (void) strcpy (draft, m_scratch (file, invo_name));
592: + #endif
593: +
594: m_update ();
595: (void) fflush (stdout);
596:
597: ***************
598: *** 774,779 ****
599: --- 783,792 ----
600: if (arg)
601: while (*arg)
602: vec[vecp++] = *arg++;
603: + #ifdef WP
604: + vec[vecp++] = "-fill-in";
605: + vec[vecp++] = draft;
606: + #endif
607: vec[vecp] = NULL;
608:
609: execvp (whomproc, vec);
610: ***************
611: *** 782,787 ****
612: --- 795,822 ----
613: _exit (-1); /* NOTREACHED */
614:
615: default:
616: + #ifndef WP
617: return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
618: + #else
619: + if (pidwait (pid, NOTOK)) {
620: + (void) unlink (draft);
621: + return 1;
622: + }
623: + break;
624: + #endif
625: }
626: +
627: + #ifdef WP
628: + if (rename (file, cp = m_backup (file)) == NOTOK) {
629: + advise (cp, "unable to rename %s to", file);
630: + (void) unlink (draft);
631: + return 1;
632: + }
633: + if (rename (draft, file) == NOTOK) {
634: + advise (file, "unable to rename %s to ", draft);
635: + return 1;
636: + }
637: +
638: + return 0;
639: + #endif
640: }
641: *** zotnet/mf/_mf.c Mon Oct 30 17:22:59 1989
642: --- zotnet/mf/mf.c Mon Oct 30 20:32:38 1989
643: ***************
644: *** 298,303 ****
645: --- 298,306 ----
646:
647: #define QUOTE '\\'
648:
649: + #ifdef WP
650: + #define LX_WP (-1)
651: + #endif
652: #define LX_END 0
653: #define LX_ERR 1
654: #define LX_ATOM 2
655: ***************
656: *** 351,361 ****
657: --- 354,375 ----
658:
659: static struct adrx adrxs2;
660:
661: +
662: + #ifdef WP
663: + char *concat ();
664: +
665: + extern int do_wp;
666: + char *wp_expand ();
667: + #endif
668: +
669: /* */
670:
671: struct adrx *getadrx (addrs)
672: register char *addrs;
673: {
674: + #ifdef WP
675: + int save_lex;
676: + #endif
677: register char *bp;
678: register struct adrx *adrxp = &adrxs2;
679:
680: ***************
681: *** 385,390 ****
682: --- 399,427 ----
683: return NULL;
684: }
685:
686: + #ifdef WP
687: + bp = cp, save_lex = last_lex;
688: + if (my_lex (adr) == LX_WP) {
689: + register char *ep,
690: + *fp;
691: +
692: + if (fp = wp_expand (adr, err)) {
693: + *bp = NULL;
694: + ep = concat (dp, fp, cp, (char *) NULL);
695: + cp = ep + strlen (dp), last_lex = save_lex;
696: + free (dp);
697: + dp = ep;
698: + free (fp);
699: + }
700: + else {
701: + ap = bp, save_lex = last_lex;
702: + goto out;
703: + }
704: + }
705: + else
706: + cp = bp, last_lex = save_lex;
707: + #endif
708: +
709: switch (parse_address ()) {
710: case DONE:
711: free (dp);
712: ***************
713: *** 409,414 ****
714: --- 446,454 ----
715: break;
716: }
717:
718: + #ifdef WP
719: + out: ;
720: + #endif
721: if (err[0])
722: for (;;) {
723: switch (last_lex) {
724: ***************
725: *** 798,803 ****
726: --- 838,858 ----
727: cp = NULL;
728: return (last_lex = LX_END);
729: }
730: +
731: + #ifdef WP
732: + if (do_wp && c == '<' && *cp == '<')
733: + for (cp++;;)
734: + switch (c = *cp++) {
735: + case '>':
736: + *bp = NULL;
737: + cp++;
738: + return (last_lex = LX_WP);
739: +
740: + default:
741: + *bp++ = c;
742: + continue;
743: + }
744: + #endif
745:
746: if (c == '(')
747: for (*bp++ = c, i = 0;;)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.