home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / nethack-3.1 / sys / share / pcunix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-18  |  2.7 KB  |  116 lines

  1. /*    SCCS Id: @(#)pcunix.c    3.1    90/22/02
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* This file collects some Unix dependencies; pager.c contains some more */
  6.  
  7. #include "hack.h"
  8.  
  9. #include    <sys/stat.h>
  10.  
  11. #ifdef OVLB
  12.  
  13. static struct stat buf;
  14. # ifdef WANT_GETHDATE
  15. static struct stat hbuf;
  16. # endif
  17.  
  18. void
  19. gethdate(name)
  20. char *name;
  21. {
  22. # ifdef WANT_GETHDATE
  23. /* old version - for people short of space */
  24. /*
  25. /* register char *np;
  26. /*      if(stat(name, &hbuf))
  27. /*          error("Cannot get status of %s.",
  28. /*              (np = rindex(name, '/')) ? np+1 : name);
  29. /*
  30. /* version using PATH from: seismo!gregc@ucsf-cgl.ARPA (Greg Couch) */
  31.  
  32. /*
  33.  * The problem with   #include  <sys/param.h> is that this include file
  34.  * does not exist on all systems, and moreover, that it sometimes includes
  35.  * <sys/types.h> again, so that the compiler sees these typedefs twice.
  36.  */
  37. #define     MAXPATHLEN      1024
  38.  
  39.     register char *np, *path;
  40.     char filename[MAXPATHLEN+1], *getenv();
  41.  
  42.     if (index(name, '/') != NULL || (path = getenv("PATH")) == NULL)
  43.     path = "";
  44.  
  45.     for (;;) {
  46.     if ((np = index(path, ':')) == NULL)
  47.         np = path + strlen(path);       /* point to end str */
  48.     if (np - path <= 1)             /* %% */
  49.         Strcpy(filename, name);
  50.     else {
  51.         (void) strncpy(filename, path, np - path);
  52.         filename[np - path] = '/';
  53.         Strcpy(filename + (np - path) + 1, name);
  54.     }
  55.     if (stat(filename, &hbuf) == 0)
  56.         return;
  57.     if (*np == '\0')
  58.     path = "";
  59.     path = np + 1;
  60.     }
  61.     error("Cannot get status of %s.", (np = rindex(name, '/')) ? np+1 : name);
  62. # endif /* WANT_GETHDATE */
  63. }
  64.  
  65. int
  66. uptodate(fd)
  67. int fd;
  68. {
  69. # ifdef WANT_GETHDATE
  70.     if(fstat(fd, &buf)) {
  71.     pline("Cannot get status of saved level? ");
  72.     return(0);
  73.     }
  74.     if(buf.st_mtime < hbuf.st_mtime) {
  75.     pline("Saved level is out of date. ");
  76.     return(0);
  77.     }
  78. # else
  79. #  if defined(MICRO) && !defined(NO_FSTAT)
  80.     if(fstat(fd, &buf)) {
  81.     if(moves > 1) pline("Cannot get status of saved level? ");
  82.     else pline("Cannot get status of saved game");
  83.     return(0);
  84.     } 
  85.     if(comp_times(buf.st_mtime)) { 
  86.     if(moves > 1) pline("Saved level is out of date");
  87.     else pline("Saved game is out of date. ");
  88.     return(0);
  89.     }
  90. #  endif  /* MICRO /* */
  91. # endif /* WANT_GETHDATE */
  92.     return(1);
  93. }
  94.  
  95. void
  96. regularize(s)
  97. /*
  98.  * normalize file name - we don't like .'s, /'s, spaces, and
  99.  * lots of other things
  100.  */
  101. register char *s;
  102. {
  103.     register char *lp;
  104.  
  105.     for (lp = s; *lp; lp++)
  106.         if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',') ||
  107.             *lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') ||
  108. # ifdef OS2
  109.             *lp == '&' || *lp == '(' || *lp == ')' ||
  110. # endif
  111.             *lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']'))
  112.                         *lp = '_';
  113. }
  114.  
  115. #endif /* OVLB */
  116.