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