home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / options.c < prev    next >
C/C++ Source or Header  |  1991-11-26  |  11KB  |  406 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.     /** change the sorting scheme... **/
  222.     /** return !0 if new sort order, else 0 **/
  223.     
  224.     int last_sortby,    /* so we know if it changes... */
  225.         sign = 1;        /* are we reverse sorting??    */
  226.     int ch;            /* character typed in ...      */
  227.  
  228.     last_sortby = sortby;    /* remember current ordering   */
  229.  
  230.     PutLine0(x, COLUMNS-29, "(SPACE for next, or R)everse)");
  231.     sort_one_liner(sortby);
  232.     MoveCursor(x, y);
  233.  
  234.     do {
  235.       ch = ReadCh();
  236.       ch = tolower(ch);
  237.       switch (ch) {
  238.         case SPACE : if (sortby < 0) { 
  239.                    sign = -1; 
  240.                    sortby = - sortby; 
  241.                }
  242.              else sign = 1;        /* insurance! */
  243.                sortby = sign * ((sortby + 1) % (STATUS+2));
  244.              if (sortby == 0) sortby = sign;  /* snicker */
  245.                PutLine0(x, y, sort_name(PAD));
  246.              sort_one_liner(sortby);
  247.                MoveCursor(x, y);
  248.              break;
  249.  
  250.         case 'r'   : sortby = - sortby;
  251.                PutLine0(x, y, sort_name(PAD));
  252.              sort_one_liner(sortby);
  253.                MoveCursor(x, y);
  254.      }
  255.         } while (ch == SPACE || ch == 'r');
  256.  
  257.     MoveCursor(x, COLUMNS-30);    CleartoEOLN();
  258.  
  259.     if (sortby != last_sortby) {
  260.       error("Resorting folder...");
  261.       sleep(1);
  262.       sort_mailbox(message_count, 0);
  263.     }
  264.     ClearLine(LINES-2);        /* clear sort_one_liner()! */
  265.     return(sortby-last_sortby);
  266. }
  267.  
  268. one_liner(string)
  269. char *string;
  270. {
  271.     /** A single-line description of the selected item... **/
  272.  
  273.     ClearLine(LINES-4);
  274.     if (string)
  275.         Centerline(LINES-4, string);
  276. }
  277.  
  278. sort_one_liner(sorting_by)
  279. int sorting_by;
  280. {
  281.     /** A one line summary of the particular sorting scheme... **/
  282.  
  283.     ClearLine(LINES-2);
  284.  
  285.     switch (sorting_by) {
  286.       
  287.       case -SENT_DATE : Centerline(LINES-2,
  288. "This sort will order most-recently-sent to least-recently-sent");    break;
  289.       case -RECEIVED_DATE : Centerline(LINES-2,
  290. "This sort will order most-recently-received to least-recently-received");
  291.                  break;
  292.       case -MAILBOX_ORDER : Centerline(LINES-2,
  293. "This sort will order most-recently-added-to-folder to least-recently");
  294.                  break;
  295.       case -SENDER : Centerline(LINES-2,
  296. "This sort will order by sender name, in reverse alphabetical order");    break;
  297.       case -SIZE   : Centerline(LINES-2,
  298. "This sort will order messages by longest to shortest");        break;
  299.       case -SUBJECT : Centerline(LINES-2,
  300. "This sort will order by subject, in reverse alphabetical order");    break;
  301.       case -STATUS  : Centerline(LINES-2,
  302. "This sort will order by reverse status - Deleted through Tagged...");    break;
  303.  
  304.       case SENT_DATE : Centerline(LINES-2,
  305. "This sort will order least-recently-sent to most-recently-sent");    break;
  306.       case RECEIVED_DATE : Centerline(LINES-2,
  307. "This sort will order least-recently-received to most-recently-received");
  308.                         break;
  309.       case MAILBOX_ORDER : Centerline(LINES-2,
  310. "This sort will order least-recently-added-to-folder to most-recently");
  311.                  break;
  312.       case SENDER : Centerline(LINES-2,
  313.                 "This sort will order by sender name");    break;
  314.       case SIZE   : Centerline(LINES-2,
  315.                 "This sort will order messages by shortest to longest");
  316.             break;
  317.       case SUBJECT : Centerline(LINES-2,
  318.                     "This sort will order messages by subject");    break;
  319.       case STATUS  : Centerline(LINES-2,
  320. "This sort will order by status - Tagged through Deleted...");        break;
  321.     }
  322. }
  323.  
  324. char *one_liner_for(c)
  325. char c;
  326. {
  327.     /** returns the one-line description of the command char... **/
  328.  
  329.     switch (c) {
  330.         case 'c' : return(
  331. "This is the file where calendar entries from messages are saved.");
  332.  
  333.         case 'd' : return(
  334. "This is the program invoked to display individual messages (try 'builtin')");
  335.  
  336.         case 'e' : return(
  337. "This is the editor that will be used for sending messages, etc.");
  338.  
  339.         case 'f' : return(
  340. "This is the folders directory used when '=' (etc) is used in filenames");
  341.  
  342.         case 'm' : return(
  343. "This determines if you have the mini-menu displayed or not");
  344.  
  345.         case 'n' : return(
  346. "Whether to display the names and addresses on mail, or names only");
  347.         case 'o' : return(
  348. "This is where copies of outbound messages are saved automatically.");
  349.  
  350.         case 'p' : return(
  351. "This is how printouts are generated.  \"%s\" will be replaced by the filename.");
  352.  
  353.         case 's' : return(
  354. "This is used to specify the sorting criteria for the folders");
  355.  
  356.         case 'y' : return(
  357. "When mail is sent out, this is what your full name will be recorded as.");
  358.  
  359.         case 'a' : return(
  360. "This defines whether the ELM cursor is an arrow or a highlight bar.");
  361.  
  362.        case 'u' : return(
  363. "The level of knowledge you have about the ELM mail system.");
  364.  
  365.         default : return(NULL);    /* nothing if we don't know! */
  366.     }
  367. }
  368.  
  369. options_help()
  370. {
  371.     /** help menu for the options screen... **/
  372.  
  373.     char c, *ptr;
  374.  
  375.     Centerline(LINES-3,
  376.   "Press the key you want help for, '?' for a key list, or '.' to exit help");
  377.  
  378.     lower_prompt("Key : ");
  379.  
  380.     while ((c = ReadCh()) != '.') {
  381.       c = tolower(c);
  382.       if (c == '?') {
  383.          display_helpfile(OPTIONS_HELP);
  384.          display_options();
  385.          return;
  386.       }
  387.       if ((ptr = one_liner_for(c)) != NULL)
  388.         error2("%c = %s.", c, ptr);
  389.       else
  390.         error1("%c isn't used in this section.", c);
  391.       lower_prompt("Key : ");
  392.     }
  393. }
  394.  
  395. char *level_name(n)
  396. int n;
  397. {
  398.     /** return the 'name' of the level... **/
  399.  
  400.     switch (n) {
  401.       case 0 : return("Beginning User   ");
  402.       case 1 : return("Intermediate User");
  403.       default: return("Expert User      ");
  404.     }
  405. }
  406.