home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / FINDFILE.C < prev    next >
Text File  |  1993-06-24  |  16KB  |  205 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   findfile.c                                                              */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  Find EXE or DLL source files.                                            */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*   02/08/91 Creation of 32-bit SD86, from 16-bit version.                  */
  13. /*                                                                           */
  14. /*...16->32 port.                                                            */
  15. /*...                                                                        */
  16. /*... 02/08/91  116   Joe       port to 32 bit.                              */
  17. /*...                                                                        */
  18. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  19. /*...                                                                        */
  20. /*... 12/19/91  500   Srinivas  HPFS file name problems.                     */
  21. /*...                                                                        */
  22. /**Includes*******************************************************************/
  23.  
  24. #include "all.h"                        /* SD86 include files                */
  25.  
  26. /*****************************************************************************/
  27. /* findsrc()                                                                 */
  28. /*                                                                           */
  29. /* Description:                                                              */
  30. /*                                                                           */
  31. /*   find exe or dll source.                                                 */
  32. /*                                                                           */
  33. /* Parameters:                                                               */
  34. /*                                                                           */
  35. /*   fs       Pointer to filespec.                                           */
  36. /*   pn       Pointer to the caller's buffer for the path.                   */
  37. /*   pnlen    Length of the caller's buffer.                                 */
  38. /*                                                                           */
  39. /* Return:                                                                   */
  40. /*                                                                           */
  41. /*****************************************************************************/
  42.  void
  43. findsrc(char *fs,char *pn,uint pnlen)   /* fs :: the passed filespec         */
  44.                                         /* pn :: the caller's buffer         */
  45.                                         /* pnlen :: caller's buffer length   */
  46. {                                       /*                                   */
  47.  char      *fn;                         /* pointer to the filename           */
  48.  USHORT     control;                    /* control word for DosSearchPath    */
  49.  char       pathref[129];               /* path buffer for DosSearchPath     */
  50.  char      *pref;                       /* a pointer to "\" in the filespec  */
  51.  uint       rc;                         /* DosSearchPath return code         */
  52.  uint       FileNameLen,i;              /*                                500*/
  53.  uint       PathFlag = 0;               /*                                500*/
  54.                                         /*                                   */
  55. /*****************************************************************************/
  56. /* First, look in the current directory.                                     */
  57. /*                                                                           */
  58. /* If the filespec has a path prefix, then we want to strip off the filename */
  59. /* part of it. If the filespec is just a filename, then use it as is.        */
  60. /*****************************************************************************/
  61.  FileNameLen = strlen(fs);                                              /*500*/
  62.  i = 0;                                                                 /*500*/
  63.  fn = fs + FileNameLen;                                                 /*500*/
  64.  while (i++ < FileNameLen)                                              /*500*/
  65.  {                                                                      /*500*/
  66.    if ( (*fn == '\\') || (*fn == '/') )                                 /*500*/
  67.    {                                                                    /*500*/
  68.      fn = fn + 1;                                                       /*500*/
  69.      break;                                                             /*500*/
  70.    }                                                                    /*500*/
  71.    else                                                                 /*500*/
  72.      fn--;                                                              /*500*/
  73.  }                                                                      /*500*/
  74.  control = 0;                           /* no impied current directory       */
  75.  rc= DosSearchPath(control,".\\",fn,pn,pnlen); /* look for the file          */
  76.  if ( rc==0 )                           /* if we found it then               */
  77.   return;                               /* return.                           */
  78.                                         /*                                   */
  79. /*****************************************************************************/
  80. /* If not in the current directory, then try the filespec as passed.         */
  81. /*                                                                           */
  82. /* We have to extract the path part of the filespec and tell DosSearchPath   */
  83. /* what it is.                                                               */
  84. /*****************************************************************************/
  85.                                         /*                                   */
  86.  i = 0;                                                                 /*500*/
  87.  pref = fs + FileNameLen;                                               /*500*/
  88.  while (i++ < FileNameLen)                                              /*500*/
  89.  {                                                                      /*500*/
  90.    if ( (*pref == '\\') || (*pref == '/') )                             /*500*/
  91.    {                                                                    /*500*/
  92.      PathFlag = 1;                                                      /*500*/
  93.      break;                                                             /*500*/
  94.    }                                                                    /*500*/
  95.    else                                                                 /*500*/
  96.      pref--;                                                            /*500*/
  97.  }                                                                      /*500*/
  98.  if(PathFlag)                           /* the filespec? If so, then      500*/
  99.  {                                      /*                                   */
  100.   *pref = '\0';                         /* copy path part of passed filespec */
  101.   strcpy(pathref,fs);                   /* to the pathref                    */
  102.   fn = pref+1;                          /* this is the filename less path    */
  103.   control = 0;                          /* use pathref as an ASCIIZ string   */
  104.   rc=DosSearchPath(control,pathref,fn,pn,pnlen); /* look for it              */
  105.   if ( rc==0 )                          /* if we found it then               */
  106.    return;                              /* return.                           */
  107.  }
  108. /*****************************************************************************/
  109. /* Now look along the SD386SRC environment variable.                      116*/
  110. /*****************************************************************************/
  111.  control = 2;                          /* use path reference as env variable */
  112.  rc=DosSearchPath(control,"SD386SRC",fn,pn,pnlen); /* look for it         116*/
  113.  if( rc==0)                             /*                                   */
  114.   return;                               /*                                   */
  115.                                         /*                                   */
  116. /*****************************************************************************/
  117. /* Now look along the PATH environment variable.                             */
  118. /*****************************************************************************/
  119.  rc=DosSearchPath(control,"PATH",fn,pn,pnlen);    /* look for it             */
  120.  if( rc==0)                             /*                                   */
  121.   return;                               /*                                   */
  122.  pn = NULL;                             /* OUT OF LUCK CHIEF.                */
  123. }                                       /*                                   */
  124.  
  125. /*****************************************************************************/
  126. /* FindExe()                                                                 */
  127. /*                                                                           */
  128. /* Description:                                                              */
  129. /*                                                                           */
  130. /*   Find EXE file.                                                          */
  131. /*                                                                           */
  132. /* Parameters:                                                               */
  133. /*                                                                           */
  134. /*   progname input  - The filespec of the EXE we're looking for.            */
  135. /*                                                                           */
  136. /*   pn       input  - Pointer to the caller's buffer to receive filespec.   */
  137. /*   pnlen    input  - Length of the caller's buffer.                        */
  138. /*                                                                           */
  139. /* Return:                                                                   */
  140. /*                                                                           */
  141. /*   rc       The return code from DosSearchPath().                          */
  142. /*            The caller's buffer gets a fully qualified file spec.          */
  143. /*                                                                           */
  144. /* Assumptions:                                                              */
  145. /*                                                                           */
  146. /*  The EXE extension has been added to the filespec.                        */
  147. /*                                                                           */
  148. /*****************************************************************************/
  149. UINT FindExe(char *progname,char *pn,UINT pnlen)
  150.                                         /* progname :: the passed filespec   */
  151.                                         /* pn :: the caller's buffer         */
  152.                                         /* pnlen :: caller's buffer length   */
  153. {                                       /*                                   */
  154.  char      *fn;                         /* pointer to the filename           */
  155.  ULONG      control;                    /* control word for DosSearchPath 822*/
  156.  char       pathref[129];               /* path buffer for DosSearchPath     */
  157.  char      *pref;                       /* a pointer to "\" in the filespec  */
  158.  UINT       rc;                         /* DosSearchPath return code         */
  159.  char       fs[256];                    /* make local copy of progname.      */
  160.  
  161. /*****************************************************************************/
  162. /* Look for the explicit filespec if there was one.                          */
  163. /*                                                                           */
  164. /* We have to extract the path part of the filespec and tell DosSearchPath   */
  165. /* what it is. If we don't find the explicit filespec, then return with a    */
  166. /* file not found code.                                                      */
  167. /*****************************************************************************/
  168.  strcpy(fs,progname);                   /* make local copy of progname.      */
  169.  control = 0;                           /* use pathref as an ASCIIZ string   */
  170.  pref=strrchr(fs,'\\');                 /* check again. Was there a path in  */
  171.  if(pref)                               /* the filespec? If so, then         */
  172.  {                                      /*                                   */
  173.   *pref = '\0';                         /* copy path part of passed filespec */
  174.   strcpy(pathref,fs);                   /* to the pathref                    */
  175.   fn = pref+1;                          /* this is the filename less path    */
  176.   rc=DosSearchPath(control,pathref,fn,pn,pnlen); /* look for it              */
  177.   return(rc);                           /* return the result of our efforts  */
  178.  }                                      /*                                   */
  179.                                         /*                                   */
  180. /*****************************************************************************/
  181. /* Look in the current directory.                                            */
  182. /*                                                                           */
  183. /* At this point, there was no explicit filespec so we will look in the      */
  184. /* current directory.                                                        */
  185. /*****************************************************************************/
  186.                                         /* or use filename as passed.        */
  187.  rc= DosSearchPath(control,".\\",fs,pn,pnlen); /* look for the file          */
  188.  if ( rc==0 )                           /* if we found it then               */
  189.   return(rc);                           /* return.                           */
  190.                                         /*                                   */
  191. /*****************************************************************************/
  192. /* Now look along the SD386SRC environment variable.                      116*/
  193. /*****************************************************************************/
  194.  control = 2;                           /* use path reference as env variable*/
  195.  rc=DosSearchPath(control,"SD386SRC",fs,pn,pnlen); /* look for it         116*/
  196.  if( rc==0)                             /*                                   */
  197.   return(rc);                           /*                                   */
  198.                                         /*                                   */
  199. /*****************************************************************************/
  200. /* Now look along the PATH environment variable.                             */
  201. /*****************************************************************************/
  202.  rc=DosSearchPath(control,"PATH",fs,pn,pnlen);    /* look for it             */
  203.  return(rc);                            /*                                   */
  204. }                                       /* end findexe()                     */
  205.