         <<< MOVIES::DISK$SYSDATA:[NOTES$LIBRARY]DOLLAR_INFO.NOTE;1 >>>
                      -< Dollar File System Information >-
================================================================================
Note 208.7                 Spiralog file scans != ODS2                    7 of 8
MOVIES::HOWELL_MA "another fine product of the Sir" 131 lines  10-JUN-1996 09:08
--------------------------------------------------------------------------------
    Here's a simple piece of code that does a wildcard lookup in the MFD
    for Files-11 and Spiralog.
    
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <atrdef.h>
#include <fibdef.h>
#include <fiddef.h>
#include <iodef.h>
#include <lib$routines.h>
#include <ssdef.h>
#include <starlet.h>
#include <stsdef.h>

#define DISK "SYS$DISK"
#define WILDCARD "*.*;*"

#define SUCCESS(p1) (((p1) & STS$M_SEVERITY) == STS$K_SUCCESS)
#define FAILURE(p1) (((p1) & STS$M_SEVERITY) != STS$K_SUCCESS)

/* Context required to restart a wildcard scan */

typedef struct qio_cxt_s {
    unsigned short chan;
    unsigned long wcc;
    struct fiddef did;
    unsigned short result_len;
    unsigned long result_dsc[2];
    char result[ATR$S_ASCNAME];
    unsigned long filename_dsc[2];
    char filename[ATR$S_ASCNAME];
} qio_cxt_t;

static unsigned long next_name (qio_cxt_t *);

int main (int argc, char *argv[])
{
    unsigned long status;
    unsigned long devnam_dsc[2];
    qio_cxt_t cxt;

    devnam_dsc[0] = sizeof (DISK) - 1;
    devnam_dsc[1] = (unsigned long) DISK;

    /* Clear context */

    memset (&cxt, 0, sizeof (cxt));

    /* Assign a channel */

    if (FAILURE (status = sys$assign (&devnam_dsc, &cxt.chan, 0, NULL)))
        lib$stop (status);

    /* Setup the directory ID as the MFD */

    cxt.did.fid$w_num = FID$C_MFD;
    cxt.did.fid$w_seq = FID$C_MFD;
    cxt.did.fid$w_rvn = 0;

    /* Clear the wildcard context */

    cxt.wcc = 0;

    /* Set up the result name descriptor */

    cxt.result_dsc[0] = sizeof (cxt.result);
    cxt.result_dsc[1] = (unsigned long) cxt.result;

    /* Set up the file name descriptor */

    cxt.filename_dsc[0] = sizeof (WILDCARD) - 1;
    cxt.filename_dsc[1] = (unsigned long) cxt.filename;
    strncpy (cxt.filename, WILDCARD, sizeof (WILDCARD) - 1);

    /* Lookup the file names */

    while (SUCCESS (status = next_name (&cxt)))
        printf ("%.*s\n", cxt.result_len, cxt.result);

    if (FAILURE (status) && status != SS$_NOMOREFILES)
        lib$stop (status);

    if (FAILURE (status = sys$dassgn (cxt.chan)))
        lib$stop (status);

    return (0);

}/* main */

static unsigned long next_name (qio_cxt_t *cxt)
{
    unsigned long status;
    unsigned short iosb[4];
    struct fibdef fib;
    unsigned long fib_dsc[2];

    memset (&fib, 0, sizeof (fib));

    fib_dsc[0] = sizeof (fib);
    fib_dsc[1] = (unsigned long) &fib;

    /* Set up FIB context information */

    fib.fib$l_wcc = cxt->wcc;
    memmove (fib.fib$w_did, &cxt->did, sizeof (fib.fib$w_did));
    fib.fib$v_wild = 1;

    /* Lookup the next file name */

    status = sys$qiow (0, cxt->chan, IO$_ACCESS, iosb, NULL, 0,
                       &fib_dsc,
                       cxt->filename_dsc,
                       &cxt->result_len,
                       cxt->result_dsc,
                       0, 0);
    if (SUCCESS (status))
        status = iosb[0];

    if (status == SS$_NOSUCHFILE)
        status = SS$_NOMOREFILES;

    /* Save the updated wildcard context */

    cxt->wcc = fib.fib$l_wcc;

    return (status);

}/* next_name */
    
