home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / XSRVFEXE.C < prev    next >
Text File  |  1994-02-03  |  8KB  |  100 lines

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