home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
125.img
/
PRO-C4.ZIP
/
BENCH1.ZIP
/
BENCH
/
PUSH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-28
|
1KB
|
84 lines
#include <stdio.h>
#include <bench.h>
#include <tree.h>
#include <dllist.h>
#define MAXPATHLEN 128
static int dir_hd = -1;
/* RT does not define this so here's the hack ... */
static int my_strcmp(a, b)
char *a, *b;
{
return(strcmp(a, b));
}
int pushd(dirnam)
register char *dirnam;
{
char dirbuf[MAXPATHLEN + 1];
if (dir_hd == -1)
dir_hd = dll_open(my_strcmp, MAXPATHLEN + 1);
getcwd(dirbuf, MAXPATHLEN);
if (dll_add(dir_hd, dirbuf, ADD_NOSORT) == -1)
{
errmsg("Stack overflow in pushd()");
return(-1);
}
#ifdef MSDOS
if (*dirnam != dirbuf[0] && *(dirnam + 1) == ':')
chdrive(*dirnam);
#endif
return(chdir(dirnam));
}
int popd()
{
register char *dirp;
char dirbuf[MAXPATHLEN + 1];
getcwd(dirbuf, MAXPATHLEN);
dirp = (char *)dll_seek(dir_hd, 0, SEEK_END);
if (dirp == NULL)
{
errmsg("Stack underflow in popd()");
return(-1);
}
#ifdef MSDOS
if (dirbuf[0] != *dirp)
chdrive(*dirp);
#endif
chdir(dirp);
return(dll_del(dir_hd));
}
#ifdef MSDOS
int chdrive(drive)
char drive;
{
char cmd[3];
cmd[0] = drive;
cmd[1] = ':';
cmd[2] = '\0';
return(system(cmd));
}
char curdrive()
{
union REGS r;
r.h.ah = 0x19;
intdos(&r, &r);
return(r.h.al + 'A');
}
#endif