Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / comp.c,v
1 head    1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.6;
12
13 1.6
14 date    92.11.04.00.40.01;      author jromine; state Exp;
15 branches;
16 next    1.5;
17
18 1.5
19 date    92.02.04.17.46.56;      author jromine; state Exp;
20 branches;
21 next    1.4;
22
23 1.4
24 date    92.01.31.22.07.37;      author jromine; state Exp;
25 branches;
26 next    1.3;
27
28 1.3
29 date    90.04.05.15.03.07;      author sources; state Exp;
30 branches;
31 next    1.2;
32
33 1.2
34 date    90.02.09.09.44.16;      author sources; state Exp;
35 branches;
36 next    1.1;
37
38 1.1
39 date    90.02.09.09.44.01;      author sources; state Exp;
40 branches;
41 next    ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* comp.c - compose a message */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: comp.c,v 1.6 1992/11/04 00:40:01 jromine Exp jromine $";
56 #endif  /* lint */
57
58 #include "../h/mh.h"
59 #include <stdio.h>
60 #include <sys/types.h>
61 #include <sys/stat.h>
62 #ifdef LOCALE
63 #include        <locale.h>
64 #endif
65
66 /* \f */
67
68 static struct swit switches[] = {
69 #define DFOLDSW 0
70     "draftfolder +folder", 0,
71 #define DMSGSW  1
72     "draftmessage msg", 0,
73 #define NDFLDSW 2
74     "nodraftfolder", 0,
75
76 #define EDITRSW 3
77     "editor editor", 0,
78 #define NEDITSW 4
79     "noedit", 0,
80
81 #define FILESW  5
82     "file file", 0,
83 #define FORMSW  6
84     "form formfile", 0,
85
86 #define USESW   7
87     "use", 0,
88 #define NUSESW  8
89     "nouse", 0,
90
91 #define WHATSW  9
92     "whatnowproc program", 0,
93 #define NWHATSW 10
94     "nowhatnowproc", 0,
95
96 #define HELPSW  11
97     "help", 4,
98
99
100     NULL, 0
101 };
102
103 /* \f */
104
105 static struct swit aqrunl[] = {
106 #define NOSW    0
107     "quit", 0,
108 #define YESW    1
109     "replace", 0,
110 #define USELSW  2
111     "use", 0,
112 #define LISTDSW 3
113     "list", 0,
114 #define REFILSW 4
115     "refile +folder", 0,
116 #define NEWSW   5
117     "new", 0,
118
119     NULL, 0
120 };
121
122
123 static struct swit aqrul[] = {
124     "quit", 0,
125     "replace", 0,
126     "use", 0,
127     "list", 0,
128     "refile", 0,
129
130     NULL, 0
131 };
132
133 /* \f */
134
135 /* ARGSUSED */
136
137 main (argc, argv)
138 int     argc;
139 char   *argv[];
140 {
141     int     use = NOUSE,
142             nedit = 0,
143             nwhat = 0,
144             i,
145             in,
146             isdf = 0,
147             out;
148     char   *cp,
149            *cwd,
150            *maildir,
151            *dfolder = NULL,
152            *ed = NULL,
153            *file = NULL,
154            *form = NULL,
155            *folder = NULL,
156            *msg = NULL,
157             buf[BUFSIZ],
158             drft[BUFSIZ],
159           **ap,
160           **argp,
161            *arguments[MAXARGS];
162     struct msgs *mp = NULL;
163     struct stat st;
164
165 #ifdef LOCALE
166         setlocale(LC_ALL, "");
167 #endif
168     invo_name = r1bindex (argv[0], '/');
169     if ((cp = m_find (invo_name)) != NULL) {
170         ap = brkstring (cp = getcpy (cp), " ", "\n");
171         ap = copyip (ap, arguments);
172     }
173     else
174         ap = arguments;
175     (void) copyip (argv + 1, ap);
176     argp = arguments;
177
178 /* \f */
179
180     while (cp = *argp++) {
181         if (*cp == '-')
182             switch (smatch (++cp, switches)) {
183                 case AMBIGSW: 
184                     ambigsw (cp, switches);
185                     done (1);
186                 case UNKWNSW: 
187                     adios (NULLCP, "-%s unknown", cp);
188                 case HELPSW: 
189                     (void) sprintf (buf, "%s [+folder] [msg] [switches]",
190                             invo_name);
191                     help (buf, switches);
192                     done (1);
193
194                 case EDITRSW: 
195                     if (!(ed = *argp++) || *ed == '-')
196                         adios (NULLCP, "missing argument to %s", argp[-2]);
197                     nedit = 0;
198                     continue;
199                 case NEDITSW: 
200                     nedit++;
201                     continue;
202
203                 case WHATSW: 
204                     if (!(whatnowproc = *argp++) || *whatnowproc == '-')
205                         adios (NULLCP, "missing argument to %s", argp[-2]);
206                     nwhat = 0;
207                     continue;
208                 case NWHATSW: 
209                     nwhat++;
210                     continue;
211
212                 case FORMSW: 
213                     if (!(form = *argp++) || *form == '-')
214                         adios (NULLCP, "missing argument to %s", argp[-2]);
215                     continue;
216
217                 case USESW: 
218                     use++;
219                     continue;
220                 case NUSESW: 
221                     use = NOUSE;
222                     continue;
223
224                 case FILESW:    /* compatibility */
225                     if (file)
226                         adios (NULLCP, "only one file at a time!");
227                     if (!(file = *argp++) || *file == '-')
228                         adios (NULLCP, "missing argument to %s", argp[-2]);
229                     isdf = NOTOK;
230                     continue;
231
232                 case DFOLDSW: 
233                     if (dfolder)
234                         adios (NULLCP, "only one draft folder at a time!");
235                     if (!(cp = *argp++) || *cp == '-')
236                         adios (NULLCP, "missing argument to %s", argp[-2]);
237                     dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
238                             *cp != '@@' ? TFOLDER : TSUBCWF);
239                     continue;
240                 case DMSGSW: 
241                     if (file)
242                         adios (NULLCP, "only one draft message at a time!");
243                     if (!(file = *argp++) || *file == '-')
244                         adios (NULLCP, "missing argument to %s", argp[-2]);
245                     continue;
246                 case NDFLDSW: 
247                     dfolder = NULL;
248                     isdf = NOTOK;
249                     continue;
250             }
251         if (*cp == '+' || *cp == '@@') {
252             if (folder)
253                 adios (NULLCP, "only one folder at a time!");
254             else
255                 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
256         }
257         else
258             if (msg)
259                 adios (NULLCP, "only one message at a time!");
260             else
261                 msg = cp;
262     }
263
264 /* \f */
265
266     cwd = getcpy (pwd ());
267
268     if (!m_find ("path"))
269         free (path ("./", TFOLDER));
270
271     if ((dfolder || m_find ("Draft-Folder")) && !folder && msg && !file)
272         file = msg, msg = NULL;
273     if (form && (folder || msg))
274             adios (NULLCP, "can't mix forms and folders/msgs");
275
276     if (folder || msg) {
277         if (!msg)
278             msg = "cur";
279         if (!folder)
280             folder = m_getfolder ();
281         maildir = m_maildir (folder);
282
283         if (chdir (maildir) == NOTOK)
284             adios (maildir, "unable to change directory to");
285         if (!(mp = m_gmsg (folder)))
286             adios (NULLCP, "unable to read folder %s", folder);
287         if (mp -> hghmsg == 0)
288             adios (NULLCP, "no messages in %s", folder);
289
290         if (!m_convert (mp, msg))
291             done (1);
292         m_setseq (mp);
293
294         if (mp -> numsel > 1)
295             adios (NULLCP, "only one message at a time!");
296
297         if ((in = open (form = getcpy (m_name (mp -> lowsel)), 0)) == NOTOK)
298             adios (form, "unable to open message");
299     }
300     else
301         if (form) {
302             if ((in = open (libpath (form), 0)) == NOTOK)
303                 adios (form, "unable to open form file");
304         }
305         else {
306             if ((in = open (libpath (components), 0)) == NOTOK)
307                 adios (components, "unable to open default components file");
308             form = components;
309         }
310
311 /* \f */
312
313 try_it_again: ;
314     (void) strcpy (drft, m_draft (dfolder, file, use, &isdf));
315     if ((out = open (drft, 0)) != NOTOK) {
316         i = fdcompare (in, out);
317         (void) close (out);
318         if (use || i)
319             goto edit_it;
320
321         if (stat (drft, &st) == NOTOK)
322             adios (drft, "unable to stat");
323         printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
324         for (i = LISTDSW; i != YESW;) {
325             if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul)))
326                 done (1);
327             switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) {
328                 case NOSW: 
329                     done (0);
330                 case NEWSW: 
331                     file = NULL;
332                     use = NOUSE;
333                     goto try_it_again;
334                 case YESW: 
335                     break;
336                 case USELSW:
337                     use++;
338                     goto edit_it;
339                 case LISTDSW: 
340                     (void) showfile (++argp, drft);
341                     break;
342                 case REFILSW: 
343                     if (refile (++argp, drft) == 0)
344                         i = YESW;
345                     break;
346                 default: 
347                     advise (NULLCP, "say what?");
348                     break;
349             }
350         }
351     }
352     else
353         if (use)
354             adios (drft, "unable to open");
355
356     if ((out = creat (drft, m_gmprot ())) == NOTOK)
357         adios (drft, "unable to create");
358     cpydata (in, out, form, drft);
359     (void) close (in);
360     (void) close (out);
361
362 edit_it: ;
363     m_update ();
364
365     if (nwhat)
366         done (0);
367     (void) what_now (ed, nedit, use, drft, NULLCP, 0, NULLMP, NULLCP, 0, cwd);
368     done (1);
369 }
370 @
371
372
373 1.6
374 log
375 @putenv -> m_putenv
376 @
377 text
378 @d3 2
379 a4 2
380 static char ident[] = "@@(#)$Id: comp.c,v 1.5 1992/02/04 17:46:56 jromine Exp jromine $";
381 #endif  lint
382 @
383
384
385 1.5
386 log
387 @rename m_whatnow() to what_now() since it's not a m_ routine
388 @
389 text
390 @d3 1
391 a3 1
392 static char ident[] = "@@(#)$Id: comp.c,v 1.4 1992/01/31 22:07:37 jromine Exp jromine $";
393 d10 3
394 d113 3
395 @
396
397
398 1.4
399 log
400 @kerberos
401 @
402 text
403 @d3 1
404 a3 1
405 static char ident[] = "@@(#)$Id: comp.c,v 1.3 1990/04/05 15:03:07 sources Exp jromine $";
406 d309 1
407 a309 1
408     (void) m_whatnow (ed, nedit, use, drft, NULLCP, 0, NULLMP, NULLCP, 0, cwd);
409 @
410
411
412 1.3
413 log
414 @add ID
415 @
416 text
417 @d3 1
418 a3 1
419 static char ident[] = "@@(#)$Id:$";
420 d45 1
421 a45 1
422     NULL, NULL
423 d64 1
424 a64 1
425     NULL, NULL
426 d75 1
427 a75 1
428     NULL, NULL
429 @
430
431
432 1.2
433 log
434 @Fixes from Van Jacobson
435 @
436 text
437 @d2 3
438 @
439
440
441 1.1
442 log
443 @Initial revision
444 @
445 text
446 @d168 1
447 @