=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/collect.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/mail/collect.c 1997/04/13 20:32:06 1.5 --- src/usr.bin/mail/collect.c 1997/07/13 21:21:10 1.6 *************** *** 1,5 **** ! /* $OpenBSD: collect.c,v 1.5 1997/04/13 20:32:06 deraadt Exp $ */ ! /* $NetBSD: collect.c,v 1.6 1996/06/08 19:48:16 christos Exp $ */ /* * Copyright (c) 1980, 1993 --- 1,5 ---- ! /* $OpenBSD: collect.c,v 1.6 1997/07/13 21:21:10 millert Exp $ */ ! /* $NetBSD: collect.c,v 1.9 1997/07/09 05:25:45 mikel Exp $ */ /* * Copyright (c) 1980, 1993 *************** *** 38,44 **** #if 0 static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; #else ! static char rcsid[] = "$OpenBSD: collect.c,v 1.5 1997/04/13 20:32:06 deraadt Exp $"; #endif #endif /* not lint */ --- 38,44 ---- #if 0 static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; #else ! static char rcsid[] = "$OpenBSD: collect.c,v 1.6 1997/07/13 21:21:10 millert Exp $"; #endif #endif /* not lint */ *************** *** 87,97 **** --- 87,100 ---- extern char *tempMail; char getsub; int omask; + int longline, lastlong, rc; /* Can deal with lines > LINESIZE */ + #if __GNUC__ /* Avoid longjmp clobbering */ (void) &escape; (void) &eofcount; (void) &getsub; + (void) &longline; #endif collf = NULL; *************** *** 115,121 **** noreset++; if ((collf = Fopen(tempMail, "w+")) == NULL) { ! perror(tempMail); goto err; } unlink(tempMail); --- 118,124 ---- noreset++; if ((collf = Fopen(tempMail, "w+")) == NULL) { ! warn(tempMail); goto err; } unlink(tempMail); *************** *** 140,145 **** --- 143,150 ---- escape = ESCAPE; eofcount = 0; hadintr = 0; + lastlong = 0; + longline = 0; if (!setjmp(colljmp)) { if (getsub) *************** *** 153,163 **** cont: if (hadintr) { fflush(stdout); ! fprintf(stderr, ! "\n(Interrupt -- one more to kill letter)\n"); } else { if (isatty(0)) { ! printf("(continue)\n"); fflush(stdout); } } --- 158,168 ---- cont: if (hadintr) { fflush(stdout); ! fputs("\n(Interrupt -- one more to kill letter)\n", ! stderr); } else { if (isatty(0)) { ! puts("(continue)"); fflush(stdout); } } *************** *** 169,187 **** if (c < 0) { if (value("interactive") != NOSTR && value("ignoreeof") != NOSTR && ++eofcount < 25) { ! printf("Use \".\" to terminate letter\n"); continue; } break; } eofcount = 0; hadintr = 0; if (linebuf[0] == '.' && linebuf[1] == '\0' && ! value("interactive") != NOSTR && (value("dot") != NOSTR || value("ignoreeof") != NOSTR)) break; ! if (linebuf[0] != escape || value("interactive") == NOSTR) { ! if (putline(collf, linebuf) < 0) goto err; continue; } --- 174,195 ---- if (c < 0) { if (value("interactive") != NOSTR && value("ignoreeof") != NOSTR && ++eofcount < 25) { ! puts("Use \".\" to terminate letter"); continue; } break; } + lastlong = longline; + longline = (c == LINESIZE - 1); eofcount = 0; hadintr = 0; if (linebuf[0] == '.' && linebuf[1] == '\0' && ! value("interactive") != NOSTR && !lastlong && (value("dot") != NOSTR || value("ignoreeof") != NOSTR)) break; ! if (linebuf[0] != escape || value("interactive") == NOSTR || ! lastlong) { ! if (putline(collf, linebuf, !longline) < 0) goto err; continue; } *************** *** 193,204 **** * Otherwise, it's an error. */ if (c == escape) { ! if (putline(collf, &linebuf[1]) < 0) goto err; else break; } ! printf("Unknown tilde escape.\n"); break; case 'C': /* --- 201,212 ---- * Otherwise, it's an error. */ if (c == escape) { ! if (putline(collf, &linebuf[1], !longline) < 0) goto err; else break; } ! puts("Unknown tilde escape."); break; case 'C': /* *************** *** 280,286 **** while (isspace(*cp)) cp++; if (*cp == '\0') { ! printf("Interpolate what file?\n"); break; } cp = expand(cp); --- 288,294 ---- while (isspace(*cp)) cp++; if (*cp == '\0') { ! puts("Interpolate what file?"); break; } cp = expand(cp); *************** *** 291,312 **** break; } if ((fbuf = Fopen(cp, "r")) == NULL) { ! perror(cp); break; } printf("\"%s\" ", cp); fflush(stdout); lc = 0; cc = 0; ! while (readline(fbuf, linebuf, LINESIZE) >= 0) { ! lc++; ! if ((t = putline(collf, linebuf)) < 0) { ! Fclose(fbuf); goto err; } cc += t; } ! Fclose(fbuf); printf("%d/%d\n", lc, cc); break; case 'w': --- 299,322 ---- break; } if ((fbuf = Fopen(cp, "r")) == NULL) { ! warn(cp); break; } printf("\"%s\" ", cp); fflush(stdout); lc = 0; cc = 0; ! while ((rc = readline(fbuf, linebuf, LINESIZE)) >= 0) { ! if (rc != LINESIZE - 1) ! lc++; ! if ((t = putline(collf, linebuf, ! rc != LINESIZE-1)) < 0) { ! (void)Fclose(fbuf); goto err; } cc += t; } ! (void)Fclose(fbuf); printf("%d/%d\n", lc, cc); break; case 'w': *************** *** 317,323 **** while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '\0') { ! fprintf(stderr, "Write what file!?\n"); break; } if ((cp = expand(cp)) == NOSTR) --- 327,333 ---- while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '\0') { ! fputs("Write what file!?\n", stderr); break; } if ((cp = expand(cp)) == NOSTR) *************** *** 340,351 **** goto cont; case '?': if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) { ! perror(_PATH_TILDE); break; } while ((t = getc(fbuf)) != EOF) (void) putchar(t); ! Fclose(fbuf); break; case 'p': /* --- 350,361 ---- goto cont; case '?': if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) { ! warn(_PATH_TILDE); break; } while ((t = getc(fbuf)) != EOF) (void) putchar(t); ! (void)Fclose(fbuf); break; case 'p': /* *************** *** 353,359 **** * message without altering anything. */ rewind(collf); ! printf("-------\nMessage contains:\n"); puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL); while ((t = getc(collf)) != EOF) (void) putchar(t); --- 363,369 ---- * message without altering anything. */ rewind(collf); ! puts("-------\nMessage contains:"); puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL); while ((t = getc(collf)) != EOF) (void) putchar(t); *************** *** 381,387 **** goto out; err: if (collf != NULL) { ! Fclose(collf); collf = NULL; } out: --- 391,397 ---- goto out; err: if (collf != NULL) { ! (void)Fclose(collf); collf = NULL; } out: *************** *** 395,401 **** signal(SIGTTOU, savettou); signal(SIGTTIN, savettin); sigsetmask(omask); ! return collf; } /* --- 405,411 ---- signal(SIGTTOU, savettou); signal(SIGTTIN, savettin); sigsetmask(omask); ! return(collf); } /* *************** *** 420,430 **** if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) { if (!f) fprintf(stderr, "%s: ", name); ! fprintf(stderr, "File exists\n"); return(-1); } if ((of = Fopen(name, "w")) == NULL) { ! perror(NOSTR); return(-1); } lc = 0; --- 430,440 ---- if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) { if (!f) fprintf(stderr, "%s: ", name); ! fputs("File exists\n", stderr); return(-1); } if ((of = Fopen(name, "w")) == NULL) { ! warn(NOSTR); return(-1); } lc = 0; *************** *** 435,446 **** lc++; (void) putc(c, of); if (ferror(of)) { ! perror(name); ! Fclose(of); return(-1); } } ! Fclose(of); printf("%d/%ld\n", lc, cc); fflush(stdout); return(0); --- 445,456 ---- lc++; (void) putc(c, of); if (ferror(of)) { ! warn(name); ! (void)Fclose(of); return(-1); } } ! (void)Fclose(of); printf("%d/%ld\n", lc, cc); fflush(stdout); return(0); *************** *** 461,467 **** if (nf != NULL) { fseek(nf, 0L, 2); collf = nf; ! Fclose(fp); } (void) signal(SIGINT, sigint); } --- 471,477 ---- if (nf != NULL) { fseek(nf, 0L, 2); collf = nf; ! (void)Fclose(fp); } (void) signal(SIGINT, sigint); } *************** *** 483,489 **** char *shell; if ((nf = Fopen(tempEdit, "w+")) == NULL) { ! perror(tempEdit); goto out; } (void) unlink(tempEdit); --- 493,499 ---- char *shell; if ((nf = Fopen(tempEdit, "w+")) == NULL) { ! warn(tempEdit); goto out; } (void) unlink(tempEdit); *************** *** 495,506 **** shell = _PATH_CSHELL; if (run_command(shell, 0, fileno(fp), fileno(nf), "-c", cmd, NOSTR) < 0) { ! (void) Fclose(nf); goto out; } if (fsize(nf) == 0) { fprintf(stderr, "No bytes from \"%s\" !?\n", cmd); ! (void) Fclose(nf); goto out; } /* --- 505,516 ---- shell = _PATH_CSHELL; if (run_command(shell, 0, fileno(fp), fileno(nf), "-c", cmd, NOSTR) < 0) { ! (void)Fclose(nf); goto out; } if (fsize(nf) == 0) { fprintf(stderr, "No bytes from \"%s\" !?\n", cmd); ! (void)Fclose(nf); goto out; } /* *************** *** 508,514 **** */ (void) fseek(nf, 0L, 2); collf = nf; ! (void) Fclose(fp); out: (void) signal(SIGINT, sigint); } --- 518,524 ---- */ (void) fseek(nf, 0L, 2); collf = nf; ! (void)Fclose(fp); out: (void) signal(SIGINT, sigint); } *************** *** 532,538 **** struct ignoretab *ig; char *tabst; ! msgvec = (int *) salloc((msgCount+1) * sizeof *msgvec); if (msgvec == (int *) NOSTR) return(0); if (getmsglist(ms, msgvec, 0) < 0) --- 542,548 ---- struct ignoretab *ig; char *tabst; ! msgvec = (int *) salloc((msgCount+1) * sizeof(*msgvec)); if (msgvec == (int *) NOSTR) return(0); if (getmsglist(ms, msgvec, 0) < 0) *************** *** 540,546 **** if (*msgvec == 0) { *msgvec = first(0, MMNORM); if (*msgvec == NULL) { ! printf("No appropriate messages\n"); return(0); } msgvec[1] = NULL; --- 550,556 ---- if (*msgvec == 0) { *msgvec = first(0, MMNORM); if (*msgvec == NULL) { ! puts("No appropriate messages"); return(0); } msgvec[1] = NULL; *************** *** 550,567 **** else if ((tabst = value("indentprefix")) == NOSTR) tabst = "\t"; ig = isupper(f) ? NULL : ignore; ! printf("Interpolating:"); for (; *msgvec != 0; msgvec++) { struct message *mp = message + *msgvec - 1; touch(mp); printf(" %d", *msgvec); if (send(mp, fp, ig, tabst) < 0) { ! perror(tempMail); return(-1); } } ! printf("\n"); return(0); } --- 560,577 ---- else if ((tabst = value("indentprefix")) == NOSTR) tabst = "\t"; ig = isupper(f) ? NULL : ignore; ! fputs("Interpolating:", stdout); for (; *msgvec != 0; msgvec++) { struct message *mp = message + *msgvec - 1; touch(mp); printf(" %d", *msgvec); if (send(mp, fp, ig, tabst) < 0) { ! warn(tempMail); return(-1); } } ! putchar('\n'); return(0); } *************** *** 649,654 **** return; while ((c = getc(fp)) != EOF) (void) putc(c, dbuf); ! Fclose(dbuf); rewind(fp); } --- 659,664 ---- return; while ((c = getc(fp)) != EOF) (void) putc(c, dbuf); ! (void)Fclose(dbuf); rewind(fp); }