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

  1. /*++
  2. /* NAME
  3. /*      path 3
  4. /* SUMMARY
  5. /*      system-dependent file name stuff
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      general
  10. /* SYNOPSIS
  11. /*    #include "str.h"
  12. /*      #include "path.h"
  13. /*
  14. /*      int pathinit()
  15. /*
  16. /*      FILE *propen()
  17. /*
  18. /*      char *fspool(file)
  19. /*      char *file;
  20. /* DESCRIPTION
  21. /*      The routines in this module know the system-dependent rules
  22. /*      for file names and printers.
  23. /*
  24. /*      pathinit() extracts the values of the environment variables
  25. /*      MAILDIR, MAILPRN, MAILCMD and EDITOR, and assumes system-dependent 
  26. /*    defaults for undefined environment variables. It checks for the 
  27. /*      existence of the spool directory.
  28. /*
  29. /*    Under Unix, the MAILPRN environment variable should be the name
  30. /*    of a command. Under MS-DOS, it should be the name of a device or file.
  31. /*
  32. /*      propen() returns a stream to print to.
  33. /*
  34. /*      fspool() constructs a path name from the spool directory and 
  35. /*    the file name in its argument.
  36. /*    Real unix uses uucp spool file names of the form 
  37. /*
  38. /*        <letter> . <system> <grade> <sequence_nr>
  39. /*
  40. /*    This is problematic for MS-DOS and similar systems that
  41. /*    only allow three characters after the dot. Instead of building
  42. /*    a tiny file system on top of MS-DOS, the pc-mail programs
  43. /*    use a different way of spool file naming:
  44. /*
  45. /*        <letter> <sequence_nr>
  46. /*
  47. /*    This scheme assumes that the pc has access to exactly one unix
  48. /*    host, since the host name is not part of spool file names.
  49. /* COMMANDS
  50. /*      lp(1)  (under unix) printer spooler program
  51. /* FILES
  52. /*      PRN     under MS-DOS
  53. /* DIAGNOSTICS
  54. /*      pathinit() returns a nonzero value (see status(5)) if one of the 
  55. /*    environment variables (or defaults) are incorrect.
  56. /*
  57. /*      File open functions return a null pointer when a file could not
  58. /*      be opened.
  59. /* BUGS
  60. /*    pathinit() only verifies the MAILDIR name.
  61. /*
  62. /*      fspool() returns a pointer to static memory.
  63. /* AUTHOR(S)
  64. /*      W.Z. Venema
  65. /*      Eindhoven University of Technology
  66. /*      Department of Mathematics and Computer Science
  67. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  68. /* CREATION DATE
  69. /*      Sun Apr  5 15:27:37 GMT+1:00 1987
  70. /* LAST MODIFICATION
  71. /*    90/01/22 13:02:26
  72. /* VERSION/RELEASE
  73. /*    2.1
  74. /*--*/
  75.  
  76. #include <sys/types.h>
  77. #include <sys/stat.h>
  78. #include "defs.h"
  79. #include "path.h"
  80. #include "status.h"
  81.  
  82.  /*
  83.   * Environment variables are loaded here. Most of them have a default; We
  84.   * only check the validity of the MAILDIR variable.
  85.   */
  86.  
  87. public char *maildir = DEFSPOOL;    /* spool directory */
  88. public char *editor  = DEFEDIT;        /* editor program */
  89. public char *mailprn = DEFPRINT;    /* where to print to */
  90. public char *mailcmd = 0;        /* do this on exit */
  91.  
  92. typedef struct {
  93.     char   *vname;
  94.     char  **ptr;
  95. } Environ;
  96.  
  97. static Environ env[] = {
  98.     "SPOOL",    &maildir,        /* backwards compatibility... */
  99.     "MAILDIR",    &maildir,
  100.     "EDITOR",    &editor,
  101.     "MAILPRN",    &mailprn,
  102.     "MAILCMD",    &mailcmd,
  103.     0,        0,            /* terminator */
  104. };
  105.  
  106. /* pathinit - consult the environment; checks existence of spool directory */
  107.  
  108. public int pathinit()
  109. {
  110.     register char *cp;
  111.     struct stat s;
  112.     register Environ *ep;
  113.  
  114.     /* load environment variables */
  115.  
  116.     for (ep = env; ep->vname; ep++)
  117.     if (cp = getenv(ep->vname))
  118.         *(ep->ptr) = cp;
  119.  
  120.     /* check existence of the spool directory */
  121.  
  122.     return (stat(maildir, &s) || (s.st_mode & S_IFMT) != S_IFDIR ? E_NOSPOOL : 0);
  123. }
  124.