Environment Manipulators, uses PUTDENV and MSLIBRARY
Bernie Roehl
broehl at watale.UUCP
Fri Sep 5 04:48:20 AEST 1986
These programs will allow you to manipulate PATH and Dpath for a PC etc etc.
PUSHENV - push something on the start of the variable
POPENV - pop something off the start of the variable
ADDENV - add something to the end of the variable
REMENV - remove something from the end of the variable
# 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 Thu Sep 4 14:36:25 EDT 1986
# Contents: addenv.c popenv.c pushenv.c remenv.c
echo x - addenv.c
sed 's/^@//' > "addenv.c" <<'@//E*O*F addenv.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: AddEnv [%cZ] env_var string_to_add\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;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
if( argc != 3 )
{
usage();
exit(1);
}
dirs = getenv(argv[1]);
if( Arg_Debug )
fprintf( stderr, "Current %s=%s\n", argv[1], getenv(argv[1]) );
sprintf( ndirs, "%s=", argv[1] );
if( dirs )
{
strcat( ndirs, dirs );
strcat( ndirs, ";" );
}
strcat( ndirs, argv[2] );
putdenv(ndir);
exit();
}
@//E*O*F addenv.c//
chmod u=rw,g=r,o=r addenv.c
echo x - popenv.c
sed 's/^@//' > "popenv.c" <<'@//E*O*F popenv.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: Popenv [%cZ] env_var\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;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
if( argc != 2 )
{
usage();
exit(1);
}
p = getenv( argv[1] );
strcpy( (dirs = dir), p );
if( Arg_Debug )
fprintf( stderr, "Current %s=%s\n", argv[1], dirs );
dira = next( &dirs, ';', -1 );
if( dira == '\0' )
{
fprintf( stderr, "PopEnv: Nothing to Pop.\n" );
exit(1);
}
dirb = next( &dirs, '\0', -1 );
if( dirb )
{
sprintf( ndirs, "%s=", argv[1] );
strcat( ndirs, dirb );
}
else
sprintf( ndirs, "%s", argv[1] );
putdenv(ndir);
exit();
}
@//E*O*F popenv.c//
chmod u=rw,g=r,o=r popenv.c
echo x - pushenv.c
sed 's/^@//' > "pushenv.c" <<'@//E*O*F pushenv.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: PushEnv [%cZ] env_var string_to_add\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;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
if( argc != 3 )
{
usage();
exit(1);
}
dirs = getenv(argv[1]);
if( Arg_Debug )
fprintf( stderr, "Current %s=%s\n", argv[1], getenv(argv[1]) );
sprintf( ndirs, "%s=", argv[1] );
strcat( ndirs, argv[2] );
if( dirs )
{
strcat( ndirs, ";" );
strcat( ndirs, dirs );
}
putdenv(ndir);
exit();
}
@//E*O*F pushenv.c//
chmod u=rw,g=r,o=r pushenv.c
echo x - remenv.c
sed 's/^@//' > "remenv.c" <<'@//E*O*F remenv.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: RemEnv [%cZ] env_var\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;
argc = getargs( argc, argv, Argtab, ARG_TABSIZE );
ctlc();
if( argc != 2 )
{
usage();
exit(1);
}
p = getenv( argv[1] );
strcpy( (dirs = dir), p );
if( Arg_Debug )
fprintf( stderr, "Current %s=%s\n", argv[1], dirs );
dirs = strrev( dirs );
dira = next( &dirs, ';', -1 );
if( dira )
dira = strrev( dira );
if( dira == '\0' )
{
fprintf( stderr, "RemEnv: Nothing to Pop.\n" );
exit(1);
}
dirb = next( &dirs, '\0', -1 );
if( dirb)
dirb = strrev( dirb );
if( dirb )
{
sprintf( ndirs, "%s=", argv[1] );
strcat( ndirs, dirb );
}
else
sprintf( ndirs, "%s", argv[1] );
putdenv(ndir);
exit();
}
@//E*O*F remenv.c//
chmod u=rw,g=r,o=r remenv.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 <<\!!!
61 177 1225 addenv.c
70 215 1400 popenv.c
61 177 1226 pushenv.c
75 235 1498 remenv.c
267 804 5349 total
!!!
wc addenv.c popenv.c pushenv.c remenv.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