Raymond Toy pushed to branch issue-437-find-self at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • src/lisp/lisp.c
    ... ... @@ -127,179 +127,12 @@ int debug_lisp_search = TRUE;
    127 127
     
    
    128 128
     /*
    
    129 129
      * From the current location of the lisp executable, create a suitable
    
    130
    - * default for CMUCLLIB
    
    130
    + * default for CMUCLLIB.  The result is a colon-separated list
    
    131
    + * directories to be used for finding the core file and for the cmucl
    
    132
    + * libraries.
    
    133
    + *
    
    134
    + * The caller must free the returned string.
    
    131 135
      */
    
    132
    -#if 0
    
    133
    -static const char *
    
    134
    -default_cmucllib(const char *argv0arg)
    
    135
    -{
    
    136
    -    char *p0;
    
    137
    -    char *defpath;
    
    138
    -    char *cwd;
    
    139
    -    char *argv0_dir = strdup(argv0arg);
    
    140
    -
    
    141
    -    /*
    
    142
    -     * From argv[0], create the appropriate directory by lopping off the
    
    143
    -     * executable name
    
    144
    -     */
    
    145
    -
    
    146
    -    p0 = strrchr(argv0_dir, '/');
    
    147
    -    if (p0 == NULL) {
    
    148
    -	*argv0_dir = '\0';
    
    149
    -    } else if (p0 != argv0_dir) {
    
    150
    -	*p0 = '\0';
    
    151
    -    }
    
    152
    -
    
    153
    -    /*
    
    154
    -     * Create the full pathname of the directory containing the
    
    155
    -     * executable.  argv[0] can be an absolute or relative path.
    
    156
    -     */
    
    157
    -    if (debug_lisp_search) {
    
    158
    -	fprintf(stderr, "argv[0] = %s\n", argv0arg);
    
    159
    -	fprintf(stderr, "argv_dir = %s\n", argv0_dir);
    
    160
    -    }
    
    161
    -
    
    162
    -
    
    163
    -    if (argv0_dir[0] == '/') {
    
    164
    -	cwd = malloc(strlen(argv0_dir) + 2);
    
    165
    -	strcpy(cwd, argv0_dir);
    
    166
    -	strcat(cwd, "/");
    
    167
    -	if (debug_lisp_search) {
    
    168
    -	    fprintf(stderr, "absolute path, argv[0] = %s\n", cwd);
    
    169
    -	}
    
    170
    -
    
    171
    -    } else if (*argv0_dir != '\0') {
    
    172
    -	/*
    
    173
    -	 * argv[0] is a relative path.  Get the current directory and
    
    174
    -	 * append argv[0], after stripping off the executable name.
    
    175
    -	 */
    
    176
    -	cwd = malloc(FILENAME_MAX + strlen(argv0_dir) + 100);
    
    177
    -	getcwd_or_die(cwd, FILENAME_MAX);
    
    178
    -	strcat(cwd, "/");
    
    179
    -	if (*argv0_dir != '\0') {
    
    180
    -	    strcat(cwd, argv0_dir);
    
    181
    -	    strcat(cwd, "/");
    
    182
    -	}
    
    183
    -	if (debug_lisp_search) {
    
    184
    -	    fprintf(stderr, "relative path, argv[0] = %s\n", cwd);
    
    185
    -	}
    
    186
    -    } else {
    
    187
    -	/*
    
    188
    -	 * argv[0] is someplace on the user's PATH
    
    189
    -	 *
    
    190
    -	 */
    
    191
    -	char *path = getenv("PATH");
    
    192
    -	char *p1, *p2 = NULL;
    
    193
    -	struct stat buf;
    
    194
    -
    
    195
    -	if (debug_lisp_search) {
    
    196
    -	    fprintf(stderr, "User's PATH = %s\n", path ? path : "<NULL>");
    
    197
    -	}
    
    198
    -
    
    199
    -	cwd = malloc(FILENAME_MAX + strlen(argv0arg) + 100);
    
    200
    -	cwd[0] = '\0';
    
    201
    -
    
    202
    -	if (path) {
    
    203
    -            const char *ptr = (p0 != NULL) ? p0 : argv0arg;
    
    204
    -
    
    205
    -	    for (p1 = path; *p1 != '\0'; p1 = p2) {
    
    206
    -		p2 = strchr(p1, ':');
    
    207
    -		if (p2 == NULL)
    
    208
    -		    p2 = p1 + strlen(p1);
    
    209
    -		strncpy(cwd, p1, p2 - p1);
    
    210
    -		cwd[p2 - p1] = '/';
    
    211
    -		cwd[p2 - p1 + 1] = '\0';
    
    212
    -		strcpy(cwd + (p2 - p1 + 1), ptr);
    
    213
    -
    
    214
    -		if (debug_lisp_search) {
    
    215
    -		    fprintf(stderr, "User's PATH, trying %s\n", cwd);
    
    216
    -		}
    
    217
    -
    
    218
    -		if (stat(cwd, &buf) == 0) {
    
    219
    -
    
    220
    -		    if (debug_lisp_search) {
    
    221
    -			fprintf(stderr, "User's PATH, found %s\n", cwd);
    
    222
    -		    }
    
    223
    -		    if (access(cwd, X_OK) == 0) {
    
    224
    -			break;
    
    225
    -		    } else {
    
    226
    -			if (debug_lisp_search) {
    
    227
    -			    fprintf(stderr,
    
    228
    -				    " But not executable.  Continuing...\n");
    
    229
    -			}
    
    230
    -		    }
    
    231
    -
    
    232
    -		}
    
    233
    -
    
    234
    -		if (*p2 == ':') {
    
    235
    -		    p2++;
    
    236
    -		}
    
    237
    -
    
    238
    -	    }
    
    239
    -	    if ((p1 == p2) || (p2 == NULL)) {
    
    240
    -		cwd[0] = '\0';
    
    241
    -	    } else {
    
    242
    -		cwd[p2 - p1 + 1] = '\0';
    
    243
    -	    }
    
    244
    -	    if (debug_lisp_search) {
    
    245
    -		fprintf(stderr, "User's PATH, Final cwd %s\n", cwd);
    
    246
    -	    }
    
    247
    -
    
    248
    -	}
    
    249
    -    }
    
    250
    -
    
    251
    -    /* Create the appropriate value for CMUCLLIB */
    
    252
    -
    
    253
    -    {
    
    254
    -	char **ptr;
    
    255
    -	int total_len;
    
    256
    -	int cwd_len;
    
    257
    -
    
    258
    -	/* First figure out how much space we need */
    
    259
    -
    
    260
    -	total_len = 0;
    
    261
    -	cwd_len = strlen(cwd);
    
    262
    -
    
    263
    -	ptr = cmucllib_search_list;
    
    264
    -
    
    265
    -	while (*ptr != NULL) {
    
    266
    -	    /* Plus 2 for the ":" and "/" we need to add */
    
    267
    -	    total_len += strlen(*ptr) + cwd_len + 2;
    
    268
    -	    ++ptr;
    
    269
    -	}
    
    270
    -
    
    271
    -	/* Create the colon separated list of directories */
    
    272
    -
    
    273
    -	defpath = malloc(total_len + 1);
    
    274
    -	*defpath = '\0';
    
    275
    -
    
    276
    -	ptr = cmucllib_search_list;
    
    277
    -	while (*ptr != NULL) {
    
    278
    -	    if (*ptr[0] != '/') {
    
    279
    -		strcat(defpath, cwd);
    
    280
    -	    }
    
    281
    -
    
    282
    -	    strcat(defpath, *ptr);
    
    283
    -
    
    284
    -	    if (ptr[1] != NULL) {
    
    285
    -		strcat(defpath, ":");
    
    286
    -	    }
    
    287
    -
    
    288
    -	    ++ptr;
    
    289
    -	}
    
    290
    -
    
    291
    -	if (strlen(defpath) > total_len) {
    
    292
    -	    abort();
    
    293
    -	}
    
    294
    -    }
    
    295
    -
    
    296
    -    free(argv0_dir);
    
    297
    -    free(cwd);
    
    298
    -
    
    299
    -    return (const char *) defpath;
    
    300
    -}
    
    301
    -#endif    
    
    302
    -
    
    303 136
     static const char *
    
    304 137
     default_cmucllib(const char *argv0arg)
    
    305 138
     {