home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 19 Printer / 19-Printer.zip / lj2up2.zip / FSEARCH.C next >
Text File  |  1988-07-12  |  2KB  |  85 lines

  1. /*
  2. **  File functions FSEARCH and FNEXT.
  3. **
  4. **
  5. **  Joe Barnhart,   21-July-86
  6. **  Steve Coles,    19-October-87 changed for OS/2
  7. **  Steve Coles,    12-July-88 changed to MSC 1.1 headers
  8. */
  9.  
  10. /* Prototypes */
  11.  
  12. char *fsearch(char *fname);
  13. char *fnext(void );
  14. char *fpath(char *fname);
  15.  
  16. #define INCL_NOCOMMON       /* These three lines define how much    */
  17. #define INCL_DOSFILEMGR     /* of the OS/2 API is defined. In this  */
  18. #include <os2.h>            /* only file functions.                 */
  19.  
  20. /* Standard C includes */
  21. #include <string.h>       
  22.  
  23.  
  24. HDIR dhand;               /* search handle */
  25. FILEFINDBUF wbuf;           /* OS/2 places directory info */
  26. USHORT nwbuf = 1;           /* number of directories */
  27.  
  28.  
  29. char *fsearch( fname )
  30. char *fname;
  31. {
  32.    unsigned rc;
  33.  
  34.    dhand = 0xffff;          /* let OS assign handle */ 
  35.    rc = DosFindFirst(fname,
  36.       &dhand,
  37.       0,
  38.       &wbuf,
  39.       sizeof(wbuf),
  40.       &nwbuf,
  41.       0L);
  42.    if (rc == 0)
  43.       return(strlwr(wbuf.achName));
  44.    return(0);
  45. }
  46.  
  47.  
  48. char *fnext()
  49. {
  50.    unsigned rc;
  51.  
  52.    rc = DosFindNext(dhand,
  53.       &wbuf,
  54.       sizeof(wbuf),
  55.       &nwbuf);
  56.    if (rc == 0)
  57.       return(strlwr(wbuf.achName));
  58.    return(0);
  59. }
  60.  
  61.  
  62. char *fpath( fname )
  63. char *fname;
  64. {
  65.     static char path[32];
  66.     register int plen;
  67.     register char *p;
  68.     char *endp;
  69.  
  70.     for( p=fname, endp=fname; *p!='\0'; p++ )
  71.     if( *p==':' || *p=='\\' )
  72.         endp = p+1;
  73.  
  74.     plen = endp - fname;
  75.     if( plen == 0 )
  76.     path[0] = '\0';
  77.     else {
  78.     strncpy( path, fname, plen );
  79.     path[ plen+1 ] = '\0';
  80.     strlwr( path );
  81.     }
  82.     return( path );
  83. }
  84. 
  85.