X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/d02aabc331c325d8206a862a43438f4a472a5306..7559e1ebf:/uip/msh.c?ds=sidebyside diff --git a/uip/msh.c b/uip/msh.c index ac1e34ae..e91924c3 100644 --- a/uip/msh.c +++ b/uip/msh.c @@ -26,45 +26,35 @@ #include #include -#include #include #include #define QUOTE '\\' /* sigh */ -static struct swit switches[] = { -#define IDSW 0 - { "idstart number", -7 }, /* interface from bbc */ -#define FDSW 1 - { "idstop number", -6 }, /* .. */ -#define QDSW 2 - { "idquit number", -6 }, /* .. */ -#define NMSW 3 - { "idname BBoard", -6 }, /* .. */ -#define PRMPTSW 4 - { "prompt string", 0 }, -#define SCANSW 5 - { "scan", 0 }, -#define NSCANSW 6 - { "noscan", 0 }, -#define READSW 7 - { "vmhread fd", -7 }, -#define WRITESW 8 - { "vmhwrite fd", -8 }, -#define PREADSW 9 - { "popread fd", -7 }, -#define PWRITSW 10 - { "popwrite fd", -8 }, -#define TCURSW 11 - { "topcur", 0 }, -#define NTCURSW 12 - { "notopcur", 0 }, -#define VERSIONSW 13 - { "version", 0 }, -#define HELPSW 14 - { "help", 0 }, - { NULL, 0 } -}; +#define MSH_SWITCHES \ + X("idstart number", -7, IDSW) /* interface from bbc */ \ + X("idstop number", -6, FDSW) /* .. */ \ + X("idquit number", -6, QDSW) /* .. */ \ + X("idname BBoard", -6, NMSW) /* .. */ \ + X("prompt string", 0, PRMPTSW) \ + X("scan", 0, SCANSW) \ + X("noscan", 0, NSCANSW) \ + X("vmhread fd", -7, READSW) \ + X("vmhwrite fd", -8, WRITESW) \ + X("popread fd", -7, PREADSW) \ + X("popwrite fd", -8, PWRITSW) \ + X("topcur", 0, TCURSW) \ + X("notopcur", 0, NTCURSW) \ + X("version", 0, VERSIONSW) \ + X("help", 0, HELPSW) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(MSH); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(MSH, switches); +#undef X static int mbx_style = MMDF_FORMAT; @@ -213,13 +203,7 @@ main (int argc, char **argv) char *cp, *file = NULL, *folder = NULL; char **argp, **arguments, buf[BUFSIZ]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc,argv, 1); @@ -361,65 +345,43 @@ main (int argc, char **argv) } -static struct swit mshcmds[] = { -#define ADVCMD 0 - { "advance", -7 }, -#define ALICMD 1 - { "ali", 0 }, -#define EXPLCMD 2 - { "burst", 0 }, -#define COMPCMD 3 - { "comp", 0 }, -#define DISTCMD 4 - { "dist", 0 }, -#define EXITCMD 5 - { "exit", 0 }, -#define FOLDCMD 6 - { "folder", 0 }, -#define FORWCMD 7 - { "forw", 0 }, -#define HELPCMD 8 - { "help", 0 }, -#define INCMD 9 - { "inc", 0 }, -#define MARKCMD 10 - { "mark", 0 }, -#define MAILCMD 11 - { "mhmail", 0 }, -#define MHNCMD 12 - { "mhn", 0 }, -#define MSGKCMD 13 - { "msgchk", 0 }, -#define NEXTCMD 14 - { "next", 0 }, -#define PACKCMD 15 - { "packf", 0 }, -#define PICKCMD 16 - { "pick", 0 }, -#define PREVCMD 17 - { "prev", 0 }, -#define QUITCMD 18 - { "quit", 0 }, -#define FILECMD 19 - { "refile", 0 }, -#define REPLCMD 20 - { "repl", 0 }, -#define RMMCMD 21 - { "rmm", 0 }, -#define SCANCMD 22 - { "scan", 0 }, -#define SENDCMD 23 - { "send", 0 }, -#define SHOWCMD 24 - { "show", 0 }, -#define SORTCMD 25 - { "sortm", 0 }, -#define WHATCMD 26 - { "whatnow", 0 }, -#define WHOMCMD 27 - { "whom", 0 }, - { NULL, 0 } -}; +#define MSHCMDS_SWITCHES \ + X("advance", -7, ADVCMD) \ + X("ali", 0, ALICMD) \ + X("burst", 0, EXPLCMD) \ + X("comp", 0, COMPCMD) \ + X("dist", 0, DISTCMD) \ + X("exit", 0, EXITCMD) \ + X("folder", 0, FOLDCMD) \ + X("forw", 0, FORWCMD) \ + X("help", 0, HELPCMD) \ + X("inc", 0, INCMD) \ + X("mark", 0, MARKCMD) \ + X("mhmail", 0, MAILCMD) \ + X("mhn", 0, MHNCMD) \ + X("msgchk", 0, MSGKCMD) \ + X("next", 0, NEXTCMD) \ + X("packf", 0, PACKCMD) \ + X("pick", 0, PICKCMD) \ + X("prev", 0, PREVCMD) \ + X("quit", 0, QUITCMD) \ + X("refile", 0, FILECMD) \ + X("repl", 0, REPLCMD) \ + X("rmm", 0, RMMCMD) \ + X("scan", 0, SCANCMD) \ + X("send", 0, SENDCMD) \ + X("show", 0, SHOWCMD) \ + X("sortm", 0, SORTCMD) \ + X("whatnow", 0, WHATCMD) \ + X("whom", 0, WHOMCMD) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(MSHCMDS); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(MSHCMDS, mshcmds); +#undef X static void @@ -635,7 +597,7 @@ fsetup (char *folder) padios (maildir, "unable to change directory to"); /* read folder and create message structure */ - if (!(mp = folder_read (folder))) + if (!(mp = folder_read (folder, 0))) padios (NULL, "unable to read folder %s", folder); /* check for empty folder */ @@ -713,8 +675,7 @@ setup (char *file) } m_init (); - mp->msgattrs[0] = getcpy ("unseen"); - mp->msgattrs[1] = NULL; + svector_push_back (mp->msgattrs, getcpy ("unseen")); scan_detect_mbox_style (fp); /* the MAGIC invocation */ if (fmsh) { @@ -839,6 +800,7 @@ msh_ready (int msgnum, int full) return yp; } + scan_reset_m_getfld_state (); scan_eom_action ((int (*)()) 0); /* XXX */ fseek (fp, Msgs[msgnum].m_start, SEEK_SET); return fp; @@ -861,7 +823,7 @@ check_folder (int scansw) low = mp->hghmsg + 1; folder_free (mp); /* free folder/message structure */ - if (!(mp = folder_read (fmsh))) + if (!(mp = folder_read (fmsh, 0))) padios (NULL, "unable to re-read folder %s", fmsh); hgh = mp->hghmsg; @@ -1013,7 +975,7 @@ readid (int msgnum) switch (state = m_getfld (&gstate, name, buf, &bufsz, zp)) { case FLD: case FLDPLUS: - if (!mh_strcasecmp (name, BBoard_ID)) { + if (!strcasecmp (name, BBoard_ID)) { bp = getcpy (buf); while (state == FLDPLUS) { bufsz = sizeof buf; @@ -1027,9 +989,10 @@ readid (int msgnum) else continue; } - while (state == FLDPLUS) + while (state == FLDPLUS) { bufsz = sizeof buf; state = m_getfld (&gstate, name, buf, &bufsz, zp); + } continue; default: @@ -1126,7 +1089,7 @@ quit (void) if (vmh) ttyNaux (NULLCMD, "FAST"); cp = NULL; - if ((dp = lkfopen (mp->foldpath, "r")) == NULL) { + if ((dp = lkfopendata (mp->foldpath, "r")) == NULL) { advise (mp->foldpath, "unable to lock"); if (vmh) { ttyR (NULLCMD); @@ -1151,7 +1114,7 @@ quit (void) close (i); else advise (mp->foldpath, "error zero'ing"); - unlink (map_name (mp->foldpath));/* XXX */ + (void) m_unlink (map_name (mp->foldpath));/* XXX */ } goto release; } @@ -1168,8 +1131,8 @@ quit (void) for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) if (does_exist(mp, msgnum) && pack (tmpfil, md, msgnum) == NOTOK) { mbx_close (tmpfil, md); - unlink (tmpfil); - unlink (map_name (tmpfil)); + (void) m_unlink (tmpfil); + (void) m_unlink (map_name (tmpfil)); goto release; } mbx_close (tmpfil, md); @@ -1182,15 +1145,15 @@ quit (void) if (rename (map1, map2) == NOTOK) { admonish (map2, "unable to rename %s to", map1); - unlink (map1); - unlink (map2); + (void) m_unlink (map1); + (void) m_unlink (map2); } } release: ; if (cp) free (cp); - lkfclose (dp, mp->foldpath); + lkfclosedata (dp, mp->foldpath); if (vmh) { ttyR (NULLCMD); pFIN (); @@ -1303,8 +1266,7 @@ static int parse (char *buffer, struct Cmd *cmdp) { int argp = 0; - unsigned char c, *cp; - char *pp; + char c, *cp, *pp; cmdp->line[0] = 0; pp = cmdp->args[argp++] = cmdp->line; @@ -1313,7 +1275,7 @@ parse (char *buffer, struct Cmd *cmdp) cmdp->stream = NULL; for (cp = buffer; (c = *cp); cp++) { - if (!isspace (c)) + if (!isspace ((unsigned char) c)) break; } if (c == '\0') { @@ -1323,8 +1285,8 @@ parse (char *buffer, struct Cmd *cmdp) } while ((c = *cp++)) { - if (isspace (c)) { - while (isspace (c)) + if (isspace ((unsigned char) c)) { + while (isspace ((unsigned char) c)) c = *cp++; if (c == 0) break; @@ -1379,7 +1341,7 @@ parse (char *buffer, struct Cmd *cmdp) } cmdp->redirect = pp + 1;/* sigh */ for (; (c = *cp); cp++) - if (!isspace (c)) + if (!isspace ((unsigned char) c)) break; if (c == 0) { padvise (NULL, cmdp->direction != PIPIO @@ -1390,7 +1352,7 @@ parse (char *buffer, struct Cmd *cmdp) strcpy (cmdp->redirect, cp); if (cmdp->direction != PIPIO) { for (; *cp; cp++) - if (isspace (*cp)) { + if (isspace ((unsigned char) *cp)) { padvise (NULL, "bad name for redirect"); return NOTOK; } @@ -1622,7 +1584,7 @@ static int pINI (void) { int i, vrsn; - unsigned char *bp; + char *bp; struct record rcs, *rc; rc = &rcs; @@ -1631,7 +1593,7 @@ pINI (void) switch (peer2rc (rc)) { case RC_INI: bp = rc->rc_data; - while (isspace (*bp)) + while (isspace ((unsigned char) *bp)) bp++; if (sscanf (bp, "%d", &vrsn) != 1) { bad_init: ; @@ -1643,9 +1605,9 @@ pINI (void) done (1); } - while (*bp && !isspace (*bp)) + while (*bp && !isspace ((unsigned char) *bp)) bp++; - while (isspace (*bp)) + while (isspace ((unsigned char) *bp)) bp++; if (sscanf (bp, "%d", &numwins) != 1 || numwins <= 0) goto bad_init; @@ -1653,9 +1615,9 @@ pINI (void) numwins = NWIN; for (i = 1; i <= numwins; i++) { - while (*bp && !isspace (*bp)) + while (*bp && !isspace ((unsigned char) *bp)) bp++; - while (isspace (*bp)) + while (isspace ((unsigned char) *bp)) bp++; if (sscanf (bp, "%d", &windows[i]) != 1 || windows[i] <= 0) goto bad_init;