]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/dytest/show.c
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / dytest / show.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../mh.h"
9 #include <stdio.h>
10 #include <strings.h>
11
12 int vecp;
13 int header = 1;
14 char *vec[MAXARGS];
15 struct msgs *mp;
16 /* The minimum match numbers below are all at least 2 as
17 /* a kludge to avoid conflict between switches intended for
18 /* "show" and those that it passes on to pr, mhl, c, ...
19 /**/
20 struct swit switches[] = {
21 "all", -3, /* 0 */
22 "draft", 2, /* 1 */
23 "header", 2, /* 2 */
24 "noheader", 3, /* 3 */
25 "format", 2, /* 4 */
26 "noformat", 3, /* 5 */
27 "pr", 2, /* 6 */
28 "nopr", 3, /* 7 */
29 "help", 4, /* 8 */
30 0, 0
31 };
32
33 extern char _sobuf[]; /* MLW standard out buffer */
34
35 /*ARGSUSED*/
36 main(argc, argv)
37 char *argv[];
38 {
39 char *folder, *maildir, *msgs[100];
40 register int msgnum;
41 register char *cp, **ap;
42 int msgp, drft, pr, format;
43 char *arguments[50], **argp;
44
45 invo_name = argv[0];
46 setbuf(stdout, _sobuf);
47 #ifdef NEWS
48 m_news();
49 #endif
50 folder = (char *) 0;
51 pr = msgp = 0;
52 format = 1;
53 vecp = 1;
54 cp = r1bindex(argv[0], '/');
55 if((cp = m_find(cp)) != NULL) {
56 ap = brkstring(cp = getcpy(cp), " ", "\n");
57 ap = copyip(ap, arguments);
58 } else
59 ap = arguments;
60 VOID copyip(argv+1, ap);
61 argp = arguments;
62 while(cp = *argp++) {
63 if(*cp == '-')
64 switch(smatch(++cp, switches)) {
65 case -2:ambigsw(cp, switches); /* ambiguous */
66 goto leave;
67 /* unknown */
68 case -1:vec[vecp++] = --cp; continue;
69 /* -all */
70 case 0: fprintf(stderr, "\"-all\" changed to \"all\"\n");
71 goto leave;
72 case 1: drft = 1; continue; /* -draft */
73 case 2: header = 1; continue; /* -header */
74 case 3: header = 0; continue; /* -noheader */
75 case 4: format = 1; continue; /* -format */
76 case 5: format = 0; continue; /* -noformat */
77 case 6: pr = 1; continue; /* -pr */
78 case 7: pr = 0; vecp = 1; continue;/* -nopr */
79 case 8: /* -help */
80 help("show [+folder] [msgs] [switches] [switches for \"type\" or \"pr\" ]",
81 switches);
82 goto leave;
83 }
84 if(*cp == '+') {
85 if(folder) {
86 fprintf(stderr, "Only one folder at a time.\n");
87 goto leave;
88 } else
89 folder = path(cp+1, TFOLDER);
90 } else
91 msgs[msgp++] = cp;
92 }
93 if(!m_find("path")) free(path("./", TFOLDER));
94 if(drft)
95 maildir = m_maildir("");
96 else {
97 if(!msgp)
98 msgs[msgp++] = "cur";
99 if(!folder)
100 folder = m_getfolder();
101 maildir = m_maildir(folder);
102 }
103 if(chdir(maildir) < 0) {
104 fprintf(stderr, "Can't chdir to: ");
105 perror(maildir);
106 goto leave;
107 }
108 if(drft) {
109 vec[vecp++] = draft;
110 goto doit;
111 }
112 if(!(mp = m_gmsg(folder))) {
113 fprintf(stderr, "Can't read folder!?\n");
114 goto leave;
115 }
116 if(mp->hghmsg == 0) {
117 fprintf(stderr, "No messages in \"%s\".\n", folder);
118 goto leave;
119 }
120 if(msgp)
121 for(msgnum = 0; msgnum < msgp; msgnum++)
122 if(!m_convert(msgs[msgnum]))
123 goto leave;
124 if(mp->numsel == 0) {
125 fprintf(stderr, "show: potato pancakes.\n"); /* never get here */
126 goto leave;
127 }
128 if(mp->numsel > MAXARGS-2) {
129 fprintf(stderr, "show: more than %d messages for show-exec\n", MAXARGS-2);
130 goto leave;
131 }
132 for(msgnum= mp->lowsel; msgnum<= mp->hghsel; msgnum++)
133 if(mp->msgstats[msgnum]&SELECTED)
134 vec[vecp++] = getcpy(m_name(msgnum));
135 m_replace(pfolder, folder);
136 if(mp->hghsel != mp->curmsg)
137 m_setcur(mp->hghsel);
138 if(vecp == 2 && header) {
139 printf("(Message %s:%s)\n", folder, vec[1]);
140 }
141 doit:
142 VOID fflush(stdout);
143 vec[vecp] = 0;
144 {
145 register char *proc;
146 if(pr)
147 proc = prproc;
148 else if(format) {
149 putenv("mhfolder", folder);
150 if (!showproc) {
151 mhl(vecp, vec);
152 m_update();
153 done(0);
154 }
155 proc = showproc;
156 } else {
157 proc = "/bin/cat";
158 /* THIS IS INEFFICIENT */
159 /* what we really should do in this case is
160 /* copy it out ourself to save the extra exec */
161 }
162 m_update();
163 vec[0] = r1bindex(proc, '/');
164 execv(proc, vec);
165 perror(proc);
166 }
167 done(0);
168 leave:
169 m_update();
170 done(0);
171 }
172
173 #define switches mhlswitches
174 #define INCLUDED_BY_SHOW
175 #define main(a,b) mhl(a,b)
176
177 #include "mhl.c"