/*
 *	Produce statistics for how heavily used various computing
 *	resources are.  In particular, how many users there are on
 *	each PAD and host throughout the day.
 *
 *	Output from connect -i opserv/netstat is one line per DTE,
 *	consisting of its name (in upper case) followed by a space,
 *	followed by either a 2-digit decimal number giving the number
 *	of users, or a 4-digit hex number giving a bitmap for usage of
 *	the 16 lines of a Z80 PAD.
 */

#include <stdio.h>

char *progname;			/* argv[0] for error reporting */

main(argc, argv)
char **argv;
{
	char line[256];		/* far too big */
	char *device;
	int nusers;
	FILE *fp;

	progname = argv[0];

	fp = popen("/usr/local/connect -i opserv/netstat", "r");
	if (fp == NULL) {
		fprintf(stderr, "%s: Failed to execute connect.\n", progname);
		exit(1);
	}

	while (gets(line) != NULL) {
		char *cp;

		/* device name is the first thing on the line */
		device = line;

		/* blat out the space with a nul */
		cp = index(line, ' ');
		if (cp == NULL) {
			fprintf(stderr, "%s: Unparsable line (no space) \"%s\".\n",
				progname, line);
			continue;
		}
		if (index(cp+1, ' ') != NULL) {
			fprintf(stderr, "%s: Unparsable line (many spaces) \"%s\".\n",
				progname, line);
			continue;
		}
		*cp++ = '\0';

		switch (strlen(cp)) {
		case 2:		/* 2-digit decimal number */
			nusers = atoi(cp);
			break;
		
		case 4:		/* 4-digit hex usage bitmap */
			if (sscanf(cp, "%x", &bitmap) != 1) {
			
