home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / awk / awk320sr.zip / AWKFIND.C < prev    next >
C/C++ Source or Header  |  1991-04-25  |  2KB  |  79 lines

  1. /*
  2.  * wildcard expansion 
  3.  *
  4.  * Copyright (C) 1988, 1989, 1990, 1991 by Rob Duff
  5.  * All rights reserved
  6.  */
  7.  
  8. #include <stddef.h>
  9. #include <string.h>
  10.  
  11. #ifdef __TURBOC__
  12. #include <dir.h>
  13.  
  14. #else
  15. #include <dos.h>
  16. #define ffblk find_t
  17. #define ff_attrib attrib
  18. #define ff_ftime wr_time
  19. #define ff_fdata wr_date
  20. #define ff_fsize size
  21. #define ff_name name
  22. #define findfirst(n, a, s) _dos_findfirst(n, s, a)
  23. #define findnext _dos_findnext
  24.  
  25. #define MAXPATH   80
  26. #define MAXDRIVE  3
  27. #define MAXDIR    66
  28. #define MAXFILE   9
  29. #define MAXEXT    5
  30.  
  31. #define fnsplit _splitpath
  32. #define fnmerge _makepath
  33. #endif
  34.  
  35. #define bits 0x21           /* archive and readonly bits */
  36.  
  37. static struct ffblk area;
  38. static char path[MAXPATH] = "";
  39. static char drive[MAXDRIVE];
  40. static char dir[MAXDIR];
  41. static char file[MAXFILE];
  42. static char ext[MAXEXT];
  43.  
  44. char *awkfind(buff, name, attr)
  45. char *buff;
  46. char *name;
  47. int attr;
  48. {
  49.  more:
  50.     if (stricmp(name, path)) {
  51.         if (strlen(name) > MAXPATH) {
  52.             path[0] = '\0';
  53.             return(NULL);
  54.         }
  55.         strcpy(path, name);
  56.         strupr(path);
  57.         if (findfirst(path, &area, attr)) {
  58.             path[0] = '\0';
  59.             return(NULL);
  60.         }
  61.     }
  62.     else
  63.         if (findnext(&area)) {
  64.             path[0] = '\0';
  65.             return(NULL);
  66.         }
  67.     if (area.ff_name[0] == '\0') {
  68.         path[0] = '\0';
  69.         return(NULL);
  70.     }
  71.     if ((attr & bits) && !(area.ff_attrib & (attr & bits)))
  72.         goto more;
  73.     fnsplit(path, drive, dir, file, ext);
  74.     fnmerge(buff, drive, dir, "", "");
  75.     strcat(buff, area.ff_name);
  76.     return(buff);
  77. }
  78.  
  79.