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

  1. /*++
  2. /* NAME
  3. /*      mailsh
  4. /* SUMMARY
  5. /*      visual mail-shell
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      mail
  10. /* SYNOPSIS
  11. /*      mail
  12. /* DESCRIPTION
  13. /*      mail is an interactive program for reading, receiving
  14. /*      and producing electronic mail. Actually, most of the work
  15. /*    is done by programs called by the mail program.
  16. /*
  17. /*      By default, the program presents the user display of a list of
  18. /*      mail messages in the form of one-line summaries. Single-key 
  19. /*    commands are available to select and manipulate mail messages.
  20. /*    Mail messages are created with an editor chosen by the user.
  21. /*
  22. /*      The name of the spool directory, printer program and editor
  23. /*      are taken from the environment, or assume system-dependent defaults.
  24. /* ENVIRONMENT
  25. /*      MAILDIR        name of spool directory
  26. /*      EDITOR          name of program to create mail
  27. /*    MAILPRN        name of program/file to print with/to
  28. /*    MAILCMD        command to execute upon termination
  29. /* COMMANDS
  30. /*      cico            network communications program
  31. /*      rmail           postprocessor for mail received by cico
  32. /* FILES
  33. /*      The mail system maintains various files in a spool directory,
  34. /*      as well as a logfile of all network transactions.
  35. /* SEE ALSO
  36. /*      path(3)         system-dependent path names
  37. /* DIAGNOSTICS
  38. /*      Error messages should be self-explanatory.
  39. /* BUGS
  40. /*      The user has to explicitly tell the system to contact a remote
  41. /*    mail host. This is a limitation of MS-DOS, not of the program.
  42. /* AUTHOR(S)
  43. /*      W.Z. Venema
  44. /*      Eindhoven University of Technology
  45. /*      Department of Mathematics and Computer Science
  46. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  47. /* CREATION DATE
  48. /*      Thu Apr  2 21:54:08 GMT+1:00 1987
  49. /* LAST MODIFICATION
  50. /*    Mon Apr  4 23:44:44 MET 1988
  51. /* VERSION/RELEASE
  52. /*    1.3
  53. /*--*/
  54.  
  55. #include <signal.h>
  56. #include "defs.h"
  57. #include "path.h"
  58. #include "status.h"
  59. #include "mailsh.h"
  60. #include "window.h"
  61.  
  62. /* forward declarations */
  63.  
  64. hidden int checkfiles();
  65.  
  66. /* for now, don't even try to look at command args */
  67.  
  68. public main(argc,argv)
  69. int argc;
  70. char **argv;
  71. {
  72.     register int stat;
  73.  
  74.     /* 
  75.     * Initializations: get screen control and function-key codes (wininit).
  76.     * check if the limit on the number of open files is ok (checkfiles),
  77.     * get the values from environment variables (pathinit), set the
  78.     * terminal driver to the desired mode (kbdinit), check for partally
  79.     * processed new mail with the rmail program.
  80.     * Also make sure that our file permissions are safe (umask).
  81.     */
  82.  
  83.     if (!isatty(fileno(stdin))) {
  84.     perror("mail: standard input");
  85.     exit(1);
  86.     }
  87.  
  88.     umask(022);                /* avoid problems */
  89.     wininit();                          /* do termcap stuff */
  90.     clrscreen();                         /* clear screen */
  91.     (stat = checkfiles())        /* get max nbr of open files */
  92.     || (stat = pathinit())        /* get spool, printer, editor */
  93.     || (stat = invokelp(RMAIL,(char *)0));/* just in case there's mail */
  94.     kbdinit();                          /* set to tty RAW, NOECHO */
  95.     if (stat)
  96.     errdisp(stat);            /* we have a problem */
  97.  
  98.     /* enter the main command loop */
  99.  
  100.     desk();                /* start the machine */
  101.  
  102.     /* finalizations */
  103.  
  104.     kbdrest();                          /* restore tty driver */
  105.     clrscreen();                         /* clear screen */
  106.     fflush(stdout);
  107.     onexit(mailcmd);            /* do exit command */
  108.     exit(0);                            /* huh?? */
  109.     /* NOTREACHED */
  110. }
  111.  
  112. /* checkfiles - make sure we can open as many files as we want */
  113.  
  114. hidden int checkfiles()
  115. {
  116.     register int i;
  117.     int fds[MINFILES];
  118.     register int stat;
  119.  
  120.     for (i = 0; i < MINFILES; i++)              /* try to open many files */
  121.     if ((fds[i] = open(NULLDEV,0)) < 0)
  122.         break;
  123.  
  124.     stat = (i < MINFILES ? E_FILENO : 0);    /* did we fail? */
  125.  
  126.     while (--i >= 0)                            /* release files */
  127.     close(fds[i]);
  128.     return(stat);
  129. }
  130.