* File I/O.
*/
-static char *SccsId = "@(#)fio.c 1.8 %G%";
+static char *SccsId = "@(#)fio.c 2.10 %G%";
/*
* Set up the input pointers while copying the mail file into
cp = linebuf;
c = getc(ibuf);
while (c != EOF && c != '\n') {
- if (cp - linebuf >= BUFSIZ - 1) {
+ if (cp - linebuf >= LINESIZE - 1) {
ungetc(c, ibuf);
*cp = 0;
break;
/*
* Terminate an editing session by attempting to write out the user's
- * file from the temporary.
+ * file from the temporary. Save any new stuff appended to the file.
*/
-
edstop()
{
register int gotcha, c;
register struct message *mp;
- FILE *obuf;
+ FILE *obuf, *ibuf, *readstat;
+ struct stat statb;
+ char tempname[30], *id;
+ int (*sigs[3])();
if (readonly)
return;
+ holdsigs();
+ if (Tflag != NOSTR) {
+ if ((readstat = fopen(Tflag, "w")) == NULL)
+ Tflag = NOSTR;
+ }
for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
if (mp->m_flag & MNEW) {
mp->m_flag &= ~MNEW;
mp->m_flag |= MSTATUS;
}
- if (mp->m_flag & (MODIFY|MDELETED|MSTATUS)) {
+ if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
gotcha++;
- break;
+ if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
+ if ((id = hfield("article-id", mp)) != NOSTR)
+ fprintf(readstat, "%s\n", id);
}
}
- if (!gotcha)
- return;
+ if (Tflag != NOSTR)
+ fclose(readstat);
+ if (!gotcha || Tflag != NOSTR)
+ goto done;
+ ibuf = NULL;
+ if (stat(editfile, &statb) >= 0 && statb.st_size > mailsize) {
+ strcpy(tempname, "/tmp/mboxXXXXXX");
+ mktemp(tempname);
+ if ((obuf = fopen(tempname, "w")) == NULL) {
+ perror(tempname);
+ relsesigs();
+ reset(0);
+ }
+ if ((ibuf = fopen(editfile, "r")) == NULL) {
+ perror(editfile);
+ fclose(obuf);
+ remove(tempname);
+ relsesigs();
+ reset(0);
+ }
+ fseek(ibuf, mailsize, 0);
+ while ((c = getc(ibuf)) != EOF)
+ putc(c, obuf);
+ fclose(ibuf);
+ fclose(obuf);
+ if ((ibuf = fopen(tempname, "r")) == NULL) {
+ perror(tempname);
+ remove(tempname);
+ relsesigs();
+ reset(0);
+ }
+ remove(tempname);
+ }
printf("\"%s\" ", editfile);
flush();
if ((obuf = fopen(editfile, "w")) == NULL) {
perror(editfile);
+ relsesigs();
reset(0);
}
c = 0;
if ((mp->m_flag & MDELETED) != 0)
continue;
c++;
- if (send(mp, obuf) < 0) {
+ if (send(mp, obuf, 0) < 0) {
perror(editfile);
+ relsesigs();
reset(0);
}
}
+ gotcha = (c == 0 && ibuf == NULL);
+ if (ibuf != NULL) {
+ while ((c = getc(ibuf)) != EOF)
+ putc(c, obuf);
+ fclose(ibuf);
+ }
fflush(obuf);
if (ferror(obuf)) {
perror(editfile);
+ relsesigs();
reset(0);
}
- if (c == 0) {
+ fclose(obuf);
+ if (gotcha) {
remove(editfile);
printf("removed\n");
}
else
printf("complete\n");
flush();
+
+done:
+ relsesigs();
+}
+
+/*
+ * Hold signals SIGHUP - SIGQUIT.
+ */
+holdsigs()
+{
+ register int i;
+
+ for (i = SIGHUP; i <= SIGQUIT; i++)
+ sighold(i);
+}
+
+/*
+ * Release signals SIGHUP - SIGQUIT
+ */
+relsesigs()
+{
+ register int i;
+
+ for (i = SIGHUP; i <= SIGQUIT; i++)
+ sigrelse(i);
}
/*
int s, pivec[2], (*sigint)();
struct stat sbuf;
+ if (name[0] == '+' && getfold(cmdbuf) >= 0) {
+ sprintf(xname, "%s/%s", cmdbuf, name + 1);
+ return(expand(savestr(xname)));
+ }
if (!anyof(name, "~{[*?$`'\"\\"))
return(name);
- /* sigint = signal(SIGINT, SIG_IGN); */
if (pipe(pivec) < 0) {
perror("pipe");
- /* signal(SIGINT, sigint) */
return(name);
}
sprintf(cmdbuf, "echo %s", name);
if ((pid = vfork()) == 0) {
+ sigchild();
Shell = value("SHELL");
if (Shell == NOSTR)
Shell = SHELL;
fprintf(stderr, "\"%s\": Ambiguous\n", name);
goto err;
}
- /* signal(SIGINT, sigint) */
return(savestr(xname));
err:
- /* signal(SIGINT, sigint); */
return(NOSTR);
}
+/*
+ * Determine the current folder directory name.
+ */
+getfold(name)
+ char *name;
+{
+ char *folder;
+
+ if ((folder = value("folder")) == NOSTR)
+ return(-1);
+ if (*folder == '/')
+ strcpy(name, folder);
+ else
+ sprintf(name, "%s/%s", homedir, folder);
+ return(0);
+}
+
/*
* A nicer version of Fdopen, which allows us to fclose
* without losing the open file.