/*
** static prototypes
*/
-static int editfile(char **, char **, char *, int, struct msgs *,
- char *, char *);
+static int editfile(char **, char **, char *, int);
static int sendfile(char **, char *);
static int refile(char **, char *);
static int removefile(char *);
static int system_in_dir(const char *dir, const char *cmd);
-#ifdef HAVE_LSTAT
-static int copyf(char *, char *);
-#endif
-
-
int
main(int argc, char **argv)
{
int use = 0;
char *cp;
- char *ed = NULL, *drft = NULL, *msgnam = NULL;
+ char *ed = NULL, *drft = NULL;
char buf[BUFSIZ], prompt[BUFSIZ];
char **argp, **arguments;
struct stat st;
if ((!drft && !(drft = getenv("mhdraft"))) || !*drft)
drft = getcpy(m_draft(seq_cur));
- msgnam = (cp = getenv("mhaltmsg")) && *cp ? getcpy(cp) : NULL;
-
if ((cp = getenv("mhuse")) && *cp)
use = atoi(cp);
/* start editing the draft, unless editor is the empty string */
if (*ed) {
- if (editfile(&ed, NULL, drft, use, NULL, msgnam, NULL) <0) {
+ if (editfile(&ed, NULL, drft, use) <0) {
if (!use) {
unlink(drft);
}
snprintf(prompt, sizeof(prompt), myprompt, invo_name);
for (;;) {
if (!(argp = getans(prompt, aleqs))) {
- unlink(altmsglink);
done(1);
}
switch (smatch(*argp, aleqs)) {
case DISPSW:
/* display the msg being replied to or distributed */
- if (msgnam) {
+ if ((cp = getenv("mhaltmsg")) && *cp) {
snprintf(buf, sizeof buf, "%s '%s'",
- listproc, msgnam);
+ listproc, cp);
system(buf);
} else {
advise(NULL, "no alternate message to display");
/* Call an editor on the draft file */
if (*++argp)
ed = *argp++;
- editfile(&ed, argp, drft, NOUSE, NULL, msgnam, NULL);
+ editfile(&ed, argp, drft, NOUSE);
break;
case LISTSW:
static int
-editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
- char *altmsg, char *cwd)
+editfile(char **ed, char **arg, char *file, int use)
{
int pid, status, vecp;
- char altpath[BUFSIZ], linkpath[BUFSIZ];
char *cp, *vec[MAXARGS];
- struct stat st;
-
-#ifdef HAVE_LSTAT
- int slinked = 0;
-#endif /* HAVE_LSTAT */
if (!*ed || !**ed) {
/* We have no explicit editor. */
}
}
- if (altmsg) {
- if (!mp || *altmsg == '/' || !cwd)
- strncpy(altpath, altmsg, sizeof(altpath));
- else
- snprintf(altpath, sizeof(altpath), "%s/%s",
- mp->foldpath, altmsg);
- if (!cwd)
- strncpy(linkpath, altmsglink, sizeof(linkpath));
- else
- snprintf(linkpath, sizeof(linkpath), "%s/%s",
- cwd, altmsglink);
- unlink(linkpath);
-#ifdef HAVE_LSTAT
- if (link(altpath, linkpath) == NOTOK) {
- symlink(altpath, linkpath);
- slinked = 1;
- } else {
- slinked = 0;
- }
-#else /* not HAVE_LSTAT */
- link(altpath, linkpath);
-#endif /* not HAVE_LSTAT */
- }
-
- context_save(); /* save the context file */
+ context_save();
fflush(stdout);
switch (pid = fork()) {
break;
case OK:
- if (cwd)
- chdir(cwd);
- if (altmsg) {
- if (mp)
- m_putenv("mhfolder", mp->foldpath);
- m_putenv("editalt", altpath);
- }
-
vecp = 0;
vec[vecp++] = mhbasename(*ed);
if (arg)
status = -1;
break;
}
-
-#ifdef HAVE_LSTAT
- if (altmsg && mp && !is_readonly(mp) && (slinked ?
- lstat (linkpath, &st) != NOTOK &&
- S_ISREG(st.st_mode) &&
- copyf(linkpath, altpath) == NOTOK :
- stat(linkpath, &st) != NOTOK &&
- st.st_nlink == 1 &&
- (unlink(altpath) == NOTOK ||
- link(linkpath, altpath) == NOTOK)))
- advise(linkpath, "unable to update %s from", altmsg);
-#else /* HAVE_LSTAT */
- if (altmsg && mp && !is_readonly(mp) &&
- stat(linkpath, &st) != NOTOK &&
- st.st_nlink == 1 &&
- (unlink(altpath) == NOTOK ||
- link(linkpath, altpath) == NOTOK))
- advise(linkpath, "unable to update %s from", altmsg);
-#endif /* HAVE_LSTAT */
}
/* remember which editor we used */
edsave = getcpy(*ed);
*ed = NULL;
- if (altmsg) {
- unlink(linkpath);
- }
return status;
}
-#ifdef HAVE_LSTAT
-static int
-copyf(char *ifile, char *ofile)
-{
- int i, in, out;
- char buffer[BUFSIZ];
-
- if ((in = open(ifile, O_RDONLY)) == NOTOK)
- return NOTOK;
- if ((out = open(ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
- admonish(ofile, "unable to open and truncate");
- close(in);
- return NOTOK;
- }
-
- while ((i = read(in, buffer, sizeof(buffer))) > OK)
- if (write(out, buffer, i) != i) {
- advise(ofile, "may have damaged");
- i = NOTOK;
- break;
- }
-
- close(in);
- close(out);
- return i;
-}
-#endif /* HAVE_LSTAT */
-
-
/*
** SEND
*/