Subversion Repositories SvarDOS

Rev

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

Rev 542 Rev 571
Line 752... Line 752...
752
    pop ax
752
    pop ax
753
  }
753
  }
754
 
754
 
755
  if (errcode != 0) printf("AX=%04x\r\n", errcode);
755
  if (errcode != 0) printf("AX=%04x\r\n", errcode);
756
}
756
}
-
 
757
 
-
 
758
 
-
 
759
/* locates executable fname in path and fill res with result. returns 0 on success,
-
 
760
 * -1 on failed match and -2 on failed match + "don't even try with other paths"
-
 
761
 * extptr is filled with a ptr to the extension in fname (NULL if no extension) */
-
 
762
int lookup_cmd(char *res, const char *fname, const char *path, const char **extptr) {
-
 
763
  unsigned short lastbslash = 0;
-
 
764
  unsigned short i, len;
-
 
765
  unsigned char explicitpath = 0;
-
 
766
 
-
 
767
  /* does the original fname has an explicit path prefix or explicit ext? */
-
 
768
  *extptr = NULL;
-
 
769
  for (i = 0; fname[i] != 0; i++) {
-
 
770
    switch (fname[i]) {
-
 
771
      case ':':
-
 
772
      case '\\':
-
 
773
        explicitpath = 1;
-
 
774
        *extptr = NULL; /* extension is the last dot AFTER all path delimiters */
-
 
775
        break;
-
 
776
      case '.':
-
 
777
        *extptr = fname + i + 1;
-
 
778
        break;
-
 
779
    }
-
 
780
  }
-
 
781
 
-
 
782
  /* normalize filename */
-
 
783
  if (file_truename(fname, res) != 0) return(-2);
-
 
784
 
-
 
785
  /* printf("truename: %s\r\n", res); */
-
 
786
 
-
 
787
  /* figure out where the command starts and if it has an explicit extension */
-
 
788
  for (len = 0; res[len] != 0; len++) {
-
 
789
    switch (res[len]) {
-
 
790
      case '?':   /* abort on any wildcard character */
-
 
791
      case '*':
-
 
792
        return(-2);
-
 
793
      case '\\':
-
 
794
        lastbslash = len;
-
 
795
        break;
-
 
796
    }
-
 
797
  }
-
 
798
 
-
 
799
  /* printf("lastbslash=%u\r\n", lastbslash); */
-
 
800
 
-
 
801
  /* if no path prefix was found in fname (no colon or backslash) AND we have
-
 
802
   * a path arg, then assemble path+filename */
-
 
803
  if ((!explicitpath) && (path != NULL) && (path[0] != 0)) {
-
 
804
    i = strlen(path);
-
 
805
    if (path[i - 1] != '\\') i++; /* add a byte for inserting a bkslash after path */
-
 
806
    /* move the filename at the place where path will end */
-
 
807
    memmove(res + i, res + lastbslash + 1, len - lastbslash);
-
 
808
    /* copy path in front of the filename and make sure there is a bkslash sep */
-
 
809
    memmove(res, path, i);
-
 
810
    res[i - 1] = '\\';
-
 
811
  }
-
 
812
 
-
 
813
  /* if no extension was initially provided, try matching COM, EXE, BAT */
-
 
814
  if (*extptr == NULL) {
-
 
815
    const char *ext[] = {".COM", ".EXE", ".BAT", NULL};
-
 
816
    len = strlen(res);
-
 
817
    for (i = 0; ext[i] != NULL; i++) {
-
 
818
      strcpy(res + len, ext[i]);
-
 
819
      /* printf("? '%s'\r\n", res); */
-
 
820
      *extptr = ext[i] + 1;
-
 
821
      if (file_getattr(res) >= 0) return(0);
-
 
822
    }
-
 
823
  } else { /* try finding it as-is */
-
 
824
    /* printf("? '%s'\r\n", res); */
-
 
825
    if (file_getattr(res) >= 0) return(0);
-
 
826
  }
-
 
827
 
-
 
828
  /* not found */
-
 
829
  if (explicitpath) return(-2); /* don't bother trying other paths, the caller had its own path preset anyway */
-
 
830
  return(-1);
-
 
831
}
-
 
832
 
-
 
833
 
-
 
834
/* fills fname with the path and filename to the linkfile related to the
-
 
835
 * executable link "linkname". returns 0 on success. */
-
 
836
int link_computefname(char *fname, const char *linkname, unsigned short env_seg) {
-
 
837
  unsigned short pathlen;
-
 
838
 
-
 
839
  /* fetch %DOSDIR% */
-
 
840
  pathlen = env_lookup_valcopy(fname, 128, env_seg, "DOSDIR");
-
 
841
  if (pathlen == 0) {
-
 
842
    outputnl("%DOSDIR% not defined");
-
 
843
    return(-1);
-
 
844
  }
-
 
845
 
-
 
846
  /* prep filename: %DOSDIR%\LINKS\PKG.LNK */
-
 
847
  if (fname[pathlen - 1] == '\\') pathlen--;
-
 
848
  sprintf(fname + pathlen, "\\LINKS\\%s.LNK", linkname);
-
 
849
 
-
 
850
  return(0);
-
 
851
}