[comp.sys.amiga.programmer] Need help w/SAS dfind

scroll@reef.cis.ufl.edu (Steve Croll) (01/30/91)

In article <18173@brahms.udel.edu> don@brahms.udel.edu (Donald R Lloyd) writes:
>
>	Anyway, I'm having trouble with dfind() and dnext(). [stuff deleted]
>... can someone give me a working example of how I should be going about it?
>

I found an old (short) program that uses dfind() and dnext().  It is
probably not bulletproof but should illustrate the above functions.

#include <dos.h>

void PrintDosError(int error);

char path[FMSIZE];

int main(int argc, char *argv[])
{
    int error;
    struct FILEINFO *info;
    int index, size;

    if (argc == 1) {
        printf("usage: %s <pattern>\n",argv[0]);
        exit(10);
    }

    info = (struct FILEINFO *)malloc(sizeof(struct FILEINFO));
    if (info == NULL) {
        printf("No memory.\n");
        exit(10);
    }

    for (index = 1; index < argc; index++) {

        printf("\nMatching: %s\n",argv[index]);
        printf("--------------------------\n");
        size = stcgfp(path,argv[index]);

        error = dfind(info,argv[index],1);
        while (error == 0) {

            if (size != 0) {
                printf("%s",path);
                if (path[size-1] != ':')
                    printf("/");
            }

            printf("%s",&(info->fib_FileName));
            if (info->fib_DirEntryType > 0)
                printf(" (dir)\n");
            else
                printf("\n");

            error = dnext(info);
        }

        if ( _OSERR != 0) {
            PrintDosError(_OSERR);
            printf("%s\n",argv[index]);
        }
    }

    return 0;

}

void PrintDosError(int error)
{
    extern int os_nerr;
    int index = 0;

    while (os_errlist[index].err_no <= os_nerr) {
        if (os_errlist[index].err_no == error) {
            printf("%s: ",os_errlist[index].msg);
            return;
        }
        index++;
    }

    printf("Unknown DOS Error: ");
}

--
--
Steve Croll (internet: scroll@reef.cis.ufl.edu  home: 904-373-8389)

lordbah@bisco.kodak.COM (Lord Bah) (01/31/91)

Some solutions have been given already, add:

1) Get SAS 5.10.  It includes opendir/readdir functions similar
   to UNIX.
2) I have something called "portabledir.shar" which I used until
   SAS picked up the UNIX functions.  It similarly provides
   opendir/readdir functions.  The file says it was created in
   1987 by Mike Meyer; I suppose it came through comp.sources.amiga
   sometime after that.

--------------------------------------------------------------------
    Jeff Van Epps    amusing!lordbah@bisco.kodak.com
                     lordbah@cup.portal.com
                     sun!portal!cup.portal.com!lordbah