if ((p = getenv("PRINTER")) == NULL)
if ((p = getenv("PRINTER")) != NULL)
static struct	hent *enter __P((char []));static struct	hent *lookup __P((char []));static int	qucmp __P((const void *, const void *));static void	rewrite __P((void));intmain(argc, argv)	int argc;	char **argv;{	register FILE *acct;	register char *cp;	euid = geteuid();	/* these aren't used in pac(1) */	uid = getuid();	while (--argc) {		cp = *++argv;		if (*cp++ == '-') {			switch(*cp++) {			case 'P':				/*				 * Printer name.				 */				printer = cp;				continue;			case 'p':				/*				 * get the price.				 */				price = atof(cp);				pflag = 1;				continue;			case 's':				/*				 * Summarize and compress accounting file.				 */				summarize++;				continue;			case 'c':				/*				 * Sort by cost.				 */				sort++;				continue;			case 'm':				/*				 * disregard machine names for each user				 */				mflag = 1;				continue;			case 'r':				/*				 * Reverse sorting order.				 */				reverse++;				continue;			default:fprintf(stderr,    "usage: pac [-Pprinter] [-pprice] [-s] [-c] [-r] [-m] [user ...]\n");				exit(1);			}		}		(void) enter(--cp);		allflag = 0;	}	if (printer == NULL) {		char *p;		printer = DEFLP;		if ((p = getenv("PRINTER")) == NULL)			printer = p;	}	if (!chkprinter(printer)) {		printf("pac: unknown printer %s\n", printer);		exit(2);	}	if ((acct = fopen(acctfile, "r")) == NULL) {		perror(acctfile);		exit(1);	}	account(acct);	fclose(acct);	if ((acct = fopen(sumfile, "r")) != NULL) {		account(acct);		fclose(acct);	}	if (summarize)		rewrite();	else		dumpit();	exit(errs);}/* * Read the entire accounting file, accumulating statistics * for the users that we have in the hash table.  If allflag * is set, then just gather the facts on everyone. * Note that we must accomodate both the active and summary file * formats here. * Host names are ignored if the -m flag is present. */static voidaccount(acct)	register FILE *acct;{	char linebuf[BUFSIZ];	double t;	register char *cp, *cp2;	register struct hent *hp;	register int ic;	while (fgets(linebuf, BUFSIZ, acct) != NULL) {		cp = linebuf;		while (any(*cp, " \t"))			cp++;		t = atof(cp);		while (any(*cp, ".0123456789"))			cp++;		while (any(*cp, " \t"))			cp++;		for (cp2 = cp; !any(*cp2, " \t\n"); cp2++)			;		ic = atoi(cp2);		*cp2 = '\0';		if (mflag && index(cp, ':'))		    cp = index(cp, ':') + 1;		hp = lookup(cp);		if (hp == NULL) {			if (!allflag)				continue;			hp = enter(cp);		}		hp->h_feetpages += t;		if (ic)			hp->h_count += ic;		else			hp->h_count++;	}}/* * Sort the hashed entries by name or footage * and print it all out. */static voiddumpit(){	struct hent **base;	register struct hent *hp, **ap;	register int hno, c, runs;	float feet;	hp = hashtab[0];	hno = 1;	base = (struct hent **) calloc(sizeof hp, hcount);	for (ap = base, c = hcount; c--; ap++) {		while (hp == NULL)			hp = hashtab[hno++];		*ap = hp;		hp = hp->h_link;	}	qsort(base, hcount, sizeof hp, qucmp);	printf("  Login               pages/feet   runs    price\n");	feet = 0.0;	runs = 0;	for (ap = base, c = hcount; c--; ap++) {		hp = *ap;		runs += hp->h_count;		feet += hp->h_feetpages;		printf("%-24s %7.2f %4d   $%6.2f\n", hp->h_name,		    hp->h_feetpages, hp->h_count, hp->h_feetpages * price);	}	if (allflag) {		printf("\n");		printf("%-24s %7.2f %4d   $%6.2f\n", "total", feet, 		    runs, feet * price);	}}/* * Rewrite the summary file with the summary information we have accumulated. */static voidrewrite(){	register struct hent *hp;	register int i;	register FILE *acctf;	if ((acctf = fopen(sumfile, "w")) == NULL) {		perror(sumfile);		errs++;		return;	}	for (i = 0; i < HSHSIZE; i++) {		hp = hashtab[i];		while (hp != NULL) {			fprintf(acctf, "%7.2f\t%s\t%d\n", hp->h_feetpages,			    hp->h_name, hp->h_count);			hp = hp->h_link;		}	}	fflush(acctf);	if (ferror(acctf)) {		perror(sumfile);		errs++;	}	fclose(acctf);	if ((acctf = fopen(acctfile, "w")) == NULL)		perror(acctfile);	else		fclose(acctf);}/* * Hashing routines. *//* * Enter the name into the hash table and return the pointer allocated. */static struct hent *enter(name)	char name[];{	register struct hent *hp;	register int h;	if ((hp = lookup(name)) != NULL)		return(hp);	h = hash(name);	hcount++;	hp = (struct hent *) calloc(sizeof *hp, 1);	hp->h_name = (char *) calloc(sizeof(char), strlen(name)+1);	strcpy(hp->h_name, name);	hp->h_feetpages = 0.0;	hp->h_count = 0;	hp->h_link = hashtab[h];	hashtab[h] = hp;	return(hp);}