static char sccsid
[] = "@(#)vpac.c 1.2 (Berkeley) %G%";
* Do Versatec and Varian accounting summary.
* to print the usage information for the named people.
#define VAACCT "/usr/adm/vaacct"
#define VASUM "/usr/adm/va_sum"
#define VPACCT "/usr/adm/vpacct"
#define VPSUM "/usr/adm/vp_sum"
#define VAPRICE 0.02 /* Dollars per page */
#define VPPRICE 0.08 /* Dollars per foot of paper */
* Names to be accumulated are hashed into the following
#define HSHSIZE 97 /* Number of hash buckets */
struct hent
*h_link
; /* Forward hash link */
char h_name
[9]; /* Name of this user */
float h_feetpages
; /* Feet or pages of paper */
int h_count
; /* Number of runs */
struct hent
*hashtab
[HSHSIZE
]; /* Hash table proper */
#define NIL ((struct hent *) 0) /* The big zero */
int allflag
; /* Get stats on everybody */
int sort
; /* Sort by cost */
int summarize
; /* Compress accounting file */
int reverse
; /* Reverse sort order */
int wide
; /* wide paper (Versatec) accounting. */
int hcount
; /* Count of hash entries */
while (*cp
) switch(*cp
++) {
* Sort by feet of typesetter film.
* Versatec, not Varian accounting.
fprintf(stderr
, "%s?\n", *argv
);
if ((acct
= fopen(acctfile
, "r")) == NULL
) {
if ((acct
= fopen(sumfile
, "r")) != NULL
) {
* 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
register struct hent
*hp
;
while (fgets(linebuf
, BUFSIZ
, acct
) != NULL
) {
while (any(*cp
, ".0123456789"))
for (cp2
= cp
; !any(*cp2
, " \t\n"); cp2
++)
if (hp
== NIL
&& !allflag
)
* Sort the hashed entries by name or footage
register struct hent
*hp
, **ap
;
register int hno
, c
, runs
;
base
= (struct hent
**) calloc(sizeof hp
, hcount
+4);
for (ap
= base
, c
= hcount
; c
--; ap
++) {
qsort(base
, hcount
, sizeof hp
, qucmp
);
printf(wide
? " Login feet runs price\n"
: " Login pages runs price\n");
for (ap
= base
, c
= hcount
; c
--; ap
++) {
printf("%-8s %7.2f %4d $%6.2f\n", hp
->h_name
, hp
->h_feetpages
,
hp
->h_count
, hp
->h_feetpages
* price
);
printf("%-8s %7.2f %4d $%6.2f\n", "total", feet
,
* Rewrite the summary file with the summary information we have accumulated.
register struct hent
*hp
;
if ((acctf
= fopen(sumfile
, "w")) == NULL
) {
for (i
= 0; i
< HSHSIZE
; i
++) {
fprintf(acctf
, "%7.2f\t%s\t%d\n", hp
->h_feetpages
,
hp
->h_name
, hp
->h_count
);
if ((acctf
= fopen(acctfile
, "w")) == NULL
)
* Enter the passed name into the hash table
* and returns the pointer allocated.
register struct hent
*hp
;
if ((hp
= lookup(name
)) != NIL
)
hp
= (struct hent
*) calloc(sizeof *hp
, 1);
strcpy(hp
->h_name
, name
);
* Lookup a name in the hash table and return a pointer
register struct hent
*hp
;
for (hp
= hashtab
[h
]; hp
!= NIL
; hp
= hp
->h_link
)
if (strcmp(hp
->h_name
, name
) == 0)
* Hash the passed name and return the index in
* the hash table to begin the search.
for (cp
= name
, h
= 0; *cp
; h
= (h
<< 2) + *cp
++)
* Throw away a hash pointer.
* The qsort comparison routine.
* The comparison is ascii collating order
* or by feet of typesetter film, according to sort.
struct hent
**left
, **right
;
register struct hent
*h1
, *h2
;
r
= h1
->h_feetpages
< h2
->h_feetpages
? -1 : h1
->h_feetpages
> h2
->h_feetpages
;
r
= strcmp(h1
->h_name
, h2
->h_name
);
return(reverse
? -r
: r
);