#include <stdio.h>
#include <strings.h>
#include <ndbm.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/types.h>

#include "inquir.h"

typedef struct mesnode
    {
    char *line;
    struct mesnode *next;
    } messagenode;

main(argc, argv)
int argc;
char **argv;
    {
    char **argp;
    int i;

    setup_strings();
    if (argc == 1)
	{
	printf("Welcome to LCS.");
	exit(0);
	}

    argc--;
    i = 2;

    while (argc)
	{
	lookup(argv[i]);
	argc--;
	i++;
	}
    exit(0);
    }

void lookup(uname)
char *uname;
{
DBM *iq;
datum key, usinfo;

if ((iq = dbm_open(Inquirdata, DBM_INSERT, 0770)) < 0)
    {
    fprintf(stderr,"Can't open dbase %s:  %s\n",Inquirdata,sys_errlist[errno]);
    exit(-1);
    }

key.dptr = Upcase(uname);
key.dsize = strlen(uname);

usinfo = dbm_fetch(iq, key);
dbm_close(iq);

if (usinfo.dptr == NULL)
    {
    fprintf(stderr,"Unknown UNAME \"%s\"\r\n",Upcase(uname));
    exit(0);
    }

entry = (char *) malloc(usinfo.dsize + 1);
strncpy(entry, usinfo.dptr, usinfo.dsize);
*(entry + entry.dsize) = '\0';

while (strlen(entry) != 0)
    {   /* note: returned lines are crlf'd */
    malloc(
    sprintf("%s\t:", GetFirstWord(entry, "\3772"));
    temp = GetFirstWord(entry, "\3772");
    while(TRUE)
	{
	printf("%s\r\n", GetFirstWord(temp, "\n"));
	if (strlen(temp) == 0) break;
	printf("\t:");
	}
    }
}
