/*
                            F I N D F I R S . C
*/

#include "icrssdef.h"

ICMAKE_FIND_
    ifs;                                    /* icmake find-struct */

char *findfirst(char *fspec, unsigned attrib)
{
    char
        *cp;                                /* pointer to matched filename */

    ifs.attrib = attrib;                    /* initialize ifs */

#ifdef MSDOS                                /* use find_pattern if 1st char */
    if (*fspec == '.')                      /* of fspec is '.' */
    {
        ifs.pattern = fspec;                /* remember old pattern */
        fspec = "*.*";                      /* now: match all       */
    }
    else
        ifs.pattern = NULL;                 /* no '.'-> no special action */
#endif

                                            /* find all entries */
    if (_dos_findfirst(fspec, (unsigned)-1, &ifs.find))
        return (NULL);                      /* failed already: return NULL */

    return
    (
        (cp = filefound()) ?                /* attrib/pattern ok: return */
            cp
        :
            findnext()                      /* or retry a match */
    );
}
