* msh.c -- The nmh shell
*
* $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
/*
#include <h/dropsbr.h>
#include <h/fmt_scan.h>
#include <h/scansbr.h>
-#include <zotnet/tws/tws.h>
-#include <zotnet/mts/mts.h>
+#include <h/tws.h>
+#include <h/mts.h>
+#include <h/utils.h>
#ifdef HAVE_TERMIOS_H
# include <termios.h>
#define VERSIONSW 13
{ "version", 0 },
#define HELPSW 14
- { "help", 4 },
+ { "help", 0 },
{ NULL, 0 }
};
if (folder)
adios (NULL, "only one folder at a time!");
else
- folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
+ folder = pluspath (cp);
}
else
if (file)
m_reset ();
- return done (0);
+ done (0);
+ return 1;
}
#ifdef BPOP
if (pmsh) {
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- padios (tmpfil, "unable to create");
- unlink (tmpfil);
+ char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) padios("msh", "unable to create temporary file");
+ unlink(tfile);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
}
else
#endif /* BPOP */
if (!(mp = (struct msgs *) calloc ((size_t) 1, sizeof(*mp))))
padios (NULL, "unable to allocate folder storage");
- if (!(mp->msgstats = calloc ((size_t) 1, msgp + 3)))
+ if (!(mp->msgstats = calloc ((size_t) msgp + 3, sizeof(*(mp->msgstats)))))
padios (NULL, "unable to allocate message status storage");
mp->hghmsg = msgp;
return;
nmsgs = nMsgs + n + MAXFOLDER / 2;
- Msgs = (struct Msg *) realloc ((char *) Msgs, (size_t) (nmsgs + 2) * sizeof *Msgs);
- if (Msgs == NULL)
- padios (NULL, "unable to reallocate Msgs structure");
+ Msgs = (struct Msg *) mh_xrealloc ((char *) Msgs, (size_t) (nmsgs + 2) * sizeof *Msgs);
memset((char *) (Msgs + nMsgs + 2), 0, (size_t) ((nmsgs - nMsgs) * sizeof *Msgs));
nMsgs = nmsgs;
if (Msgs[msgnum].m_top == 0)
padios (NULL, "msh_ready (%d, %d) botch", msgnum, full);
if (!full) {
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((yp = fopen (tmpfil, "w+")) == NULL)
- padios (tmpfil, "unable to create");
- unlink (tmpfil);
+ char *tfile = m_mktemp2(NULL, invo_name, NULL, &yp);
+ if (tfile == NULL) padios("msh", "unable to create temporary file");
+ unlink(tfile);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
if (pop_top (Msgs[msgnum].m_top, 4, pop_action) == NOTOK)
padios (NULL, "%s", response);
void
readids (int id)
{
- register int cur, seqnum, i, msgnum;
+ register int cur, seqnum, i=0, msgnum;
if (mp->curmsg == 0)
seq_setcur (mp, mp->lowmsg);
case FLD:
case FLDEOF:
case FLDPLUS:
- if (!strcasecmp (name, BBoard_ID)) {
+ if (!mh_strcasecmp (name, BBoard_ID)) {
bp = getcpy (buf);
while (state == FLDPLUS) {
state = m_getfld (state, name, buf, sizeof(buf), zp);
continue;
if (buffer[0] == '?') {
printf ("commands:\n");
- print_sw (ALL, sw, "");
+ print_sw (ALL, sw, "", stdout);
printf ("type CTRL-D or use ``quit'' to leave %s\n",
invo_name);
continue;
parse (char *buffer, struct Cmd *cmdp)
{
int argp = 0;
- char c, *cp, *pp;
+ unsigned char c, *cp;
+ char *pp;
cmdp->line[0] = 0;
pp = cmdp->args[argp++] = cmdp->line;
pINI (void)
{
int i, vrsn;
- char *bp;
+ unsigned char *bp;
struct record rcs, *rc;
rc = &rcs;
case OK:
printf ("commands:\n");
- print_sw (ALL, sw, "");
+ print_sw (ALL, sw, "", stdout);
printf ("type ``quit'' to leave %s\n", invo_name);
fflush (stdout);
fflush (stderr);