home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / options.c < prev    next >
C/C++ Source or Header  |  1992-03-15  |  12KB  |  407 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: options.c,v 4.1 90/04/28 22:43:38 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  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:    options.c,v $
  17.  * Revision 4.1  90/04/28  22:43:38  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** This set of routines allows the alteration of a number of paramaters
  24.     in the Elm mailer, including the following;
  25.  
  26.     calendar-file    <where to put calendar entries>
  27.     display pager    <how to page messages>
  28.     editor        <name of composition editor>
  29.     folder-dir    <folder directory>
  30.     sort-by        <how to sort folders>
  31.     sent-mail    <file to save outbound message copies to>
  32.     printmail    <how to print messages>
  33.     full_username    <your full user name for outgoing mail>
  34.  
  35.     arrow-cursor    <on or off>
  36.     menu-display    <on or off>
  37.  
  38.     user-level    <BEGINNER|INTERMEDIATE|EXPERT>
  39.         names-only      <on or off>
  40.  
  41.     And others as they seem useful.
  42.  
  43. **/
  44.  
  45. #include "headers.h"
  46.  
  47. #ifdef BSD
  48. #undef tolower
  49. #endif
  50.  
  51. #undef onoff
  52. #define   onoff(n)    (n == 1? "ON ":"OFF")
  53.  
  54. char *one_liner_for(), *level_name();
  55. unsigned long sleep();
  56.  
  57. options()
  58. {
  59.     /** change options... **/
  60.     /* return:
  61.      *    > 0    if restort was done - to indicate we might need to
  62.      *         change the page of our headers as a consequence
  63.      *        of the new sort order
  64.      *    < 0    if user entered 'x' to quit elm immediately
  65.      *    0    otherwise
  66.      */
  67.  
  68.     int    ch,
  69.              resort = 0;
  70.     char    *strcpy(),
  71.              temp[SLEN];    /* needed when an option is run through
  72.                  * expand_env(), because that function
  73.                  * is destructive of the original
  74.                  */
  75.  
  76.     display_options();
  77.  
  78.     clearerr(stdin);
  79.  
  80.     while(1) {
  81.       ClearLine(LINES-4);
  82.  
  83.       Centerline(LINES-4,
  84.  "Select first letter of option line, '>' to save, or 'i' to return to index.");
  85.  
  86.       PutLine0(LINES-2, 0, "Command: ");
  87.  
  88.       ch = ReadCh();
  89.       ch = tolower(ch);
  90.  
  91.       clear_error();    /* remove possible "sorting" message etc... */
  92.  
  93.       one_liner(one_liner_for(ch));
  94.  
  95.       switch (ch) {
  96.         case 'c' : optionally_enter(raw_calendar_file, 2, 23, FALSE, FALSE);
  97.                strcpy(temp, raw_calendar_file);
  98.                expand_env(calendar_file, temp);
  99.                break;
  100.         case 'd' : optionally_enter(raw_pager, 3, 23, FALSE, FALSE);
  101.                strcpy(temp, raw_pager);
  102.                expand_env(pager, temp);
  103.                clear_pages = (equal(pager, "builtin+") ||
  104.                          equal(pager, "internal+"));
  105.                break;
  106.         case 'e' : optionally_enter(raw_editor, 4, 23, FALSE, FALSE);
  107.                strcpy(temp, raw_editor);
  108.                expand_env(editor, temp);
  109.                    break;
  110.         case 'f' : optionally_enter(raw_folders, 5, 23, FALSE, FALSE);
  111.                strcpy(temp, raw_folders);
  112.                expand_env(folders, temp);
  113.                break;
  114.         case 's' : if(change_sort(6,23)) resort++;            break;
  115.         case 'o' : optionally_enter(raw_sentmail, 7, 23, FALSE, FALSE);
  116.                strcpy(temp, raw_sentmail);
  117.                expand_env(sent_mail, temp);
  118.                break;
  119.         case 'p' : optionally_enter(raw_printout, 8, 23, FALSE, FALSE);
  120.                strcpy(temp, raw_printout);
  121.                expand_env(printout, temp);
  122.                break;
  123.         case 'y' : optionally_enter(full_username, 9, 23, FALSE, FALSE);
  124.                break;
  125.         case 'a' : on_or_off(&arrow_cursor, 12, 23);         break;
  126.         case 'm' : on_or_off(&mini_menu, 13, 23);
  127.                headers_per_page = LINES - (mini_menu ? 13 : 8); break;
  128.  
  129.         case 'u' : switch_user_level(&user_level,15, 23);        break;
  130.         case 'n' : on_or_off(&names_only, 16, 23);            break;
  131.  
  132.         case '?' : options_help();
  133.                    PutLine0(LINES-2,0,"Command: ");            break;
  134.  
  135.         case '>' : printf("Save options in .elm/elmrc...");
  136.                fflush(stdout);    save_options();        break;
  137.  
  138.         case 'x' :    return(-1);    /* exit elm */
  139.         case 'q' :    /* pop back up to previous level, in this case == 'i' */
  140.         case 'i' :  /* return to index screen */
  141.             return(resort ? 1 : 0);
  142.         case ctrl('L'): display_options();                break;
  143.         default: error("Command unknown!");
  144.       }
  145.  
  146.     }
  147. }
  148.  
  149. display_options()
  150. {
  151.     /** Display all the available options.. **/
  152.  
  153.     char *sort_name();
  154.  
  155.     ClearScreen();
  156.     Centerline(0,"-- ELM Options Editor --");
  157.  
  158. #ifdef ENABLE_CALENDAR
  159.     PutLine1(2, 0, "C)alendar file       : %s", raw_calendar_file);
  160. #endif
  161.     PutLine1(3, 0, "D)isplay mail using  : %s", raw_pager);
  162.     PutLine1(4, 0, "E)ditor              : %s", raw_editor);
  163.     PutLine1(5, 0, "F)older directory    : %s", raw_folders);
  164.     PutLine1(6, 0, "S)orting criteria    : %s", sort_name(FULL));
  165.     PutLine1(7, 0, "O)utbound mail saved : %s", raw_sentmail);
  166.     PutLine1(8, 0, "P)rint mail using    : %s", raw_printout);
  167.     PutLine1(9, 0, "Y)our full name      : %s", full_username);
  168.  
  169.     PutLine1(12,0, "A)rrow cursor        : %s", onoff(arrow_cursor));
  170.     PutLine1(13,0, "M)enu display        : %s", onoff(mini_menu));
  171.  
  172.     PutLine1(15,0, "U)ser level          : %s", level_name(user_level));
  173.     PutLine1(16,0, "N)ames only          : %s", onoff(names_only));
  174. }
  175.  
  176. on_or_off(var, x, y)
  177. int *var, x,y;
  178. {
  179.     /** 'var' field at x.y toggles between on and off... **/
  180.  
  181.     char ch;
  182.  
  183.          PutLine0(x, y+6,
  184.         "(use <space> to toggle, any other key to leave)");
  185.  
  186.     MoveCursor(x,y+3);    /* at end of value... */
  187.  
  188.     do {
  189.       ch = ReadCh();
  190.  
  191.       if (ch == SPACE) {
  192.         *var = ! *var;
  193.         PutLine0(x,y, onoff(*var));
  194.       }
  195.     } while (ch == SPACE);
  196.  
  197.     MoveCursor(x,y+4);     CleartoEOLN();    /* remove help prompt */
  198. }
  199.  
  200.  
  201. switch_user_level(ulevel, x, y)
  202. int *ulevel, x, y;
  203. {
  204.     /** step through possible user levels... **/
  205.  
  206.          PutLine0(x, y+20, "<space> to change");
  207.  
  208.     MoveCursor(x,y);    /* at end of value... */
  209.  
  210.     while (ReadCh() == ' ') {
  211.       *ulevel = (*ulevel >= 2? 0 : *ulevel + 1);
  212.       PutLine1(x,y, "%s", level_name(*ulevel));
  213.     }
  214.  
  215.     MoveCursor(x,y+20);     CleartoEOLN();    /* remove help prompt */
  216. }
  217.  
  218. change_sort(x, y)
  219. int x,y;
  220. {
  221.     char *sort_name();
  222.     /** change the sorting scheme... **/
  223.     /** return !0 if new sort order, else 0 **/
  224.  
  225.     int last_sortby,    /* so we know if it changes... */
  226.         sign = 1;        /* are we reverse sorting??    */
  227.     int ch;            /* character typed in ...      */
  228.  
  229.     last_sortby = sortby;    /* remember current ordering   */
  230.  
  231.     PutLine0(x, COLUMNS-29, "(SPACE for next, or R)everse)");
  232.     sort_one_liner(sortby);
  233.     MoveCursor(x, y);
  234.  
  235.     do {
  236.       ch = ReadCh();
  237.       ch = tolower(ch);
  238.       switch (ch) {
  239.         case SPACE : if (sortby < 0) {
  240.                    sign = -1;
  241.                    sortby = - sortby;
  242.                }
  243.              else sign = 1;        /* insurance! */
  244.                sortby = sign * ((sortby + 1) % (STATUS+2));
  245.              if (sortby == 0) sortby = sign;  /* snicker */
  246.                PutLine0(x, y, sort_name(PAD));
  247.              sort_one_liner(sortby);
  248.                MoveCursor(x, y);
  249.              break;
  250.  
  251.         case 'r'   : sortby = - sortby;
  252.                PutLine0(x, y, sort_name(PAD));
  253.              sort_one_liner(sortby);
  254.                MoveCursor(x, y);
  255.      }
  256.         } while (ch == SPACE || ch == 'r');
  257.  
  258.     MoveCursor(x, COLUMNS-30);    CleartoEOLN();
  259.  
  260.     if (sortby != last_sortby) {
  261.       error("Resorting folder...");
  262.       sleep(1);
  263.       sort_mailbox(message_count, 0);
  264.     }
  265.     ClearLine(LINES-2);        /* clear sort_one_liner()! */
  266.     return(sortby-last_sortby);
  267. }
  268.  
  269. one_liner(string)
  270. char *string;
  271. {
  272.     /** A single-line description of the selected item... **/
  273.  
  274.     ClearLine(LINES-4);
  275.     if (string)
  276.         Centerline(LINES-4, string);
  277. }
  278.  
  279. sort_one_liner(sorting_by)
  280. int sorting_by;
  281. {
  282.     /** A one line summary of the particular sorting scheme... **/
  283.  
  284.     ClearLine(LINES-2);
  285.  
  286.     switch (sorting_by) {
  287.  
  288.       case -SENT_DATE : Centerline(LINES-2,
  289. "This sort will order most-recently-sent to least-recently-sent");    break;
  290.       case -RECEIVED_DATE : Centerline(LINES-2,
  291. "This sort will order most-recently-received to least-recently-received");
  292.                  break;
  293.       case -MAILBOX_ORDER : Centerline(LINES-2,
  294. "This sort will order most-recently-added-to-folder to least-recently");
  295.                  break;
  296.       case -SENDER : Centerline(LINES-2,
  297. "This sort will order by sender name, in reverse alphabetical order");    break;
  298.       case -SIZE   : Centerline(LINES-2,
  299. "This sort will order messages by longest to shortest");        break;
  300.       case -SUBJECT : Centerline(LINES-2,
  301. "This sort will order by subject, in reverse alphabetical order");    break;
  302.       case -STATUS  : Centerline(LINES-2,
  303. "This sort will order by reverse status - Deleted through Tagged...");    break;
  304.  
  305.       case SENT_DATE : Centerline(LINES-2,
  306. "This sort will order least-recently-sent to most-recently-sent");    break;
  307.       case RECEIVED_DATE : Centerline(LINES-2,
  308. "This sort will order least-recently-received to most-recently-received");
  309.                         break;
  310.       case MAILBOX_ORDER : Centerline(LINES-2,
  311. "This sort will order least-recently-added-to-folder to most-recently");
  312.                  break;
  313.       case SENDER : Centerline(LINES-2,
  314.                 "This sort will order by sender name");    break;
  315.       case SIZE   : Centerline(LINES-2,
  316.                 "This sort will order messages by shortest to longest");
  317.             break;
  318.       case SUBJECT : Centerline(LINES-2,
  319.                     "This sort will order messages by subject");    break;
  320.       case STATUS  : Centerline(LINES-2,
  321. "This sort will order by status - Tagged through Deleted...");        break;
  322.     }
  323. }
  324.  
  325. char *one_liner_for(c)
  326. char c;
  327. {
  328.     /** returns the one-line description of the command char... **/
  329.  
  330.     switch (c) {
  331.         case 'c' : return(
  332. "This is the file where calendar entries from messages are saved.");
  333.  
  334.         case 'd' : return(
  335. "This is the program invoked to display individual messages (try 'builtin')");
  336.  
  337.         case 'e' : return(
  338. "This is the editor that will be used for sending messages, etc.");
  339.  
  340.         case 'f' : return(
  341. "This is the folders directory used when '=' (etc) is used in filenames");
  342.  
  343.         case 'm' : return(
  344. "This determines if you have the mini-menu displayed or not");
  345.  
  346.         case 'n' : return(
  347. "Whether to display the names and addresses on mail, or names only");
  348.         case 'o' : return(
  349. "This is where copies of outbound messages are saved automatically.");
  350.  
  351.         case 'p' : return(
  352. "This is how printouts are generated.  \"%s\" will be replaced by the filename.");
  353.  
  354.         case 's' : return(
  355. "This is used to specify the sorting criteria for the folders");
  356.  
  357.         case 'y' : return(
  358. "When mail is sent out, this is what your full name will be recorded as.");
  359.  
  360.         case 'a' : return(
  361. "This defines whether the ELM cursor is an arrow or a highlight bar.");
  362.  
  363.        case 'u' : return(
  364. "The level of knowledge you have about the ELM mail system.");
  365.  
  366.         default : return(NULL);    /* nothing if we don't know! */
  367.     }
  368. }
  369.  
  370. options_help()
  371. {
  372.     /** help menu for the options screen... **/
  373.  
  374.     char c, *ptr;
  375.  
  376.     Centerline(LINES-3,
  377.   "Press the key you want help for, '?' for a key list, or '.' to exit help");
  378.  
  379.     lower_prompt("Key : ");
  380.  
  381.     while ((c = ReadCh()) != '.') {
  382.       c = tolower(c);
  383.       if (c == '?') {
  384.          display_helpfile(OPTIONS_HELP);
  385.          display_options();
  386.          return;
  387.       }
  388.       if ((ptr = one_liner_for(c)) != NULL)
  389.         error2("%c = %s.", c, ptr);
  390.       else
  391.         error1("%c isn't used in this section.", c);
  392.       lower_prompt("Key : ");
  393.     }
  394. }
  395.  
  396. char *level_name(n)
  397. int n;
  398. {
  399.     /** return the 'name' of the level... **/
  400.  
  401.     switch (n) {
  402.       case 0 : return("Beginning User   ");
  403.       case 1 : return("Intermediate User");
  404.       default: return("Expert User      ");
  405.     }
  406. }
  407.