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 a

⟦c3af2ffa3⟧ TextFile

    Length: 1769 (0x6e9)
    Types: TextFile
    Names: »apropos.c«

Derivation

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

TextFile

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

/*
 * $Log:    apropos.c,v $
 * Revision 1.5  85/08/27  15:16:08  broome
 * Last cleanup before release.
 * 
 * Revision 1.4  85/07/24  10:38:26  broome
 * Ready to ship out ... (?)
 * 
 * Revision 1.3  85/07/04  20:26:25  broome
 * Fixed error messages to conform to the rfc.
 */


#include "response.h"
#include <stdio.h>

#define LIST "/usr/lib/whatis"

/*ARGSUSED*/
apropos (argc, argv)
int     argc;
char    **argv;
{
    register FILE *fp;
    char     buf[512];
    int      found = 0;

    argv++;
    if ((fp = fopen (LIST, "r")) == NULL) {
        printf ("%d cannot open %s\r\n", ERR_NOFILE, LIST);
        return;
    }

    while (fgets (buf, 512, fp)) {
        if (substr (buf, *argv)) {
            if (found == 0)
                printf ("%d information on %s coming.\r\n", OK_COMING, *argv);
            printf ("%s", buf);
            (void) fflush (stdout);    /* so it doesn't seem as slow to them */
            found++;
        }
    }
    if (!found) 
        printf ("%d %s: nothing appropriate.\n", ERR_NOENT, *argv);
    else
        puts (".\r");
}


/*
 *  Returns 1 if `sub' is contained in `str'.
 */

substr (buf, str)
register char *buf, *str;
{
    register char *i;

    i = str;

    while (*buf) {
        if (tolower (*buf) == *i) {   /* first char matches */
            while (*buf) {            /* does rest match?   */
                if (tolower (*buf) != *i)
                    break;
                buf++, i++;
            }
            if (!*i)                  /* ran out of substring */
                return (1);
            i = str;                  /* reset i */
        }
        buf++;
    }
    return (0);
}