X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fwhatnow.c;h=bbb468dafb768bc16a206519265174e23da3b6fb;hb=ccf4f175ef4c4e7522f9510a4a1149c15d810dd9;hp=f26dcb7c00e48e4e604a3fa8d290870de8ce3c70;hpb=8bdc45422ae3279fde81b1d1e7eb9dcf881f961f;p=mmh diff --git a/uip/whatnow.c b/uip/whatnow.c index f26dcb7..bbb468d 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -46,9 +46,9 @@ static struct swit whatnowswitches[] = { #define EDITRSW 0 { "editor editor", 0 }, #define PRMPTSW 1 - { "prompt string", 4 }, + { "prompt string", 0 }, #define VERSIONSW 2 - { "version", 0 }, + { "Version", 0 }, #define HELPSW 3 { "help", 0 }, { NULL, 0 } @@ -92,8 +92,7 @@ static char *myprompt = "\nWhat now? "; /* ** 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 *); @@ -103,17 +102,12 @@ static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type); 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; @@ -123,10 +117,7 @@ main(int argc, char **argv) FILE *f; /* read pointer for bgnd proc */ int n; /* set on -n to detach command */ -#ifdef LOCALE setlocale(LC_ALL, ""); -#endif - invo_name = mhbasename(argv[0]); /* read user profile/context */ @@ -185,8 +176,6 @@ main(int argc, char **argv) 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); @@ -196,7 +185,7 @@ main(int argc, char **argv) /* 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); } @@ -208,15 +197,14 @@ main(int argc, char **argv) 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"); @@ -227,7 +215,7 @@ main(int argc, char **argv) /* 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: @@ -575,17 +563,10 @@ static char *edsave = NULL; /* the editor we used previously */ 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. */ @@ -605,31 +586,7 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, } } - 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()) { @@ -639,14 +596,6 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, 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) @@ -679,68 +628,17 @@ editfile(char **ed, char **arg, char *file, int use, struct msgs *mp, 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 */