int refile (char **, char *);
void ruserpass(char *, char **, char **);
int remdir (char *);
+void scan_detect_mbox_style (FILE *);
+void scan_finished ();
+void scan_eom_action (int (*)());
int seq_addmsg (struct msgs *, char *, int, int, int);
int seq_addsel (struct msgs *, char *, int, int);
char *seq_bits (struct msgs *);
static
void
-m_getfld_state_init (m_getfld_state_t *gstate) {
+m_getfld_state_init (m_getfld_state_t *gstate, FILE *iob) {
m_getfld_state_t s;
s = *gstate = (m_getfld_state_t) mh_xmalloc(sizeof (struct m_getfld_state));
s->readpos = s->end = s->msg_buf;
s->bytes_read = s->total_bytes_read = 0;
s->last_caller_pos = s->last_internal_pos = 0;
- /* s->iob gets loaded on every call to m_getfld()/m_unknown(). */
+ s->iob = iob;
s->pat_map = NULL;
s->msg_style = MS_DEFAULT;
s->msg_delim = "";
/* scan() needs to force a state an initial state of FLD for each message. */
void
m_getfld_state_reset (m_getfld_state_t *gstate) {
- if (! *gstate) {
- m_getfld_state_init (gstate);
+ if (*gstate) {
+ (*gstate)->state = FLD;
}
-
- (*gstate)->state = FLD;
}
void m_getfld_state_destroy (m_getfld_state_t *gstate) {
off_t pos = ftello (iob);
if (! *gstate) {
- m_getfld_state_init (gstate);
+ m_getfld_state_init (gstate, iob);
}
s = *gstate;
s->bytes_read = 0;
- /* Ugly. The parser (used to) open the input file multiple times,
- so we have to always use the FILE * that's passed to
- m_getfld(). Though this might not be necessary any more, as
- long as the parser inits a new m_getfld_state for each file.
- See comment below about the readpos shift code being currently
- unused. */
+ /* This is ugly and no longer necessary, but is retained just in
+ case it's needed again. The parser used to open the input file
+ multiple times, so we had to always use the FILE * that's
+ passed to m_getfld(). Now the parser inits a new
+ m_getfld_state for each file. See comment below about the
+ readpos shift code being currently unused. */
s->iob = iob;
if (pos != 0 || s->last_internal_pos != 0) {
*/
char *map_name(char *);
-extern m_getfld_state_t gstate;
-
static void inc_done(int) NORETURN;
static int pop_action(char *);
static int pop_pack(char *);
* Get the mail from file (usually mail spool)
*/
if (inc_type == INC_FILE && Maildir == NULL) {
- m_unknown (&gstate, in); /* the MAGIC invocation... */
+ scan_detect_mbox_style (in); /* the MAGIC invocation... */
hghnum = msgnum = mp->hghmsg;
for (;;) {
/*
free (Maildir); /* From now on Maildir is just a flag - don't dref! */
}
- m_getfld_state_destroy (&gstate);
+ scan_finished ();
if (incerr < 0) { /* error */
if (locked) {
void padios (char *, char *, ...);
void padvise (char *, char *, ...);
-extern m_getfld_state_t gstate;
+extern m_getfld_state_t gstate; /* use the gstate in scansbr.c */
/*
display_info (id > 0 ? scansw : 0);
msh (id > 0 ? scansw : 0);
- m_getfld_state_destroy (&gstate);
+ scan_finished ();
m_reset ();
mp->msgattrs[0] = getcpy ("unseen");
mp->msgattrs[1] = NULL;
- m_unknown (&gstate, fp); /* the MAGIC invocation */
+ scan_detect_mbox_style (fp); /* the MAGIC invocation */
if (fmsh) {
free (fmsh);
fmsh = NULL;
return yp;
}
- m_eomsbr (gstate, (int (*)()) 0); /* XXX */
+ scan_eom_action ((int (*)()) 0); /* XXX */
fseek (fp, Msgs[msgnum].m_start, SEEK_SET);
return fp;
}
static void copy_message (int, FILE *);
static void copy_digest (int, FILE *);
-extern m_getfld_state_t gstate;
+extern m_getfld_state_t gstate; /* use the gstate in scansbr.c */
void
forkcmd (char **args, char *pgm)
args[i++] = getcpy (m_name (msgnum));
args[i] = NULL;
mhlsbr (i, args, mhl_action);
- m_eomsbr (gstate, (int (*) ()) 0);
+ scan_eom_action ((int (*) ()) 0);
fclose (stdout);
_exit (0);
if (mp->numsel == 1 && headersw)
show (mp->lowsel);
mhlsbr (vecp, vec, mhl_action);
- m_eomsbr (gstate, (int (*)()) 0);
+ scan_eom_action ((int (*)()) 0);
while (msgp < vecp)
free (vec[msgp++]);
} else {
mhlfp = msh_ready (msgnum, 1);
if (!fmsh)
- m_eomsbr (gstate, eom_action);
+ scan_eom_action (eom_action);
return mhlfp;
}
*/
char *getusername(void);
-extern m_getfld_state_t gstate;
-
/*
* static prototypes
*/
/* get new format string */
nfs = new_fs (form, format, SCANFMT);
scan (stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0);
- m_getfld_state_destroy (&gstate);
+ scan_finished ();
if (newline)
write (fd, "\n\r", 2);
write (fd, scanl, strlen (scanl));
*/
void clear_screen(void); /* from termsbr.c */
-extern m_getfld_state_t gstate;
-
int
main (int argc, char **argv)
printf ("FOLDER %s\t%s\n", file, dtimenow (1));
}
- m_unknown (&gstate, in);
+ scan_detect_mbox_style (in);
for (msgnum = 1; ; ++msgnum) {
state = scan (in, msgnum, -1, nfs, width, 0, 0,
hdrflag ? file : NULL, 0L, 1);
if (state != SCNMSG && state != SCNENC)
break;
}
- m_getfld_state_destroy (&gstate);
+ scan_finished ();
fclose (in);
done (0);
}
advise (NULL, "message %d: empty", msgnum);
break;
}
- m_getfld_state_destroy (&gstate);
+ scan_finished ();
hdrflag = 0;
fclose (in);
if (ontty)
#include <h/tws.h>
#include <h/utils.h>
-m_getfld_state_t gstate;
-
#define MAXSCANL 256 /* longest possible scan line */
/*
static int dat[5]; /* aux. data for format routine */
char *scanl = 0; /* text of most recent scanline */
+m_getfld_state_t gstate; /* for access by msh */
#define DIEWRERR() adios (scnmsg, "write error on")
return (0);
}
+/* The following three functions allow access to the global gstate above. */
+void
+scan_finished () {
+ m_getfld_state_destroy (&gstate);
+}
+
+void
+scan_detect_mbox_style (FILE *f) {
+ m_unknown (&gstate, f);
+}
+
+void
+scan_eom_action (int (*action)()) {
+ m_eomsbr (gstate, action);
+}