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

  1. /*++
  2. /* NAME
  3. /*      mail
  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. /*      nmail           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. /*    90/01/22 13:02:04
  51. /* VERSION/RELEASE
  52. /*    2.1
  53. /*--*/
  54.  
  55. #include <stdio.h>
  56. #include <signal.h>
  57. #include "defs.h"
  58. #include "path.h"
  59. #include "status.h"
  60. #include "mail.h"
  61. #include "window.h"
  62.  
  63. public char *progname = "mail";        /* for diagnostics */
  64.  
  65. /* forward declarations */
  66.  
  67. hidden int checkfiles();
  68.  
  69. /* for now, don't even try to look at command args */
  70.  
  71. public  main(argc, argv)
  72. int     argc;
  73. char  **argv;
  74. {
  75.     register int stat;
  76.  
  77.     /*
  78.      * Initializations: get screen control and function-key codes (wininit).
  79.      * check if the limit on the number of open files is ok (checkfiles), get
  80.      * the values from environment variables (pathinit), set the terminal
  81.      * driver to the desired mode (kbdinit), check for partally processed new
  82.      * mail with the nmail program. Also make sure that our file permissions
  83.      * are safe (umask).
  84.      */
  85.  
  86.     if (!isatty(fileno(stdin))) {
  87.     perror("mail: standard input");
  88.     exit(1);
  89.     }
  90.     umask(022);                    /* avoid problems */
  91.     wininit();                    /* do termcap stuff */
  92.     clrscreen();                /* clear screen */
  93.     (stat = checkfiles())            /* get max nbr of open files */
  94.     ||(stat = pathinit())            /* get spool, printer, editor */
  95.     ||(stat = invokelp(NMAIL, (char *) 0));    /* just in case there's mail */
  96.     kbdinit();                    /* set to tty RAW, NOECHO */
  97.     if (stat) {
  98.     errdisp(stat);                /* we have a problem */
  99.     } else {
  100.     init();                    /* start the machine */
  101.     }
  102.  
  103.     /* finalizations */
  104.  
  105.     kbdrest();                    /* restore tty driver */
  106.     clrscreen();                /* clear screen */
  107.     fflush(stdout);
  108.     if (stat == 0)
  109.     onexit(mailcmd);            /* do exit command */
  110.     exit(stat);
  111.     /* NOTREACHED */
  112. }
  113.  
  114. /* checkfiles - make sure we can open as many files as we want */
  115.  
  116. hidden int checkfiles()
  117. {
  118.     register int i;
  119.     int     fds[MINFILES];
  120.     register int stat;
  121.  
  122.     for (i = 0; i < MINFILES; i++)        /* try to open many files */
  123.     if ((fds[i] = open(NULLDEV, 0)) < 0)
  124.         break;
  125.  
  126.     stat = (i < MINFILES ? E_FILENO : 0);    /* did we fail? */
  127.  
  128.     while (--i >= 0)                /* release files */
  129.     close(fds[i]);
  130.     return (stat);
  131. }
  132.  
  133. /* onexit - exec another command */
  134.  
  135. int     onexit(command)
  136. char   *command;
  137. {
  138.     if (command && *command)
  139.     return (system(command));
  140. }
  141.