home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume3 / pcmail / part06 / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  3.9 KB  |  157 lines

  1. /*++
  2. /* NAME
  3. /*    setup 3
  4. /* SUMMARY
  5. /*    edit/display configuration parameters
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    mailsh
  10. /* SYNOPSIS
  11. /*    #include "mailsh.h"
  12. /*
  13. /*    int setup()
  14. /* DESCRIPTION
  15. /*    The functions in this module handle the configurations file with 
  16. /*    communications parameters.
  17. /*
  18. /*    setup() starts a dialogue with the user. It allows the user to
  19. /*    select a parameter and enter a new value. All modifications are
  20. /*    done in core (pager file). Upon exit, the setup is written to 
  21. /*    disk if any changes were made.
  22. /* FUNCTIONS AND MACROS
  23. /*    open_pager(), app_pager(), gets_pager(), puts_pager()
  24. /*    kbdinp()
  25. /* FILES
  26. /*    In the spool directory: the configuration file s00000.
  27. /* SEE ALSO
  28. /*    cico(1)    communications program.
  29. /* DIAGNOSTICS
  30. /*    An error message if the setup file could not be created.
  31. /* BUGS
  32. /*    Does not check parameter values at all, just like the UUCP 
  33. /*    configurations files L.sys etcetera.
  34. /* AUTHOR(S)
  35. /*    W.Z. Venema
  36. /*    Eindhoven University of Technology
  37. /*    Department of Mathematics and Computer Science
  38. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  39. /* CREATION DATE
  40. /*    Wed Apr  8 15:16:18 GMT+1:00 1987
  41. /* LAST MODIFICATION
  42. /*    Mon Apr  4 23:49:37 MET 1988
  43. /* VERSION/RELEASE
  44. /*    1.3
  45. /*--*/
  46.  
  47. #include "defs.h"
  48. #include "path.h"
  49. #include "screen.h"
  50. #include "mailsh.h"
  51. #include "pager.h"
  52. #include "params.h"
  53. #include "status.h"
  54. #include "window.h"
  55.  
  56. hidden void make_setup();            /* forward declarations */
  57. hidden int change_setup();
  58. hidden int pick_setup();
  59. hidden int show_setup();
  60.  
  61. hidden File *setfile = 0;            /* memory! */
  62. hidden Info *prmtable = 0;            /* more memory */
  63. hidden int chgflag = 0;                /* more flags! */
  64.  
  65. /* setup - start dialogue */
  66.  
  67. public int setup()
  68. {
  69.     static Screen screen[] = {
  70.     'C',    "Close",        0,      initscreen,
  71.     PGUP,    PgUp,        pu_pager,pageup,
  72.     PGDN,    PgDn,        pd_pager,pagedn,
  73.     UP,    "Up",           up_pager,csrup,
  74.     DOWN,    "Down",         dn_pager,csrdn,
  75.     ENTER,    "Enter",        pick_setup,"Modify selected parameter",
  76.     0,    0,              show_setup,
  77.     "Select communications parameter with cursor keys, then press ENTER",
  78.     };
  79.  
  80.     kbdinp(screen);                /* start dialogue */
  81.     if (chgflag && cp_pager(parm_file())) {
  82.     errdisp(E_WRITERR);            /* save failed */
  83.     } else {
  84.     chgflag = 0;                /* save succeeded */
  85.     }
  86.     close_pager(setfile);
  87.     setfile = 0;
  88.     return(S_REDRAW);                /* refresh screen */
  89. }
  90.  
  91. /* show_setup - make setup display or use existing one */
  92.  
  93. hidden int show_setup()
  94. {
  95.     if (setfile == 0 || prmtable == 0) {    /* no setup display */
  96.     prmtable = getparams();
  97.     setfile = open_pager();
  98.     make_setup();
  99.     } else {                    /* use existing display */
  100.     set_pager(setfile);
  101.     }
  102.     ds_pager();                    /* display it */
  103.     return(0);
  104. }
  105.  
  106. /* make_setup - create setup display */
  107.  
  108. hidden void make_setup()
  109. {
  110.     register File *f = setfile;
  111.     register Info *i;
  112.  
  113.     for (i = prmtable; i->ident; i++)
  114.     app_pager(f,strcons("%-20s %s",i->ident,i->strval ? i->strval : ""));
  115. }
  116.  
  117. /* pick_setup - user has selected one parameter */
  118.  
  119. hidden int pick_setup()
  120. {
  121.     static Screen screen[] = {
  122.     STRING,    0,              change_setup,int_error,
  123.     0,    0,              0,
  124.     "Press ESC to cancel. New parameter value:"
  125.     };
  126.     register char *sp = gets_pager();
  127.     register Info *ip;
  128.  
  129.     for (ip = prmtable; ip->ident; ip++)        /* check id string */
  130.     if (strncmp(ip->ident,sp,ip->length) == 0)
  131.         break;
  132.     if (ip) {
  133.     kbdinp(screen);                    /* ask for new value */
  134.     return(S_REDRAW);
  135.     } else {
  136.     beep();                        /* bad id string */
  137.     return(0);
  138.     }
  139. }
  140.  
  141. /* change_setup - enter new communications parameter value */
  142.  
  143. hidden int change_setup(newval)
  144. char *newval;
  145. {
  146.     register char *sp = gets_pager();            /* read from display */
  147.     register Info *ip;
  148.  
  149.     for (ip = prmtable; ip->ident; ip++) {        /* check id string */
  150.     if (strncmp(ip->ident,sp,ip->length) == 0) {
  151.         puts_pager(strcons("%-20s %s",ip->ident,newval)); /* new entry */
  152.         chgflag = 1;                /* say change made */
  153.     }
  154.     }
  155.     return(S_BREAK|S_REDRAW);                /* screen changed */
  156. }
  157.