home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / mush6.0 / part05 / viewopts.c < prev   
Encoding:
C/C++ Source or Header  |  1988-04-12  |  12.3 KB  |  329 lines

  1. /* @(#)viewopts.c    (c) copyright    10/18/86 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4.  
  5. struct viewopts {
  6.     char *v_opt;
  7.     char *v_prompt;
  8.     int  v_usage;
  9. #define TOOL  01
  10. #define TEXT  02
  11.     char *v_description;
  12. };
  13.  
  14. /*
  15.  * struct contains the option, a prompt if it has a string value, whether
  16.  * or not it applies to non suntools, line mode, or both, and a
  17.  * string describing what the option does. If the prompt string starts
  18.  * with a minus sign, then the value can be set without a value. This
  19.  * is there to indicate to option_line to print a toggle (cycle) pixrect
  20.  * and to print TRUE/FALSE telling whether the value is on or off regardless
  21.  * of it's "string" value.
  22.  */
  23. struct viewopts viewopts[] = {
  24.     { "alwaysignore", NULL, TOOL | TEXT,
  25.       "alwaysignore the message headers on the 'ignored' list." },
  26.     { "ask", NULL, TOOL | TEXT,
  27.       "Prompts for a subject on outgoing mail." },
  28.     { "askcc", NULL, TOOL | TEXT,
  29.       "Ask for list of Carbon Copy recipients whenever sending mail.", },
  30.     { "autodelete", NULL, TOOL | TEXT,
  31.       "Automatically delete ALL READ messages whenever you update mail.", },
  32.     { "autoedit", NULL, TOOL | TEXT,
  33.       "Automatically enter editor whenever you REPLY to mail.", },
  34.     { "autoinclude", NULL, TOOL | TEXT,
  35.       "Include a copy of author's message each time you reply to mail." },
  36.     { "autoprint", NULL, TOOL | TEXT,
  37.       "Display the next message on the list when you delete a message." },
  38.     { "auto_route", NULL, TOOL | TEXT,
  39.       "Remove redundant uucp addresses when replying to messages." },
  40.     { "autosign", "-Filename", TOOL | TEXT,
  41.       "Add file (~/.signature if set but no value) at end of all letters." },
  42.     { "autosign2", "Address : Filename", TOOL | TEXT,
  43.       "signature to use for specific addresses. \"addr, ... : <signature>\"", },
  44.     { "cdpath", "Path", TEXT,
  45.       "Path to search for directories when the \"cd\" command is issued." },
  46.     { "crt", "Lines", TEXT,
  47.       "The number of lines a message must have for 'pager' to be invoked." },
  48.     { "dead", "Filename", TOOL | TEXT,
  49.       "The name of the file to store dead mail. ~/dead.letter by default." },
  50.     { "dot", NULL, TOOL | TEXT,
  51.       "allow \".\" on a line by itself to send letter." },
  52.     { "editor", "Editor name/path", TOOL | TEXT,
  53.       "editor to use by default. Default is evironment EDITOR or \"vi\"" },
  54.     { "escape", "Character", TOOL | TEXT,
  55.       "Escape character for extended editing commands. (default = ~)" },
  56.     { "folder", "Pathname", TOOL | TEXT,
  57.       "Full pathname to the directory where personal folders are kept." },
  58.     { "fortune", "-Flag", TOOL | TEXT,
  59.       "Add fortune to end of letters. Flag to \"fortune\" is optional" },
  60.     { "fortunates", "Users", TOOL | TEXT,
  61.       "Those who will receive fortunes if fortune is set (default: All)." },
  62.     { "hdr_format", "Format", TOOL | TEXT,
  63.       "Formatting string for headers. \"headers -?\" or help hdr_format" },
  64.     { "history", "Number", TEXT,
  65.       "How many commands to remember (like csh)." },
  66.     { "hold", NULL, TOOL | TEXT,
  67.       "Read but not deleted messages are saved in spool -- not mbox." },
  68.     { "ignore_bang", NULL, TEXT,
  69.       "Ignore '!' as a history reference. Otherwise, escape by: \\!" },
  70.     { "ignoreeof", "-Command", TEXT,
  71.       "Ignores ^D as exit, or (if set), execute \"command\"." },
  72.     { "indent_str", "String", TOOL | TEXT,
  73.       "String to offset included messages within your letter", },
  74.     { "in_reply_to", NULL, TOOL | TEXT,
  75.       "When responding to mail, add In-Reply-To: to message headers." },
  76.     { "keepsave", NULL, TOOL | TEXT,
  77.       "Prevents messages from being marked as `deleted' when you `save'." },
  78.     { "known_hosts", "Host list", TOOL | TEXT,
  79.       "List of hosts that your site is known to uucp mail to." },
  80.     { "lister", "Arguemnts", TOOL | TEXT,
  81.       "Arguments passed to the 'ls' command." },
  82.     { "mbox", "Filename", TOOL | TEXT,
  83.       "Filename to use instead of ~/mbox for default mailbox." },
  84.     { "metoo", NULL, TOOL | TEXT,
  85.       "When replying to mail, metoo preserves your name on mailing list." },
  86.     { "mil_time", NULL, TOOL | TEXT,
  87.       "24-hour military time format is used whenever a time is printed. " },
  88.     { "newline", "-Command", TEXT,
  89.       "Ignore RETURN. If set to a string, execute \"command\"" },
  90.     { "no_expand", NULL, TEXT | TOOL,
  91.       "Prevents expansion of Mush aliases in outgoing mail." },
  92.     { "no_hdr", NULL, TOOL | TEXT,
  93.       "If set, personalized headers are NOT inserted to outgoing mail." },
  94.     { "no_reverse", NULL, TOOL | TEXT,
  95.       "disables reverse video in curses mode -- uses \"bold\" in tool mode." },
  96.     { "nosave", NULL, TOOL | TEXT,
  97.       "prevents aborted mail from being saved in dead.letter" },
  98.     { "pager", "Program", TEXT,
  99.       "Program name to be used as a pager for messages longer than crt." },
  100.     { "pre_indent_str", "String", TEXT | TOOL,
  101.       "String to precede interpolated message text into message body." },
  102.     { "post_indent_str", "String", TEXT | TOOL,
  103.       "String to succeed interpolated message text into message body." },
  104.     { "print_cmd", "Program", TOOL | TEXT,
  105.       "Alternate program to use to send messages to the printer." },
  106.     { "printer", "Printer", TOOL | TEXT,
  107.       "Printer to send messages to. Default is environment PRINTER" },
  108.     { "prompt", "String", TEXT,
  109.       "Your prompt.  \"help prompt\" for more information." },
  110.     { "quiet", NULL, TEXT,
  111.       "Don't print the version number of Mush on startup." },
  112.     { "record", "Filename", TOOL | TEXT,
  113.       "Save all outgoing mail in specified filename" },
  114.     { "reply_to_hdr", "Headers", TOOL | TEXT,
  115.       "List of headers use to construct reply adresses from a message.", },
  116.     { "screen", "Number of Headers", TEXT,
  117.       "Number of headers to print in non-suntools (text) mode" },
  118.     { "screen_win", "Number of Headers", TOOL,
  119.       "Set the size of the header window for the tool mode only." },
  120.     { "show_deleted", NULL, TOOL | TEXT,
  121.       "Show deleted messages in headers listings (unused in curses mode)" },
  122.     { "show_hdrs", "Headers", TOOL | TEXT,
  123.       "When displaying a message, show list of \"headers\" only." },
  124.     { "sendmail", "Program", TOOL | TEXT,
  125.       "Program to use to deliver mail instead of using the default."},
  126.     { "sort", "-Option", TOOL | TEXT,
  127.       "Pre-sorting of messages on program startup (set to valid sort option)" },
  128.     { "squeeze", NULL, TOOL | TEXT,
  129.       "When reading messages, squeeze all blank lines into one." },
  130.     { "top", "Lines", TOOL | TEXT,
  131.       "Number of lines to print of a message for the 'top' command."  },
  132.     { "unix", NULL, TEXT,
  133.       "Non-mush commands are considered to be UNIX commands." },
  134.     { "verify", NULL, TEXT,
  135.       "Verify to send, re-edit, or abort letter after editing." },
  136.     { "visual", "Visual editor", TOOL | TEXT,
  137.       "Visual editor to use by default. \"editor\" is used if not set." },
  138.     { "warning", NULL, TOOL | TEXT,
  139.       "Print warning messages for non-fatal errors." },
  140.     { "wrap", NULL, TOOL | TEXT,
  141.       "After referencing last message, message pointer wraps to start." }
  142. };
  143.  
  144. #define total_opts (sizeof viewopts / sizeof (struct viewopts))
  145.  
  146. #ifdef SUNTOOL
  147.  
  148. static int start_cnt;
  149.  
  150. #define twenty     5 + 20*l_width(DEFAULT)
  151. #define forty     5 + 40*l_width(DEFAULT)
  152. #define image_at(x,y,image) pw_rop(msg_win, x, y, 16, 16, PIX_SRC, image, 0,0)
  153.  
  154. /* print in default text, but increment in large text segments */
  155. view_options()
  156. {
  157.     if (msg_rect.r_height < 80) {
  158.     print("Window not big enough to display options.");
  159.     return;
  160.     }
  161.     do_clear();
  162.     getting_opts = 1, start_cnt = 0;
  163.     win_setcursor(msg_sw->ts_windowfd, &checkmark);
  164.     highlight(msg_win, txt.x, txt.y, LARGE,
  165.         "    : Toggle Value       : Description       : Menu (Help)");
  166.     image_at(txt.x +  2 * l_width(DEFAULT), txt.y - 12, &mouse_left);
  167.     image_at(txt.x + 25 * l_width(DEFAULT), txt.y - 12, &mouse_middle);
  168.     image_at(txt.x + 48 * l_width(DEFAULT), txt.y - 12, &mouse_right);
  169.  
  170.     pw_vector(msg_win, 0, txt.y+6, msg_rect.r_width, txt.y+6, PIX_SRC, 1);
  171.     pw_vector(msg_win, 0, txt.y+8, msg_rect.r_width, txt.y+8, PIX_SRC, 1);
  172.  
  173.     txt.y += 24;
  174.  
  175.     pw_text(msg_win, 5,      txt.y, PIX_SRC, fonts[LARGE], "Option");
  176.     pw_text(msg_win, twenty, txt.y, PIX_SRC, fonts[LARGE], "On/Off");
  177.     pw_text(msg_win, forty,  txt.y, PIX_SRC, fonts[LARGE], "Values");
  178.  
  179.     pw_vector(msg_win, 0, txt.y+6, msg_rect.r_width, txt.y+6, PIX_SRC, 1);
  180.     pw_vector(msg_win, 0, txt.y+8, msg_rect.r_width, txt.y+8, PIX_SRC, 1);
  181.  
  182.     pw_text(msg_win, 59*l_width(DEFAULT),txt.y,PIX_SRC,fonts[LARGE],"Scroll:");
  183.     pw_rop(msg_win, 60*l_width(LARGE), txt.y-13,16,16,PIX_SRC, &dn_arrow,0,0);
  184.     pw_rop(msg_win, 60*l_width(LARGE)+20,txt.y-13,16,16,PIX_SRC, &up_arrow,0,0);
  185.  
  186.     display_opts(0); /* create the pixrect and all that */
  187. }
  188.  
  189. display_opts(count)
  190. register int count;
  191. {
  192.     register int total_displayable = (msg_rect.r_height - 60) / 20;
  193.  
  194.     if (count < 0 && start_cnt + count < 0) {
  195.     print("At the beginning");
  196.     return;
  197.     } else if (count && start_cnt + count + total_displayable > total_opts) {
  198.     print("At the end");
  199.     return;
  200.     }
  201.     start_cnt += count;
  202.     if (!msg_pix) {
  203.     register int x = (total_opts+1) * 20;
  204.     if (x < msg_rect.r_height)
  205.         x = msg_rect.r_height;
  206.     if (!(msg_pix = mem_create(msg_rect.r_width, x, 1))) {
  207.         error("mem_create");
  208.         return;
  209.     }
  210.     pr_rop(msg_pix,0,0, msg_rect.r_width-1, x-1, PIX_CLR,0,0,0);
  211.     for (count = 0; count < total_opts; count++)
  212.         option_line(count);
  213.     }
  214.     pw_rop(msg_win, 0, 50, msg_rect.r_width - 1, msg_rect.r_height - 50,
  215.        PIX_SRC, msg_pix, 0, start_cnt * 20);
  216. }
  217.  
  218. void
  219. toggle_opt(line)
  220. {
  221.     register char *p = viewopts[start_cnt+line].v_prompt;
  222.  
  223.     if (do_set(set_options, viewopts[start_cnt+line].v_opt))
  224.     un_set(&set_options, viewopts[start_cnt+line].v_opt);
  225.     else {
  226.     if (p) {
  227.         txt.x = 5 + 40 * l_width(DEFAULT) +
  228.             (1 + strlen(p) - (*p=='-')) * l_width(DEFAULT);
  229.         txt.y = 50 + line*20 + l_height(curfont);
  230.     }
  231.     if (!p || *p == '-') {
  232.         register char *argv[2];
  233.         argv[0] = viewopts[start_cnt+line].v_opt;
  234.         argv[1] = NULL;
  235.         (void) add_option(&set_options, argv);
  236.     }
  237.     }
  238.     option_line(line);
  239.     display_opts(0);
  240.     if (txt.x > 5)
  241.     type_cursor(PIX_SRC);
  242. }
  243.  
  244. void
  245. help_opt(line)
  246. {
  247.     print(viewopts[start_cnt+line].v_description);
  248. }
  249.  
  250. add_opt(p, line)
  251. register char *p;
  252. {
  253.     char buf[80], **argv;
  254.     int argc;
  255.     u_long save_bang = ison(glob_flags, IGN_BANG);
  256.  
  257.     (void) sprintf(buf, "set %s=\"%s\"", viewopts[start_cnt+line].v_opt, p);
  258.     turnon(glob_flags, IGN_BANG);
  259.     if (argv = make_command(buf, DUBL_NULL, &argc))
  260.     (void) do_command(argc, argv, msg_list);
  261.     if (!save_bang)
  262.     turnoff(glob_flags, IGN_BANG);
  263.     option_line(line); /* make sure new value is entered into database */
  264. }
  265.  
  266. option_line(count)
  267. register int count;
  268. {
  269.     register char *p, *v = do_set(set_options, viewopts[start_cnt+count].v_opt);
  270.     struct pr_prpos win;
  271.  
  272.     win.pr = msg_pix;
  273.     win.pos.y = (start_cnt + count) * 20 + 16;
  274.     win.pos.x = 5;
  275.  
  276.     pf_text(win, PIX_SRC, fonts[DEFAULT], blank);
  277.     pf_text(win, PIX_SRC, fonts[DEFAULT], viewopts[start_cnt+count].v_opt);
  278.     win.pos.x = twenty+20;
  279.  
  280.     if (!(p = viewopts[start_cnt+count].v_prompt) || *p == '-') {
  281.     pr_rop(msg_pix, twenty, win.pos.y-10, 16, 16, PIX_SRC, &cycle, 0, 0);
  282.     pf_text(win, PIX_SRC, fonts[DEFAULT], (v)? "TRUE  ": "FALSE");
  283.     win.pos.x++;
  284.     pf_text(win, PIX_SRC, fonts[DEFAULT], (v)? "TRUE  ": "FALSE");
  285.     }
  286.     if (p) {
  287.     if (*p == '-')
  288.         p++;
  289.     win.pos.x = forty;
  290.     /* heighlight */
  291.     pf_text(win, PIX_SRC, fonts[DEFAULT], p);
  292.     win.pos.x++;
  293.     pf_text(win, PIX_SRC, fonts[DEFAULT], p);
  294.         win.pos.x = forty + strlen(p) * l_width(DEFAULT);
  295.     pf_text(win, PIX_SRC, fonts[DEFAULT], ":");
  296.     if (v) {
  297.         win.pos.x += (2 * l_width(DEFAULT));
  298.         pf_text(win, PIX_SRC, fonts[DEFAULT], v);
  299.     }
  300.     }
  301. }
  302.  
  303. #endif /* SUNTOOL */
  304.  
  305. /*
  306.  * return a string describing a variable.
  307.  * parameters: count, str, buf.
  308.  * If str != NULL, check str against ALL variables
  309.  * in viewopts array.  The one that matches, set count to it and 
  310.  * print up all the stuff from the viewopts[count] into the buffer
  311.  * space in "buf" and return it.
  312.  */
  313. char *
  314. variable_stuff(count, str, buf)
  315. register char *str, buf[];
  316. {
  317.     if (str)
  318.     for (count = 0; count < total_opts; count++)
  319.         if (!strcmp(str, viewopts[count].v_opt))
  320.         break;
  321.     if (count >= total_opts) {
  322.     (void) sprintf(buf, "%s: Not a default %s variable.",
  323.                str? str : itoa(count), prog_name);
  324.     return NULL;
  325.     }
  326.     return sprintf(buf, "%s: %s",
  327.     viewopts[count].v_opt, viewopts[count].v_description);
  328. }
  329.