DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T f

⟦98197495c⟧ TextFile

    Length: 3500 (0xdac)
    Types: TextFile
    Names: »find.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/rman/daemon/find.c« 

TextFile

#ifndef lint
static char RCSid[] = "$Header: find.c,v 1.4 85/08/27 15:16:36 broome Exp $";
#endif

/*
 * $Log:    find.c,v $
 * Revision 1.4  85/08/27  15:16:36  broome
 * Last cleanup before release.
 * 
 * Revision 1.3  85/08/04  16:32:15  broome
 * Increased efficiency by checking for directory existence before stat'ing
 * each possible file name.
 * 
 * Revision 1.2  85/07/06  16:56:18  broome
 * 
 * Revision 1.1  85/07/05  18:19:13  broome
 * Initial revision
 */

#include <sys/file.h>
#include "defs.h"

/*
 *  Take the name/section argument and try to 
 *  find the corresponding files.
 */

struct where *
find (argc, argv)
int   argc;
char  *argv[];
{
    static struct where wp;
    SEC    *sec;
    DIR    *dir;
    int    d;

    bzero ((char *)&wp, sizeof (wp));

    if (argc == 2) {   /* section specified */
        wp.section = strsave (argv[0]);
        wp.name    = strsave (argv[1]);

        if (strlen (*argv) == 2)              /* subsection kludge */
            wp.subsec = (*argv)[1];

        if (sec = find_section (*argv++)) {
            for (d = 0; sec->dirs[d]; d++)    /* check each dir pointed to */
                if (checkpath (sec->dirs[d], *argv, &wp))
                    break;
        }
    } else {
        wp.name = strsave (*argv);

        /*
         *   Default action is to check all known
         *   directories and suffixes.
         */

        for (dir = dirs; dir; dir = dir->next)
            if (checkpath (dir, *argv, &wp))
                break;
    }
    return (&wp);
}


/*
 *  Return a pointer to the section structure for the named section,
 *  Null pointer if not found.
 */

SEC *
find_section (name)
char *name;
{
    register SEC *sec;
    register int len = strlen (name);

    for (sec = sections; sec; sec = sec->next) {
        if (eq (name, sec->name))
            return (sec);
        if (len == 2 && strlen (sec->name) == 1)  /* kludge for `man 3x foo' */
            if (*name == *sec->name)
                return (sec);
    }
    return ((SEC *) 0);
}


/*
 *  Given a filename and DIR pointer, see if a file exists whose name
 *  is the concatenation of the dir, name, and suffix.
 */

checkpath (dir, name, wp)
DIR  *dir;
char *name;
struct where *wp;
{
    char  *suff;
    int   i;

    if (wp->subsec) {            /* forced subsection, don't search list */
        char suf[10];

        sprintf (suf, ".%s", wp->section);
        return (docheck (dir, name, suf, wp));
    }

    if (access (dir->man, 0) == -1) {   /* test for dir existence */
        if (debug)
            printf ("%s: No such directory.\n", dir->man);
        return (0);
    }

    for (i = 0; suff = dir->suff[i]; i++)      /* test each possible suffix */
        if (docheck (dir, name, suff, wp))
            return (1);
    return (0);
}

/*
 *  Common code to check on one file.
 */

static 
docheck (dir, name, suff, wp)
DIR  *dir;
char *name;
char *suff;
struct where *wp;
{
    char buf[256];

    sprintf (buf, "%s/%s%s", dir->man, name, suff);   /* full name of file */

    if (debug)     /* show file we are checking */
        printf ("Checking %s\t", buf);

    if (access (buf, R_OK) == -1) {         /* doesn't exist */
        if (debug)
            printf ("not found.\n");
        return (0);
    }

    if (debug)
        printf ("found.\n");

    wp->man = strsave (buf);
    sprintf (buf, "%s/%s%s", dir->cat, name, suff);   /* name of cat file */
    wp->cat = strsave (buf);
    wp->found = 1;
    return (1);
}