/* This is the source code for the hesinfo program, used to test the
 * Hesiod name server.
 *
 *	$Source: /afs/athena.mit.edu/user/g/h/ghudson/thesis/hesiod/RCS/hesinfo.c,v $
 *	$Author: ghudson $
 *	$Athena: hesinfo.c,v 1.4 88/08/07 21:52:19 treese Locked $
 *	$Log: hesinfo.c,v $
 * Revision 1.1  1995/03/18  07:04:51  ghudson
 * Initial revision
 *
 * Revision 1.6  91/01/21  12:35:27  probe
 * PS/2 integration - added detailed Hesiod errors
 * 
 * Revision 1.5  88/08/07  23:16:50  treese
 * Second-public-distribution
 * 
 * Revision 1.4  88/08/07  21:52:19  treese
 * First public distribution
 * 
 * Revision 1.3  88/06/12  00:52:34  treese
 * Cleaned up to work with Saber.
 * First public distribution.
 * 
 * Revision 1.2  88/06/05  19:51:18  treese
 * Cleaned up for public distribution
 * 
 *
 * Copyright 1988 by the Massachusetts Institute of Technology.  See the
 * file <mit-copyright.h> for copying and distribution information.
 */

#include "mit-copyright.h"

#ifndef lint
static char rcsid_hesinfo_c[] = "$Header: /afs/athena.mit.edu/user/g/h/ghudson/thesis/hesiod/RCS/hesinfo.c,v 1.1 1995/03/18 07:04:51 ghudson Exp $";
#endif

#include <pthread.h>
#include <stdio.h>
#include <hesiod.h>

void *resolve(arg)
void *arg;
{
	char *buf[100], **cpp, **argv = (char **) arg;
	char *name = argv[0], *type = argv[1];

	switch (hes_resolve_r(name, type, buf, 100)) {
		case HES_ER_OK:
			if (*buf && !buf[1]) {
				printf("%s %s => %s\n", name, type, *buf);
			} else {
				flockfile(stdout);
				printf("%s %s:\n", name, type);
				for (cpp = buf; *cpp; cpp++)
					puts(*cpp);
				funlockfile(stdout);
			}
			break;
		case HES_ER_NOTFOUND:
			fputs("Hesiod name not found\n", stderr);
			break;
		case HES_ER_CONFIG:
			fputs("Hesiod configuration error\n", stderr);
			break;
		default:
			fputs("Unknown Hesiod error\n", stderr);
			break;
	}
	return NULL;
}

main(argc, argv)
int argc;
char *argv[];
{
	pthread_t id;

	if (argc % 2 != 1) {
		fprintf(stderr,"Usage: %s [-bl] identifier type ...\n",argv[0]);
		fprintf(stderr,"	-b also does hes_to_bind conversion\n");
		exit(2);
	}

	hes_init();

	argv++;
	while (*argv) {
		pthread_create(&id, NULL, resolve, argv);
		pthread_detach(id);
	}
	pthread_exit(NULL);
}

