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

  1. /*--------------------------------------------------------------------*/
  2. /*    p u s h p o p . c                                               */
  3. /*                                                                    */
  4. /*    Directory save/restore functions for UUPC/extended              */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: pushpop.c 1.7 1993/11/06 17:54:55 rhg Exp $
  21.  *
  22.  *    $Log: pushpop.c $
  23.  *     Revision 1.7  1993/11/06  17:54:55  rhg
  24.  *     Drive Drew nuts by submitting cosmetic changes mixed in with bug fixes
  25.  *
  26.  *     Revision 1.6  1993/10/24  21:45:49  rhg
  27.  *     Save the changed directory of the correct drive!
  28.  *
  29.  *     Revision 1.5  1993/06/15  12:37:16  ahd
  30.  *     Correct compile warning message about const assignment
  31.  *
  32.  *     Revision 1.4  1993/06/15  12:18:06  ahd
  33.  *     Save pushed directory name for debugging
  34.  *
  35.  *     Revision 1.3  1993/06/13  14:06:00  ahd
  36.  *     Insure directories PUSHED are POPPED
  37.  *
  38.  * Revision 1.2  1992/11/22  21:06:14  ahd
  39.  * Use strpool for memory allocation
  40.  *
  41.  */
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*                        System include files                        */
  45. /*--------------------------------------------------------------------*/
  46.  
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <sys/types.h>
  50.  
  51. #include <direct.h>
  52. #include <string.h>
  53. #include <ctype.h>
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                    UUPC/extended include files                     */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. #include "lib.h"
  60. #include "pushpop.h"
  61.  
  62. #define MAXDEPTH 10
  63.  
  64. /*--------------------------------------------------------------------*/
  65. /*                          Global variables                          */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. static char *dirstack[MAXDEPTH];
  69. static int drivestack[MAXDEPTH];
  70. static depth = 0;
  71.  
  72. currentfile();
  73.  
  74. /*--------------------------------------------------------------------*/
  75. /*        Change to a directory and push old one on our stack         */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. void PushDir( const char *directory )
  79. {
  80.    char cwd[FILENAME_MAX];
  81.  
  82.    if ( depth >= MAXDEPTH )
  83.       panic();
  84.  
  85. /*--------------------------------------------------------------------*/
  86. /*       Unlike Unix, DOS has a CWD per drive.  We must,              */
  87. /*       therefore, change to the new drive before we save the        */
  88. /*       CWD.  Otherwise we will lose the old CWD for the new         */
  89. /*       drive.  For straight PushDir/PopDir pairing, we need not     */
  90. /*       save the CWD on the old drive because we won't be changing   */
  91. /*       it.  Note, however, that the sequence PushDir/CHDIR/         */
  92. /*       PopDir (as opposed to just PushDir/PopDir pairs) could       */
  93. /*       lose information if the CHDIR changes back to the drive      */
  94. /*       from which PushDir changed away.  If any UUPC/extended       */
  95. /*       code really did this, then drivestack would have to be       */
  96. /*       changed to a full pathname like dirstack.  Lucky for us,     */
  97. /*       it doesn't do so in any known sequences.  --RHG/AHD          */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. #ifdef __TURBOC__
  101.    drivestack[depth] = getdisk();
  102.    if (isalpha(*directory) && (directory[1] == ':'))
  103.       setdisk(toupper(*directory) - 'A');
  104.    dirstack[depth] = newstr( getcwd( cwd, FILENAME_MAX ) );
  105. #else
  106.    drivestack[depth] = _getdrive();
  107.    if (isalpha(*directory) && (directory[1] == ':'))
  108.       _chdrive( toupper(*directory) - 'A' + 1);
  109.  
  110.    dirstack[depth] = newstr( _getdcwd( 0, cwd, FILENAME_MAX ) );
  111. #endif
  112.  
  113.    if (dirstack[depth] == NULL )
  114.    {
  115.       printerr("PushDir");
  116.       panic();
  117.    }
  118.  
  119.    depth++;
  120.  
  121.    if (equal(directory,"."))
  122.       E_cwd = dirstack[depth - 1];
  123.    else
  124.       CHDIR( directory );        /* CHDIR sets E_cwd                 */
  125.  
  126. } /* PushDir */
  127.  
  128. /*--------------------------------------------------------------------*/
  129. /*               Return to a directory saved by PushDir               */
  130. /*--------------------------------------------------------------------*/
  131.  
  132. void PopDir( void )
  133. {
  134.    char cwd[FILENAME_MAX];
  135.  
  136.    if ( depth == 0 )
  137.       panic();
  138.  
  139.    CHDIR( dirstack[--depth] );
  140.  
  141. #ifdef __TURBOC__
  142.    setdisk(drivestack[depth]);
  143.  
  144.    E_cwd = newstr( getcwd( cwd, FILENAME_MAX ) );
  145. #else
  146.    _chdrive(drivestack[depth]);
  147.  
  148.    E_cwd = newstr( _getdcwd( 0, cwd, FILENAME_MAX ) );
  149. #endif
  150.  
  151. } /* PopDir */
  152.