[Contents] [Index] [Help] [Retrace] [browse <] [Browse >]


NAME
    MatchFirst -- Finds file that matches pattern (V36)

SYNOPSIS
    error = MatchFirst(pat, AnchorPath)
    D0                 D1       D2

    LONG MatchFirst(STRPTR, struct anchorpath *)

FUNCTION
    Locates the first file or directory that matches a given pattern.
    MatchFirst() is passed your pattern (you do not pass it through
    parsepattern() - matchfirst() does that for you), and the control
    structure.  MatchFirst() normally initializes your anchorpath
    structure for you, and returns the first file that matched your
    pattern, or an error.  Note that matchfirst()/matchnext() are unusual
    for Dos in that they return 0 for success, or the error code (see
    <dos/dos.h>), instead of the application getting the error code
    from ioerr().

    When looking at the result of matchfirst()/matchnext(), the ap_info
    field of your anchorpath has the results of an examine() of the object.
    You normally get the name of the object from fib_FileName, and the
    directory it's in from ap_Current->an_Lock.  To access this object,
    normally you would temporarily currentdir() to the lock, do an action
    to the file/dir, and then currentdir() back to your original directory.
    This makes certain you affect the right object even when two volumes
    of the same name are in the system.  You can use ap_Buf (with
    ap_Strlen) to get a name to report to the user.

    To initialize the anchorpath structure (particularily when reusing
    it), set ap_BreakBits to the signal bits (CDEF) that you want to take
    a break on, or NULL, if you don't want to convenience the user.
    ap_Flags should be set to any flags you need or all 0's otherwise.
    ap_FoundBreak should be cleared if you'll be using breaks.

    If you want to have the FULL PATH NAME of the files you found,
    allocate a buffer at the END of this structure, and put the size of
    it into ap_Strlen.  If you don't want the full path name, make sure
    you set ap_Strlen to zero.  In this case, the name of the file, and
    stats are available in the ap_Info, as per usual.

    Then call MatchFirst() and then afterwards, matchnext() with this
    structure.  You should check the return value each time (see below)
    and take the appropriate action, ultimately calling matchend() when
    there are no more files or you are done.  You can tell when you are
    done by checking for the normal AmigaDOS return code
    ERROR_NO_MORE_ENTRIES.

    Note: patterns with trailing slashes may cause matchfirst()/matchnext()
    to return with an ap_Current->an_Lock on the object, and a filename
    of the empty string ("").

    See parsepattern() for more information on the patterns.

INPUTS
    pat        - Pattern to search for
    anchorpath - place holder for search.  must be longword aligned!

RESULT
    error - 0 for success or error code.  (Opposite of most Dos calls!)

BUGS
    In V36, there were a number of bugs with matchfirst()/matchnext().
    One was that if you entered a directory with a name like "df0:l"
    using DODIR, it would re-lock the full string "df0:l", which can
    cause problems if the disk has changed.  It also had problems
    with patterns such as #?/abc/def - the ap_Current->an_Lock would
    not be on the directory def is found in.  ap_Buf would be correct,
    however.  It had similar problems with patterns with trailing
    slashes.  These have been fixed for V37 and later.

    A bug that has not been fixed for V37 concerns a pattern of a
    single directory name (such as "l").  If you enter such a directory
    via DODIR, it re-locks l relative to the current directory.  Thus
    you must not change the current directory before calling matchnext()
    with DODIR in that situation.  If you aren't using DODIR to enter
    directories you can ignore this.  This may be fixed in some upcoming
    release.

SEE ALSO
    matchnext(), parsepattern(), examine(), currentdir(), examine(),
    matchend(), exnext(), <dos/dosasl.h>