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

  1. /*++
  2. /* NAME
  3. /*    alias
  4. /* SUMMARY
  5. /*    manipulate alias data base
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    mailsh
  10. /* SYNOPSIS
  11. /*    #include "alias.h"
  12. /*
  13. /*    int alias()
  14. /* DESCRIPTION
  15. /*    The alias data base is a text file. Each line is of the form
  16. /*
  17. /*        alias    replacement
  18. /*
  19. /*    where a replacement may consist of several words, which may
  20. /*    be aliases themselves. Comma, blank and tab are separators.
  21. /*    Leading or trailing blanks are ignored. If an alias is defined
  22. /*    more than once, only the last definition will be effective.
  23. /*
  24. /*    alias() is invoked from the main menu and displays the contents
  25. /*    of the alias data base. An editor is invoked if the user wants
  26. /*    to make changes.
  27. /* COMMANDS
  28. /*    the program specified in the EDITOR environment variable,
  29. /*    or a system-dependent default.
  30. /* FILES
  31. /*      temporary edit file in current directory
  32. /*    alias data base file in spool directory
  33. /* SEE ALSO
  34. /*      pager(3), pager(5), kbdinp(3)
  35. /* AUTHOR(S)
  36. /*      W.Z. Venema
  37. /*      Eindhoven University of Technology
  38. /*      Department of Mathematics and Computer Science
  39. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  40. /* CREATION DATE
  41. /*    Wed Apr  6 20:21:35 MET 1988
  42. /* LAST MODIFICATION
  43. /*    Wed Apr  6 20:21:35 MET 1988
  44. /* VERSION/RELEASE
  45. /*    1.0
  46. /*--*/
  47.  
  48. #include <errno.h>
  49. #include "defs.h"
  50. #include "path.h"
  51. #include "pager.h"
  52. #include "mailsh.h"
  53. #include "screen.h"
  54. #include "status.h"
  55.  
  56. /* forward declarations */
  57.  
  58. hidden int edit_alias();
  59. hidden void junk_alias();
  60. hidden int show_alias();
  61.  
  62. hidden File *afile = 0;            /* pager file */
  63.  
  64. /* alias - display alias data base */
  65.  
  66. public int alias()
  67. {
  68.     static Screen screen[] = {
  69.     'C',    "Close",    0,    initscreen,
  70.     'E',    "Edit",        edit_alias,"Edit alias data base",
  71.     'P',    "Print",    print,    "Print alias data base",
  72.     PGUP,    PgUp,        pu_pager,pageup,
  73.     PGDN,    PgDn,        pd_pager,pagedn,
  74.     UP,    "Up",           up_pager,csrup,
  75.     DOWN,    "Down",         dn_pager,csrdn,
  76.     0,    0,              show_alias,
  77.     "(Reading alias database)",
  78.     };
  79.  
  80.     kbdinp(screen);                /* ask disposition */
  81.     junk_alias();                /* forget alias display */
  82.     return(S_REDRAW);                /* say screen was changed */
  83. }
  84.  
  85. /* show_alias - show alias data base or error message in middle window */
  86.  
  87. hidden int show_alias()
  88. {
  89.     static char *noalias[] = {            /* Ha ha ha ho ho hum */
  90.     "",
  91.     "The alias data base is empty. Normally it holds lines of the form",
  92.     "",
  93.     "    alias-name   one-or-more-mail-addresses",
  94.     "",
  95.     "You can create and change the alias data base with the E command.",
  96.     0,
  97.     };
  98.     if (afile) {                /* check pager file exists */
  99.     set_pager(afile);            /* select existing display */
  100.     } else if (rd_pager(afile = open_pager(),aliases())) {
  101.     mesg_pager(afile,noalias);        /* no alias database */
  102.     }
  103.     ds_pager();                    /* (re)draw display */
  104.     return(0);                    /* screen is up-to-date */
  105. }
  106.  
  107. /* junk_alias - destroy alias data base display */
  108.  
  109. hidden void junk_alias()
  110. {
  111.     if (afile) {                /* no-op if no display */
  112.     close_pager(afile);            /* release memory */
  113.     afile = 0;                /* say it is gone */
  114.     }
  115. }
  116.  
  117. /* edit_alias - edit or create alias data base */
  118.  
  119. hidden int edit_alias()
  120. {
  121.     register int stat;
  122.  
  123.     if (stat = edit(aliases(),TMPALIAS))
  124.     errdisp(stat);                /* edit() had a problem */
  125.     junk_alias();                /* force new display */
  126.     return(S_REDRAW);                /* say screen has changed */
  127. }
  128.