Added PATH search.

* If argv[0] contains a '/', then we look for argv[0]++".boot"
* Otherwise, search the path[i] for where argv[0] came from and
  append ".boot" to that.
This commit is contained in:
Abdulaziz Ghuloum 2006-12-01 11:18:01 -05:00
parent d0355ead97
commit d04eb83cf3
3 changed files with 66 additions and 4 deletions

Binary file not shown.

View File

@ -42,19 +42,81 @@ get_option(char* opt, int argc, char** argv){
return 0;
}
int
file_exists(char* filename){
struct stat sb;
int s = stat(filename, &sb);
return (s == 0);
}
int
copy_fst_path(char* buff, char* x){
int i = 0;
while(1){
char c = x[i];
if ((c == 0) || (c == ':')){
return i;
}
buff[i] = c;
i++;
}
}
int global_exe(char* x){
while(1){
char c = *x;
if(c == 0){
return 1;
}
if(c == '/'){
return 0;
}
x++;
}
}
int main(int argc, char** argv){
char ikarus_boot[FILENAME_MAX];
char buff[FILENAME_MAX];
char* boot_file = get_option("-b", argc, argv);
if(boot_file){
argc -= 2;
}
else if(global_exe(argv[0])){
/* search path name */
char* path = getenv("PATH");
if(path == NULL){
fprintf(stderr, "unable to locate boot file\n");
exit(-1);
}
while(*path){
int len = copy_fst_path(buff, path);
char* x = buff + len;
x = stpcpy(x, "/");
x = stpcpy(x, argv[0]);
if(file_exists(buff)){
x = stpcpy(x, ".boot");
boot_file = buff;
path = "";
}
else {
if(path[len]){
path += (len+1);
} else {
boot_file = ikarus_boot;
char* x = ikarus_boot;
fprintf(stderr, "unable to locate %s\n", argv[0]);
exit(-1);
}
}
}
}
else {
char* x = buff;
x = stpcpy(x, argv[0]);
x = stpcpy(x, ".boot");
boot_file = buff;
}
if(sizeof(mp_limb_t) != sizeof(int)){
fprintf(stderr, "ERROR: limb size\n");
}

Binary file not shown.