Raymond Toy pushed to branch issue-437-find-self at cmucl / cmucl Commits: 858da43e by Raymond Toy at 2025-10-26T16:18:14-07:00 Remove old version and add some more comments. - - - - - 1 changed file: - src/lisp/lisp.c Changes: ===================================== src/lisp/lisp.c ===================================== @@ -127,179 +127,12 @@ int debug_lisp_search = TRUE; /* * From the current location of the lisp executable, create a suitable - * default for CMUCLLIB + * default for CMUCLLIB. The result is a colon-separated list + * directories to be used for finding the core file and for the cmucl + * libraries. + * + * The caller must free the returned string. */ -#if 0 -static const char * -default_cmucllib(const char *argv0arg) -{ - char *p0; - char *defpath; - char *cwd; - char *argv0_dir = strdup(argv0arg); - - /* - * From argv[0], create the appropriate directory by lopping off the - * executable name - */ - - p0 = strrchr(argv0_dir, '/'); - if (p0 == NULL) { - *argv0_dir = '\0'; - } else if (p0 != argv0_dir) { - *p0 = '\0'; - } - - /* - * Create the full pathname of the directory containing the - * executable. argv[0] can be an absolute or relative path. - */ - if (debug_lisp_search) { - fprintf(stderr, "argv[0] = %s\n", argv0arg); - fprintf(stderr, "argv_dir = %s\n", argv0_dir); - } - - - if (argv0_dir[0] == '/') { - cwd = malloc(strlen(argv0_dir) + 2); - strcpy(cwd, argv0_dir); - strcat(cwd, "/"); - if (debug_lisp_search) { - fprintf(stderr, "absolute path, argv[0] = %s\n", cwd); - } - - } else if (*argv0_dir != '\0') { - /* - * argv[0] is a relative path. Get the current directory and - * append argv[0], after stripping off the executable name. - */ - cwd = malloc(FILENAME_MAX + strlen(argv0_dir) + 100); - getcwd_or_die(cwd, FILENAME_MAX); - strcat(cwd, "/"); - if (*argv0_dir != '\0') { - strcat(cwd, argv0_dir); - strcat(cwd, "/"); - } - if (debug_lisp_search) { - fprintf(stderr, "relative path, argv[0] = %s\n", cwd); - } - } else { - /* - * argv[0] is someplace on the user's PATH - * - */ - char *path = getenv("PATH"); - char *p1, *p2 = NULL; - struct stat buf; - - if (debug_lisp_search) { - fprintf(stderr, "User's PATH = %s\n", path ? path : "<NULL>"); - } - - cwd = malloc(FILENAME_MAX + strlen(argv0arg) + 100); - cwd[0] = '\0'; - - if (path) { - const char *ptr = (p0 != NULL) ? p0 : argv0arg; - - for (p1 = path; *p1 != '\0'; p1 = p2) { - p2 = strchr(p1, ':'); - if (p2 == NULL) - p2 = p1 + strlen(p1); - strncpy(cwd, p1, p2 - p1); - cwd[p2 - p1] = '/'; - cwd[p2 - p1 + 1] = '\0'; - strcpy(cwd + (p2 - p1 + 1), ptr); - - if (debug_lisp_search) { - fprintf(stderr, "User's PATH, trying %s\n", cwd); - } - - if (stat(cwd, &buf) == 0) { - - if (debug_lisp_search) { - fprintf(stderr, "User's PATH, found %s\n", cwd); - } - if (access(cwd, X_OK) == 0) { - break; - } else { - if (debug_lisp_search) { - fprintf(stderr, - " But not executable. Continuing...\n"); - } - } - - } - - if (*p2 == ':') { - p2++; - } - - } - if ((p1 == p2) || (p2 == NULL)) { - cwd[0] = '\0'; - } else { - cwd[p2 - p1 + 1] = '\0'; - } - if (debug_lisp_search) { - fprintf(stderr, "User's PATH, Final cwd %s\n", cwd); - } - - } - } - - /* Create the appropriate value for CMUCLLIB */ - - { - char **ptr; - int total_len; - int cwd_len; - - /* First figure out how much space we need */ - - total_len = 0; - cwd_len = strlen(cwd); - - ptr = cmucllib_search_list; - - while (*ptr != NULL) { - /* Plus 2 for the ":" and "/" we need to add */ - total_len += strlen(*ptr) + cwd_len + 2; - ++ptr; - } - - /* Create the colon separated list of directories */ - - defpath = malloc(total_len + 1); - *defpath = '\0'; - - ptr = cmucllib_search_list; - while (*ptr != NULL) { - if (*ptr[0] != '/') { - strcat(defpath, cwd); - } - - strcat(defpath, *ptr); - - if (ptr[1] != NULL) { - strcat(defpath, ":"); - } - - ++ptr; - } - - if (strlen(defpath) > total_len) { - abort(); - } - } - - free(argv0_dir); - free(cwd); - - return (const char *) defpath; -} -#endif - static const char * default_cmucllib(const char *argv0arg) { View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/858da43e80c12c1dcbc63c11... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/858da43e80c12c1dcbc63c11... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)