home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / mush5.7 / part12 / doproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-19  |  12.1 KB  |  420 lines

  1. /* @(#)doproc.c        (c) copyright    10/18/86 (Dan Heller) */
  2.  
  3. /* do main panel item procedures */
  4. #include "mush.h"
  5.  
  6. respond_mail(item, value, event)
  7. Panel_item item;
  8. int value;
  9. struct inputevent *event;
  10. {
  11.     char buf[80];
  12.  
  13.     if (value == 4)
  14.     return help(panel_sw->ts_windowfd, "respond", tool_help);
  15.     if (ison(glob_flags, IS_GETTING)) {
  16.     print("Finish editing current message first");
  17.     return;
  18.     }
  19.     if (!msg_cnt) {
  20.     print("No messages to respond to.\n");
  21.     return;
  22.     }
  23.     print("Responding to message %d", current_msg+1);
  24.     if (event && event->ie_code == MS_LEFT)
  25.     value = 0;
  26.     (void) sprintf(buf, "%s %s %d",
  27.     (value == 2 || value == 3)? "replyall" : "replysender",
  28.     (value == 1 || value == 3)? "-i": NO_STRING, current_msg+1);
  29.     (void) cmd_line(buf, msg_list);
  30. }
  31.  
  32. /* following macro is for the next two procedures */
  33. #define hdr_item (item == sub_hdr_item[0] || item == sub_hdr_item[1] || \
  34.                   item == sub_hdr_item[2] || item == sub_hdr_item[3] || \
  35.                   item == sub_hdr_item[4] || item == sub_hdr_item[5])
  36.  
  37. delete_mail(item, val, event)
  38. register Panel_item item;
  39. int val;
  40. register struct inputevent *event;
  41. {
  42.     register int value = val, c;
  43.     char buf[92];
  44.  
  45.     panel_set(item, PANEL_VALUE, 0, 0);
  46.     if (hdr_item && event->ie_code != MS_LEFT || value == 6)
  47.     return help(panel_sw->ts_windowfd, "delete", tool_help);
  48.     /* if selected "delete" in header panel, set value = 4 (delete "range") */
  49.     if (hdr_item)
  50.     value = 4;
  51.     /* delete current message */
  52.     if (!value || value == 1 && event && event->ie_code == MS_LEFT)
  53.     if (ison(msg[current_msg].m_flags, DELETE)) {
  54.         print("%d Already deleted", current_msg+1);
  55.         return;
  56.     } else {
  57.         print("Deleted Message %d. ", current_msg+1);
  58.         (void) strcpy(buf, "delete");
  59.     }
  60.     else switch(value) {
  61.     case 1:
  62.         print("Really delete everything?");
  63.         if ((c = confirm(panel_sw->ts_windowfd)) == 'y' ||
  64.              c == MS_LEFT) {
  65.         print("Deleted All Messages. ");
  66.         (void) strcpy(buf, "delete *");
  67.         } else { print("Whew!"); return; }
  68.     when 2:
  69.         /* undelete current message */
  70.         if (isoff(msg[current_msg].m_flags, DELETE)) {
  71.         print("%d isn't deleted", current_msg+1);
  72.         return;
  73.         }
  74.         print("Undeleted Message #%d. ", current_msg+1);
  75.         (void) strcpy(buf, "undelete");
  76.     when 3:
  77.         /* undelete all messages */
  78.         print("Uneleted All Messages. ");
  79.         (void) strcpy (buf, "undelete *");
  80.     when 4: case 5:
  81.         /* delete a range of messages */
  82.         (void) sprintf(buf, "%selete \"%s\"", (value == 4)? "d": "und",
  83.             panel_get_value(msg_num_item));
  84.         panel_set(msg_num_item, PANEL_VALUE, NO_STRING, 0);
  85.     }
  86.     (void) cmd_line(buf, msg_list);
  87. }
  88.  
  89. read_mail(item, value, event)
  90. register Panel_item item;
  91. register int value;
  92. register struct inputevent *event;
  93. {
  94.     register int this_msg = current_msg;
  95.  
  96.     /* check "event" in case we were called from select.c
  97.      * in which case event would be NULL
  98.      */
  99.     if (event && event->ie_code == MS_RIGHT &&
  100.         item && (item == read_item && value ||
  101.     (item == sub_hdr_item[0] || item == sub_hdr_item[1])))
  102.     return help(panel_sw->ts_windowfd, "next", tool_help);
  103.     if (item && (item == sub_hdr_item[4] || item == sub_hdr_item[5]))
  104.     return help(panel_sw->ts_windowfd, "msg_menu", tool_help);
  105.     if (!msg_cnt) {
  106.     print ("No Mail.");
  107.     return -1;
  108.     }
  109.     if (item && item == read_item || ison(msg[current_msg].m_flags, DELETE))
  110.     (void) next_msg(FALSE, DELETE);
  111.     if (this_msg != current_msg || ison(msg[current_msg].m_flags, UNREAD) ||
  112.         (current_msg < n_array[0] || current_msg > n_array[screen])) {
  113.     set_isread(current_msg);
  114.     (void) do_hdrs(0, DUBL_NULL, NULL);
  115.     }
  116.     display_msg(current_msg, (long)0);
  117.     return -1;
  118. }
  119.  
  120. /* the panel button that says "filename" and "directory", etc... text item */
  121. file_dir(item, event)
  122. Panel_item item;
  123. struct inputevent *event;
  124. {
  125.     register char *p;
  126.     char buf[128], *which = panel_get(item, PANEL_LABEL_STRING);
  127.  
  128.     if (!strcmp(which, "folder:"))
  129.     if (event->ie_code == '\n' || event->ie_code == '\r')
  130.         (void) sprintf(buf, "folder %s", panel_get_value(item));
  131.     else
  132.         (void) sprintf(buf, "folder ! %s", panel_get_value(item));
  133.  
  134.     else if (!strcmp(which, "directory:"))
  135.     (void) sprintf(buf, "cd %s", panel_get_value(item));
  136.  
  137.     else if (!msg_cnt)
  138.     print("No messages to save");
  139.  
  140.     else if (!strcmp(which, "filename:")) {
  141.     int x = 1;
  142.     if (event->ie_code == '\n' || event->ie_code == '\r')
  143.         (void) strcpy(buf, "save  ");
  144.     else
  145.         (void) strcpy(buf, "write ");
  146.     if (!(p = panel_get_value(item)) || !*p &&
  147.         (!(p = do_set(set_options, "mbox")) || !*p))
  148.         p = DEF_MBOX;
  149.     (void) sprintf(buf+6, "%d %s", current_msg+1, p);
  150.     print("save message %d in %s? ", current_msg+1, p);
  151.     if ((x = confirm(print_sw->ts_windowfd)) != 'y' && x != MS_LEFT) {
  152.         print("Message not saved");
  153.         return;
  154.     }
  155.     }
  156.     (void) cmd_line(buf, msg_list);
  157. }
  158.  
  159. do_file_dir(item, value, event)
  160. Panel_item item;
  161. int value;
  162. struct inputevent *event;
  163. {
  164.     char buf[92];
  165.     int x; /* used for confirmation */
  166.  
  167.     if (item == folder_item) {
  168.     (void) strcpy(buf, "folder ");
  169.     if (event->ie_code == MS_LEFT) {
  170.         panel_set(file_item, PANEL_LABEL_STRING, "folder:", 0);
  171.         panel_set(file_item, PANEL_MENU_CHOICE_STRINGS,
  172.                 "Change without updating current folder", 0, 0);
  173.     } else {
  174.         if (!value)
  175.         (void) strcat(buf, "%");
  176.         else if (value == 1)
  177.         (void) strcat(buf, "&");
  178.         else if (value == 2)
  179.         (void) strcat(buf, "#");
  180.         else {
  181.         (void) sprintf(buf, "folder %s",
  182.                   panel_get(item, PANEL_CHOICE_STRING, value));
  183.         if (!strcmp(buf+8, "Help"))
  184.             return help(panel_sw->ts_windowfd, "folder", tool_help);
  185.         }
  186.     }
  187.     } else if (item == cd_item) {
  188.     (void) strcpy(buf, "cd ");
  189.     if (event->ie_code == MS_LEFT || !value) {
  190.         panel_set(file_item, PANEL_LABEL_STRING, "directory:", 0);
  191.         panel_set(file_item, PANEL_MENU_CHOICE_STRINGS,
  192.                 "Change to specified directory", 0, 0);
  193.     } else if (value == 1)
  194.         (void) strcat(buf, "~");
  195.     else if (value == 2)
  196.         (void) strcat(buf, "+");
  197.     else
  198.         return help(panel_sw->ts_windowfd, "chdir", tool_help);
  199.     } else if (item == save_item) {
  200.     (void) strcpy(buf, "save ");
  201.     if (event->ie_code == MS_LEFT)
  202.         if (!strcmp("filename:", panel_get(file_item,PANEL_LABEL_STRING))) {
  203.         event->ie_code = '\n';  /* let file_dir think it got a \n */
  204.         return file_dir(file_item, event);
  205.         } else {
  206.         panel_set(file_item, PANEL_LABEL_STRING, "filename:", 0);
  207.         panel_set(file_item, PANEL_MENU_CHOICE_STRINGS,
  208.             "Save message WITHOUT headers", 0,0);
  209.         print("Type in Main Panel Window a filename to save message");
  210.         return;
  211.         }
  212.     else if (value == 1) {
  213.         register char *p = panel_get_value(file_item);
  214.         if ((!p || !*p) && (!(p = do_set(set_options, "mbox")) || !*p))
  215.         p = DEF_MBOX;
  216.         print("Save in %s? ", p);
  217.         if ((x = confirm(panel_sw->ts_windowfd)) != 'y' && x != MS_LEFT) {
  218.         print("Message not saved");
  219.         return;
  220.         }
  221.         (void) sprintf(buf, "save \"%s\" %s",
  222.                        panel_get_value(msg_num_item), p);
  223.         panel_set(msg_num_item, PANEL_VALUE, NO_STRING, 0);
  224.     } else {
  225.         (void) sprintf(buf, "save %s",
  226.         panel_get(item, PANEL_CHOICE_STRING, value));
  227.         if (!strcmp(buf+6, "Help"))
  228.         return help(panel_sw->ts_windowfd, "save", tool_help);
  229.     }
  230.     }
  231.     (void) cmd_line(buf, msg_list);
  232.     panel_set(item, PANEL_VALUE, NO_STRING, 0); /* remove last value */
  233. }
  234.  
  235. text_done(item, event)
  236. Panel_item item;
  237. struct inputevent *event;
  238. {
  239.     char opt[30], buf[82], cmd[82];
  240.     register char *p;
  241.     Panel_item which = NO_ITEM;
  242.     int set_it;
  243.  
  244.     if ((event->ie_code == '\n' || event->ie_code == '\r') && 
  245.                  *strcpy(buf, panel_get_value(item))) {
  246.     (void) strcpy(opt, panel_get(item, PANEL_LABEL_STRING));
  247.     set_it = (*opt == 'S');
  248.     if (!(p = index(opt, ' '))) {
  249.         print("Hmmm... there seems to be a problem here.");
  250.         return;
  251.     }
  252.     ++p;
  253.     switch(lower(*p)) {
  254.         case 'o':
  255.         (void) sprintf(cmd, "%set %s", (set_it)? "s": "uns", buf);
  256.         which = option_item;
  257.         when 'i':
  258.         (void) sprintf(cmd, "%sgnore %s", (set_it)? "i": "uni", buf);
  259.         which = ignore_item;
  260.         when 'a':
  261.         (void) sprintf(cmd, "%slias %s", (set_it)? "a": "una", buf);
  262.         which = alias_item;
  263.         otherwise: print("HUH!? (%c)", *p); return;
  264.     }
  265.     (void) cmd_line(buf, msg_list);
  266.     }
  267.     panel_set(input_item, PANEL_VALUE, NO_STRING, 0); /* remove last value */
  268.     panel_set(item, PANEL_SHOW_ITEM, FALSE, 0);
  269. }
  270.  
  271. do_help(item, value, event)
  272. Panel_item item;
  273. register int value;
  274. struct inputevent *event;
  275. {
  276.     register char *p, *helpfile = tool_help;
  277.     switch(value) {
  278.     case 1: p = "help";
  279.     when 2: p = "mouse";
  280.     when 3: p = "windows";
  281.     when 4: p = "function keys";
  282.     when 5: p = "hdr_format", helpfile = cmd_help;
  283.     when 6: p = "msg_list", helpfile = cmd_help;
  284.     otherwise: p = "general";
  285.     }
  286.     (void) help(panel_sw->ts_windowfd, p, helpfile);
  287. }
  288.  
  289. toolquit(item, value, event)
  290. Panel_item item;
  291. int value;
  292. struct inputevent *event;
  293. {
  294.     register int which;
  295.  
  296.     if (!value || event->ie_code == MS_LEFT) {
  297.     do_update(NO_ITEM, 0, NO_EVENT);
  298.     turnoff(glob_flags, NEW_MAIL);
  299.     mail_status(0); /* lower flag (if up) print current num of msgs */
  300.     wmgr_changestate (tool->tl_windowfd, rootfd, TRUE);
  301.     wmgr_changelevel (tool->tl_windowfd, parentfd, TRUE);
  302.     return;
  303.     } else if (value == 2) {
  304.     (void) help(panel_sw->ts_windowfd, "quit", tool_help);
  305.     return;
  306.     }
  307.     print("Left updates changes. Middle does not. Right aborts quit.");
  308.     if ((which = confirm(panel_sw->ts_windowfd)) == MS_RIGHT) {
  309.     print("Quit aborted.");
  310.     return;
  311.     }
  312.     abort_mail(NO_ITEM, 0);
  313.     if (which == MS_LEFT)
  314.     lock_cursors(), copyback();
  315.     else
  316.     print("Bye bye");
  317.     cleanup(0);
  318. }
  319.  
  320. do_lpr(item, value, event)
  321. Panel_item item;
  322. int value;
  323. struct inputevent *event;
  324. {
  325.     char buf[128];
  326.  
  327.     if (event && (event->ie_code == MS_LEFT || value == 1)) {
  328.     print("Sending message %d to printer...", current_msg+1);
  329.     (void) strcpy(buf, "lpr ");
  330.     if (value)
  331.         (void) sprintf(buf, "lpr \"%s\"", panel_get_value(msg_num_item));
  332.     lock_cursors();
  333.     (void) cmd_line(buf, msg_list);
  334.     unlock_cursors();
  335.     } else
  336.     (void) help(panel_sw->ts_windowfd, "printer", tool_help);
  337. }
  338.  
  339. do_clear()
  340. {
  341.     /* actions that clears window indicates user wants to quit getting opts */
  342.     if (msg_pix)
  343.     pr_destroy(msg_pix), msg_pix = (struct pixrect *)NULL;
  344.     if (getting_opts)
  345.     getting_opts = 0, unlock_cursors();
  346.     pw_writebackground(msg_win, 0,0, msg_rect.r_width,msg_rect.r_height,
  347.                PIX_CLR);
  348.     txt.x = 5, txt.y = l_height(curfont) - 1;
  349. }
  350.  
  351. do_update(item, value, event)
  352. Panel_item item;
  353. register int value;
  354. struct inputevent *event;
  355. {
  356.     char *argv[2];
  357.     if (event && event->ie_code != MS_LEFT)
  358.     return help(panel_sw->ts_windowfd, "update", tool_help);
  359.     argv[0] = "update";
  360.     argv[1] = NULL;
  361.     (void) folder(0, argv, NULL);
  362. }
  363.  
  364. /* panel selction button to send a letter.
  365.  * add a CR if necessary, and finish up letter
  366.  */
  367. do_send(item, value, event)
  368. Panel_item item;
  369. register int value;
  370. register struct inputevent *event;
  371. {
  372.     if (event->ie_code != MS_LEFT)
  373.     return help(panel_sw->ts_windowfd, "send", tool_help);
  374.     if (txt.x > 5) {
  375.     pw_char(msg_win, txt.x,txt.y, PIX_CLR, fonts[curfont], '_');
  376.     add_to_letter(rite('\n')); /* if line isn't complete, flush it */
  377.     }
  378.     finish_up_letter();
  379. }
  380.  
  381. do_edit(item, value, event)
  382. Panel_item item;
  383. register int value;
  384. register struct inputevent *event;
  385. {
  386.     char buf[4];
  387.     if (event->ie_code != MS_LEFT)
  388.     return help(panel_sw->ts_windowfd, "edit", tool_help);
  389.     if (txt.x > 5)
  390.     add_to_letter(rite('\n')); /* flush line for him */
  391.     add_to_letter(sprintf(buf, "%cv", *escape));
  392. }
  393.  
  394. do_compose(item, value, event)
  395. Panel_item item;
  396. register int value;
  397. struct inputevent *event;
  398. {
  399.     if (event && event->ie_code != MS_LEFT)
  400.     return help(panel_sw->ts_windowfd, "compose", tool_help);
  401.     print("Composing letter.");
  402.     win_setcursor(msg_sw->ts_windowfd, &write_cursor);
  403.     do_mail(0, DUBL_NULL, NULL);
  404. }
  405.  
  406. change_font(item, value, event)
  407. Panel_item item;
  408. register int value;
  409. struct inputevent event;
  410. {
  411.     if (ison(glob_flags, IS_GETTING))
  412.     pw_char(msg_win, txt.x, txt.y, PIX_SRC^PIX_DST, fonts[curfont], '_');
  413.     curfont = value % total_fonts;
  414.     print("New font: %s\n",
  415.         (!curfont)? "Normal": (curfont == 1)? "Small": "Large");
  416.     if (ison(glob_flags, IS_GETTING))
  417.     pw_char(msg_win, txt.x, txt.y, PIX_SRC^PIX_DST, fonts[curfont], '_');
  418.     crt = msg_rect.r_height / l_height(curfont);
  419. }
  420.