home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / mush5.7 / part12 / viewopts.c < prev   
Encoding:
C/C++ Source or Header  |  1987-09-19  |  12.4 KB  |  352 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.     { "askcc", NULL, TOOL | TEXT,
  27.       "Ask for list of Carbon Copy recipients whenever sending mail.", },
  28.     { "autodelete", NULL, TOOL | TEXT,
  29.       "Automatically delete ALL READ messages whenever you update mail.", },
  30.     { "autoedit", NULL, TOOL | TEXT,
  31.       "Automatically enter editor whenever you REPLY to mail.", },
  32.     { "autoinclude", NULL, TOOL | TEXT,
  33.       "Include a copy of author's message each time you reply to mail." },
  34.     { "autoprint", NULL, TOOL | TEXT,
  35.       "Display the next message on the list when you delete a message." },
  36.     { "auto_route", NULL, TOOL | TEXT,
  37.       "Automatic optimization of uucp paths is done removing redundancies." },
  38.     { "autosign", "-Filename", TOOL | TEXT,
  39.       "Add file (~/.signature if set but no value) at end of all letters." },
  40.     { "crt", "Lines", TEXT,
  41.       "The number of lines a message must have for 'pager' to be invoked." },
  42.     { "dead", "Filename", TOOL | TEXT,
  43.       "The name of the file to store dead mail. ~/dead.letter by default." },
  44.     { "dot", NULL, TOOL | TEXT,
  45.       "allow \".\" on a line by itself to send letter." },
  46.     { "editor", "Editor name/path", TOOL | TEXT,
  47.       "editor to use by default. Default is evironment EDITOR or \"vi\"" },
  48.     { "escape", "Character", TOOL | TEXT,
  49.       "Escape character for extended editing commands. (default = ~)" },
  50.     { "fixaddr", NULL, TOOL | TEXT,
  51.       "makes \"replyall\" route recipient addresses through sender's host." },
  52.     { "folder", "Pathname", TOOL | TEXT,
  53.       "Full pathname to the directory where personal folders are kept." },
  54.     { "fortune", "-Flag", TOOL | TEXT,
  55.       "Add fortune to end of letters. Flag to \"fortune\" is optional" },
  56.     { "fortunates", "Users", TOOL | TEXT,
  57.       "Those who will receive fortunes if fortune is set (default: All)." },
  58.     { "hdr_format", "Format", TOOL | TEXT,
  59.       "Formatting string for headers. \"headers -?\" or help hdr_format" },
  60.     { "history", "Number", TEXT,
  61.       "How many commands to remember (like csh)." },
  62.     { "hold", NULL, TOOL | TEXT,
  63.       "Read but not deleted messages are saved in spool -- not mbox." },
  64.     { "ignore_bang", NULL, TEXT,
  65.       "Ignore '!' as a history reference. Otherwise, escape by: \\!" },
  66.     { "ignoreeof", "-Command", TEXT,
  67.       "Ignores ^D as exit, or (if set), execute \"command\"." },
  68.     { "indent_str", "String", TOOL | TEXT,
  69.       "String to offset included messages within your letter", },
  70.     { "in_reply_to", NULL, TOOL | TEXT,
  71.       "When responding to mail, add In-Reply-To: to message headers." },
  72.     { "keepsave", NULL, TOOL | TEXT,
  73.       "Prevents messages from being marked as `deleted' when you `save'." },
  74.     { "known_hosts", "Host list", TOOL | TEXT,
  75.       "List of hosts that your site is known to uucp mail to." },
  76.     { "lister", "Arguemnts", TOOL | TEXT,
  77.       "Arguments passed to the 'ls' command." },
  78.     { "mbox", "Filename", TOOL | TEXT,
  79.       "Filename to use instead of ~/mbox for default mailbox." },
  80.     { "metoo", NULL, TOOL | TEXT,
  81.       "When replying to mail, metoo preserves your name on mailing list." },
  82.     { "newline", "-Command", TEXT,
  83.       "Ignore RETURN. If set to a string, execute \"command\"" },
  84.     { "no_hdr", NULL, TOOL | TEXT,
  85.       "If set, personalized headers are NOT inserted to outgoing mail." },
  86.     { "no_reverse", NULL, TOOL | TEXT,
  87.       "disables reverse video in curses mode -- uses \"bold\" in tool mode." },
  88.     { "nosave", NULL, TOOL | TEXT,
  89.       "prevents aborted mail from being saved in dead.letter" },
  90.     { "pager", "Program", TEXT,
  91.       "Program name to be used as a pager for messages longer than crt." },
  92.     { "print_cmd", "Program", TOOL | TEXT,
  93.       "Alternate program to use to send messages to the printer." },
  94.     { "printer", "Printer", TOOL | TEXT,
  95.       "Printer to send messages to. Default is environment PRINTER" },
  96.     { "prompt", "String", TEXT,
  97.       "Your prompt.  \"help prompt\" for more information." },
  98.     { "quiet", NULL, TEXT,
  99.       "Don't print the version number of Mush on startup." },
  100.     { "record", "Filename", TOOL | TEXT,
  101.       "Save all outgoing mail in specified filename" },
  102.     { "reply_to_hdr", "Headers", TOOL | TEXT,
  103.       "List of headers to search in messages to construct reply adresses.", },
  104.     { "screen", "Number of Headers", TEXT,
  105.       "Number of headers to print in non-suntools (text) mode" },
  106.     { "screen_win", "Number of Headers", TOOL,
  107.       "Set the size of the header window." },
  108.     { "show_deleted", NULL, TOOL | TEXT,
  109.       "Show deleted messages in headers listings" },
  110.     { "sort", "-Option", TOOL | TEXT,
  111.       "Sorting upon startup of mail or `update/folder' (sort -? for help)" },
  112.     { "squeeze", NULL, TOOL | TEXT,
  113.       "When reading messages, squeeze all blank lines into one." },
  114.     { "top", "Lines", TOOL | TEXT,
  115.       "Number of lines to print of a message for the 'top' command."  },
  116.     { "unix", NULL, TEXT,
  117.       "Non-mush commands are considered to be UNIX commands." },
  118.     { "verify", NULL, TEXT,
  119.       "Verify to send, re-edit, or abort letter after editing." },
  120.     { "visual", "Visual editor", TOOL | TEXT,
  121.       "Visual editor to use by default. \"editor\" is used if not set." },
  122.     { "warning", NULL, TOOL | TEXT,
  123.       "Warns when standard variables are set differently from the default." }
  124. };
  125.  
  126. static int total_opts;
  127.  
  128. #ifdef NOT_NOW
  129. /*
  130.  * put all the tool stuff at the beginning, or all the text stuff at
  131.  * the beginning depending on whether or not we're running as a tool
  132.  * With all the inappropriate variables out of the way, we set total
  133.  * opts to the number of variables which are of the right type and
  134.  * nothing inappropriate will ever be displayed.
  135.  *
  136.  * Note, this doesn't really work right now and I don't wanna fix it now..
  137.  */
  138. static
  139. opt_eliminator(a, b)
  140. register struct viewopts *a, *b;
  141. {
  142.     if (istool)
  143.     return a->v_usage == TOOL;
  144.     return a->v_usage == TEXT;
  145. }
  146. #endif NOT_NOW
  147.  
  148. static
  149. opt_sorter(a, b)
  150. register struct viewopts *a, *b;
  151. {
  152.     return !strcmp(a->v_opt, b->v_opt);
  153. }
  154.  
  155. sort_variables()
  156. {
  157.     /*
  158.     register int optnum;
  159.  
  160.     for (optnum=0; optnum < sizeof viewopts / sizeof(struct viewopts); optnum++)
  161.     if (istool && viewopts[optnum].v_usage & TOOL
  162.         || !istool && viewopts[optnum].v_usage & TEXT)
  163.         total_opts++;
  164.     */
  165.     total_opts = sizeof viewopts / sizeof (struct viewopts);
  166.     qsort((char *)viewopts, sizeof viewopts / sizeof (struct viewopts),
  167.             sizeof(struct viewopts), opt_sorter);
  168. }
  169.  
  170. #ifdef SUNTOOL
  171.  
  172. static int start_cnt;
  173.  
  174. #define twenty     5 + 20*l_width(DEFAULT)
  175. #define forty     5 + 40*l_width(DEFAULT)
  176. #define image_at(x,y,image) pw_rop(msg_win, x, y, 16, 16, PIX_SRC, image, 0,0)
  177.  
  178. /* print in default text, but increment in large text segments */
  179. view_options()
  180. {
  181.     if (msg_rect.r_height < 80) {
  182.     print("Window not big enough to display options.");
  183.     return;
  184.     }
  185.     do_clear();
  186.     getting_opts = 1, start_cnt = 0;
  187.     win_setcursor(msg_sw->ts_windowfd, &checkmark);
  188.     highlight(msg_win, txt.x, txt.y, LARGE,
  189.         "    : Toggle Value       : Description       : Menu (Help)");
  190.     image_at(txt.x +  2 * l_width(DEFAULT), txt.y - 12, &mouse_left);
  191.     image_at(txt.x + 25 * l_width(DEFAULT), txt.y - 12, &mouse_middle);
  192.     image_at(txt.x + 48 * l_width(DEFAULT), txt.y - 12, &mouse_right);
  193.  
  194.     pw_vector(msg_win, 0, txt.y+6, msg_rect.r_width, txt.y+6, PIX_SRC, 1);
  195.     pw_vector(msg_win, 0, txt.y+8, msg_rect.r_width, txt.y+8, PIX_SRC, 1);
  196.  
  197.     txt.y += 24;
  198.  
  199.     pw_text(msg_win, 5,      txt.y, PIX_SRC, fonts[LARGE], "Option");
  200.     pw_text(msg_win, twenty, txt.y, PIX_SRC, fonts[LARGE], "On/Off");
  201.     pw_text(msg_win, forty,  txt.y, PIX_SRC, fonts[LARGE], "Values");
  202.  
  203.     pw_vector(msg_win, 0, txt.y+6, msg_rect.r_width, txt.y+6, PIX_SRC, 1);
  204.     pw_vector(msg_win, 0, txt.y+8, msg_rect.r_width, txt.y+8, PIX_SRC, 1);
  205.  
  206.     pw_text(msg_win, 59*l_width(DEFAULT),txt.y,PIX_SRC,fonts[LARGE],"Scroll:");
  207.     pw_rop(msg_win, 60*l_width(LARGE), txt.y-13,16,16,PIX_SRC, &dn_arrow,0,0);
  208.     pw_rop(msg_win, 60*l_width(LARGE)+20,txt.y-13,16,16,PIX_SRC, &up_arrow,0,0);
  209.  
  210.     display_opts(0); /* create the pixrect and all that */
  211. }
  212.  
  213. display_opts(count)
  214. register int count;
  215. {
  216.     register int total_displayable = (msg_rect.r_height - 60) / 20;
  217.  
  218.     if (count < 0 && start_cnt + count < 0) {
  219.     print("At the beginning");
  220.     return;
  221.     } else if (count && start_cnt + count + total_displayable > total_opts) {
  222.     print("At the end");
  223.     return;
  224.     }
  225.     start_cnt += count;
  226.     if (!msg_pix) {
  227.     register int x = (total_opts+1) * 20;
  228.     if (x < msg_rect.r_height)
  229.         x = msg_rect.r_height;
  230.     if (!(msg_pix = mem_create(msg_rect.r_width, x, 1))) {
  231.         error("mem_create");
  232.         return;
  233.     }
  234.     pr_rop(msg_pix,0,0, msg_rect.r_width-1, x-1, PIX_CLR,0,0,0);
  235.     for (count = 0; count < total_opts; count++)
  236.         option_line(count);
  237.     }
  238.     pw_rop(msg_win, 0, 50, msg_rect.r_width - 1, msg_rect.r_height - 50,
  239.        PIX_SRC, msg_pix, 0, start_cnt * 20);
  240. }
  241.  
  242. void
  243. toggle_opt(line)
  244. {
  245.     register char *p = viewopts[start_cnt+line].v_prompt;
  246.  
  247.     if (do_set(set_options, viewopts[start_cnt+line].v_opt))
  248.     un_set(&set_options, viewopts[start_cnt+line].v_opt);
  249.     else {
  250.     if (p) {
  251.         txt.x = 5 + 40 * l_width(DEFAULT) +
  252.             (1 + strlen(p) - (*p=='-')) * l_width(DEFAULT);
  253.         txt.y = 50 + line*20 + l_height(curfont);
  254.     }
  255.     if (!p || *p == '-') {
  256.         register char *argv[2];
  257.         argv[0] = viewopts[start_cnt+line].v_opt;
  258.         argv[1] = NULL;
  259.         (void) add_option(&set_options, argv);
  260.     }
  261.     }
  262.     option_line(line);
  263.     display_opts(0);
  264.     if (txt.x > 5)
  265.     pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[DEFAULT], '_');
  266. }
  267.  
  268. void
  269. help_opt(line)
  270. {
  271.     print(viewopts[start_cnt+line].v_description);
  272. }
  273.  
  274. add_opt(p, line)
  275. register char *p;
  276. {
  277.     char buf[80], **argv;
  278.     int argc, save_bang = ison(glob_flags, IGN_BANG);
  279.  
  280.     (void) sprintf(buf, "set %s=\"%s\"", viewopts[start_cnt+line].v_opt, p);
  281.     turnon(glob_flags, IGN_BANG);
  282.     if (argv = make_command(buf, DUBL_NULL, &argc))
  283.     (void) do_command(argc, argv, msg_list);
  284.     if (!save_bang)
  285.     turnoff(glob_flags, IGN_BANG);
  286.     option_line(line); /* make sure new value is entered into database */
  287. }
  288.  
  289. option_line(count)
  290. register int count;
  291. {
  292.     register char *p, *v = do_set(set_options, viewopts[start_cnt+count].v_opt);
  293.     struct pr_prpos win;
  294.  
  295.     win.pr = msg_pix;
  296.     win.pos.y = (start_cnt + count) * 20 + 16;
  297.     win.pos.x = 5;
  298.  
  299.     pf_text(win, PIX_SRC, fonts[DEFAULT], blank);
  300.     pf_text(win, PIX_SRC, fonts[DEFAULT], viewopts[start_cnt+count].v_opt);
  301.     win.pos.x = twenty+20;
  302.  
  303.     if (!(p = viewopts[start_cnt+count].v_prompt) || *p == '-') {
  304.     pr_rop(msg_pix, twenty, win.pos.y-10, 16, 16, PIX_SRC, &cycle, 0, 0);
  305.     pf_text(win, PIX_SRC, fonts[DEFAULT], (v)? "TRUE  ": "FALSE");
  306.     win.pos.x++;
  307.     pf_text(win, PIX_SRC, fonts[DEFAULT], (v)? "TRUE  ": "FALSE");
  308.     }
  309.     if (p) {
  310.     if (*p == '-')
  311.         p++;
  312.     win.pos.x = forty;
  313.     /* heighlight */
  314.     pf_text(win, PIX_SRC, fonts[DEFAULT], p);
  315.     win.pos.x++;
  316.     pf_text(win, PIX_SRC, fonts[DEFAULT], p);
  317.         win.pos.x = forty + strlen(p) * l_width(DEFAULT);
  318.     pf_text(win, PIX_SRC, fonts[DEFAULT], ":");
  319.     if (v) {
  320.         win.pos.x += (2 * l_width(DEFAULT));
  321.         pf_text(win, PIX_SRC, fonts[DEFAULT], v);
  322.     }
  323.     }
  324. }
  325.  
  326. #endif SUNTOOL
  327.  
  328. /*
  329.  * return a string describing a variable.
  330.  * parameters: count, str, buf.
  331.  * If str != NULL, check str against ALL variables
  332.  * in viewopts array.  The one that matches, set count to it and 
  333.  * print up all the stuff from the viewopts[count] into the buffer
  334.  * space in "buf" and return it.
  335.  */
  336. char *
  337. variable_stuff(count, str, buf)
  338. register char *str, buf[];
  339. {
  340.     if (str)
  341.     for (count = 0; count < total_opts; count++)
  342.         if (!strcmp(str, viewopts[count].v_opt))
  343.         break;
  344.     if (count >= total_opts) {
  345.     (void) sprintf(buf, "%s: Not a default %s variable.",
  346.                str? str : itoa(count), prog_name);
  347.     return NULL;
  348.     }
  349.     return sprintf(buf, "%12.12s: %s",
  350.     viewopts[count].v_opt, viewopts[count].v_description);
  351. }
  352.