From: David Levine Date: Thu, 24 Jan 2013 02:24:21 +0000 (-0600) Subject: Added functions for inc, msh, rcvtty, and scan to access X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/d02aabc331c325d8206a862a43438f4a472a5306?hp=--cc Added functions for inc, msh, rcvtty, and scan to access scansbr's gstate instance so it can be hidden, except for msh's uses of m_getfld(). --- d02aabc331c325d8206a862a43438f4a472a5306 diff --git a/h/prototypes.h b/h/prototypes.h index bd44f537..2a0ed6d5 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -108,6 +108,9 @@ void readconfig (struct node **, FILE *, char *, int); 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 *); diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 8303b54a..ba135aa5 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -257,14 +257,14 @@ struct m_getfld_state { 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 = ""; @@ -277,11 +277,9 @@ m_getfld_state_init (m_getfld_state_t *gstate) { /* 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) { @@ -329,17 +327,17 @@ enter_getfld (m_getfld_state_t *gstate, FILE *iob) { 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) { diff --git a/uip/inc.c b/uip/inc.c index 210c3b63..54711e09 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -171,8 +171,6 @@ static FILE *in; */ 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 *); @@ -723,7 +721,7 @@ go_to_it: * 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 (;;) { /* @@ -890,7 +888,7 @@ go_to_it: 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) { diff --git a/uip/msh.c b/uip/msh.c index 02a613be..ac1e34ae 100644 --- a/uip/msh.c +++ b/uip/msh.c @@ -164,7 +164,7 @@ void seq_setcur (struct msgs *, int); 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 */ /* @@ -352,7 +352,7 @@ main (int argc, char **argv) display_info (id > 0 ? scansw : 0); msh (id > 0 ? scansw : 0); - m_getfld_state_destroy (&gstate); + scan_finished (); m_reset (); @@ -716,7 +716,7 @@ setup (char *file) 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; @@ -839,7 +839,7 @@ msh_ready (int msgnum, int full) return yp; } - m_eomsbr (gstate, (int (*)()) 0); /* XXX */ + scan_eom_action ((int (*)()) 0); /* XXX */ fseek (fp, Msgs[msgnum].m_start, SEEK_SET); return fp; } diff --git a/uip/mshcmds.c b/uip/mshcmds.c index b8bc4250..be6c50d1 100644 --- a/uip/mshcmds.c +++ b/uip/mshcmds.c @@ -51,7 +51,7 @@ static int process (int, char *, int, char **); 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) @@ -986,7 +986,7 @@ forw (char *proc, char *filter, int vecp, char **vec) 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); @@ -2307,7 +2307,7 @@ finish: ; 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 { @@ -2379,7 +2379,7 @@ mhl_action (char *name) mhlfp = msh_ready (msgnum, 1); if (!fmsh) - m_eomsbr (gstate, eom_action); + scan_eom_action (eom_action); return mhlfp; } diff --git a/uip/rcvtty.c b/uip/rcvtty.c index a5c2d67e..6e6bbccf 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -68,8 +68,6 @@ static char *format = NULL; */ char *getusername(void); -extern m_getfld_state_t gstate; - /* * static prototypes */ @@ -263,7 +261,7 @@ header_fd (void) /* 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)); diff --git a/uip/scan.c b/uip/scan.c index 27a8efeb..56afc181 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -56,8 +56,6 @@ extern struct msgs *fmt_current_folder; */ void clear_screen(void); /* from termsbr.c */ -extern m_getfld_state_t gstate; - int main (int argc, char **argv) @@ -190,14 +188,14 @@ 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); } @@ -297,7 +295,7 @@ main (int argc, char **argv) advise (NULL, "message %d: empty", msgnum); break; } - m_getfld_state_destroy (&gstate); + scan_finished (); hdrflag = 0; fclose (in); if (ontty) diff --git a/uip/scansbr.c b/uip/scansbr.c index bdf0de33..8fc88257 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -14,8 +14,6 @@ #include #include -m_getfld_state_t gstate; - #define MAXSCANL 256 /* longest possible scan line */ /* @@ -38,6 +36,7 @@ static struct comp **used_buf = 0; /* stack for comp that use buffers */ 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") @@ -380,3 +379,18 @@ mh_fputs(char *s, FILE *stream) 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); +}