home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / chdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-03  |  3.1 KB  |  93 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    c h d i r . c                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <ctype.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. #ifndef __GNUC__
  19. #include <dos.h>
  20. #include <direct.h>
  21. #endif
  22.  
  23. /*--------------------------------------------------------------------*/
  24. /*                    UUPC/extended include files                     */
  25. /*--------------------------------------------------------------------*/
  26.  
  27. #include "lib.h"
  28. #include "hlib.h"
  29.  
  30. static int changedir( const char *path);
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*    C H D I R                                                       */
  34. /*                                                                    */
  35. /*    Like chdir() but create the directory if necessary              */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. int CHDIR(const char *path)
  39. {
  40.  
  41.    if (*path == '\0')
  42.       return 0;
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*        Try to change directories, returning if successful          */
  46. /*--------------------------------------------------------------------*/
  47.  
  48.    if (!changedir( path ))
  49.       return 0;
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*                      Try making the directory                      */
  53. /*--------------------------------------------------------------------*/
  54.  
  55.    MKDIR(path);
  56.  
  57.    /* change to last directory */
  58.    return changedir(path);
  59.  
  60. } /*CHDIR*/
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*    c h a n g e d i r                                               */
  64. /*                                                                    */
  65. /*    Like chdir() but also changes the current drive                 */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. static int changedir(const char *pathx)
  69. {
  70.    static char path[FILENAME_MAX];
  71.  
  72.    strcpy( path, pathx );
  73.  
  74.    if ((*path != '\0') && (path[1] == ':')) {
  75.       if (isalpha(*path))
  76.       {
  77. #ifdef __TURBOC__
  78.          setdisk(toupper(*path) - 'A');
  79. #else
  80.          if (_chdrive( toupper(*path) - 'A' + 1))  /* MS C      */
  81.             return -1;                 /* Return if failure           */
  82. #endif
  83.       } /* if */
  84.       else
  85.          return -1;
  86.    }
  87.  
  88.    E_cwd = (char *) path;
  89.  
  90.    return chdir(path);
  91.  
  92. } /*changedir*/
  93.