home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / FINDEXE.C < prev    next >
Text File  |  1993-05-07  |  8KB  |  110 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   findexe.c                                                               */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  Find EXE file.                                                           */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   11/30/92 Created.                                                       */
  12. /*                                                                           */
  13. /*...Release 1.02 (10/22/92)                                                 */
  14. /*...                                                                        */
  15. /*... 05/06/93  822   Joe       Add mte table handling.                      */
  16. /*...                                                                        */
  17. /*****************************************************************************/
  18.  
  19. /*****************************************************************************/
  20. /* Includes.                                                                 */
  21. /*****************************************************************************/
  22. #define INCL_DOSMISC
  23. #include <os2.h>
  24.  
  25. #include <string.h>
  26.  
  27. #define INCL_FINDEXE
  28. #include "funcs.h"
  29.  
  30. /*****************************************************************************/
  31. /* FindExe()                                                                 */
  32. /*                                                                           */
  33. /* Description:                                                              */
  34. /*                                                                           */
  35. /*   Find EXE file.                                                          */
  36. /*                                                                           */
  37. /* Parameters:                                                               */
  38. /*                                                                           */
  39. /*   progname input  - The filespec of the EXE we're looking for.            */
  40. /*                                                                           */
  41. /*   pn       input  - Pointer to the caller's buffer to receive filespec.   */
  42. /*   pnlen    input  - Length of the caller's buffer.                        */
  43. /*                                                                           */
  44. /* Return:                                                                   */
  45. /*                                                                           */
  46. /*   rc       The return code from DosSearchPath().                          */
  47. /*            The caller's buffer gets a fully qualified file spec.          */
  48. /*                                                                           */
  49. /* Assumptions:                                                              */
  50. /*                                                                           */
  51. /*  The EXE extension has been added to the filespec.                        */
  52. /*                                                                           */
  53. /*****************************************************************************/
  54. UINT FindExe(char *progname,char *pn,UINT pnlen)
  55.                                         /* progname :: the passed filespec   */
  56.                                         /* pn :: the caller's buffer         */
  57.                                         /* pnlen :: caller's buffer length   */
  58. {                                       /*                                   */
  59.  char      *fn;                         /* pointer to the filename           */
  60.  ULONG      control;                    /* control word for DosSearchPath 822*/
  61.  char       pathref[129];               /* path buffer for DosSearchPath     */
  62.  char      *pref;                       /* a pointer to "\" in the filespec  */
  63.  UINT       rc;                         /* DosSearchPath return code         */
  64.  char       fs[256];                    /* make local copy of progname.      */
  65.  
  66. /*****************************************************************************/
  67. /* Look for the explicit filespec if there was one.                          */
  68. /*                                                                           */
  69. /* We have to extract the path part of the filespec and tell DosSearchPath   */
  70. /* what it is. If we don't find the explicit filespec, then return with a    */
  71. /* file not found code.                                                      */
  72. /*****************************************************************************/
  73.  strcpy(fs,progname);                   /* make local copy of progname.      */
  74.  control = 0;                           /* use pathref as an ASCIIZ string   */
  75.  pref=strrchr(fs,'\\');                 /* check again. Was there a path in  */
  76.  if(pref)                               /* the filespec? If so, then         */
  77.  {                                      /*                                   */
  78.   *pref = '\0';                         /* copy path part of passed filespec */
  79.   strcpy(pathref,fs);                   /* to the pathref                    */
  80.   fn = pref+1;                          /* this is the filename less path    */
  81.   rc=DosSearchPath(control,pathref,fn,pn,pnlen); /* look for it              */
  82.   return(rc);                           /* return the result of our efforts  */
  83.  }                                      /*                                   */
  84.                                         /*                                   */
  85. /*****************************************************************************/
  86. /* Look in the current directory.                                            */
  87. /*                                                                           */
  88. /* At this point, there was no explicit filespec so we will look in the      */
  89. /* current directory.                                                        */
  90. /*****************************************************************************/
  91.                                         /* or use filename as passed.        */
  92.  rc= DosSearchPath(control,".\\",fs,pn,pnlen); /* look for the file          */
  93.  if ( rc==0 )                           /* if we found it then               */
  94.   return(rc);                           /* return.                           */
  95.                                         /*                                   */
  96. /*****************************************************************************/
  97. /* Now look along the SD386SRC environment variable.                      116*/
  98. /*****************************************************************************/
  99.  control = 2;                           /* use path reference as env variable*/
  100.  rc=DosSearchPath(control,"SD386SRC",fs,pn,pnlen); /* look for it         116*/
  101.  if( rc==0)                             /*                                   */
  102.   return(rc);                           /*                                   */
  103.                                         /*                                   */
  104. /*****************************************************************************/
  105. /* Now look along the PATH environment variable.                             */
  106. /*****************************************************************************/
  107.  rc=DosSearchPath(control,"PATH",fs,pn,pnlen);    /* look for it             */
  108.  return(rc);                            /*                                   */
  109. }                                       /* end findexe()                     */
  110.