From: Ralph Corderoy Date: Thu, 10 Aug 2017 14:44:20 +0000 (+0100) Subject: m_getfld() et al: Add wrapper without FILE *iob parameter. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/0ff76f3b2823f98e75b76dc93f2b5be293171610 m_getfld() et al: Add wrapper without FILE *iob parameter. m_getfld(), m_getfld_track_filepos(), and m_unknown() all take a FILE *iob that's used to update *m_getfld_state_t, even though it's probably, hopefully, the same as the previous calls. Create wrapper functions for these with an arbitrary `2' suffix that don't have this parameter. After checking the m_getfld_state_t is initialised, they pass in its existing FILE *iob. This allows callers to transition to the wrappers in the cases where it's obviously the same FILE *iob being passed in. It isn't always obvious, in part because of the convention for calling this variable `in', even when it's a file-level static, a word that also occurs in comments. --- diff --git a/h/prototypes.h b/h/prototypes.h index 81983010..7cce0ba7 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -230,11 +230,14 @@ m_getfld_state_t m_getfld_state_init(FILE *iob); void m_getfld_state_reset (m_getfld_state_t *); void m_getfld_state_destroy (m_getfld_state_t *); void m_getfld_track_filepos (m_getfld_state_t *, FILE *); +void m_getfld_track_filepos2(m_getfld_state_t *); int m_getfld (m_getfld_state_t *, char[NAMESZ], char *, int *, FILE *); +int m_getfld2(m_getfld_state_t *, char[NAMESZ], char *, int *); int m_gmprot (void); char *m_name (int); void m_unknown(m_getfld_state_t *, FILE *); +void m_unknown2(m_getfld_state_t *); /* * Clear the screen, using the appropriate entry from the terminfo database diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 9e017090..f674792e 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -346,6 +346,15 @@ m_getfld_track_filepos (m_getfld_state_t *gstate, FILE *iob) { (*gstate)->track_filepos = 1; } +/* m_getfld_track_filepos() with the existing iob. */ +void m_getfld_track_filepos2(m_getfld_state_t *gstate) +{ + if (!*gstate) + adios(NULL, "m_getfld_track_filepos2 without gstate"); + + m_getfld_track_filepos(gstate, (*gstate)->iob); +} + void m_getfld_state_destroy (m_getfld_state_t *gstate) { m_getfld_state_t s = *gstate; @@ -831,6 +840,16 @@ m_getfld (m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz, } +/* m_getfld() with the existing iob. */ +int m_getfld2(m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz) +{ + if (!*gstate) + adios(NULL, "m_getfld2 without gstate"); + + return m_getfld(gstate, name, buf, bufsz, (*gstate)->iob); +} + + void m_unknown(m_getfld_state_t *gstate, FILE *iob) { @@ -921,6 +940,16 @@ m_unknown(m_getfld_state_t *gstate, FILE *iob) } +/* m_unknown() with the existing iob. */ +void m_unknown2(m_getfld_state_t *gstate) +{ + if (!*gstate) + adios(NULL, "m_unknown2 without gstate"); + + m_unknown(gstate, (*gstate)->iob); +} + + /* * test for msg delimiter string */