pac.c (27635) | pac.c (29780) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 19 unchanged lines hidden (view full) --- 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#ifndef lint | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 19 unchanged lines hidden (view full) --- 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#ifndef lint |
36static char copyright[] = | 36static const char copyright[] = |
37"@(#) Copyright (c) 1983, 1993\n\ 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint | 37"@(#) Copyright (c) 1983, 1993\n\ 38 The Regents of the University of California. All rights reserved.\n"; 39#endif /* not lint */ 40 41#ifndef lint |
42#if 0 |
|
42static char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93"; | 43static char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93"; |
44#endif 45static const char rcsid[] = 46 "$Id$"; |
|
43#endif /* not lint */ 44 45/* 46 * Do Printer accounting summary. 47 * Currently, usage is 48 * pac [-Pprinter] [-pprice] [-s] [-r] [-c] [-m] [user ...] 49 * to print the usage information for the named people. 50 */ --- 43 unchanged lines hidden (view full) --- 94static int any __P((int, char [])); 95static int chkprinter __P((char *)); 96static void dumpit __P((void)); 97static int hash __P((char [])); 98static struct hent *enter __P((char [])); 99static struct hent *lookup __P((char [])); 100static int qucmp __P((const void *, const void *)); 101static void rewrite __P((void)); | 47#endif /* not lint */ 48 49/* 50 * Do Printer accounting summary. 51 * Currently, usage is 52 * pac [-Pprinter] [-pprice] [-s] [-r] [-c] [-m] [user ...] 53 * to print the usage information for the named people. 54 */ --- 43 unchanged lines hidden (view full) --- 98static int any __P((int, char [])); 99static int chkprinter __P((char *)); 100static void dumpit __P((void)); 101static int hash __P((char [])); 102static struct hent *enter __P((char [])); 103static struct hent *lookup __P((char [])); 104static int qucmp __P((const void *, const void *)); 105static void rewrite __P((void)); |
106static void usage __P((void)); |
|
102 103int 104main(argc, argv) 105 int argc; 106 char **argv; 107{ 108 register FILE *acct; 109 register char *cp; --- 43 unchanged lines hidden (view full) --- 153 case 'r': 154 /* 155 * Reverse sorting order. 156 */ 157 reverse++; 158 continue; 159 160 default: | 107 108int 109main(argc, argv) 110 int argc; 111 char **argv; 112{ 113 register FILE *acct; 114 register char *cp; --- 43 unchanged lines hidden (view full) --- 158 case 'r': 159 /* 160 * Reverse sorting order. 161 */ 162 reverse++; 163 continue; 164 165 default: |
161fprintf(stderr, 162 "usage: pac [-Pprinter] [-pprice] [-s] [-c] [-r] [-m] [user ...]\n"); 163 exit(1); | 166 usage(); |
164 } 165 } 166 (void) enter(--cp); 167 allflag = 0; 168 } 169 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 170 printer = DEFLP; 171 if (!chkprinter(printer)) { --- 13 unchanged lines hidden (view full) --- 185 } 186 if (summarize) 187 rewrite(); 188 else 189 dumpit(); 190 exit(errs); 191} 192 | 167 } 168 } 169 (void) enter(--cp); 170 allflag = 0; 171 } 172 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 173 printer = DEFLP; 174 if (!chkprinter(printer)) { --- 13 unchanged lines hidden (view full) --- 188 } 189 if (summarize) 190 rewrite(); 191 else 192 dumpit(); 193 exit(errs); 194} 195 |
196static void 197usage() 198{ 199 fprintf(stderr, 200 "usage: pac [-Pprinter] [-pprice] [-s] [-c] [-r] [-m] [user ...]\n"); 201 exit(1); 202} 203 |
|
193/* 194 * Read the entire accounting file, accumulating statistics 195 * for the users that we have in the hash table. If allflag 196 * is set, then just gather the facts on everyone. 197 * Note that we must accomodate both the active and summary file 198 * formats here. 199 * Host names are ignored if the -m flag is present. 200 */ --- 81 unchanged lines hidden (view full) --- 282static void 283rewrite() 284{ 285 register struct hent *hp; 286 register int i; 287 register FILE *acctf; 288 289 if ((acctf = fopen(sumfile, "w")) == NULL) { | 204/* 205 * Read the entire accounting file, accumulating statistics 206 * for the users that we have in the hash table. If allflag 207 * is set, then just gather the facts on everyone. 208 * Note that we must accomodate both the active and summary file 209 * formats here. 210 * Host names are ignored if the -m flag is present. 211 */ --- 81 unchanged lines hidden (view full) --- 293static void 294rewrite() 295{ 296 register struct hent *hp; 297 register int i; 298 register FILE *acctf; 299 300 if ((acctf = fopen(sumfile, "w")) == NULL) { |
290 perror(sumfile); | 301 warn("%s", sumfile); |
291 errs++; 292 return; 293 } 294 for (i = 0; i < HSHSIZE; i++) { 295 hp = hashtab[i]; 296 while (hp != NULL) { 297 fprintf(acctf, "%7.2f\t%s\t%d\n", hp->h_feetpages, 298 hp->h_name, hp->h_count); 299 hp = hp->h_link; 300 } 301 } 302 fflush(acctf); 303 if (ferror(acctf)) { | 302 errs++; 303 return; 304 } 305 for (i = 0; i < HSHSIZE; i++) { 306 hp = hashtab[i]; 307 while (hp != NULL) { 308 fprintf(acctf, "%7.2f\t%s\t%d\n", hp->h_feetpages, 309 hp->h_name, hp->h_count); 310 hp = hp->h_link; 311 } 312 } 313 fflush(acctf); 314 if (ferror(acctf)) { |
304 perror(sumfile); | 315 warn("%s", sumfile); |
305 errs++; 306 } 307 fclose(acctf); 308 if ((acctf = fopen(acctfile, "w")) == NULL) | 316 errs++; 317 } 318 fclose(acctf); 319 if ((acctf = fopen(acctfile, "w")) == NULL) |
309 perror(acctfile); | 320 warn("%s", acctfile); |
310 else 311 fclose(acctf); 312} 313 314/* 315 * Hashing routines. 316 */ 317 --- 115 unchanged lines hidden (view full) --- 433 434 if (cgetstr(bp, "af", &acctfile) == -1) { 435 printf("accounting not enabled for printer %s\n", printer); 436 exit(2); 437 } 438 if (!pflag && (cgetnum(bp, "pc", &price100) == 0)) 439 price = price100/10000.0; 440 sumfile = (char *) calloc(sizeof(char), strlen(acctfile)+5); | 321 else 322 fclose(acctf); 323} 324 325/* 326 * Hashing routines. 327 */ 328 --- 115 unchanged lines hidden (view full) --- 444 445 if (cgetstr(bp, "af", &acctfile) == -1) { 446 printf("accounting not enabled for printer %s\n", printer); 447 exit(2); 448 } 449 if (!pflag && (cgetnum(bp, "pc", &price100) == 0)) 450 price = price100/10000.0; 451 sumfile = (char *) calloc(sizeof(char), strlen(acctfile)+5); |
441 if (sumfile == NULL) { 442 perror("pac"); 443 exit(1); 444 } | 452 if (sumfile == NULL) 453 errx(1, "calloc failed"); |
445 strcpy(sumfile, acctfile); 446 strcat(sumfile, "_sum"); 447 return(1); 448} | 454 strcpy(sumfile, acctfile); 455 strcat(sumfile, "_sum"); 456 return(1); 457} |