0
|
1 /* scan.c - display a one-line "scan" listing */
|
|
2 #ifndef lint
|
12
|
3 static char ident[] = "@(#)$Id: scan.c,v 1.2 2006/12/05 18:18:13 kono Exp $";
|
0
|
4 #endif /* lint */
|
|
5
|
|
6 #include "../h/mh.h"
|
|
7 #include "../h/formatsbr.h"
|
|
8 #include "../h/scansbr.h"
|
|
9 #include "../zotnet/tws.h"
|
|
10 #include <errno.h>
|
|
11 #include <stdio.h>
|
|
12 #ifdef LOCALE
|
|
13 #include <locale.h>
|
|
14 #endif
|
|
15
|
|
16 /* */
|
|
17
|
|
18 static struct swit switches[] = {
|
|
19 #define CLRSW 0
|
|
20 "clear", 0,
|
|
21 #define NCLRSW 1
|
|
22 "noclear", 0,
|
|
23
|
|
24 #define FORMSW 2
|
|
25 "form formatfile", 0,
|
|
26 #define FMTSW 3
|
|
27 "format string", 5,
|
|
28
|
|
29 #define HEADSW 4
|
|
30 "header", 0,
|
|
31 #define NHEADSW 5
|
|
32 "noheader", 0,
|
|
33
|
|
34 #define WIDSW 6
|
|
35 "width columns", 0,
|
|
36
|
|
37 #define REVSW 7
|
|
38 "reverse", 0,
|
|
39 #define NREVSW 8
|
|
40 "noreverse", 0,
|
|
41
|
|
42 #define FILESW 9
|
|
43 "file file", 4,
|
|
44
|
|
45 #define HELPSW 10
|
|
46 "help", 4,
|
|
47
|
|
48 NULL, 0
|
|
49 };
|
|
50
|
|
51 /* */
|
|
52
|
|
53 #ifdef LBL /* global for sbr/formatsbr.c - yech! */
|
|
54 extern struct msgs *fmt_current_folder;
|
|
55 #endif
|
|
56
|
|
57
|
16
|
58 void clear_screen0 ();
|
0
|
59
|
|
60 /* */
|
|
61
|
|
62 /* ARGSUSED */
|
|
63
|
|
64 main (argc, argv)
|
|
65 int argc;
|
|
66 char *argv[];
|
|
67 {
|
|
68 int clearflag = 0,
|
|
69 hdrflag = 0,
|
|
70 revflag = 0, /* used to be #ifdef BERK */
|
|
71 width = 0,
|
|
72 msgp = 0,
|
|
73 bits, /* should match mp->msgstats[] type */
|
|
74 ontty,
|
|
75 state,
|
|
76 msgnum;
|
|
77 time_t clock;
|
|
78 char *cp,
|
|
79 *maildir,
|
|
80 *file = NULL,
|
|
81 *folder = NULL,
|
|
82 *form = NULL,
|
|
83 *format = NULL,
|
|
84 buf[100],
|
|
85 **ap,
|
|
86 **argp,
|
|
87 *nfs,
|
|
88 *arguments[MAXARGS],
|
|
89 *msgs[MAXARGS];
|
|
90 struct msgs *mp;
|
|
91 FILE * in;
|
|
92
|
|
93 #ifdef LOCALE
|
|
94 setlocale(LC_ALL, "");
|
|
95 #endif
|
|
96 #ifdef JAPAN
|
|
97 ml_init();
|
|
98 #endif /* JAPAN */
|
|
99
|
|
100 invo_name = r1bindex (argv[0], '/');
|
|
101 mts_init (invo_name);
|
|
102 if ((cp = m_find (invo_name)) != NULL) {
|
|
103 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
104 ap = copyip (ap, arguments);
|
|
105 }
|
|
106 else
|
|
107 ap = arguments;
|
|
108 (void) copyip (argv + 1, ap);
|
|
109 argp = arguments;
|
|
110
|
|
111 /* */
|
|
112
|
|
113 while (cp = *argp++) {
|
|
114 if (*cp == '-')
|
|
115 switch (smatch (++cp, switches)) {
|
|
116 case AMBIGSW:
|
|
117 ambigsw (cp, switches);
|
|
118 done (1);
|
|
119 case UNKWNSW:
|
|
120 adios (NULLCP, "-%s unknown", cp);
|
|
121 case HELPSW:
|
|
122 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
|
|
123 invo_name);
|
|
124 help (buf, switches);
|
|
125 done (1);
|
|
126
|
|
127 case CLRSW:
|
|
128 clearflag++;
|
|
129 continue;
|
|
130 case NCLRSW:
|
|
131 clearflag = 0;
|
|
132 continue;
|
|
133
|
|
134 case FORMSW:
|
|
135 if (!(form = *argp++) || *form == '-')
|
|
136 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
137 format = NULL;
|
|
138 continue;
|
|
139 case FMTSW:
|
|
140 if (!(format = *argp++) || *format == '-')
|
|
141 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
142 form = NULL;
|
|
143 continue;
|
|
144
|
|
145 case HEADSW:
|
|
146 hdrflag++;
|
|
147 continue;
|
|
148 case NHEADSW:
|
|
149 hdrflag = 0;
|
|
150 continue;
|
|
151
|
|
152 case WIDSW:
|
|
153 if (!(cp = *argp++) || *cp == '-')
|
|
154 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
155 width = atoi (cp);
|
|
156 continue;
|
|
157 case REVSW:
|
|
158 revflag++;
|
|
159 continue;
|
|
160 case NREVSW:
|
|
161 revflag = 0;
|
|
162 continue;
|
|
163
|
|
164 case FILESW:
|
|
165 if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
|
|
166 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
167 if (strcmp (file = cp, "-"))
|
|
168 file = path (cp, TFILE);
|
|
169 continue;
|
|
170 }
|
|
171 if (*cp == '+' || *cp == '@') {
|
|
172 if (folder)
|
|
173 adios (NULLCP, "only one folder at a time!");
|
|
174 else
|
|
175 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
|
|
176 }
|
|
177 else
|
|
178 msgs[msgp++] = cp;
|
|
179 }
|
|
180
|
|
181
|
|
182 if (!m_find ("path"))
|
|
183 free (path ("./", TFOLDER));
|
|
184 nfs = new_fs (form, format, FORMAT); /* must be before chdir() */
|
|
185
|
|
186 if (file) {
|
|
187 if (msgp)
|
|
188 adios (NULLCP, "\"msgs\" not allowed with -file");
|
|
189 if (folder)
|
|
190 adios (NULLCP, "\"+folder\" not allowed with -file");
|
|
191 /* we've been asked to scan a maildrop file */
|
|
192 if (strcmp (file, "-")) {
|
|
193 in = fopen (file, "r");
|
|
194 if (in == NULL)
|
|
195 adios (file, "unable to open");
|
|
196 }
|
|
197 else {
|
|
198 in = stdin;
|
|
199 file = "stdin";
|
|
200 }
|
|
201
|
|
202 #ifndef JLR
|
|
203 if (hdrflag) {
|
|
204 (void) time (&clock);
|
|
205 printf ("Folder %-32s%s\n\n", file,
|
|
206 dasctime (dlocaltime (&clock), TW_NULL));
|
|
207 }
|
|
208 #endif /* JLR */
|
|
209 m_unknown (in);
|
|
210 for (msgnum = 1; ; ++msgnum) {
|
|
211 state = scan (in, msgnum, -1, nfs, width, 0, 0,
|
|
212 hdrflag, file, 0L, 1);
|
|
213 if (state != SCNMSG && state != SCNENC)
|
|
214 break;
|
|
215 }
|
|
216 fclose (in);
|
|
217 done (0);
|
|
218 }
|
|
219
|
|
220 if (!msgp)
|
|
221 msgs[msgp++] = "all";
|
|
222 if (!folder)
|
|
223 folder = m_getfolder ();
|
|
224 maildir = m_maildir (folder);
|
|
225
|
|
226 if (chdir (maildir) == NOTOK)
|
|
227 adios (maildir, "unable to change directory to");
|
|
228 if (!(mp = m_gmsg (folder)))
|
|
229 adios (NULLCP, "unable to read folder %s", folder);
|
|
230 if (mp -> hghmsg == 0)
|
|
231 adios (NULLCP, "no messages in %s", folder);
|
|
232
|
|
233 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
234 if (!m_convert (mp, msgs[msgnum]))
|
|
235 done(1);
|
|
236 m_setseq (mp);
|
|
237
|
|
238 m_replace (pfolder, folder);
|
|
239 m_sync (mp);
|
|
240 m_update ();
|
|
241
|
|
242 if (cp = m_find(usequence)) { /* set bits for each unseen sequence */
|
|
243 char *dp = NULL;
|
|
244
|
|
245 bits = 0;
|
|
246 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++)
|
|
247 bits |= m_seqflag(mp, *ap);
|
|
248
|
|
249 if (dp)
|
|
250 free(dp);
|
|
251 }
|
|
252
|
|
253 ontty = isatty (fileno (stdout));
|
|
254
|
|
255 #ifdef LBL
|
|
256 else
|
|
257 fmt_current_folder = mp;
|
|
258 #endif
|
|
259
|
|
260 /* */
|
|
261
|
|
262 for (msgnum = revflag ? mp -> hghsel : mp -> lowsel;
|
|
263 (revflag ? msgnum >= mp -> lowsel : msgnum <= mp -> hghsel);
|
|
264 msgnum += revflag ? (-1) : 1)
|
|
265 if (mp -> msgstats[msgnum] & SELECTED) {
|
|
266 if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) {
|
|
267 #ifdef notdef
|
|
268 if (errno != EACCES)
|
|
269 #endif
|
|
270 admonish (cp, "unable to open message");
|
|
271 #ifdef notdef
|
|
272 else
|
|
273 printf ("%*d unreadable\n", DMAXFOLDER, msgnum);
|
|
274 #endif
|
|
275 continue;
|
|
276 }
|
|
277
|
|
278 #ifndef JLR
|
|
279 if (hdrflag) {
|
|
280 (void) time (&clock);
|
|
281 printf ("Folder %-32s%s\n\n", folder,
|
|
282 dasctime (dlocaltime (&clock), TW_NULL));
|
|
283 }
|
|
284 #endif /* JLR */
|
|
285 switch (state = scan (in, msgnum, 0, nfs, width,
|
|
286 msgnum == mp -> curmsg,
|
|
287 mp -> msgstats[msgnum] & bits,
|
|
288 hdrflag, folder, 0L, 1)) {
|
|
289 case SCNMSG:
|
|
290 case SCNENC:
|
|
291 case SCNERR:
|
|
292 break;
|
|
293
|
|
294 default:
|
|
295 adios (NULLCP, "scan() botch (%d)", state);
|
|
296
|
|
297 case SCNEOF:
|
|
298 #ifdef notdef
|
|
299 printf ("%*d empty\n", DMAXFOLDER, msgnum);
|
|
300 #else
|
|
301 advise (NULLCP, "message %d: empty", msgnum);
|
|
302 #endif
|
|
303 break;
|
|
304 }
|
|
305 hdrflag = 0;
|
|
306 (void) fclose (in);
|
|
307 if (ontty)
|
|
308 (void) fflush (stdout);
|
|
309 }
|
|
310 #ifdef LBL
|
|
311 m_sync (mp); /* because formatsbr might have made changes */
|
|
312 #endif
|
|
313
|
|
314 /* */
|
|
315
|
|
316 if (clearflag)
|
16
|
317 clear_screen0 ();
|
0
|
318
|
|
319 done (0);
|
|
320 }
|