Subversion Repositories SvarDOS

Rev

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

Rev 1046 Rev 1072
Line 651... Line 651...
651
 * extptr is filled with a ptr to the extension in fname (NULL if no extension) */
651
 * extptr is filled with a ptr to the extension in fname (NULL if no extension) */
652
int lookup_cmd(char *res, const char *fname, const char *path, const char **extptr) {
652
int lookup_cmd(char *res, const char *fname, const char *path, const char **extptr) {
653
  unsigned short lastbslash = 0;
653
  unsigned short lastbslash = 0;
654
  unsigned short i, len;
654
  unsigned short i, len;
655
  unsigned char explicitpath = 0;
655
  unsigned char explicitpath = 0;
-
 
656
  const char *exec_ext[] = {"COM", "EXE", "BAT", NULL};
656
 
657
 
657
  /* does the original fname has an explicit path prefix or explicit ext? */
658
  /* does the original fname has an explicit path prefix or explicit ext? */
658
  *extptr = NULL;
659
  *extptr = NULL;
659
  for (i = 0; fname[i] != 0; i++) {
660
  for (i = 0; fname[i] != 0; i++) {
660
    switch (fname[i]) {
661
    switch (fname[i]) {
Line 667... Line 668...
667
        *extptr = fname + i + 1;
668
        *extptr = fname + i + 1;
668
        break;
669
        break;
669
    }
670
    }
670
  }
671
  }
671
 
672
 
-
 
673
  /* if explicit ext found, make sure it is executable */
-
 
674
  if (*extptr != NULL) {
-
 
675
    for (i = 0; exec_ext[i] != NULL; i++) if (imatch(*extptr, exec_ext[i])) break;
-
 
676
    if (exec_ext[i] == NULL) return(-2); /* bad extension - don't try running it ever */
-
 
677
  }
-
 
678
 
672
  /* normalize filename */
679
  /* normalize filename */
673
  if (file_truename(fname, res) != 0) return(-2);
680
  if (file_truename(fname, res) != 0) return(-2);
674
 
681
 
675
  /* printf("truename: %s\r\n", res); */
682
  /* printf("truename: %s\r\n", res); */
676
 
683
 
677
  /* figure out where the command starts and if it has an explicit extension */
684
  /* figure out where the command starts */
678
  for (len = 0; res[len] != 0; len++) {
685
  for (len = 0; res[len] != 0; len++) {
679
    switch (res[len]) {
686
    switch (res[len]) {
680
      case '?':   /* abort on any wildcard character */
687
      case '?':   /* abort on any wildcard character */
681
      case '*':
688
      case '*':
682
        return(-2);
689
        return(-2);
Line 700... Line 707...
700
    res[i - 1] = '\\';
707
    res[i - 1] = '\\';
701
  }
708
  }
702
 
709
 
703
  /* if no extension was initially provided, try matching COM, EXE, BAT */
710
  /* if no extension was initially provided, try matching COM, EXE, BAT */
704
  if (*extptr == NULL) {
711
  if (*extptr == NULL) {
705
    const char *ext[] = {".COM", ".EXE", ".BAT", NULL};
712
    int attr;
706
    len = strlen(res);
713
    len = strlen(res);
-
 
714
    res[len++] = '.';
707
    for (i = 0; ext[i] != NULL; i++) {
715
    for (i = 0; exec_ext[i] != NULL; i++) {
708
      strcpy(res + len, ext[i]);
716
      strcpy(res + len, exec_ext[i]);
709
      /* printf("? '%s'\r\n", res); */
717
      /* printf("? '%s'\r\n", res); */
710
      *extptr = ext[i] + 1;
718
      *extptr = exec_ext[i];
711
      if (file_getattr(res) >= 0) return(0);
719
      attr = file_getattr(res);
-
 
720
      if (attr < 0) continue; /* file not found */
-
 
721
      if (attr & DOS_ATTR_DIR) continue; /* this is a directory */
-
 
722
      if (attr & DOS_ATTR_VOL) continue; /* this is a volume */
-
 
723
      return(0);
712
    }
724
    }
713
  } else { /* try finding it as-is */
725
  } else { /* try finding it as-is */
714
    /* printf("? '%s'\r\n", res); */
726
    /* printf("? '%s'\r\n", res); */
715
    if (file_getattr(res) >= 0) return(0);
727
    int attr = file_getattr(res);
-
 
728
    if ((attr >= 0) &&  /* file exists */
-
 
729
        ((attr & DOS_ATTR_DIR) == 0) && /* is not a directory */
-
 
730
        ((attr & DOS_ATTR_VOL) == 0)) { /* is not a volume */
-
 
731
      return(0);
-
 
732
    }
716
  }
733
  }
717
 
734
 
718
  /* not found */
735
  /* not found */
719
  if (explicitpath) return(-2); /* don't bother trying other paths, the caller had its own path preset anyway */
736
  if (explicitpath) return(-2); /* don't bother trying other paths, the caller had its own path preset anyway */
720
  return(-1);
737
  return(-1);