home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / pcmail / main / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  4.5 KB  |  321 lines

  1. /*++
  2.  
  3. /* NAME
  4.  
  5. /*    setup 3
  6.  
  7. /* SUMMARY
  8.  
  9. /*    edit/display configuration parameters
  10.  
  11. /* PROJECT
  12.  
  13. /*    pc-mail
  14.  
  15. /* PACKAGE
  16.  
  17. /*    mail
  18.  
  19. /* SYNOPSIS
  20.  
  21. /*    #include "mail.h"
  22.  
  23. /*
  24.  
  25. /*    int setup()
  26.  
  27. /* DESCRIPTION
  28.  
  29. /*    The functions in this module handle the configurations file with
  30.  
  31. /*    communications parameters.
  32.  
  33. /*
  34.  
  35. /*    setup() starts a dialogue with the user. It allows the user to
  36.  
  37. /*    select a parameter and enter a new value. All modifications are
  38.  
  39. /*    done in core (pager file). Upon exit, the setup is written to
  40.  
  41. /*    disk if any changes were made.
  42.  
  43. /* FUNCTIONS AND MACROS
  44.  
  45. /*    open_pager(), app_pager(), gets_pager(), puts_pager()
  46.  
  47. /*    kbdinp()
  48.  
  49. /* FILES
  50.  
  51. /*    In the spool directory: the configuration file s00000.
  52.  
  53. /* SEE ALSO
  54.  
  55. /*    cico(1)    communications program.
  56.  
  57. /* DIAGNOSTICS
  58.  
  59. /*    An error message if the setup file could not be created.
  60.  
  61. /* BUGS
  62.  
  63. /*    Does not check parameter values at all, just like the UUCP
  64.  
  65. /*    configurations files L.sys etcetera.
  66.  
  67. /* AUTHOR(S)
  68.  
  69. /*    W.Z. Venema
  70.  
  71. /*    Eindhoven University of Technology
  72.  
  73. /*    Department of Mathematics and Computer Science
  74.  
  75. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  76.  
  77. /* CREATION DATE
  78.  
  79. /*    Wed Apr  8 15:16:18 GMT+1:00 1987
  80.  
  81. /* LAST MODIFICATION
  82.  
  83. /*    90/01/22 13:02:36
  84.  
  85. /* VERSION/RELEASE
  86.  
  87. /*    2.1
  88.  
  89. /*--*/
  90.  
  91.  
  92.  
  93. #include "defs.h"
  94.  
  95. #include "path.h"
  96.  
  97. #include "screen.h"
  98.  
  99. #include "mail.h"
  100.  
  101. #include "pager.h"
  102.  
  103. #include "params.h"
  104.  
  105. #include "status.h"
  106.  
  107. #include "window.h"
  108.  
  109.  
  110.  
  111. hidden void make_setup();        /* forward declarations */
  112.  
  113. hidden int change_setup();
  114.  
  115. hidden int pick_setup();
  116.  
  117. hidden int show_setup();
  118.  
  119.  
  120.  
  121. hidden File *setfile = 0;        /* memory! */
  122.  
  123. hidden Info *prmtable = 0;        /* more memory */
  124.  
  125. hidden int chgflag = 0;            /* more flags! */
  126.  
  127.  
  128.  
  129. hidden char setfmt[] = "%-20s %s";    /* display format */
  130.  
  131. #define    LABLEN    20            /* length of first %s specifier */
  132.  
  133.  
  134.  
  135. /* setup - start dialogue */
  136.  
  137.  
  138.  
  139. public int setup()
  140.  
  141. {
  142.  
  143.     static Screen screen[] = {
  144.  
  145.     'C',    "Close",0,        prevscreen,
  146.  
  147.     PGUP,    PgUp,    pu_pager,    pageup,
  148.  
  149.     PGDN,    PgDn,    pd_pager,    pagedn,
  150.  
  151.     UP,    "Up",    up_pager,    csrup,
  152.  
  153.     DOWN,    "Down",    dn_pager,    csrdn,
  154.  
  155.     ENTER,    "Enter",pick_setup,    "Modify selected parameter",
  156.  
  157.     0,    0,    show_setup,
  158.  
  159.     "Select communications parameter with cursor keys, then press ENTER",
  160.  
  161.     };
  162.  
  163.  
  164.  
  165.     kbdinp(screen);                /* start dialogue */
  166.  
  167.     if (chgflag && cp_pager(parm_file())) {    /* save setup if changed */
  168.  
  169.     errdisp(E_WRITERR);            /* save failed */
  170.  
  171.     } else {
  172.  
  173.     chgflag = 0;                /* save succeeded */
  174.  
  175.     }
  176.  
  177.     close_pager(setfile);
  178.  
  179.     setfile = 0;
  180.  
  181.     return (S_REDRAW);                /* refresh screen */
  182.  
  183. }
  184.  
  185.  
  186.  
  187. /* show_setup - make setup display or use existing one */
  188.  
  189.  
  190.  
  191. hidden int show_setup()
  192.  
  193. {
  194.  
  195.     if (setfile == 0 || prmtable == 0) {    /* no setup display */
  196.  
  197.     prmtable = getparams();
  198.  
  199.     setfile = open_pager();
  200.  
  201.     make_setup();
  202.  
  203.     } else {                    /* use existing display */
  204.  
  205.     set_pager(setfile);
  206.  
  207.     }
  208.  
  209.     ds_pager();                    /* display it */
  210.  
  211.     return (0);
  212.  
  213. }
  214.  
  215.  
  216.  
  217. /* make_setup - create setup display */
  218.  
  219.  
  220.  
  221. hidden void make_setup()
  222.  
  223. {
  224.  
  225.     register File *f = setfile;
  226.  
  227.     register Info *i;
  228.  
  229.  
  230.  
  231.     for (i = prmtable; i->ident; i++)
  232.  
  233.     app_pager(f, strcons(setfmt, i->ident, i->strval ? i->strval : ""));
  234.  
  235. }
  236.  
  237.  
  238.  
  239. /* pick_setup - user has selected one parameter */
  240.  
  241.  
  242.  
  243. hidden int pick_setup()
  244.  
  245. {
  246.  
  247.     static Screen screen[] = {
  248.  
  249.     EDIT,    0,    change_setup,    0,
  250.  
  251.     0,    0,    0,
  252.  
  253.     "Press ESC to cancel. New parameter value:"
  254.  
  255.     };
  256.  
  257.     register char *sp = gets_pager();
  258.  
  259.     register Info *ip;
  260.  
  261.  
  262.  
  263.     for (ip = prmtable; ip->ident; ip++)    /* check id string */
  264.  
  265.     if (strncmp(ip->ident, sp, ip->length) == 0)
  266.  
  267.         break;
  268.  
  269.     if (ip) {
  270.  
  271.     screen->help = sp + LABLEN + 1;        /* default is current value */
  272.  
  273.     kbdinp(screen);                /* ask for new value */
  274.  
  275.     return (S_REDRAW);
  276.  
  277.     } else {
  278.  
  279.     beep();                    /* bad id string */
  280.  
  281.     return (0);
  282.  
  283.     }
  284.  
  285. }
  286.  
  287.  
  288.  
  289. /* change_setup - enter new communications parameter value */
  290.  
  291.  
  292.  
  293. hidden int change_setup(newval)
  294.  
  295. char   *newval;
  296.  
  297. {
  298.  
  299.     register char *sp = gets_pager();    /* read from display */
  300.  
  301.     register Info *ip;
  302.  
  303.  
  304.  
  305.     for (ip = prmtable; ip->ident; ip++) {    /* check id string */
  306.  
  307.     if (strncmp(ip->ident, sp, ip->length) == 0) {
  308.  
  309.         puts_pager(strcons(setfmt, ip->ident, newval));
  310.  
  311.         chgflag = 1;            /* say change made */
  312.  
  313.     }
  314.  
  315.     }
  316.  
  317.     return (S_BREAK | S_REDRAW);        /* screen changed */
  318.  
  319. }
  320.  
  321.