xref: /titanic_51/usr/src/cmd/mailx/translate.c (revision b453864f3587ccc3324d7a3b0438a1e542dcfde7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * University Copyright- Copyright (c) 1982, 1986, 1988
28  * The Regents of the University of California
29  * All Rights Reserved
30  *
31  * University Acknowledgment- Portions of this document are derived from
32  * software developed by the University of California, Berkeley, and its
33  * contributors.
34  */
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #include "rcv.h"
39 
40 struct name *
41 translate(struct name *np)
42 {
43 	struct name	*n, *t, *x;
44 	void	(*sigint)(int), (*sigquit)(int);
45 	char	*xl = value("translate");
46 	char	line[LINESIZE];
47 	char	postmark[256];
48 	char	*cmd;
49 	FILE	*pp;
50 	int	i;
51 
52 	if (!xl)
53 		return np;
54 	askme = 0;
55 	postmark[0] = 0;
56 	i = strlen(xl) + 1;
57 	for (n = np; n; n = n->n_flink)
58 		if (! (n->n_type & GDEL))
59 			i += strlen(n->n_name) + 3;
60 	cmd = (char *)salloc((unsigned)i);
61 	strcpy(cmd, xl);
62 	for (n = np; n; n = n->n_flink)
63 		if (! (n->n_type & GDEL)) {
64 			strcat(cmd, " \"");
65 			strcat(cmd, n->n_name);
66 			strcat(cmd, "\"");
67 		}
68 	if ((pp = npopen(cmd, "r")) == NULL) {
69 		perror(xl);
70 		senderr++;
71 		return np;
72 	}
73 	sigint = sigset(SIGINT, SIG_IGN);
74 	sigquit = sigset(SIGQUIT, SIG_IGN);
75 	fgets(postmark, sizeof postmark, pp);
76 	if (postmark[0])
77 		{
78 		postmark[strlen(postmark)-1] = 0;
79 		assign("postmark", postmark);
80 		}
81 	for (n = np; n; n = n->n_flink) {
82 		if (n->n_type & GDEL)
83 			continue;
84 		if (fgets(line, sizeof line, pp) == NULL)
85 			break;
86 		line[strlen(line)-1] = 0;
87 		if (!strcmp(line, n->n_name))
88 			continue;
89 		x = extract(line, n->n_type);
90 		n->n_type |= GDEL;
91 		n->n_name = "";
92 		if (x && !x->n_flink && strpbrk(n->n_full, "(<"))
93 			x->n_full = splice(x->n_name, n->n_full);
94 		if (x) {
95 			t = tailof(x);
96 			cat(t, n->n_flink);
97 			n->n_flink = NULL;
98 			cat(n, x);
99 			n = t;
100 		}
101 	}
102 	if (getc(pp) == 'y')
103 		askme++;
104 	if (npclose(pp) != 0 || n)
105 		senderr++;
106 	sigset(SIGINT, sigint);
107 	sigset(SIGQUIT, sigquit);
108 	return np;
109 }
110