home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / showmsg_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-11  |  10.7 KB  |  362 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: showmsg_c.c,v 5.3 1992/11/26 00:46:13 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.3 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: showmsg_c.c,v $
  17.  * Revision 5.3  1992/11/26  00:46:13  syd
  18.  * changes to first change screen back (Raw off) and then issue final
  19.  * error message.
  20.  * From: Syd
  21.  *
  22.  * Revision 5.2  1992/11/07  19:37:21  syd
  23.  * Enhanced printing support.  Added "-I" to readmsg to
  24.  * suppress spurious diagnostic messages.
  25.  * From: chip@chinacat.unicom.com (Chip Rosenthal)
  26.  *
  27.  * Revision 5.1  1992/10/03  22:58:40  syd
  28.  * Initial checkin as of 2.4 Release at PL0
  29.  *
  30.  *
  31.  ******************************************************************************/
  32.  
  33. /** This is an interface for the showmsg command line.  The possible
  34.     functions that could be invoked from the showmsg command line are
  35.     almost as numerous as those from the main command line and include
  36.     the following;
  37.  
  38.        |    = pipe this message to command...
  39.        !    = call Unix command
  40.        <    = scan message for calendar info
  41.        b    = bounce (remail) message
  42.        d    = mark message for deletion
  43.        f    = forward message
  44.        g    = group reply
  45.        h    = redisplay this message from line #1, showing headers
  46.        <CR> = redisplay this message from line #1, weeding out headers
  47.        i,q  = move back to the index page (simply returns from function)
  48.        J    = move to body of next message
  49.        j,n  = move to body of next undeleted message
  50.        K    = move to body of previous message
  51.        k    = move to body of previous undeleted message
  52.        m    = mail a message out to someone
  53.        p    = print this (all tagged) message
  54.        r    = reply to this message
  55.        s    = save this message to a maibox/folder 
  56.        t    = tag this message
  57.        u    = undelete message
  58.        x    = Exit Elm NOW 
  59.  
  60.     all commands not explicitly listed here are beeped at.  Use i)ndex
  61.     to get back to the main index page, please.
  62.  
  63.     This function returns when it is ready to go back to the index
  64.     page.
  65. **/
  66.  
  67. #include "headers.h"
  68. #include "s_elm.h"
  69.  
  70. int    screen_mangled = 0;
  71. char    msg_line[SLEN];
  72. static    char *put_help_prompt = NULL;
  73. #define store_msg(a)    (void)strcpy(msg_line,a)
  74. #define put_prompt()    PutLine0(LINES-3, 0, Prompt)
  75. #define put_help()    PutLine0(LINES-3, 45, put_help_prompt)
  76. #define POST_PROMPT_COL    strlen(Prompt)
  77.  
  78.  
  79. int
  80. process_showmsg_cmd(command)
  81. int command;
  82. {
  83.     int     i, intbuf;        /* for dummy parameters...etc */
  84.     int     ch;            /* for arrow keys */
  85.     int    key_offset;        /* for arrow keys */
  86.     int    istagged;        /* for tagging and subsequent msg */
  87.  
  88.     if (put_help_prompt == NULL) {
  89.         put_help_prompt = catgets(elm_msg_cat, ElmSet, ElmUseIToReturnIndex,
  90.                 "(Use 'i' to return to index.)");
  91.     }
  92.     Raw(ON);
  93.  
  94.     while (TRUE) {
  95.       clear_error();
  96.       switch (command) {
  97.         case '?' : if (help(TRUE)) {
  98.              ClearScreen();
  99.              build_bottom();
  100.                } else screen_mangled = TRUE;
  101.                break;
  102.  
  103.         case '|' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmPipe, "Pipe"), TRUE);
  104.                (void) do_pipe();     /* do pipe - ignore return val */
  105.                ClearScreen();
  106.                build_bottom();
  107.                break; 
  108.  
  109. #ifdef ALLOW_SUBSHELL
  110.         case '!' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmSystemCall,
  111.                 "System call"), TRUE);
  112.                (void) subshell();
  113.                ClearScreen();
  114.                build_bottom();
  115.                break;
  116. #endif
  117.  
  118.         case '<' : 
  119. #ifdef ENABLE_CALENDAR
  120.                put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmScanForCalendarCmd,
  121.                 "Scan messages for calendar entries"), TRUE);
  122.                scan_calendar();
  123. #else
  124.                store_msg(catgets(elm_msg_cat, ElmSet, ElmCantScanForCalendar,
  125.                 "Can't scan for calendar entries!"));
  126. #endif
  127.                break;
  128.  
  129.         case '%' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmDisplayReturnAdd,
  130.                 "Display return address"), TRUE);
  131.                get_return(msg_line, current-1);
  132.                break;
  133.  
  134.         case 'b' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmBounceMessage,
  135.                 "Bounce message"), TRUE);
  136.                remail();
  137.                break;
  138.   
  139.         case 'd' : delete_msg(TRUE, FALSE); /* really delete it, silent */
  140.                if (! resolve_mode)
  141.              store_msg(catgets(elm_msg_cat, ElmSet, ElmMessageMarkedForDeleteion,
  142.                 "Message marked for deletion."));
  143.                else
  144.              goto next_undel_msg;
  145.                break;
  146.  
  147.         case 'f' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmForwardMessage,
  148.                 "Forward message"), TRUE);
  149.                if(forward()) put_border();
  150.                break;
  151.  
  152.         case 'g' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmGroupReply,
  153.                 "Group reply"), TRUE);
  154.                (void) reply_to_everyone();
  155.                break;
  156.  
  157.         case 'h' : screen_mangled = 0;
  158.                if (filter) { 
  159.                  filter = 0; 
  160.                  intbuf = show_msg(current); 
  161.                  filter = 1;
  162.              return(intbuf);
  163.                } else
  164.                  return(show_msg(current)); 
  165.  
  166.         case 'q' :
  167.         case 'i' : (void) get_page(current);
  168.                clear_error();        /* zero out pending msg   */
  169.                if (cursor_control)
  170.              transmit_functions(ON);
  171.                screen_mangled = 0;
  172.                return(0);        /* avoid <return> looping */
  173.  
  174. next_undel_msg :    /* a target for resolve mode actions */
  175.  
  176.         case ' ' :
  177.         case 'j' :
  178.         case 'n' : screen_mangled = 0;
  179.                if((i=next_message(current-1, TRUE)) != -1)
  180.              return(show_msg(current = i+1));
  181.                else return(0);
  182.  
  183. next_msg:
  184.         case 'J' : screen_mangled = 0;
  185.                if((i=next_message(current-1, FALSE)) != -1)
  186.              return(show_msg(current = i+1));
  187.                else return(0);
  188.  
  189. prev_undel_msg:
  190.         case 'k' : screen_mangled = 0;
  191.                if((i=prev_message(current-1, TRUE)) != -1)
  192.              return(show_msg(current = i+1));
  193.                else return(0);
  194.  
  195.         case 'K' : screen_mangled = 0;
  196.                if((i=prev_message(current-1, FALSE)) != -1)
  197.              return(show_msg(current = i+1));
  198.                else return(0);
  199.  
  200.         case 'm' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmMailMessage,
  201.                 "Mail message"), TRUE);
  202.                if(send_msg("","","", TRUE, allow_forms, FALSE))
  203.              put_border();
  204.                break;
  205.  
  206.         case 'p' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmPrintMessage,
  207.                 "Print message"), FALSE);
  208.                (void) print_msg(FALSE);
  209.                break;
  210.  
  211.         case 'r' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmReplyToMessage,
  212.                 "Reply to message"), TRUE);
  213.                if(reply()) put_border();
  214.                break;
  215.  
  216.         case '>' :
  217.         case 'C' :
  218.         case 's' : put_cmd_name((command != 'C' ? cap_save_word : cap_copy_word), TRUE);
  219.                (void) save(&intbuf, TRUE, (command != 'C'));
  220.                if (resolve_mode && command != 'C')
  221.              goto next_undel_msg;
  222.                break;
  223.  
  224.         case 'T' :
  225.         case 't' : istagged=tag_message(FALSE);    
  226.                if (command == 'T')
  227.              goto next_undel_msg;
  228.                else if (istagged)
  229.              store_msg(catgets(elm_msg_cat, ElmSet, ElmMessageTagged,
  230.                 "Message tagged."));
  231.                else 
  232.              store_msg(catgets(elm_msg_cat, ElmSet, ElmMessageUntagged,
  233.                 "Message untagged."));
  234.                break;
  235.  
  236.         case 'u' : undelete_msg(FALSE); /* undelete it, silently */
  237.                if (! resolve_mode)
  238.              store_msg(catgets(elm_msg_cat, ElmSet, ElmMessageUndeleted,
  239.                 "Message undeleted."));
  240.                else {
  241. /******************************************************************************
  242.  ** We're special casing the U)ndelete command here *not* to move to the next
  243.  ** undeleted message ; instead it'll blindly move to the next message in the
  244.  ** list.  See 'elm.c' and the command by "case 'u'" for further information.
  245.  ** The old code was:
  246.              goto next_undel_msg;
  247. *******************************************************************************/
  248.              goto next_msg;
  249.                }
  250.                break;
  251.  
  252.         case 'X' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmQuickExit,
  253.                 "Quick Exit"), TRUE);
  254.                leave(0);
  255.                break;
  256.  
  257.         case 'x' : put_cmd_name(catgets(elm_msg_cat, ElmSet, ElmExit, "Exit"), TRUE);
  258.                exit_prog();
  259.                break;
  260.         
  261.         case ctrl('J'):
  262.         case ctrl('M'):  screen_mangled = 0;
  263.                  return(show_msg(current));
  264.  
  265.  
  266.             case ESCAPE : if (cursor_control) {
  267.   
  268.                             key_offset = 1;
  269.   
  270.                             ch = ReadCh(); 
  271.   
  272.                             if (ch == ESCAPE)
  273.                              ch = ReadCh();
  274.   
  275.                             if ( ch == '[' || ch == 'O') 
  276.                             {
  277.                               ch = ReadCh();
  278.                               key_offset++;
  279.                             }
  280.   
  281.                             if (ch == up[key_offset])
  282.                   goto prev_undel_msg;
  283.                             else if (ch == down[key_offset])
  284.                   goto next_undel_msg;
  285.                             else {
  286.                   screen_mangled = 0;
  287.                               return(0);
  288.                 }
  289.                           }
  290.                           else          /* Eat 2 chars for escape codes */
  291.                           {
  292.                             ch = ReadCh();
  293.                             ch = ReadCh();
  294.                             putchar((char) 007);
  295.                             fflush(stdout);
  296.                 screen_mangled = 0;
  297.                             return(0);
  298.                            }
  299.   
  300.         default  : putchar((char) 007);    /* BEEP! */
  301.       }
  302.  
  303.       /* display prompt */
  304.       if (screen_mangled) {
  305.         /* clear what was left over from previous command 
  306.          * and display last generated message.
  307.          */
  308.         put_prompt();
  309.         CleartoEOS();
  310.         put_help();
  311.         Centerline(LINES, msg_line);
  312.         MoveCursor(LINES-3, POST_PROMPT_COL);
  313.       } else {
  314.         /* display bottom line prompt with last generated message */
  315.         MoveCursor(LINES, 0);
  316.         CleartoEOS();
  317.         StartBold();
  318.         Write_to_screen(catgets(elm_msg_cat, ElmSet, ElmCommandLine,
  319.         "%s Command ('i' to return to index): "),
  320.         1, msg_line);
  321.         EndBold();
  322.       }
  323.       *msg_line = '\0';    /* null last generated message */
  324.  
  325.       command = ReadCh();    /* get next command from user */
  326.     }
  327. }
  328.  
  329. put_cmd_name(command, will_mangle)
  330. char *command;
  331. int will_mangle;
  332. {
  333.  
  334.     /* If screen is or will be mangled display the command name 
  335.      * and erase the bottom of the screen.
  336.      * But first if the border line hasn't yet been drawn, draw it.
  337.      */
  338.     if(will_mangle && !screen_mangled) {
  339.       build_bottom();
  340.       screen_mangled = TRUE;
  341.     }
  342.     if(screen_mangled) {
  343.       PutLine0(LINES-3, POST_PROMPT_COL, command);
  344.       CleartoEOS();
  345.     }
  346. }
  347.  
  348. put_border()
  349. {
  350.      PutLine0(LINES-4, 0, 
  351. "--------------------------------------------------------------------------\n");
  352. }
  353.  
  354. build_bottom()
  355. {
  356.      MoveCursor(LINES-4, 0);
  357.      CleartoEOS();
  358.      put_border();
  359.      put_prompt();
  360.      put_help();
  361. }
  362.