]> diplodocus.org Git - nmh/commitdiff
Added functions for inc, msh, rcvtty, and scan to access
authorDavid Levine <levinedl@acm.org>
Thu, 24 Jan 2013 02:24:21 +0000 (20:24 -0600)
committerDavid Levine <levinedl@acm.org>
Thu, 24 Jan 2013 02:24:21 +0000 (20:24 -0600)
scansbr's gstate instance so it can be hidden, except for
msh's uses of m_getfld().

h/prototypes.h
sbr/m_getfld.c
uip/inc.c
uip/msh.c
uip/mshcmds.c
uip/rcvtty.c
uip/scan.c
uip/scansbr.c

index bd44f5370e2bcd648f951ff2a61e7fdccd57edb4..2a0ed6d51a39fbae6089d7345025aea70f05fa19 100644 (file)
@@ -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 *);
index 8303b54a4a08579334cf4a8e52356a3101fb9476..ba135aa5bce12a24c06b330dcd1c958b26ec5eef 100644 (file)
@@ -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) {
index 210c3b63ff546c9a081addb81956b4d610ec882e..54711e091f05fefadeba319af42ae2c6605852a0 100644 (file)
--- 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) {
index 02a613be4f2c293990a52bbf6f5cf02ad177c90c..ac1e34ae6e04a8ee39a1cbbc0a6062b710c23017 100644 (file)
--- 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;
 }
index b8bc425038ce5bdfed61205a4d13a98e3d4882ad..be6c50d1718f7e6e1d6fc10daadcb40657de915c 100644 (file)
@@ -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;
 }
index a5c2d67e7a934bce86b6789d03d02fb7fc7c9db6..6e6bbccf51442b8955655a738a1c6f6eda40e91a 100644 (file)
@@ -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));
index 27a8efeb4de285297ae3d0670a14fb03e0a5089e..56afc181d404a3c3ff17ff7251bcfb57b0575406 100644 (file)
@@ -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)
index bdf0de3307b29d6209f5d904af344759edd292c8..8fc88257cb8850b2842b7e2709d3ab8ea77253ef 100644 (file)
@@ -14,8 +14,6 @@
 #include <h/tws.h>
 #include <h/utils.h>
 
-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);
+}