/[MITgcm]/MITgcm/tools/mpack-1.6/unixpk.c
ViewVC logotype

Contents of /MITgcm/tools/mpack-1.6/unixpk.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Tue Aug 26 20:45:25 2003 UTC (20 years, 7 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint58l_post, checkpoint51k_post, checkpoint57t_post, checkpoint57o_post, checkpoint52l_pre, checkpoint52e_pre, hrcube4, checkpoint58e_post, mitgcm_mapl_00, checkpoint52n_post, checkpoint52j_post, checkpoint53d_post, checkpoint58u_post, checkpoint58w_post, checkpoint54a_pre, checkpoint51o_pre, checkpoint57m_post, checkpoint55c_post, checkpoint54e_post, checkpoint52e_post, checkpoint57s_post, checkpoint51n_pre, checkpoint54a_post, checkpoint53c_post, checkpoint57k_post, checkpoint55d_pre, checkpoint57d_post, checkpoint51l_post, checkpoint57g_post, checkpoint51q_post, checkpoint57b_post, checkpoint57c_pre, checkpoint51j_post, checkpoint58r_post, checkpoint55j_post, checkpoint56b_post, checkpoint57i_post, checkpoint57y_post, hrcube_1, checkpoint57e_post, branch-netcdf, checkpoint52d_pre, checkpoint52l_post, checkpoint55h_post, checkpoint58n_post, checkpoint53b_post, checkpoint58x_post, checkpoint52k_post, checkpoint52b_pre, checkpoint57g_pre, checkpoint54b_post, checkpoint53b_pre, checkpoint55b_post, checkpoint58t_post, checkpoint58h_post, checkpoint54d_post, checkpoint56c_post, checkpoint52m_post, checkpoint57y_pre, checkpoint55, checkpoint53a_post, checkpoint57f_pre, checkpoint57a_post, checkpoint54, checkpoint58q_post, checkpoint54f_post, checkpoint57v_post, checkpoint55g_post, checkpoint51o_post, checkpoint51p_post, checkpoint58j_post, checkpoint52a_pre, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint55f_post, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint59j, checkpoint57r_post, checkpoint59, checkpoint58, checkpoint57a_pre, checkpoint55i_post, checkpoint57, checkpoint56, checkpoint51i_post, checkpoint53, checkpoint52, checkpoint51f_post, checkpoint52d_post, eckpoint57e_pre, checkpoint51r_post, checkpoint52a_post, checkpoint57h_done, checkpoint58f_post, checkpoint52b_post, checkpoint53g_post, checkpoint52f_post, branchpoint-genmake2, checkpoint57x_post, checkpoint57n_post, checkpoint52c_post, checkpoint58d_post, checkpoint58c_post, checkpoint57w_post, checkpoint57p_post, checkpint57u_post, checkpoint57f_post, checkpoint58a_post, checkpoint51h_pre, checkpoint51l_pre, checkpoint58i_post, checkpoint57q_post, checkpoint51g_post, checkpoint58g_post, ecco_c52_e35, hrcube5, checkpoint58o_post, checkpoint57z_post, checkpoint57c_post, checkpoint58y_post, checkpoint55e_post, checkpoint58k_post, checkpoint52i_post, checkpoint52j_pre, checkpoint58v_post, checkpoint53f_post, checkpoint55a_post, checkpoint51t_post, checkpoint53d_pre, checkpoint54c_post, checkpoint58s_post, checkpoint58p_post, checkpoint51n_post, checkpoint57j_post, checkpoint58b_post, checkpoint57h_pre, checkpoint51i_pre, checkpoint58m_post, checkpoint57l_post, checkpoint52i_pre, checkpoint51u_post, checkpoint52h_pre, checkpoint52f_pre, checkpoint57h_post, hrcube_2, hrcube_3, checkpoint56a_post, checkpoint51m_post, checkpoint51s_post, checkpoint55d_post
Branch point for: branch-nonh, branch-genmake2, tg2-branch, checkpoint51n_branch, netcdf-sm0
File MIME type: text/plain
Initial check-in of the CMU "mpack" utility.  This allows us to (portably)
send MITgcm output as MIME-encoded email messages and will be used by the
"testreport" script.  The CMU license is basically an "AS-IS" statement.

1 /* (C) Copyright 1993,1994 by Carnegie Mellon University
2 * All Rights Reserved.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of Carnegie
9 * Mellon University not be used in advertising or publicity
10 * pertaining to distribution of the software without specific,
11 * written prior permission. Carnegie Mellon University makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
14 * warranty.
15 *
16 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
17 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
19 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
22 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 * SOFTWARE.
24 */
25 #include <stdio.h>
26 #include <string.h>
27 #include <errno.h>
28 #include "common.h"
29 #include "version.h"
30 #include "xmalloc.h"
31
32 #define MAXADDRESS 100
33
34 extern char *getenv();
35
36 extern int errno;
37 extern int optind;
38 extern char *optarg;
39
40 void usage(void);
41 void sendmail(FILE *infile, char **addr, int start);
42 void inews(FILE *infile);
43
44 int main(int argc, char **argv)
45 {
46 int opt;
47 char *fname = 0;
48 char *subject = 0;
49 char *descfname = 0;
50 long maxsize = 0;
51 char *outfname = 0;
52 char *newsgroups = 0;
53 char *ctype = 0;
54 char *headers = 0;
55 int i;
56 char *p;
57 char sbuf[1024];
58 char fnamebuf[4096];
59 int part;
60 FILE *infile;
61 FILE *descfile = 0;
62
63 if ((p = getenv("SPLITSIZE")) && *p >= '0' && *p <= '9') {
64 maxsize = atoi(p);
65 }
66
67 while ((opt = getopt(argc, argv, "s:d:m:c:o:n:")) != EOF) {
68 switch (opt) {
69 case 's':
70 subject = optarg;
71 break;
72
73 case 'd':
74 descfname = optarg;
75 break;
76
77 case 'm':
78 maxsize = atoi(optarg);
79 break;
80
81 case 'c':
82 ctype = optarg;
83 break;
84
85 case 'o':
86 outfname = optarg;
87 break;
88
89 case 'n':
90 newsgroups = optarg;
91 break;
92
93 default:
94 usage();
95
96 }
97 }
98
99 if (ctype) {
100 if (!strncasecmp(ctype, "text/", 5)) {
101 fprintf(stderr, "This program is not appropriate for encoding textual data\n");
102 exit(1);
103 }
104 if (strncasecmp(ctype, "application/", 12) && strncasecmp(ctype, "audio/", 6) &&
105 strncasecmp(ctype, "image/", 6) && strncasecmp(ctype, "video/", 6)) {
106 fprintf(stderr, "Content type must be subtype of application, audio, image, or video\n");
107 exit(1);
108 }
109 }
110
111 if (optind == argc) {
112 fprintf(stderr, "An input file must be specified\n");
113 usage();
114 }
115 fname = argv[optind++];
116
117 /* Must have exactly one of -o, -n, or destination addrs */
118 if (optind == argc) {
119 if (outfname && newsgroups) {
120 fprintf(stderr, "The -o and -n switches are mutually exclusive.\n");
121 usage();
122 }
123 if (!outfname && !newsgroups) {
124 fprintf(stderr, "Either an address or one of the -o or -n switches is required\n");
125 usage();
126 }
127 if (newsgroups) {
128 headers = xmalloc(strlen(newsgroups) + 25);
129 sprintf(headers, "Newsgroups: %s\n", newsgroups);
130 }
131 }
132 else {
133 if (outfname) {
134 fprintf(stderr, "The -o switch and addresses are mutually exclusive.\n");
135 usage();
136 }
137 if (newsgroups) {
138 fprintf(stderr, "The -n switch and addresses are mutually exclusive.\n");
139 usage();
140 }
141 headers = xmalloc(strlen(argv[optind]) + 25);
142 sprintf(headers, "To: %s", argv[optind]);
143 for (i = optind+1; i < argc; i++) {
144 headers = xrealloc(headers, strlen(headers)+strlen(argv[i]) + 25);
145 strcat(headers, ",\n\t");
146 strcat(headers, argv[i]);
147 }
148 strcat(headers, "\n");
149 }
150
151 if (!subject) {
152 fputs("Subject: ", stdout);
153 fflush(stdout);
154 if (!fgets(sbuf, sizeof(sbuf), stdin)) {
155 fprintf(stderr, "A subject is required\n");
156 usage();
157 }
158 if (p = strchr(sbuf, '\n')) *p = '\0';
159 subject = sbuf;
160 }
161
162 if (!outfname) {
163 if (getenv("TMPDIR")) {
164 strcpy(fnamebuf, getenv("TMPDIR"));
165 }
166 else {
167 strcpy(fnamebuf, "/usr/tmp");
168 }
169 strcat(fnamebuf, "/mpackXXXXXX");
170 mktemp(fnamebuf);
171 outfname = strsave(fnamebuf);
172 }
173
174 infile = fopen(fname, "r");
175 if (!infile) {
176 os_perror(fname);
177 exit(1);
178 }
179
180 if (descfname) {
181 descfile = fopen(descfname, "r");
182 if (!descfile) {
183 os_perror(descfname);
184 exit(1);
185 }
186 }
187
188 if (encode(infile, (FILE *)0, fname, descfile, subject, headers,
189 maxsize, ctype, outfname)) exit(1);
190
191 if (optind < argc || newsgroups) {
192 for (part = 0;;part++) {
193 sprintf(fnamebuf, "%s.%02d", outfname, part);
194 infile = fopen(part ? fnamebuf : outfname, "r");
195 if (!infile) {
196 if (part) break;
197 continue;
198 }
199 if (newsgroups) {
200 inews(infile);
201 }
202 else {
203 sendmail(infile, argv, optind);
204 }
205 fclose(infile);
206 remove(part ? fnamebuf : outfname);
207 }
208 }
209
210 exit(0);
211 }
212
213 void usage(void)
214 {
215 fprintf(stderr, "mpack version %s\n", MPACK_VERSION);
216 fprintf(stderr,
217 "usage: mpack [-s subj] [-d file] [-m maxsize] [-c content-type] file address...\n");
218 fprintf(stderr,
219 " mpack [-s subj] [-d file] [-m maxsize] [-c content-type] -o file file\n");
220 fprintf(stderr,
221 " mpack [-s subj] [-d file] [-m maxsize] [-c content-type] -n groups file\n");
222 exit(1);
223 }
224
225 void sendmail(FILE *infile, char **addr, int start)
226 {
227 int status;
228 int pid;
229
230 if (start < 2) abort();
231
232 #ifdef SCO
233 addr[--start] = "execmail";
234 #else
235 addr[--start] = "-oi";
236 addr[--start] = "sendmail";
237 #endif
238
239 do {
240 pid = fork();
241 } while (pid == -1 && errno == EAGAIN);
242
243 if (pid == -1) {
244 perror("fork");
245 return;
246 }
247 if (pid != 0) {
248 while (pid != wait(&status));
249 return;
250 }
251
252 dup2(fileno(infile), 0);
253 fclose(infile);
254 #ifdef SCO
255 execv("/usr/lib/mail/execmail", addr+start);
256 #else
257 execv("/usr/lib/sendmail", addr+start);
258 execv("/usr/sbin/sendmail", addr+start);
259 #endif
260 perror("execv");
261 _exit(1);
262 }
263
264 void inews(FILE *infile)
265 {
266 int status;
267 int pid;
268
269 do {
270 pid = fork();
271 } while (pid == -1 && errno == EAGAIN);
272
273 if (pid == -1) {
274 perror("fork");
275 return;
276 }
277 if (pid != 0) {
278 while (pid != wait(&status));
279 return;
280 }
281
282 dup2(fileno(infile), 0);
283 fclose(infile);
284 execlp("inews", "inews", "-h", "-S", (char *)0);
285 execl("/usr/local/news/inews", "inews", "-h", "-S", (char *)0);
286 execl("/usr/local/lib/news/inews", "inews", "-h", "-S", (char *)0);
287 execl("/etc/inews", "inews", "-h", "-S", (char *)0);
288 execl("/usr/etc/inews", "inews", "-h", "-S", (char *)0);
289 execl("/usr/news/inews", "inews", "-h", "-S", (char *)0);
290 execl("/usr/news/bin/inews", "inews", "-h", "-S", (char *)0);
291 perror("execl");
292 _exit(1);
293 }
294
295 void warn(void)
296 {
297 abort();
298 }

  ViewVC Help
Powered by ViewVC 1.1.22