Skip to content
Snippets Groups Projects
Commit 756b6c2c authored by Fons Rademakers's avatar Fons Rademakers
Browse files

remove dropit executable and do path manipulation directly in shell.

Allows for thisroot.[c]sh to work without to have compile anything.


git-svn-id: http://root.cern.ch/svn/root/trunk@41612 27541ba8-7e3a-0410-8455-c3a389f83636
parent ba4ee3b8
Branches
Tags
No related merge requests found
......@@ -14,7 +14,6 @@ MODDIR := $(ROOT_SRCDIR)/$(MODNAME)
RMKDEPDIR := $(MODDIR)/rmkdepend
BINDEXPDIR := $(MODDIR)/win/bindexplib
DROPDIR := $(MODDIR)/unix/drop_from_path
##### rmkdepend #####
RMKDEPH := $(wildcard $(RMKDEPDIR)/*.h)
......@@ -26,14 +25,6 @@ RMKDEPO := $(RMKDEPO1) $(RMKDEPO2)
RMKDEP := bin/rmkdepend$(EXEEXT)
RMKDEPCFLAGS := -DINCLUDEDIR=\"/usr/include\" -DOBJSUFFIX=\".o\"
##### drop_from_path #####
ifneq ($(PLATFORM),win32)
DROPH := $(wildcard $(DROPDIR)/*.h)
DROPS := $(wildcard $(DROPDIR)/*.c)
DROPO := $(call stripsrc,$(DROPS:.c=.o))
DROP := bin/drop_from_path$(EXEEXT)
endif
##### bindexplib #####
ifeq ($(PLATFORM),win32)
BINDEXPS := $(wildcard $(BINDEXPDIR)/*.cxx)
......@@ -44,17 +35,12 @@ W32PRAGMA := $(ROOT_SRCDIR)/build/win/w32pragma.h
ALLHDRS += include/w32pragma.h
endif
POSTBIN += $(DROP)
##### local rules #####
.PHONY: all-$(MODNAME) clean-$(MODNAME) distclean-$(MODNAME)
$(RMKDEP): $(RMKDEPO)
$(LD) $(LDFLAGS) -o $@ $(RMKDEPO)
$(DROP): $(DROPO)
$(LD) $(LDFLAGS) -o $@ $(DROPO)
ifeq ($(PLATFORM),win32)
include/%.h: $(ROOT_SRCDIR)/build/win/%.h
cp $< $@
......@@ -66,16 +52,16 @@ $(BINDEXPO): $(ORDER_) $(RMKDEP)
all-$(MODNAME): $(RMKDEP) $(BINDEXP)
else
all-$(MODNAME): $(RMKDEP) $(DROP)
all-$(MODNAME): $(RMKDEP)
endif
clean-$(MODNAME):
@rm -f $(RMKDEPO) $(BINDEXPO) $(DROPO)
@rm -f $(RMKDEPO) $(BINDEXPO)
clean:: clean-$(MODNAME)
distclean-$(MODNAME): clean-$(MODNAME)
@rm -f $(RMKDEP) $(BINDEXP) $(DROP)
@rm -f $(RMKDEP) $(BINDEXP)
distclean:: distclean-$(MODNAME)
......
/* dropit.c, originated at Fermilab */
/* Note: this program was deliberately written in a K&R style. */
#include <stdio.h>
#include <string.h>
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
static const char *command = "<Unknown>";
static char *safe = 0;
struct Cell_s {
struct Cell_s *next;
char *value;
};
static struct Cell_s *pathlist = 0;
static struct Cell_s *
make_Cell(const char *str)
{
struct Cell_s *retval = (struct Cell_s *)malloc(sizeof(struct Cell_s));
if(retval) {
if(str) {
char *value = (char *)malloc(strlen(str) + 1);
if(value) {
(void) strcpy(value,str);
retval->next = 0;
retval->value = value;
} else {
free(retval);
retval = 0;
}
}
}
return retval;
}
static void
destroy_Cell(
struct Cell_s *cell)
{
/*
** This used to not be ifdefed, and sometimes free-ed
** things that were not malloc-ed. (like the "." string,
** and argv[n], etc.
** besides, we free a bunch of stuff and then exit, so
** why waste the cygles? -- mengel
*/
#ifdef slow_me_down_and_free_things_not_malloced
if(cell) {
if(cell->value) free(cell->value);
free(cell);
}
#else
if (cell) {}; // avoid unused variable message.
#endif
}
static void
add_at_front(
struct Cell_s **list, struct Cell_s *cell)
{
if(list && cell) {
cell->next = *list;
*list = cell;
} else {
printf("%s\n",safe);
exit(1);
}
}
static void
add_at_back(
struct Cell_s **list, struct Cell_s *cell)
{
if(list && cell) {
struct Cell_s *previous, *current;
for(previous = 0, current = *list;
current;
previous = current, current = current->next) {
}
if(previous) {
previous->next = cell;
} else {
*list = cell;
}
cell->next = 0;
} else {
printf("%s\n",safe);
exit(1);
}
}
static int
contains(char *field,char *test)
{
char *place;
int len = strlen(test);
if(len == 0) {
return 1;
}
while( (place = strchr(field,test[0])) ) {
if(strncmp(place,test,len) == 0) {
return 1;
}
field = place + 1;
}
return 0;
}
static int
anchored(char *field,char *test)
{
int len = strlen(test);
if(len == 0) {
return 1;
}
if (strncmp(field,test,len) == 0) {
return 1;
}
return 0;
}
static int
exact(char *field,char *test)
{
if(strcmp(field,test) == 0) {
return 1;
}
return 0;
}
int main(int argc,char **argv)
{
extern char *getenv();
int (*compare)() = 0;
void (*insert)() = 0;
const char *path = "";
const char *odel = "";
const char *null = "";
char idel = 0;
char **cpp;
// char *temp;
extern int getopt();
extern char *optarg;
extern int optind; // , opterr;
int any = 0;
int opt;
int error = 0;
// int length;
// int Lodel;
// extern int errno;
// extern char *sys_errlis[];
int Anchored = 0;
int Exact = 0;
int first = 0;
int cshmode = 0;
int setup = 0;
int Safe = 0;
int duplicates = 1;
int protected = 0;
int existance = 0;
int Ddefault = 1;
int Edefault = 1;
int Pdefault = 1;
int Sdefault = 1;
int adefault = 1;
int cdefault = 1;
int edefault = 1;
int fdefault = 1;
int idefault = 1;
int ndefault = 1;
int odefault = 1;
int pdefault = 1;
int sdefault = 1;
struct Cell_s *previous, *current;
struct stat sb;
if(argv && *argv) {
char *cp = strrchr(argv[0],'/');
command = cp ? (cp+1) : *argv;
}
while((opt = getopt(argc,argv,"i:d:n:p:aefsciDEPS?")) != -1) {
switch(opt) {
case 'D':
duplicates = 0;
if(Ddefault) Ddefault = 0; else error = 1;
break;
case 'E':
existance = 1;
if(Edefault) Edefault = 0; else error = 1;
break;
case 'P':
protected = 1;
if(Pdefault) Pdefault = 0; else error = 1;
break;
case 'S':
Safe = 1;
if(Sdefault) Sdefault = 0; else error = 1;
break;
case 'a':
Anchored = 1;
if(adefault) adefault = 0; else error = 1;
break;
case 'e':
Exact = 1;
if(edefault) edefault = 0; else error = 1;
break;
case 'f':
first = 1;
if(fdefault) fdefault = 0; else error = 1;
break;
case 'p':
path = optarg;
if(pdefault) pdefault = 0; else error = 1;
break;
case 'i':
idel = optarg[0];
if(idefault) idefault = 0; else error = 1;
break;
case 'd':
odel = optarg;
if(odefault) odefault = 0; else error = 1;
break;
case 'n':
null = optarg;
if(ndefault) ndefault = 0; else error = 1;
break;
case 's':
setup = 1;
if(sdefault) sdefault = 0; else error = 1;
break;
case 'c':
cshmode = 1;
if(cdefault) cdefault = 0; else error = 1;
break;
default:
error = 1;
}
}
if(cshmode) {
if(idefault) idel = pdefault ? ':' : ' ';
if(odefault) odel = " ";
} else {
if(idefault) idel = ':';
if(odefault) odel = ":";
}
/* Create a `safe' path, preferably their current PATH */
{ char *syspath = getenv("PATH");
if(!syspath) syspath = "/bin:/sbin:/usr/bin:/usr/bin";
if(strlen(odel) == 1) {
safe = (char *)malloc(strlen(syspath)+1);
if(safe) {
char *cp;
(void) strcpy(safe,syspath);
for(cp = safe; *cp; ++cp) if(*cp == ':') *cp = odel[0];
}
} else {
char *cp;
int del = 0;
for(cp = syspath; *cp; ++cp) if(*cp == ':') ++del;
safe = (char *)malloc(strlen(syspath)+del*(strlen(odel)-1)+1);
if(safe) {
char byte[2];
byte[1] = '\0';
safe[0] = '\0';
for(cp = syspath; *cp; ++cp) {
byte[0] = *cp;
if(*cp == ':') {
strcat(safe,odel);
} else {
strcat(safe,byte);
}
}
}
}
if(!safe) {
if(strlen(odel) == 1) {
if(odel[0] == ' ') {
safe = "/bin /sbin /usr/bin /usr/bin";
} else if(odel[0] == ':') {
safe = "/bin:/sbin:/usr/bin:/usr/bin";
} else {
safe = "/bin";
}
} else {
safe = "/bin";
}
}
}
/* After this point, `safe' must not be changed! */
if(error) {
fprintf(stderr,
"%s: usage: %s [-[aefscDEPS]] ... [-i x] [-d x] [-p path] [string] ...\n",
command,command);
printf("%s\n",safe);
exit(1);
}
if(pdefault) ndefault = 1;
if(ndefault) null = ".";
if(pdefault) {
path = getenv("PATH");
if(!path) {
idel = ':';
path = "/bin:/sbin:/usr/bin:/usr/bin";
}
}
if(path[0]) {
char *lcp, *rcp;
char *copy = (char *)malloc(strlen(path)+1);
if(copy) {
(void) strcpy(copy,path);
} else {
fprintf(stderr,"No memory to copy path\n");
printf("%s\n",safe);
exit(1);
}
for(lcp = copy, rcp = lcp; *rcp; ++rcp) {
if(*rcp == idel) {
*rcp = '\0';
if(*lcp) {
add_at_back(&pathlist,make_Cell(lcp));
} else {
add_at_back(&pathlist,make_Cell(null));
}
lcp = rcp + 1;
}
}
if(*lcp) {
add_at_back(&pathlist,make_Cell(lcp));
} else {
add_at_back(&pathlist,make_Cell(null));
}
free(copy);
}
compare = (Exact ? exact : (Anchored ? anchored : contains));
insert = (first ? add_at_front : add_at_back);
/* Do removals */
for(cpp = argv+optind; *cpp; ++cpp) {
struct Cell_s *next;
if(Safe) {
if(**cpp == '\0') continue;
if(strcmp(*cpp,"/bin") == 0) continue;
}
for(previous = 0, current = pathlist; current; current = next) {
next = current->next;
if(compare(current->value,*cpp)) {
if(previous) {
previous->next = current->next;
} else {
pathlist = current->next;
}
destroy_Cell(current);
} else {
previous = current;
}
}
}
/* Do insertations, if requested */
if(setup) {
for(cpp = argv+optind; *cpp; ++cpp) {
insert(&pathlist,
make_Cell((**cpp == '\0') ? null : *cpp));
}
}
/* Do insertations of system director(y)(ies), if requested */
if(protected) {
add_at_front(&pathlist,make_Cell("/usr/bin/X11"));
add_at_front(&pathlist,make_Cell("/usr/etc"));
add_at_front(&pathlist,make_Cell("/etc"));
add_at_front(&pathlist,make_Cell("/usr/sbin"));
add_at_front(&pathlist,make_Cell("/usr/bin"));
add_at_front(&pathlist,make_Cell("/sbin"));
add_at_front(&pathlist,make_Cell("/bin"));
add_at_back(&pathlist,make_Cell("/usr/local/bin"));
}
/* Remove duplicates */
if(Safe || protected || !duplicates) {
for(current = pathlist; current; current = current -> next) {
struct Cell_s *prev, *curr, *next;
for(prev = current, curr = current->next; curr; curr = next) {
next = curr->next;
if(strcmp(current->value,curr->value) == 0) {
prev->next = curr->next;
destroy_Cell(curr);
} else {
prev = curr;
}
}
}
}
/* Remove nonexistant file system objects or non-directories, */
/* if requested */
if(existance) {
for(previous = 0, current = pathlist;
current;
current = current -> next) {
sb.st_mode = -1;
if(stat(current->value,&sb) ||
(sb.st_mode & S_IFMT) != S_IFDIR) {
if(previous) {
previous->next = current->next;
} else {
pathlist = current->next;
}
destroy_Cell(current);
} else {
previous = current;
}
}
}
/* Do insertations of minimal system director(y)(ies), */
/* if requested and needed */
if(Safe && !pathlist) {
add_at_front(&pathlist,make_Cell("/usr/sbin"));
add_at_front(&pathlist,make_Cell("/usr/bin"));
add_at_front(&pathlist,make_Cell("/sbin"));
add_at_front(&pathlist,make_Cell("/bin"));
/* Remove nonexistant file system objects or non-directories */
for(previous = 0, current = pathlist;
current;
current = current -> next) {
sb.st_mode = -1;
if(stat(current->value,&sb) ||
(sb.st_mode & S_IFMT) != S_IFDIR) {
if(previous) {
previous->next = current->next;
} else {
pathlist = current->next;
}
destroy_Cell(current);
} else {
previous = current;
}
}
/* Recheck */
if(!pathlist) add_at_front(&pathlist,make_Cell("/bin"));
}
/* Generate the new PATH value */
{
struct Cell_s *next;
for(current = pathlist; current; current = next) {
next = current->next;
if(any) printf("%s",odel); else any = 1;
printf("%s",current->value);
destroy_Cell(current);
}
}
pathlist = 0;
printf("\n");
exit(0);
}
......@@ -17,29 +17,51 @@ set THIS="`dirname ${ARGS[2]}`"
setenv ROOTSYS "`(cd ${THIS}/..;pwd)`"
if ($?OLD_ROOTSYS) then
if ( ! -e @bindir@/drop_from_path ) then
echo "ERROR: the utility drop_from_path has not been build yet. Do:"
echo "make bin/drop_from_path"
exit 1
endif
setenv PATH `@bindir@/drop_from_path -e "$OLD_ROOTSYS/bin"`
setenv PATH `echo $PATH | sed -e "s;:$OLD_ROOTSYS/bin:;:;g" \
-e "s;:$OLD_ROOTSYS/bin;;g" \
-e "s;$OLD_ROOTSYS/bin:;;g" \
-e "s;$OLD_ROOTSYS/bin;;g"`
if ($?LD_LIBRARY_PATH) then
setenv LD_LIBRARY_PATH `@bindir@/drop_from_path -D -e -p "$LD_LIBRARY_PATH" "$OLD_ROOTSYS/lib"`
setenv LD_LIBRARY_PATH `echo $LD_LIBRARY_PATH | \
sed -e "s;:$OLD_ROOTSYS/lib:;:;g" \
-e "s;:$OLD_ROOTSYS/lib;;g" \
-e "s;$OLD_ROOTSYS/lib:;;g" \
-e "s;$OLD_ROOTSYS/lib;;g"`
endif
if ($?DYLD_LIBRARY_PATH) then
setenv DYLD_LIBRARY_PATH `@bindir@/drop_from_path -D -e -p "$DYLD_LIBRARY_PATH" "$OLD_ROOTSYS/lib"`
setenv DYLD_LIBRARY_PATH `echo $DYLD_LIBRARY_PATH | \
sed -e "s;:$OLD_ROOTSYS/lib:;:;g" \
-e "s;:$OLD_ROOTSYS/lib;;g" \
-e "s;$OLD_ROOTSYS/lib:;;g" \
-e "s;$OLD_ROOTSYS/lib;;g"`
endif
if ($?SHLIB_PATH) then
setenv SHLIB_PATH `@bindir@/drop_from_path -D -e -p "$SHLIB_PATH" "$OLD_ROOTSYS/lib"`
setenv SHLIB_PATH `echo $SHLIB_PATH | \
sed -e "s;:$OLD_ROOTSYS/lib:;:;g" \
-e "s;:$OLD_ROOTSYS/lib;;g" \
-e "s;$OLD_ROOTSYS/lib:;;g" \
-e "s;$OLD_ROOTSYS/lib;;g"`
endif
if ($?LIBPATH) then
setenv LIBPATH `@bindir@/drop_from_path -D -e -p "$LIBPATH" "$OLD_ROOTSYS/lib"`
setenv LIBPATH `echo $LIBPATH | \
sed -e "s;:$OLD_ROOTSYS/lib:;:;g" \
-e "s;:$OLD_ROOTSYS/lib;;g" \
-e "s;$OLD_ROOTSYS/lib:;;g" \
-e "s;$OLD_ROOTSYS/lib;;g"`
endif
if ($?PYTHONPATH) then
setenv PYTHONPATH `@bindir@/drop_from_path -D -e -p "$PYTHONPATH" "$OLD_ROOTSYS/lib"`
setenv PYTHONPATH `echo $PYTHONPATH | \
sed -e "s;:$OLD_ROOTSYS/lib:;:;g" \
-e "s;:$OLD_ROOTSYS/lib;;g" \
-e "s;$OLD_ROOTSYS/lib:;;g" \
-e "s;$OLD_ROOTSYS/lib;;g"`
endif
if ($?MANPATH) then
setenv MANPATH `@bindir@/drop_from_path -D -e -p "$MANPATH" "$OLD_ROOTSYS/man"`
setenv MANPATH `echo $MANPATH | \
sed -e "s;:$OLD_ROOTSYS/man:;:;g" \
-e "s;:$OLD_ROOTSYS/man;;g" \
-e "s;$OLD_ROOTSYS/man:;;g" \
-e "s;$OLD_ROOTSYS/man;;g"`
endif
endif
......
......@@ -7,6 +7,23 @@
#
# Author: Fons Rademakers, 18/8/2006
drop_from_path()
{
# Assert that we got enough arguments
if test $# -ne 2 ; then
echo "drop_from_path: needs 2 arguments"
return 1
fi
path=$1
drop=$2
newpath=`echo $path | sed -e "s;:${drop}:;:;g" \
-e "s;:${drop};;g" \
-e "s;${drop}:;;g" \
-e "s;${drop};;g"`
}
if [ -n "${ROOTSYS}" ] ; then
OLD_ROOTSYS=${ROOTSYS}
fi
......@@ -25,31 +42,33 @@ else
fi
if [ -n "${OLD_ROOTSYS}" ] ; then
if [ ! -e @bindir@/drop_from_path ]; then
echo "ERROR: the utility drop_from_path has not been build yet. Do:"
echo "make bin/drop_from_path"
return 1
fi
if [ -n "${PATH}" ]; then
PATH=`@bindir@/drop_from_path -e "${OLD_ROOTSYS}/bin"`
drop_from_path $PATH ${OLD_ROOTSYS}/bin
PATH=$newpath
fi
if [ -n "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=`@bindir@/drop_from_path -D -e -p "${LD_LIBRARY_PATH}" "${OLD_ROOTSYS}/lib"`
drop_from_path $LD_LIBRARY_PATH ${OLD_ROOTSYS}/lib
LD_LIBRARY_PATH=$newpath
fi
if [ -n "${DYLD_LIBRARY_PATH}" ]; then
DYLD_LIBRARY_PATH=`@bindir@/drop_from_path -D -e -p "${DYLD_LIBRARY_PATH}" "${OLD_ROOTSYS}/lib"`
drop_from_path $DYLD_LIBRARY_PATH ${OLD_ROOTSYS}/lib
DYLD_LIBRARY_PATH=$newpath
fi
if [ -n "${SHLIB_PATH}" ]; then
SHLIB_PATH=`@bindir@/drop_from_path -D -e -p "${SHLIB_PATH}" "${OLD_ROOTSYS}/lib"`
drop_from_path $SHLIB_PATH ${OLD_ROOTSYS}/lib
SHLIB_PATH=$newpath
fi
if [ -n "${LIBPATH}" ]; then
LIBPATH=`@bindir@/drop_from_path -D -e -p "${LIBPATH}" "${OLD_ROOTSYS}/lib"`
drop_from_path $LIBPATH ${OLD_ROOTSYS}/lib
LIBPATH=$newpath
fi
if [ -n "${PYTHONPATH}" ]; then
PYTHONPATH=`@bindir@/drop_from_path -D -e -p "${PYTHONPATH}" "${OLD_ROOTSYS}/lib"`
drop_from_path $PYTHONPATH ${OLD_ROOTSYS}/lib
PYTHONPATH=$newpath
fi
if [ -n "${MANPATH}" ]; then
MANPATH=`@bindir@/drop_from_path -D -e -p "${MANPATH}" "${OLD_ROOTSYS}/man"`
drop_from_path $MANPATH ${OLD_ROOTSYS}/man
MANPATH=$newpath
fi
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment