PUSHPOP, instead of CDing, needs PUTDENV
Bernie Roehl
broehl at watale.UUCP
Sun Aug 24 12:13:26 AEST 1986
This program will allow you to PUSHD too a directory instead of CDing. You
can then POPD back to wehere you were before.
NOTE: This needs an INT24 handler library which has been posted to
net.micro.pc. I have no source for it.
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by watale!broehl on Sat Aug 23 22:11:24 EDT 1986
# Contents: cd.c next.c popd.c pushd.c
echo x - cd.c
sed 's/^@//' > "cd.c" <<'@//E*O*F cd.c//'
#include <stdio.h>
#include <dos.h>
cd( name )
register char *name;
{
/* Change the current directory to the indicated name.
* Log in a new disk if necessary. This routine is
* a bit more sophisticated than DOS itself, in that
* it checks if a disk exists before trying to
* log it on. This checking is done using the
* "Get diskette status" service of BIOS interrupt 0x13.
* Get to the current directory on another disk by saying
* "cd x:" Get to another directory on another disk by
* saying "cd x:/dir/subdir/etc".
*/
if( name[1] == ':')
{
bdos( 0x0E, toupper(*name) - 'A', 0);
name += 2;
}
if( *name && chdir( name ) < 0 )
return( -1 );
return( 0 );
}
@//E*O*F cd.c//
chmod u=rw,g=r,o=r cd.c
echo x - next.c
sed 's/^@//' > "next.c" <<'@//E*O*F next.c//'
/*
* NEXT.C:
*
* Skip to the next delimiter seperated object
*
*/
#define iswhite(c) ( (c) == ' ' || (c) == '\t' || (c) == '\n' )
char *next( linep, delim, esc )
char **linep;
{
/* Linep is the address of a character pointer that points to
* a string containing a series of delim seperated objects.
* Next will return a pointer to the first non-white object in
* *linep, replace the first delimiter it finds with a null, and
* advance *linep to point past the null (provided that it's not
* at end of string). 0 is returned when an empty string is passed
* to next(). White space may be used as a delimiter but
* in this case whitespace won't be skipped. A delimiter preceeded
* by "esc" is ignored. Quoted strings are copied verbatum.
*/
register char *start, *end ;
int inquote = 0;
if( !**linep )
return 0;
start = *linep;
if( !iswhite(delim) )
for( ; iswhite(*start) ; start++ )
;
for( end = start; *end && (*end != delim || inquote) ; end++ )
{
if( *end == esc && *(end+1) )
end++;
else if( *end == '"' || *end == '\'' )
inquote = ~inquote;
}
if( *end )
*end++ = '\0';
*linep = end;
return start;
}
@//E*O*F next.c//
chmod u=rw,g=r,o=r next.c
echo x - popd.c
sed 's/^@//' > "popd.c" <<'@//E*O*F popd.c//'
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include "getargs.h"
#include "masdos.h"
int Arg_Debug = 0;
ARG Argtab[] =
{
{ 'z', ARG_FBOOLEAN, &Arg_Debug, "Debug Mode" }
};
#define ARG_TABSIZE ( sizeof(Argtab) / sizeof(ARG) )
void usage()
{
fprintf( stderr, "Usage: popd [%cZ]\n", ARG_Switch );
fprintf( stderr, "\n");
fprintf( stderr, "Set the environment variable SWITCHAR to the character\n");
fprintf( stderr, "you wish to use for the Switch Character\n");
fprintf( stderr, "\n" );
fprintf( stderr, "Case of the command line switches %s important\n",
ARG_ICase ? "is not" : "is" );
fprintf( stderr, "\n" );
fprintf( stderr, "(C) 1986 Michael A. Shiels\n");
fprintf( stderr, "\n" );
}
main( argc, argv )
int argc;
char *argv[];
{
char ndir[1000], *ndirs = ndir;
char dir[1000], *dirs, *p, *dira, *dirb;
char cwd[80], *pa;
int error;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
insint24();
if( argc != 1 )
{
usage();
exit(1);
}
p = getenv( "PUSHPOP" );
strcpy( (dirs = dir), p );
if( Arg_Debug )
fprintf( stderr, "Current PUSHPOP=%s\n", dirs );
dira = next( &dirs, ';', -1 );
if( dira == '\0' )
{
fprintf( stderr, "Popd: No directory to Pop to.\n" );
exit(1);
}
getcwd( cwd, 1000 );
for( pa = cwd ; *pa ; pa++ )
if( *pa == '\\' )
*pa = '/';
error = cd( dira );
if( !error )
{
error = int24err();
if( !error )
{
dirb = next( &dirs, '\0', -1 );
strcpy( ndirs, "PUSHPOP=" );
strcat( ndirs, dirb );
putdenv(ndir);
fprintf( stderr, "Poping to %s\n", dira );
exit();
}
else
{
cd(cwd);
fprintf( stderr, "Popd: Error CDing to directory %s.", dira );
exit(1);
}
}
else
{
fprintf( stderr, "Popd: Error CDing to directory %s.", dira );
exit(1);
}
}
@//E*O*F popd.c//
chmod u=rw,g=r,o=r popd.c
echo x - pushd.c
sed 's/^@//' > "pushd.c" <<'@//E*O*F pushd.c//'
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include "getargs.h"
#include "masdos.h"
int Arg_Debug = 0;
ARG Argtab[] =
{
{ 'z', ARG_FBOOLEAN, &Arg_Debug, "Debug Mode" }
};
#define ARG_TABSIZE ( sizeof(Argtab) / sizeof(ARG) )
void usage()
{
fprintf( stderr, "Usage: pushd [%cZ] [directory]\n", ARG_Switch );
fprintf( stderr, "\n");
fprintf( stderr, "Set the environment variable SWITCHAR to the character\n");
fprintf( stderr, "you wish to use for the Switch Character\n");
fprintf( stderr, "\n" );
fprintf( stderr, "Case of the command line switches %s important\n",
ARG_ICase ? "is not" : "is" );
fprintf( stderr, "\n" );
fprintf( stderr, "(C) 1986 Michael A. Shiels\n");
fprintf( stderr, "\n" );
}
main( argc, argv )
int argc;
char *argv[];
{
char ndir[1000], *ndirs = ndir;
char *dirs;
char cwd[80], *p;
int error;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
insint24();
if( argc != 2 )
{
usage();
exit(1);
}
dirs = getenv("PUSHPOP");
if( Arg_Debug )
fprintf( stderr, "Current PUSHPOP=%s\n", getenv("PUSHPOP") );
getcwd( cwd, 1000 );
for( p = cwd ; *p ; p++ )
if( *p == '\\' )
*p = '/';
strcpy( ndirs, "PUSHPOP=" );
strcat( ndirs, cwd );
strcat( ndirs, ";" );
if( dirs )
strcat( ndirs, dirs );
error = cd(argv[1]);
if( !error )
{
error = int24err();
if( !error )
{
putdenv(ndir);
fprintf( stderr, "Pushing to %s.\n", argv[1] );
exit();
}
else
{
cd(cwd);
fprintf( stderr, "Pushd: Error CDing to directory %s.", argv[1] );
exit(1);
}
}
else
{
fprintf( stderr, "Pushd: Error CDing to directory %s.", argv[1] );
exit(1);
}
}
@//E*O*F pushd.c//
chmod u=rw,g=r,o=r pushd.c
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
28 128 692 cd.c
51 221 1174 next.c
94 284 1797 popd.c
88 251 1669 pushd.c
261 884 5332 total
!!!
wc cd.c next.c popd.c pushd.c | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0
--
Michael A. Shiels
clyde-\
decvax-\\
ihnp4-\\\
+++-----> watmath!watale!broehl
tektronix-///
ubc-vision-//
utzoo-/
More information about the Comp.sources.unix
mailing list