/*
 *	UKC password system, 4.2 BSD version.
 *	We generate the actual gid number from the first three letters
 *	of the system id - this routine generates those numbers.
 *	from Mike Bayliss' original 4.1 call
 *	Peter Collinson UKC, Martin Guy UKC
 *
 *	Usage:
 *	gidhash groupname
 *		just prints the group-id(s) for the named group(s)
 *	gidhash
 *		with no arguments, reads group names from stdin and
 *		outputs lines suitable for inclusion in /etc/group
 */

#include <stdio.h>

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

	if (argc < 2) {
		char buf[256];

		while (gets(buf) != NULL) {
			printf("%s:*:%d:\n", buf, gidhash(buf));
		}
	} else {
		for (i=1; i<argc; i++) {
			printf("%d\n", gidhash(argv[i]));
		}
	}
	exit(0);
}

gidhash(group)
register char *group;
{
	register int i;

	if(!strncmp(group,"sys",3))
		return(0);
	i = group[0] - 'a';
	i <<= 10;
	i += ((group[1] - 'a') << 5);
	i += group[2] - 'a';
	return(i+100);
}
