Subversion Repositories SvarDOS

Rev

Rev 505 | Rev 507 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 505 Rev 506
Line 273... Line 273...
273
  *s = 0;
273
  *s = 0;
274
  output(buff);
274
  output(buff);
275
}
275
}
276
 
276
 
277
 
277
 
278
/* tries locating executable fname in path and fille res with result. returns 0 on success,
278
/* tries locating executable fname in path and fill res with result. returns 0 on success,
279
 * -1 on failed match and -2 on failed match + "don't even try with other paths"
279
 * -1 on failed match and -2 on failed match + "don't even try with other paths"
280
 * format is filled the offset where extension starts in fname (-1 if not found) */
280
 * extptr contains a ptr to the extension in fname (NULL if not found) */
281
int lookup_cmd(char *res, const char *fname, const char *path, const char **extptr) {
281
static int lookup_cmd(char *res, const char *fname, const char *path, const char **extptr) {
282
  unsigned short lastbslash = 0xffff;
282
  unsigned short lastbslash = 0;
283
  unsigned short i, len;
283
  unsigned short i, len;
284
  unsigned char explicitpath = 0;
284
  unsigned char explicitpath = 0;
285
 
285
 
286
  /* does the original fname had an explicit path prefix or explicit ext? */
286
  /* does the original fname has an explicit path prefix or explicit ext? */
287
  *extptr = NULL;
287
  *extptr = NULL;
288
  for (i = 0; fname[i] != 0; i++) {
288
  for (i = 0; fname[i] != 0; i++) {
289
    switch (fname[i]) {
289
    switch (fname[i]) {
290
      case ':':
290
      case ':':
291
      case '\\':
291
      case '\\':
Line 315... Line 315...
315
    }
315
    }
316
  }
316
  }
317
 
317
 
318
  /* printf("lastbslash=%u\r\n", lastbslash); */
318
  /* printf("lastbslash=%u\r\n", lastbslash); */
319
 
319
 
320
  /* if no path prefix in fname (':' or backslash), then assemble path+filename */
320
  /* if no path prefix was found in fname (no colon or backslash) AND we have
321
  if (!explicitpath) {
321
   * a path arg, then assemble path+filename */
322
    if (path != NULL) {
322
  if ((!explicitpath) && (path != NULL) && (path[0] != 0)) {
323
      i = strlen(path);
323
    i = strlen(path);
324
    } else {
-
 
325
      i = 0;
-
 
326
    }
-
 
327
    if ((i != 0) && (path[i - 1] != '\\')) i++; /* add a byte for inserting a bkslash after path */
324
    if (path[i - 1] != '\\') i++; /* add a byte for inserting a bkslash after path */
-
 
325
    /* move the filename at the place where path will end */
328
    memmove(res + i, res + lastbslash + 1, len - lastbslash);
326
    memmove(res + i, res + lastbslash + 1, len - lastbslash);
329
    if (i != 0) {
327
    /* copy path in front of the filename and make sure there is a bkslash sep */
330
      memmove(res, path, i);
328
    memmove(res, path, i);
331
      res[i - 1] = '\\';
329
    res[i - 1] = '\\';
332
    }
-
 
333
  }
330
  }
334
 
331
 
335
  /* if no extension was initially provided, try matching COM, EXE, BAT */
332
  /* if no extension was initially provided, try matching COM, EXE, BAT */
336
  if (*extptr == NULL) {
333
  if (*extptr == NULL) {
337
    const char *ext[] = {".COM", ".EXE", ".BAT", NULL};
334
    const char *ext[] = {".COM", ".EXE", ".BAT", NULL};