home *** CD-ROM | disk | FTP | other *** search
- /* find files from wildcards, for MicroSoft C v4.0 */
-
- /* ------------------------------------------------------------ */
- /* copyright 1986: */
- /* Nourse Gregg & Browne, Inc. */
- /* 1 Horizon Road. #612 */
- /* Fort Lee, NJ 07024 */
- /* */
- /* ------------------------------------------------------------ */
-
-
- /* ----------------------------------------------------------------------*
- This pair of routines will do a wildcard search
-
- you must call dfirst() once to supply the search pattern
- and get back the first file that matches that pattern.
-
- then, call dnext() to get the next file in the list.
-
- both dfirst() and dnext() return zero if a file has been found,
- non-zero otherwise.
-
-
- The calling parameters are as follows:
-
-
- dfirst(pattern,attr,file_name,file_date,file_time,file_size);
-
- dnext(file_name,file_date,file_time,file_size);
-
-
- Where:
-
- char *pattern; (wild card pattern. eg. "*.c" )
- int attr; (the file attribute qualifier )
- char *file_name; (output: the name of found file (13 bytes min.) )
- int *file_date; (output: the file's date (directory format) )
- int *file_time; (output: the file's time )
- long *file_size; (output: the file's size in bytes )
-
-
-
- *----------------------------------------------------------------- */
-
- #include <dos.h>
- #include <stdlib.h>
-
- #define SET_DTA 0x1A
- #define GET_DTA 0x2F
- #define FIND_FIRST 0x4E
- #define FIND_NEXT 0x4F
-
-
-
- struct dta_struct {
- char dummy[21];
- char attr;
- int time;
- int date;
- int low_size;
- int hi_size;
- char name[13];
- char dummy2[14];
- };
-
- static struct dta_struct dta;
-
- dfirst (fmask,fattr,fname,fdate,ftime,fsize)
- char *fmask;
- int fattr;
- char *fname;
- int *fdate;
- int *ftime;
- long *fsize;
- {
- union REGS inregs,outregs;
- struct SREGS segregs;
- int old_dta_seg;
- int old_dta_offset;
- int rc;
- long l;
-
- segread(&segregs);
-
- inregs.h.ah=GET_DTA;
- intdosx(&inregs,&outregs,&segregs);
- old_dta_seg=segregs.es;
- old_dta_offset=outregs.x.bx;
-
- inregs.h.ah=SET_DTA;
- inregs.x.dx=&dta;
- intdos(&inregs,&outregs);
-
- inregs.h.ah=FIND_FIRST;
- inregs.x.dx=fmask;
- inregs.x.cx=fattr;
- intdos(&inregs,&outregs);
- rc=(outregs.x.cflag & 0x0001);
-
- inregs.h.ah=SET_DTA;
- inregs.x.dx=old_dta_offset;
- segregs.ds=old_dta_seg;
- intdosx(&inregs,&outregs,&segregs);
-
- if (rc==0)
- {
- *ftime=dta.time;
- *fdate=dta.date;
- l=dta.hi_size;
- l=l<<16;
- l=l+dta.low_size;
- *fsize=l;
- strncpy(fname,dta.name,13);
- }
- return(rc);
- }
-
- dnext (fname,fdate,ftime,fsize)
- char *fname;
- int *fdate;
- int *ftime;
- long *fsize;
- {
- union REGS inregs,outregs;
- struct SREGS segregs;
- int old_dta_seg;
- int old_dta_offset;
- int rc;
- long l;
-
- segread(&segregs);
-
- inregs.h.ah=GET_DTA;
- intdosx(&inregs,&outregs,&segregs);
- old_dta_seg=segregs.es;
- old_dta_offset=outregs.x.bx;
-
- inregs.h.ah=SET_DTA;
- inregs.x.dx=&dta;
- intdos(&inregs,&outregs);
-
- inregs.h.ah=FIND_NEXT;
- intdos(&inregs,&outregs);
- rc=(outregs.x.cflag & 0x0001);
-
- inregs.h.ah=SET_DTA;
- inregs.x.dx=old_dta_offset;
- segregs.ds=old_dta_seg;
- intdosx(&inregs,&outregs,&segregs);
-
- if (rc==0)
- {
- *ftime=dta.time;
- *fdate=dta.date;
- l=dta.hi_size;
- l=l<<16;
- l=l+dta.low_size;
- *fsize=l;
- strncpy(fname,dta.name,13);
- }
- return(rc);
- }