]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/scan.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / scan.c,v
1 head 1.17;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.17
9 date 94.04.21.18.20.50; author jromine; state Exp;
10 branches;
11 next 1.16;
12
13 1.16
14 date 92.12.15.00.20.22; author jromine; state Exp;
15 branches;
16 next 1.15;
17
18 1.15
19 date 92.11.04.01.01.43; author jromine; state Exp;
20 branches;
21 next 1.14;
22
23 1.14
24 date 92.02.09.07.13.34; author jromine; state Exp;
25 branches;
26 next 1.13;
27
28 1.13
29 date 92.02.05.22.50.17; author jromine; state Exp;
30 branches;
31 next 1.12;
32
33 1.12
34 date 92.02.05.07.26.30; author jromine; state Exp;
35 branches;
36 next 1.11;
37
38 1.11
39 date 92.02.03.22.45.20; author jromine; state Exp;
40 branches;
41 next 1.10;
42
43 1.10
44 date 92.01.31.22.26.24; author jromine; state Exp;
45 branches;
46 next 1.9;
47
48 1.9
49 date 92.01.23.23.06.45; author jromine; state Exp;
50 branches;
51 next 1.8;
52
53 1.8
54 date 90.04.05.14.59.58; author sources; state Exp;
55 branches;
56 next 1.7;
57
58 1.7
59 date 90.04.02.14.43.19; author sources; state Exp;
60 branches;
61 next 1.6;
62
63 1.6
64 date 90.03.12.11.07.47; author sources; state Exp;
65 branches;
66 next 1.5;
67
68 1.5
69 date 90.02.21.15.36.00; author sources; state Exp;
70 branches;
71 next 1.4;
72
73 1.4
74 date 90.02.09.10.34.35; author sources; state Exp;
75 branches;
76 next 1.3;
77
78 1.3
79 date 90.02.09.10.17.36; author sources; state Exp;
80 branches;
81 next 1.2;
82
83 1.2
84 date 90.02.01.14.28.48; author sources; state Exp;
85 branches;
86 next 1.1;
87
88 1.1
89 date 90.02.01.14.19.44; author sources; state Exp;
90 branches;
91 next ;
92
93
94 desc
95 @@
96
97
98 1.17
99 log
100 @update for scansbr.c -- overload {folder}.c_flags with hdrflg
101 @
102 text
103 @/* scan.c - display a one-line "scan" listing */
104 #ifndef lint
105 static char ident[] = "@@(#)$Id: scan.c,v 1.16 1992/12/15 00:20:22 jromine Exp jromine $";
106 #endif /* lint */
107
108 #include "../h/mh.h"
109 #include "../h/formatsbr.h"
110 #include "../h/scansbr.h"
111 #include "../zotnet/tws.h"
112 #include <errno.h>
113 #include <stdio.h>
114 #ifdef LOCALE
115 #include <locale.h>
116 #endif
117
118 /* \f */
119
120 static struct swit switches[] = {
121 #define CLRSW 0
122 "clear", 0,
123 #define NCLRSW 1
124 "noclear", 0,
125
126 #define FORMSW 2
127 "form formatfile", 0,
128 #define FMTSW 3
129 "format string", 5,
130
131 #define HEADSW 4
132 "header", 0,
133 #define NHEADSW 5
134 "noheader", 0,
135
136 #define WIDSW 6
137 "width columns", 0,
138
139 #define REVSW 7
140 "reverse", 0,
141 #define NREVSW 8
142 "noreverse", 0,
143
144 #define FILESW 9
145 "file file", 4,
146
147 #define HELPSW 10
148 "help", 4,
149
150 NULL, 0
151 };
152
153 /* \f */
154
155 extern int errno;
156 #ifdef LBL /* global for sbr/formatsbr.c - yech! */
157 extern struct msgs *fmt_current_folder;
158 #endif
159
160
161 void clear_screen ();
162
163 /* \f */
164
165 /* ARGSUSED */
166
167 main (argc, argv)
168 int argc;
169 char *argv[];
170 {
171 int clearflag = 0,
172 hdrflag = 0,
173 revflag = 0, /* used to be #ifdef BERK */
174 width = 0,
175 msgp = 0,
176 bits, /* should match mp->msgstats[] type */
177 ontty,
178 state,
179 msgnum;
180 long clock;
181 char *cp,
182 *maildir,
183 *file = NULL,
184 *folder = NULL,
185 *form = NULL,
186 *format = NULL,
187 buf[100],
188 **ap,
189 **argp,
190 *nfs,
191 *arguments[MAXARGS],
192 *msgs[MAXARGS];
193 struct msgs *mp;
194 FILE * in;
195
196 #ifdef LOCALE
197 setlocale(LC_ALL, "");
198 #endif
199 invo_name = r1bindex (argv[0], '/');
200 mts_init (invo_name);
201 if ((cp = m_find (invo_name)) != NULL) {
202 ap = brkstring (cp = getcpy (cp), " ", "\n");
203 ap = copyip (ap, arguments);
204 }
205 else
206 ap = arguments;
207 (void) copyip (argv + 1, ap);
208 argp = arguments;
209
210 /* \f */
211
212 while (cp = *argp++) {
213 if (*cp == '-')
214 switch (smatch (++cp, switches)) {
215 case AMBIGSW:
216 ambigsw (cp, switches);
217 done (1);
218 case UNKWNSW:
219 adios (NULLCP, "-%s unknown", cp);
220 case HELPSW:
221 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
222 invo_name);
223 help (buf, switches);
224 done (1);
225
226 case CLRSW:
227 clearflag++;
228 continue;
229 case NCLRSW:
230 clearflag = 0;
231 continue;
232
233 case FORMSW:
234 if (!(form = *argp++) || *form == '-')
235 adios (NULLCP, "missing argument to %s", argp[-2]);
236 format = NULL;
237 continue;
238 case FMTSW:
239 if (!(format = *argp++) || *format == '-')
240 adios (NULLCP, "missing argument to %s", argp[-2]);
241 form = NULL;
242 continue;
243
244 case HEADSW:
245 hdrflag++;
246 continue;
247 case NHEADSW:
248 hdrflag = 0;
249 continue;
250
251 case WIDSW:
252 if (!(cp = *argp++) || *cp == '-')
253 adios (NULLCP, "missing argument to %s", argp[-2]);
254 width = atoi (cp);
255 continue;
256 case REVSW:
257 revflag++;
258 continue;
259 case NREVSW:
260 revflag = 0;
261 continue;
262
263 case FILESW:
264 if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
265 adios (NULLCP, "missing argument to %s", argp[-2]);
266 if (strcmp (file = cp, "-"))
267 file = path (cp, TFILE);
268 continue;
269 }
270 if (*cp == '+' || *cp == '@@') {
271 if (folder)
272 adios (NULLCP, "only one folder at a time!");
273 else
274 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
275 }
276 else
277 msgs[msgp++] = cp;
278 }
279
280
281 if (!m_find ("path"))
282 free (path ("./", TFOLDER));
283 nfs = new_fs (form, format, FORMAT); /* must be before chdir() */
284
285 if (file) {
286 if (msgp)
287 adios (NULLCP, "\"msgs\" not allowed with -file");
288 if (folder)
289 adios (NULLCP, "\"+folder\" not allowed with -file");
290 /* we've been asked to scan a maildrop file */
291 if (strcmp (file, "-")) {
292 in = fopen (file, "r");
293 if (in == NULL)
294 adios (file, "unable to open");
295 }
296 else {
297 in = stdin;
298 file = "stdin";
299 }
300
301 #ifndef JLR
302 if (hdrflag) {
303 (void) time (&clock);
304 printf ("Folder %-32s%s\n\n", file,
305 dasctime (dlocaltime (&clock), TW_NULL));
306 }
307 #endif /* JLR */
308 m_unknown (in);
309 for (msgnum = 1; ; ++msgnum) {
310 state = scan (in, msgnum, -1, nfs, width, 0, 0,
311 hdrflag, file, 0L, 1);
312 if (state != SCNMSG && state != SCNENC)
313 break;
314 }
315 fclose (in);
316 done (0);
317 }
318
319 if (!msgp)
320 msgs[msgp++] = "all";
321 if (!folder)
322 folder = m_getfolder ();
323 maildir = m_maildir (folder);
324
325 if (chdir (maildir) == NOTOK)
326 adios (maildir, "unable to change directory to");
327 if (!(mp = m_gmsg (folder)))
328 adios (NULLCP, "unable to read folder %s", folder);
329 if (mp -> hghmsg == 0)
330 adios (NULLCP, "no messages in %s", folder);
331
332 for (msgnum = 0; msgnum < msgp; msgnum++)
333 if (!m_convert (mp, msgs[msgnum]))
334 done(1);
335 m_setseq (mp);
336
337 m_replace (pfolder, folder);
338 m_sync (mp);
339 m_update ();
340
341 if (cp = m_find(usequence)) { /* set bits for each unseen sequence */
342 char *dp = NULL;
343
344 bits = 0;
345 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++)
346 bits |= m_seqflag(mp, *ap);
347
348 if (dp)
349 free(dp);
350 }
351
352 ontty = isatty (fileno (stdout));
353
354 #ifdef LBL
355 else
356 fmt_current_folder = mp;
357 #endif
358
359 /* \f */
360
361 for (msgnum = revflag ? mp -> hghsel : mp -> lowsel;
362 (revflag ? msgnum >= mp -> lowsel : msgnum <= mp -> hghsel);
363 msgnum += revflag ? (-1) : 1)
364 if (mp -> msgstats[msgnum] & SELECTED) {
365 if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) {
366 #ifdef notdef
367 if (errno != EACCES)
368 #endif
369 admonish (cp, "unable to open message");
370 #ifdef notdef
371 else
372 printf ("%*d unreadable\n", DMAXFOLDER, msgnum);
373 #endif
374 continue;
375 }
376
377 #ifndef JLR
378 if (hdrflag) {
379 (void) time (&clock);
380 printf ("Folder %-32s%s\n\n", folder,
381 dasctime (dlocaltime (&clock), TW_NULL));
382 }
383 #endif /* JLR */
384 switch (state = scan (in, msgnum, 0, nfs, width,
385 msgnum == mp -> curmsg,
386 mp -> msgstats[msgnum] & bits,
387 hdrflag, folder, 0L, 1)) {
388 case SCNMSG:
389 case SCNENC:
390 case SCNERR:
391 break;
392
393 default:
394 adios (NULLCP, "scan() botch (%d)", state);
395
396 case SCNEOF:
397 #ifdef notdef
398 printf ("%*d empty\n", DMAXFOLDER, msgnum);
399 #else
400 advise (NULLCP, "message %d: empty", msgnum);
401 #endif
402 break;
403 }
404 hdrflag = 0;
405 (void) fclose (in);
406 if (ontty)
407 (void) fflush (stdout);
408 }
409 #ifdef LBL
410 m_sync (mp); /* because formatsbr might have made changes */
411 #endif
412
413 /* \f */
414
415 if (clearflag)
416 clear_screen ();
417
418 done (0);
419 }
420 @
421
422
423 1.16
424 log
425 @endif sugar
426 @
427 text
428 @d3 1
429 a3 1
430 static char ident[] = "@@(#)$Id: scan.c,v 1.15 1992/11/04 01:01:43 jromine Exp jromine $";
431 d209 1
432 a209 1
433 hdrflag ? file : (char *)0, 0L, 1);
434 d285 1
435 a285 1
436 hdrflag ? folder : (char *)0, 0L, 1)) {
437 @
438
439
440 1.15
441 log
442 @LOCALE
443 @
444 text
445 @d3 2
446 a4 2
447 static char ident[] = "@@(#)$Id: scan.c,v 1.14 1992/02/09 07:13:34 jromine Exp jromine $";
448 #endif lint
449 @
450
451
452 1.14
453 log
454 @allow headers with -file
455 allow "-file -" to mean read stdin
456 put V.Jacobson changes under "options LBL"
457 @
458 text
459 @d3 1
460 a3 1
461 static char ident[] = "@@(#)$Id: scan.c,v 1.13 1992/02/05 22:50:17 jromine Exp jromine $";
462 d12 3
463 d94 3
464 @
465
466
467 1.13
468 log
469 @allow "-file -" for stdin
470 @
471 text
472 @d3 1
473 a3 1
474 static char ident[] = "@@(#)$Id: scan.c,v 1.12 1992/02/05 07:26:30 jromine Exp jromine $";
475 d51 1
476 a51 1
477 #ifdef VAN /* global for sbr/formatsbr.c - yech! */
478 d156 1
479 a156 1
480 if (!(cp = *argp++) || *cp == '-')
481 d158 2
482 a159 1
483 file = path (cp, TFILE);
484 d193 7
485 d246 1
486 a246 1
487 #ifdef VAN
488 d301 1
489 a301 1
490 #ifdef VAN
491 @
492
493
494 1.12
495 log
496 @put unseen sequence in mh-format
497 @
498 text
499 @d3 1
500 a3 1
501 static char ident[] = "@@(#)$Id: scan.c,v 1.11 1992/02/03 22:45:20 jromine Exp jromine $";
502 d182 9
503 a190 3
504 in = fopen (file, "r");
505 if (in == NULL)
506 adios (file, "unable to open");
507 @
508
509
510 1.11
511 log
512 @move -file up so folder context doesn't happen
513 @
514 text
515 @d3 1
516 a3 1
517 static char ident[] = "@@(#)$Id: scan.c,v 1.10 1992/01/31 22:26:24 jromine Exp jromine $";
518 d71 1
519 d188 1
520 a188 1
521 state = scan (in, msgnum, -1, nfs, width, 0,
522 d219 11
523 d264 1
524 @
525
526
527 1.10
528 log
529 @kerberos
530 @
531 text
532 @d3 1
533 a3 1
534 static char ident[] = "@@(#)$Id: scan.c,v 1.9 1992/01/23 23:06:45 jromine Exp jromine $";
535 d173 23
536 a201 2
537 nfs = new_fs (form, format, FORMAT); /* must be before chdir() */
538
539 a219 16
540 if (file) {
541 /* we've been asked to scan a maildrop file */
542 in = fopen (file, "r");
543 if (in == NULL)
544 adios (NULLCP, "can't open %s (%d)", file, errno);
545
546 m_unknown (in);
547 for (msgnum = 1; ; ++msgnum) {
548 state = scan (in, msgnum, -1, nfs, width, 0,
549 hdrflag ? file : (char *)0, 0L, 1);
550 if (state != SCNMSG && state != SCNENC)
551 break;
552 }
553 fclose (in);
554 done (0);
555 }
556 @
557
558
559 1.9
560 log
561 @new formatsbr changes under JLR
562 @
563 text
564 @d3 1
565 a3 1
566 static char ident[] = "@@(#)$Id: scan.c,v 1.8 1990/04/05 14:59:58 sources Exp jromine $";
567 d45 1
568 a45 1
569 NULL, NULL
570 @
571
572
573 1.8
574 log
575 @add ID
576 @
577 text
578 @d3 1
579 a3 1
580 static char ident[] = "@@(#)$Id:$";
581 d207 2
582 a208 1
583 state = scan (in, msgnum, -1, nfs, width, 0, hdrflag, 0L, 1);
584 d238 1
585 d244 1
586 d247 1
587 a247 1
588 hdrflag, 0L, 1)) {
589 @
590
591
592 1.7
593 log
594 @RAND fixes
595 @
596 text
597 @d2 3
598 @
599
600
601 1.6
602 log
603 @change "empty" and "unreadable" message to be error messages
604 via advise(). I don't agree with this change -- eventually,
605 formatsbr should have to deal with these errors.
606 /JLR
607 @
608 text
609 @d88 1
610 @
611
612
613 1.5
614 log
615 @add #ifdef VAN
616 @
617 text
618 @d222 1
619 d224 1
620 d226 1
621 d229 1
622 d250 1
623 d252 3
624 d262 1
625 d264 1
626 @
627
628
629 1.4
630 log
631 @Fixes from Van Jacobson
632 @
633 text
634 @d48 3
635 a50 1
636 extern struct msgs *fmt_current_folder; /* global for sbr/formatsbr.c - yech! */
637 d210 1
638 d213 1
639 @
640
641
642 1.3
643 log
644 @fixup -reverse
645 @
646 text
647 @d36 4
648 a39 1
649 #define HELPSW 9
650 d48 1
651 d72 1
652 d147 6
653 a163 1
654 /* \f */
655 d193 18
656 d250 1
657 @
658
659
660 1.2
661 log
662 @relent and add -[no]reverse
663 @
664 text
665 @a184 12
666 #ifdef notdef
667 if (revflag) {
668 firstlim = mp -> hghsel;
669 lastlim = mp -> lowsel;
670 incr = -1;
671 }
672 else {
673 firstlim = mp -> lowsel;
674 lastlim = mp -> hghsel;
675 incr = 1;
676 }
677 #endif notdef
678 @
679
680
681 1.1
682 log
683 @Initial revision
684 @
685 text
686 @a30 1
687 #ifdef BERK
688 a36 3
689 #else not BERK
690 #define HELPSW 7
691 #endif not BERK
692 d59 1
693 a64 6
694 #ifdef BERK
695 register int revflag = 0,
696 firstlim,
697 lastlim,
698 incr;
699 #endif BERK
700 a135 1
701 #ifdef BERK
702 a141 1
703 #endif BERK
704 d185 1
705 a185 1
706 #ifdef BERK
707 d196 4
708 a199 7
709
710 for (msgnum = firstlim;
711 (revflag ? msgnum >= lastlim : msgnum <= lastlim);
712 msgnum += incr)
713 #else not BERK
714 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
715 #endif not BERK
716 @