home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / usrcmdos2.c < prev    next >
C/C++ Source or Header  |  1993-02-28  |  1KB  |  54 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "alias.h"
  4.  
  5. /* This does the dirty work for find_path_file () and find_user_command ().
  6.    NAME is the name of the file to search for.
  7.    PATH_LIST is a colon separated list of directories to search.
  8.    FLAGS contains bit fields which control the files which are eligible.
  9.    Some values are:
  10.       FS_EXEC_ONLY:        The file must be an executable to be found.
  11.       FS_EXEC_PREFERRED:    If we can't find an executable, then the
  12.                 the first file matching NAME will do.
  13.       FS_EXISTS:        The first file found will do.
  14. */
  15. char *
  16. find_user_command_in_path (name, path_list, flags)
  17.      char *name;
  18.      char *path_list;
  19.      int flags;
  20. {char tempPath[257];
  21. char        *altName;
  22. int            name_len;
  23.  
  24. altName = NULL;
  25. if(!DosSearchPath(3, "PATH", name, tempPath, 256))
  26.     goto l2;
  27.  
  28. /* if input name does not end in .exe append this string to name and save
  29.    in altName
  30. */
  31. name_len = strlen(name);
  32. if(!strcmp(name+name_len-4, ".exe"))
  33.     return NULL;
  34. else
  35.     {altName = xmalloc(name_len+5);
  36.     strcpy(altName, name);
  37.     strcat(altName, ".exe");
  38.     }
  39. if(DosSearchPath(3, "PATH", altName, tempPath, 256))
  40.     {free(altName);
  41.     return NULL;
  42.     }
  43.  
  44. l2:
  45.  
  46. if(altName != NULL)
  47.     free(altName);
  48. altName = xmalloc(strlen(tempPath)+1);
  49. strcpy(altName, tempPath);
  50. return altName;
  51. }
  52.  
  53.  
  54.