home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name drsfirst -- Find the first matching file
- *
- * Synopsis ercode = drsfirst(pname,sattr,pfile);
- *
- * int ercode Returned DOS function error code
- * char *pname Filename specification string
- * int sattr Attribute which files must match
- * FSPEC *pfile File information for matching file
- *
- * Description DRSFIRST finds the first occurrence of a file which
- * matches both the specified attribute and the file
- * "name." If a file is found that matches the filename
- * (including drive, path and attribute), the file's
- * attribute, time and date stamp, size, and filename are
- * returned in the FSPEC structure.
- *
- * The name specification can be any legal DOS path name,
- * possibly with embedded wild card characters ('*' or '?')
- * in the last portion of the name (the filename). The
- * name must be terminated by a NUL character ('\0').
- *
- * The search attribute parameter specifies which files are
- * potential candidates for a match. The acceptable search
- * attributes are:
- *
- * AT_GENERAL ( 0) - Normal file
- * AT_RDONLY ( 1) - Read-only file
- * AT_HIDDEN ( 2) - Hidden file
- * AT_SYSTEM ( 4) - System file
- * AT_DIR (16) - Subdirectory
- *
- * Attribute values may be combined by adding them
- * together. Files are found which match a subset (some or
- * none) of the specified attributes. For example, search
- * attribute 23 qualifies all files, while 16 finds
- * subdirectories and ordinary files.
- *
- * If the value of the function is 0 (i.e., no error), then
- * a file was found and DRSNEXT can be used to find further
- * files matching the specified name and attribute. If the
- * value of the function is 18, then no matching files were
- * found, and neither will DRSNEXT find any matching files.
- *
- * Method DRSFIRST is used in conjunction with DRSNEXT to search
- * through the file directory. DOS uses a portion of the
- * current Disk Transfer Area for a scratch area and to
- * communicate when subsequent calls are made to DRSNEXT.
- * Because the current DTA can be overwritten if defined in
- * another function (it can be set by by I/O calls and
- * placed on the stack), DRSFIRST changes the DTA to a
- * static area and then returns the DTA to its previous
- * location. DRSNEXT uses the same communication area,
- * performing a similar DTA switch.
- *
- * Returns ercode DOS function error code
- * *pfile FSPEC structure containing file information
- * for match file.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bdirect.h>
- #include <bfile.h>
-
- char b_drbuffer[48] = {0}; /* DRSFIRST, DRSNEXT communica- */
- /* tion buffer. */
-
- int drsfirst(pname,sattr,pfile)
- char *pname;
- int sattr;
- FSPEC *pfile;
- {
- ADS dta_ads,buf_ads,file_ads;
- int ercode;
- DOSREG dos_reg;
-
- flretdta(&dta_ads); /* Return DTA location, and set */
- utabsptr(b_drbuffer,&buf_ads); /* the new DTA location. */
- flsetdta(&buf_ads);
-
- dos_reg.ax = 0x4e00; /* DOS function 4E */
- dos_reg.cx = sattr;
- utabsptr(pname,&file_ads); /* Set the pointer to the */
- dos_reg.ds = file_ads.s; /* search name. */
- dos_reg.dx = file_ads.r;
-
- ercode = dos(&dos_reg);
-
- if (ercode == 0) /* Found a match, now get info */
- { /* and move into the FSPEC */
- /* structure. */
- utabsptr((char *) pfile,&file_ads);
- buf_ads.r += 20; /* File info is at offset 20 */
- utslmove(&buf_ads,&file_ads,23);
- pfile->fattr = uthibyte(pfile->fattr); /* Move attribute value */
- } /* into the proper byte. */
-
- flsetdta(&dta_ads); /* Restore the DTA location */
-
- return(ercode);
- }