home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / uip / send / s_input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-11  |  10.8 KB  |  484 lines

  1. /* name:
  2.     input
  3.  
  4. function:
  5.     To accept the text of the message and allow ed, msg
  6.     to be called.
  7.  
  8. algorithm:
  9.     Read until end-of-file, then ask for a valid command
  10.  
  11. parameters:
  12.     none
  13.  
  14. returns:
  15.     With a null terminated letter in the string pointed to by
  16.     the global variable letter.
  17.  
  18. globals:
  19.     letter    address of the buffer.
  20.  
  21. calls:
  22.     write    system
  23.     printf
  24.     getchar
  25.     system  system
  26.  
  27. called by:
  28.     main
  29.  
  30.  
  31.  */
  32. /*
  33. **    R E V I S I O N  H I S T O R Y
  34. **
  35. **    03/31/83  GWH    Split the SEND program into component parts
  36. **
  37. **    04/05/83  GWH    Changed execl calls to execlp's.
  38. **
  39. **    11/21/83  GWH    Added directedit option.
  40. **
  41. **    05/29/84  GWH    Fixed a but that allowed drafts created in an edit
  42. **            mode to be deleted if an interrupt was made by
  43. **            mistake. Also fixed a bug which resulted in the
  44. **            copy flag (cflag) being erroneously set.
  45. **
  46. **    04/02/85 M. Vasoll  Added the spelling checker command.
  47. */
  48.  
  49. #include "./s.h"
  50. #include "./s_externs.h"
  51.  
  52. extern  char *verdate;
  53. extern  int errno;
  54. extern    sigtype onint (), onint2(), onint3 ();
  55.  
  56. input ()
  57. {
  58.     int     infile;
  59.     int     stat;
  60.     char    tempbuf[80];
  61.     sigtype (*old1) (),
  62.         (*old2) (),
  63.         (*old3) ();
  64.     register int    i;
  65.  
  66.     printf ("SEND  (%s)\n", verdate);
  67.  
  68.     if (to[0] != '\0')
  69.     printf (shrtfmt, toname, to);
  70.     if (cc[0] != '\0')
  71.     printf (shrtfmt, ccname, cc);
  72.     if (subject[0] != '\0')
  73.     printf (shrtfmt, subjname, subject);
  74.     if (bcc[0] != '\0')
  75.     printf (shrtfmt, bccname, bcc);
  76.  
  77.     if (toflag)
  78.     getaddr (toname, to, NO, host);
  79.     if (ccflag)
  80.     getaddr (ccname, cc, NO, host);
  81.     if (subjflag)
  82.     gethead (subjname, subject, NO);
  83.  
  84.     fflush (stdout);
  85.     if (!noinputflag) {
  86.         if( dflag > 0 )
  87.         {
  88.         drclose ();
  89.     
  90.         old1 =  signal (SIGHUP, SIG_IGN); /* ignore signals intended for edit */
  91.         old2 =  signal (SIGINT, SIG_IGN);
  92.         old3 =  signal (SIGQUIT, SIG_IGN);
  93.     
  94.         if (fork () == 0) {
  95.         signal (SIGHUP, old1);
  96.         signal (SIGINT, orig);
  97.         signal (SIGQUIT, old3);
  98.         if( dflag == 2 )
  99.             execlp (editor, editor, drffile, (char *)0);
  100.         else
  101.             execlp( veditor, veditor, drffile, (char *)0);
  102.         printf ("can't execute\n");
  103.         s_exit (-1);
  104.         }
  105.         wait (&stat);
  106.         body = TRUE;    /* Don't know but assume he created a draft */
  107.         lastsend = 0;
  108.         signal (SIGHUP, old1);     /* restore signals */
  109.         signal (SIGINT, old2);
  110.         signal (SIGQUIT, old3);
  111.         dropen (DREND);
  112.     } else {
  113.         if (inclfile[0] == '\0')
  114.         printf ("Type message; end with CTRL-D...\n\n");
  115.         else
  116.         printf ("Enter comment; end with CTRL-D...\n\n");
  117.     
  118.     more: 
  119.         dropen (DREND);
  120.         fflush (stdout);
  121.         signal (SIGINT, SIG_IGN);
  122.         signal (SIGQUIT, SIG_IGN);
  123.     
  124.         while ((i = read (0, bigbuf, BBSIZE - 1)) > 0) {
  125.         if (i == 2 && strncmp (bigbuf, ".\n", 2) == 0)
  126.             break;        /* Accept . on a line by itself */
  127.         body = TRUE;
  128.         if (write (drffd, bigbuf, i) != i)
  129.             s_exit (NOTOK);
  130.         }
  131.         drclose ();
  132.         if (i < 0)
  133.         s_exit (NOTOK);
  134.     
  135.         signal (SIGINT, onint);    
  136.     }
  137.     }
  138.     setjmp (savej);
  139.     nsent = 0;
  140.  
  141.     if (inclfile[0] != '\0')
  142.     {                             /* tack file to end of message        */
  143.     putc('\n', stdout);
  144.     body = TRUE;
  145.     strcpy (bigbuf, inclfile);
  146.     goto doincl;
  147.     }
  148.  
  149.     for (;;)
  150.     {
  151.     char *cp;
  152.  
  153.     signal (SIGINT, onint3);
  154.     printf ("Command or ?: ");
  155.     fflush (stdout);
  156.     aborted = FALSE;
  157.     if (fgets (bigbuf, BBSIZE, stdin) == NULL)
  158.         goto byebye;
  159.     if (cp = index(bigbuf, '\n'))
  160.         *cp = '\0';
  161.  
  162.     if( strncmp( "set", bigbuf, 3) == 0){
  163.         char *av[NARGS];
  164.  
  165.         i = sstr2arg(bigbuf, 20, av, " \t");
  166.         if( i == 1 ) {    /* tell him what the current options are */
  167.             printf(" Copyfile  - '%s'\n", copyfile);
  168.             printf(" Signature - '%s'\n", signature);
  169.             printf(" Aliases   - '%s'\n", aliasfilename);
  170.             printf(" Editor    - '%s'\n", editor);
  171.             printf(" Veditor   - '%s'\n", veditor);
  172.             printf(" Checker   - '%s'\n", checker);
  173.             printf(" Subargs   - '%s'\n", subargs);
  174.             if( dflag > 0 )
  175.             printf(" Directedit option on with %s\n",
  176.                 (dflag==1?veditor:editor));
  177.             if(qflag == 0 && cflag == 1)
  178.                 printf(" File copy option is on\n");
  179.             if(qflag == 1 && cflag == 0)
  180.                 printf(" File copy on confirmation only\n");
  181.             if(pflag == 1)
  182.                 printf(" Paging option is on\n");
  183.             continue;
  184.         }
  185.         if( (i = picko( av[1] ) ) < 0) {
  186.             printf("Option '%s' is invalid.\n", av[1]);
  187.             continue;
  188.         }
  189.         select_o( i, &av[1] );
  190.         continue;
  191.     }
  192.     compress (bigbuf, bigbuf);
  193.                   /* so prefix works on multi-words     */
  194.     if (bigbuf[0] == '\0')
  195.         continue;             /* just hit newline                   */
  196.  
  197.     signal (SIGINT, onint);
  198.  
  199.     for (i = 0; !isnull (bigbuf[i]); i++)
  200.         bigbuf[i] = uptolow (bigbuf[i]);
  201.  
  202.     if (prefix ("bcc", bigbuf))
  203.     {
  204.         getaddr (bccname, bcc, YES, locname);
  205.         continue;
  206.     }
  207.     if (prefix ("delete body", bigbuf))
  208.     {
  209.         printf ("Are you sure?");
  210.         if (!confirm ())
  211.         continue;
  212.         body = FALSE;
  213.         drempty ();
  214.         continue;
  215.     }
  216.  
  217.     if (prefix ("edit", bigbuf) || prefix("vedit", bigbuf))
  218.     {
  219.         drclose ();
  220.  
  221.         old1 =  signal (SIGHUP, SIG_IGN); /* ignore signals intended for edit */
  222.         old2 =  signal (SIGINT, SIG_IGN);
  223.         old3 =  signal (SIGQUIT, SIG_IGN);
  224.  
  225.         if (fork () == 0)
  226.         {
  227.         signal (SIGHUP, old1);
  228.         signal (SIGINT, orig);
  229.         signal (SIGQUIT, old3);
  230.         if( bigbuf[0] == 'e' )
  231.             execlp (editor, editor, drffile, (char *)0);
  232.         else
  233.             execlp( veditor, veditor, drffile, (char *)0);
  234.         printf ("can't execute\n");
  235.         s_exit (-1);
  236.         }
  237.         wait (&stat);
  238.         body = TRUE;    /* assume he created a draft file */
  239.         lastsend = 0;
  240.         signal (SIGHUP, old1);     /* restore signals */
  241.         signal (SIGINT, old2);
  242.         signal (SIGQUIT, old3);
  243.         dropen (DREND);
  244.         continue;
  245.     }
  246.  
  247.     if (prefix ("file include", bigbuf))
  248.     {
  249.         printf ("File: ");
  250.         gather (bigbuf, BBSIZE - 1);
  251.         if (bigbuf[0] == '\0')
  252.         continue;
  253.  
  254. doincl:
  255.         infile = open (bigbuf, 0);
  256.         if (inclfile[0] != '\0')
  257.         {                     /* and include file                   */
  258.         inclfile[0] = '\0';
  259.         }
  260.         if (infile < 0)
  261.         {
  262.         printf ("can't open: '%s'\n", bigbuf);
  263.         continue;
  264.         }
  265.         dropen (DREND);
  266.         body = TRUE;
  267.         while ((i = read (infile, bigbuf, BBSIZE - 1)) > 0)
  268.         write (drffd, bigbuf, i);
  269.         close (infile);
  270.         printf (" ...included\n");
  271.         continue;
  272.     }
  273.  
  274.     if (prefix ("header edit", bigbuf))
  275.     {
  276.         struct header *hp;
  277.  
  278.         printf ("[RETURN (skip) + (append) - (delete one) # (delete all)]\n");
  279.         getaddr (toname, to, YES, locname);
  280.         getaddr (ccname, cc, YES, locname);
  281.         gethead (subjname, subject, YES);
  282.         if (bcc[0] != '\0')
  283.         getaddr (bccname, bcc, YES, locname);
  284.         for (hp = headers; hp != NULL; hp = hp->hnext)
  285.         gethead (hp->hname, hp->hdata, YES);
  286.         nsent = lastsend = 0;
  287.         continue;
  288.     }
  289.  
  290.     if (prefix ("input more body", bigbuf))
  291.     {
  292.         printf ("Continue message; end with CTRL-D...\n");
  293.         goto more;
  294.     }
  295.  
  296.  
  297.     if (prefix ("program run", bigbuf))
  298.     {
  299.         printf ("Program: ");
  300.         fflush (stdout);
  301.         if (gets (tempbuf) == NULL)
  302.         continue;
  303.         drclose ();
  304.  
  305.         /* ignore signals intended for subprocess */
  306.         old1 = signal (SIGHUP, SIG_IGN);
  307.         old2 = signal (SIGINT, SIG_IGN);
  308.         old3 = signal (SIGQUIT, SIG_IGN);
  309.  
  310.         if (fork () == 0)
  311.         {
  312.         signal (SIGHUP, old1);
  313.         signal (SIGINT, orig);
  314.         signal (SIGQUIT, old3);
  315.         execlp ("sh", "send-shell", "-c", tempbuf, (char *)0);
  316.         printf ("can't execute\n");
  317.         s_exit (-1);
  318.         }
  319.         wait (&stat);
  320.         signal (SIGHUP, old1);     /* restore signals */
  321.         signal (SIGINT, old2);
  322.         signal (SIGQUIT, old3);
  323.         dropen (DREND);
  324.         continue;
  325.     }
  326.  
  327.     if (prefix ("quit", bigbuf) ||
  328.         prefix ("bye", bigbuf))
  329.     {
  330.     byebye: 
  331.         if ( body && !nsent)
  332.         {
  333.         printf ("Quit without sending draft");
  334.         if (confirm ())
  335.             return;
  336.         else
  337.             continue;
  338.         }
  339.         drclose ();
  340.         return;
  341.     }
  342.  
  343.     if (prefix ("review message", bigbuf))
  344.     {
  345.         struct header *hp;
  346.  
  347.         printf (hdrfmt, fromname, signature);
  348.         i = 1;
  349.         if (to[0] != '\0')
  350.         {
  351.         i++;
  352.             do_review(toname, to);
  353.         }
  354.         else
  355.         if (bcc[0] != '\0')
  356.         {
  357.             i++;
  358.             do_review(toname, "list: ;");
  359.          }
  360.  
  361.         if (cc[0] != '\0')
  362.         {
  363.         i++;
  364.         do_review(ccname, cc);
  365.         }
  366.         if (subject[0] != '\0')
  367.         {
  368.         i++;
  369.         do_review(subjname, subject);
  370.         }
  371.         if (bcc[0] != '\0')
  372.         {
  373.         i++;
  374.         do_review(bccname, bcc);
  375.         }
  376.         for (hp = headers; hp != NULL; hp = hp->hnext)
  377.         if (isstr(hp->hdata))
  378.             do_review(hp->hname, hp->hdata);
  379.         putc ('\n', stdout);
  380.         fflush (stdout);
  381.  
  382.         if (body) {
  383.         dropen (DRBEGIN);
  384.         inrdwr = TRUE;
  385.         msgreview (++i);
  386.         inrdwr = FALSE;
  387.         }
  388.         continue;
  389.     }
  390.  
  391.     if (prefix ("check spelling", bigbuf))
  392.     {
  393.         drclose ();
  394.  
  395.         old1 =  signal (SIGHUP, SIG_IGN); /* ignore signals intended for cheker */
  396.         old2 =  signal (SIGINT, SIG_IGN);
  397.         old3 =  signal (SIGQUIT, SIG_IGN);
  398.  
  399.         if (fork () == 0)
  400.         {
  401.         signal (SIGHUP, old1);
  402.         signal (SIGINT, orig);
  403.         signal (SIGQUIT, old3);
  404.         execlp (checker, checker, drffile, (char *)0);
  405.         printf ("can't execute\n");
  406.         s_exit (-1);
  407.         }
  408.         wait (&stat);
  409.         signal (SIGHUP, old1);     /* restore signals */
  410.         signal (SIGINT, old2);
  411.         signal (SIGQUIT, old3);
  412.         dropen (DREND);
  413.         continue;
  414.     }
  415.  
  416.     if (prefix ("post message", bigbuf) ||
  417.         prefix ("send message", bigbuf))
  418.     {
  419.         if (lastsend && lastsend == body)
  420.         {
  421.         printf ("Without changing anything");
  422.         if (!confirm ())
  423.             break;
  424.         }
  425.         signal (SIGINT, onint2);
  426.         if( qflag == 1 ){
  427.         printf(" Do you want a file copy of this message ?  ");
  428.         fflush(stdout);
  429.         fgets(tempbuf, sizeof(tempbuf), stdin );
  430.         if( tempbuf[0] == 'y' || tempbuf[0] == 'Y' || tempbuf[0] == '\n')
  431.             cflag = 1;
  432.             else
  433.                 cflag = 0;
  434.         }
  435.         post ();
  436.         if ( qflag == 1 )
  437.         cflag = 0;
  438.  
  439. /* *** auto-exit, upon successfull send, since draft is saved *** */
  440.  
  441.         goto byebye;
  442.     }
  443.  
  444.     if (prefix ("?", bigbuf) || prefix("help", bigbuf))
  445.     {
  446.         printf ("bcc\n");
  447.         printf ("bye\n");
  448.         printf ("check spelling\n");
  449.         printf ("delete body\n");
  450.         printf ("edit body (using editor)\n");
  451.         printf ("vedit body (using veditor)\n");
  452.         printf ("file include\n");
  453.         printf ("header edit\n");
  454.         printf ("input more body\n");
  455.         printf ("program run\n");
  456.         printf ("quit\n");
  457.         printf ("review message\n");
  458.         printf ("send message\n");
  459.         printf ("set [option] [option value]\n");
  460.         continue;
  461.     }
  462.  
  463.     printf (" unknown command (type ? for help)\n");
  464.     }                  /* end of loop */
  465. }
  466.  
  467. do_review (name, data)            /* send out a header field            */
  468.     char name[],                  /* name of field                      */
  469.     *data;                    /* value-part of field                */
  470. {
  471.     register int ind;
  472.     register char *curptr;
  473.  
  474.     for (curptr = data, ind = 0; ind >= 0; curptr += ind + 1)
  475.     {
  476.     if ((ind = strindex ("\n", curptr)) >= 0)
  477.         curptr[ind] = '\0';   /* format lines properly              */
  478.  
  479.     printf (hdrfmt, (curptr == data) ? name : "", curptr);
  480.     if (ind >= 0)
  481.         curptr[ind] = '\n';   /* put it back                        */
  482.     }
  483. }
  484.