]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/scan.c
1 /* scan.c - display a one-line "scan" listing */
3 static char ident
[] = "@(#)$Id: scan.c,v 1.17 1994/04/21 18:20:50 jromine Exp $";
7 #include "../h/formatsbr.h"
8 #include "../h/scansbr.h"
9 #include "../zotnet/tws.h"
18 static struct swit switches
[] = {
54 #ifdef LBL /* global for sbr/formatsbr.c - yech! */
55 extern struct msgs
*fmt_current_folder
;
71 revflag
= 0, /* used to be #ifdef BERK */
74 bits
, /* should match mp->msgstats[] type */
95 setlocale(LC_ALL
, "");
97 invo_name
= r1bindex (argv
[0], '/');
99 if ((cp
= m_find (invo_name
)) != NULL
) {
100 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
101 ap
= copyip (ap
, arguments
);
105 (void) copyip (argv
+ 1, ap
);
110 while (cp
= *argp
++) {
112 switch (smatch (++cp
, switches
)) {
114 ambigsw (cp
, switches
);
117 adios (NULLCP
, "-%s unknown", cp
);
119 (void) sprintf (buf
, "%s [+folder] [msgs] [switches]",
121 help (buf
, switches
);
132 if (!(form
= *argp
++) || *form
== '-')
133 adios (NULLCP
, "missing argument to %s", argp
[-2]);
137 if (!(format
= *argp
++) || *format
== '-')
138 adios (NULLCP
, "missing argument to %s", argp
[-2]);
150 if (!(cp
= *argp
++) || *cp
== '-')
151 adios (NULLCP
, "missing argument to %s", argp
[-2]);
162 if (!(cp
= *argp
++) || (cp
[0] == '-' && cp
[1]))
163 adios (NULLCP
, "missing argument to %s", argp
[-2]);
164 if (strcmp (file
= cp
, "-"))
165 file
= path (cp
, TFILE
);
168 if (*cp
== '+' || *cp
== '@') {
170 adios (NULLCP
, "only one folder at a time!");
172 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
179 if (!m_find ("path"))
180 free (path ("./", TFOLDER
));
181 nfs
= new_fs (form
, format
, FORMAT
); /* must be before chdir() */
185 adios (NULLCP
, "\"msgs\" not allowed with -file");
187 adios (NULLCP
, "\"+folder\" not allowed with -file");
188 /* we've been asked to scan a maildrop file */
189 if (strcmp (file
, "-")) {
190 in
= fopen (file
, "r");
192 adios (file
, "unable to open");
201 (void) time (&clock
);
202 printf ("Folder %-32s%s\n\n", file
,
203 dasctime (dlocaltime (&clock
), TW_NULL
));
207 for (msgnum
= 1; ; ++msgnum
) {
208 state
= scan (in
, msgnum
, -1, nfs
, width
, 0, 0,
209 hdrflag
, file
, 0L, 1);
210 if (state
!= SCNMSG
&& state
!= SCNENC
)
218 msgs
[msgp
++] = "all";
220 folder
= m_getfolder ();
221 maildir
= m_maildir (folder
);
223 if (chdir (maildir
) == NOTOK
)
224 adios (maildir
, "unable to change directory to");
225 if (!(mp
= m_gmsg (folder
)))
226 adios (NULLCP
, "unable to read folder %s", folder
);
227 if (mp
-> hghmsg
== 0)
228 adios (NULLCP
, "no messages in %s", folder
);
230 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
231 if (!m_convert (mp
, msgs
[msgnum
]))
235 m_replace (pfolder
, folder
);
239 if (cp
= m_find(usequence
)) { /* set bits for each unseen sequence */
243 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++)
244 bits
|= m_seqflag(mp
, *ap
);
250 ontty
= isatty (fileno (stdout
));
254 fmt_current_folder
= mp
;
259 for (msgnum
= revflag
? mp
-> hghsel
: mp
-> lowsel
;
260 (revflag
? msgnum
>= mp
-> lowsel
: msgnum
<= mp
-> hghsel
);
261 msgnum
+= revflag
? (-1) : 1)
262 if (mp
-> msgstats
[msgnum
] & SELECTED
) {
263 if ((in
= fopen (cp
= m_name (msgnum
), "r")) == NULL
) {
267 admonish (cp
, "unable to open message");
270 printf ("%*d unreadable\n", DMAXFOLDER
, msgnum
);
277 (void) time (&clock
);
278 printf ("Folder %-32s%s\n\n", folder
,
279 dasctime (dlocaltime (&clock
), TW_NULL
));
282 switch (state
= scan (in
, msgnum
, 0, nfs
, width
,
283 msgnum
== mp
-> curmsg
,
284 mp
-> msgstats
[msgnum
] & bits
,
285 hdrflag
, folder
, 0L, 1)) {
292 adios (NULLCP
, "scan() botch (%d)", state
);
296 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
298 advise (NULLCP
, "message %d: empty", msgnum
);
305 (void) fflush (stdout
);
308 m_sync (mp
); /* because formatsbr might have made changes */