
#include <hsubs.h>

char hnam[64], hto[64];
main(c,v)
char **v;
{
	char *outfile, *infile;

	if(c > 3){
		printf("Usage: makehash [infile outprefix]\n");
		exit(1);
	}

	if(c == 3){
		infile = *++v;
		outfile = *++v;
	}
	else {
		infile = "/etc/passwd";
		outfile = HPREF;
	}


	if(makehash(infile, HTMP)){
		printf("\nMakehash has failed -- please find out why!\n");
		exit(2);
	}
	strcpy(hnam, HTMP);
	strcpy(hto, outfile);
	strcat(hnam, "nm");
	strcat(hto, "nm");
	unlink(hto);
	if(link(hnam, hto)){
lerr:
		printf("Link to %s failed\nOutput of command stored in %s\n",
			hto, hnam);
		exit(2);
	}
	unlink(hnam);
	chmod(hto, 0644);
	chown(hto, 3, 3);
	strcpy(hnam, HTMP);
	strcpy(hto, outfile);
	strcat(hnam, "ud");
	strcat(hto, "ud");
	unlink(hto);
	if(link(hnam, hto) == -1)
		goto lerr;
	unlink(hnam);
	chmod(hto, 0644);
	chown(hto, 3, 3);
}

