collect.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) | collect.c (6d8484b0d0191b66f9bfd0dfa89c06a29647f02a) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 56 unchanged lines hidden (view full) --- 65static FILE *collf; /* File for saving away */ 66static int hadintr; /* Have seen one SIGINT so far */ 67 68static jmp_buf colljmp; /* To get back to work */ 69static int colljmp_p; /* whether to long jump */ 70static jmp_buf collabort; /* To end collection with error */ 71 72FILE * | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 56 unchanged lines hidden (view full) --- 65static FILE *collf; /* File for saving away */ 66static int hadintr; /* Have seen one SIGINT so far */ 67 68static jmp_buf colljmp; /* To get back to work */ 69static int colljmp_p; /* whether to long jump */ 70static jmp_buf collabort; /* To end collection with error */ 71 72FILE * |
73collect(hp, printheaders) 74 struct header *hp; 75 int printheaders; | 73collect(struct header *hp, int printheaders) |
76{ 77 FILE *fbuf; 78 int lc, cc, escape, eofcount, fd, c, t; 79 char linebuf[LINESIZE], tempname[PATHSIZE], *cp, getsub; 80 sigset_t nset; 81 int longline, lastlong, rc; /* So we don't make 2 or more lines 82 out of a long input line. */ 83 --- 406 unchanged lines hidden (view full) --- 490 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL); 491 return (collf); 492} 493 494/* 495 * Write a file, ex-like if f set. 496 */ 497int | 74{ 75 FILE *fbuf; 76 int lc, cc, escape, eofcount, fd, c, t; 77 char linebuf[LINESIZE], tempname[PATHSIZE], *cp, getsub; 78 sigset_t nset; 79 int longline, lastlong, rc; /* So we don't make 2 or more lines 80 out of a long input line. */ 81 --- 406 unchanged lines hidden (view full) --- 488 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL); 489 return (collf); 490} 491 492/* 493 * Write a file, ex-like if f set. 494 */ 495int |
498exwrite(name, fp, f) 499 char name[]; 500 FILE *fp; 501 int f; | 496exwrite(char name[], FILE *fp, int f) |
502{ 503 FILE *of; 504 int c, lc; 505 long cc; 506 struct stat junk; 507 508 if (f) { 509 printf("\"%s\" ", name); --- 28 unchanged lines hidden (view full) --- 538 return (0); 539} 540 541/* 542 * Edit the message being collected on fp. 543 * On return, make the edit file the new temp file. 544 */ 545void | 497{ 498 FILE *of; 499 int c, lc; 500 long cc; 501 struct stat junk; 502 503 if (f) { 504 printf("\"%s\" ", name); --- 28 unchanged lines hidden (view full) --- 533 return (0); 534} 535 536/* 537 * Edit the message being collected on fp. 538 * On return, make the edit file the new temp file. 539 */ 540void |
546mesedit(fp, c) 547 FILE *fp; 548 int c; | 541mesedit(FILE *fp, int c) |
549{ 550 sig_t sigint = signal(SIGINT, SIG_IGN); 551 FILE *nf = run_editor(fp, (off_t)-1, c, 0); 552 553 if (nf != NULL) { 554 (void)fseeko(nf, (off_t)0, SEEK_END); 555 collf = nf; 556 (void)Fclose(fp); 557 } 558 (void)signal(SIGINT, sigint); 559} 560 561/* 562 * Pipe the message through the command. 563 * Old message is on stdin of command; 564 * New message collected from stdout. 565 * Sh -c must return 0 to accept the new message. 566 */ 567void | 542{ 543 sig_t sigint = signal(SIGINT, SIG_IGN); 544 FILE *nf = run_editor(fp, (off_t)-1, c, 0); 545 546 if (nf != NULL) { 547 (void)fseeko(nf, (off_t)0, SEEK_END); 548 collf = nf; 549 (void)Fclose(fp); 550 } 551 (void)signal(SIGINT, sigint); 552} 553 554/* 555 * Pipe the message through the command. 556 * Old message is on stdin of command; 557 * New message collected from stdout. 558 * Sh -c must return 0 to accept the new message. 559 */ 560void |
568mespipe(fp, cmd) 569 FILE *fp; 570 char cmd[]; | 561mespipe(FILE *fp, char cmd[]) |
571{ 572 FILE *nf; 573 int fd; 574 sig_t sigint = signal(SIGINT, SIG_IGN); 575 char *sh, tempname[PATHSIZE]; 576 577 (void)snprintf(tempname, sizeof(tempname), 578 "%s/mail.ReXXXXXXXXXX", tmpdir); --- 33 unchanged lines hidden (view full) --- 612 * Interpolate the named messages into the current 613 * message, preceding each line with a tab. 614 * Return a count of the number of characters now in 615 * the message, or -1 if an error is encountered writing 616 * the message temporary. The flag argument is 'm' if we 617 * should shift over and 'f' if not. 618 */ 619int | 562{ 563 FILE *nf; 564 int fd; 565 sig_t sigint = signal(SIGINT, SIG_IGN); 566 char *sh, tempname[PATHSIZE]; 567 568 (void)snprintf(tempname, sizeof(tempname), 569 "%s/mail.ReXXXXXXXXXX", tmpdir); --- 33 unchanged lines hidden (view full) --- 603 * Interpolate the named messages into the current 604 * message, preceding each line with a tab. 605 * Return a count of the number of characters now in 606 * the message, or -1 if an error is encountered writing 607 * the message temporary. The flag argument is 'm' if we 608 * should shift over and 'f' if not. 609 */ 610int |
620forward(ms, fp, fn, f) 621 char ms[]; 622 FILE *fp; 623 char *fn; 624 int f; | 611forward(char ms[], FILE *fp, char *fn, int f) |
625{ 626 int *msgvec; 627 struct ignoretab *ig; 628 char *tabst; 629 630 msgvec = (int *)salloc((msgCount+1) * sizeof(*msgvec)); 631 if (msgvec == NULL) 632 return (0); --- 27 unchanged lines hidden (view full) --- 660 return (0); 661} 662 663/* 664 * Print (continue) when continued after ^Z. 665 */ 666/*ARGSUSED*/ 667void | 612{ 613 int *msgvec; 614 struct ignoretab *ig; 615 char *tabst; 616 617 msgvec = (int *)salloc((msgCount+1) * sizeof(*msgvec)); 618 if (msgvec == NULL) 619 return (0); --- 27 unchanged lines hidden (view full) --- 647 return (0); 648} 649 650/* 651 * Print (continue) when continued after ^Z. 652 */ 653/*ARGSUSED*/ 654void |
668collstop(s) 669 int s; | 655collstop(int s) |
670{ 671 sig_t old_action = signal(s, SIG_DFL); 672 sigset_t nset; 673 674 (void)sigemptyset(&nset); 675 (void)sigaddset(&nset, s); 676 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL); 677 (void)kill(0, s); --- 7 unchanged lines hidden (view full) --- 685} 686 687/* 688 * On interrupt, come here to save the partial message in ~/dead.letter. 689 * Then jump out of the collection loop. 690 */ 691/*ARGSUSED*/ 692void | 656{ 657 sig_t old_action = signal(s, SIG_DFL); 658 sigset_t nset; 659 660 (void)sigemptyset(&nset); 661 (void)sigaddset(&nset, s); 662 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL); 663 (void)kill(0, s); --- 7 unchanged lines hidden (view full) --- 671} 672 673/* 674 * On interrupt, come here to save the partial message in ~/dead.letter. 675 * Then jump out of the collection loop. 676 */ 677/*ARGSUSED*/ 678void |
693collint(s) 694 int s; | 679collint(int s __unused) |
695{ 696 /* 697 * the control flow is subtle, because we can be called from ~q. 698 */ 699 if (!hadintr) { 700 if (value("ignore") != NULL) { 701 printf("@"); 702 (void)fflush(stdout); --- 6 unchanged lines hidden (view full) --- 709 rewind(collf); 710 if (value("nosave") == NULL) 711 savedeadletter(collf); 712 longjmp(collabort, 1); 713} 714 715/*ARGSUSED*/ 716void | 680{ 681 /* 682 * the control flow is subtle, because we can be called from ~q. 683 */ 684 if (!hadintr) { 685 if (value("ignore") != NULL) { 686 printf("@"); 687 (void)fflush(stdout); --- 6 unchanged lines hidden (view full) --- 694 rewind(collf); 695 if (value("nosave") == NULL) 696 savedeadletter(collf); 697 longjmp(collabort, 1); 698} 699 700/*ARGSUSED*/ 701void |
717collhup(s) 718 int s; | 702collhup(int s __unused) |
719{ 720 rewind(collf); 721 savedeadletter(collf); 722 /* 723 * Let's pretend nobody else wants to clean up, 724 * a true statement at this time. 725 */ 726 exit(1); 727} 728 729void | 703{ 704 rewind(collf); 705 savedeadletter(collf); 706 /* 707 * Let's pretend nobody else wants to clean up, 708 * a true statement at this time. 709 */ 710 exit(1); 711} 712 713void |
730savedeadletter(fp) 731 FILE *fp; | 714savedeadletter(FILE *fp) |
732{ 733 FILE *dbuf; 734 int c; 735 char *cp; 736 737 if (fsize(fp) == 0) 738 return; 739 cp = getdeadletter(); 740 c = umask(077); 741 dbuf = Fopen(cp, "a"); 742 (void)umask(c); 743 if (dbuf == NULL) 744 return; 745 while ((c = getc(fp)) != EOF) 746 (void)putc(c, dbuf); 747 (void)Fclose(dbuf); 748 rewind(fp); 749} | 715{ 716 FILE *dbuf; 717 int c; 718 char *cp; 719 720 if (fsize(fp) == 0) 721 return; 722 cp = getdeadletter(); 723 c = umask(077); 724 dbuf = Fopen(cp, "a"); 725 (void)umask(c); 726 if (dbuf == NULL) 727 return; 728 while ((c = getc(fp)) != EOF) 729 (void)putc(c, dbuf); 730 (void)Fclose(dbuf); 731 rewind(fp); 732} |