xref: /freebsd/usr.sbin/accton/accton.c (revision 0b8224d1cc9dc6c9778ba04a75b2c8d47e5d7481)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
4dea673e9SRodney W. Grimes  * Copyright (c) 1988, 1993
5dea673e9SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6dea673e9SRodney W. Grimes  *
7dea673e9SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
8dea673e9SRodney W. Grimes  * modification, are permitted provided that the following conditions
9dea673e9SRodney W. Grimes  * are met:
10dea673e9SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
11dea673e9SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
12dea673e9SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
13dea673e9SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
14dea673e9SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
16dea673e9SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
17dea673e9SRodney W. Grimes  *    without specific prior written permission.
18dea673e9SRodney W. Grimes  *
19dea673e9SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20dea673e9SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21dea673e9SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22dea673e9SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23dea673e9SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24dea673e9SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25dea673e9SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26dea673e9SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27dea673e9SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28dea673e9SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29dea673e9SRodney W. Grimes  * SUCH DAMAGE.
30dea673e9SRodney W. Grimes  */
31dea673e9SRodney W. Grimes 
32dea673e9SRodney W. Grimes #include <sys/types.h>
33b63f602aSPhilippe Charnier #include <err.h>
34dea673e9SRodney W. Grimes #include <stdio.h>
35b63f602aSPhilippe Charnier #include <stdlib.h>
36dea673e9SRodney W. Grimes #include <string.h>
37b63f602aSPhilippe Charnier #include <unistd.h>
38dea673e9SRodney W. Grimes 
39*72e1ea2fSAlfonso Gregory static void usage(void) __dead2;
40dea673e9SRodney W. Grimes 
41dea673e9SRodney W. Grimes int
main(int argc,char * argv[])421fb354a1SAlfred Perlstein main(int argc, char *argv[])
43dea673e9SRodney W. Grimes {
44dea673e9SRodney W. Grimes 	int ch;
45dea673e9SRodney W. Grimes 
466c3f552aSWarner Losh 	while ((ch = getopt(argc, argv, "")) != -1)
47dea673e9SRodney W. Grimes 		switch(ch) {
48dea673e9SRodney W. Grimes 		case '?':
49dea673e9SRodney W. Grimes 		default:
50dea673e9SRodney W. Grimes 			usage();
51dea673e9SRodney W. Grimes 		}
52dea673e9SRodney W. Grimes 	argc -= optind;
53dea673e9SRodney W. Grimes 	argv += optind;
54dea673e9SRodney W. Grimes 
55dea673e9SRodney W. Grimes 	switch(argc) {
56dea673e9SRodney W. Grimes 	case 0:
57b63f602aSPhilippe Charnier 		if (acct(NULL))
58b63f602aSPhilippe Charnier 			err(1, NULL);
59dea673e9SRodney W. Grimes 		break;
60dea673e9SRodney W. Grimes 	case 1:
61b63f602aSPhilippe Charnier 		if (acct(*argv))
62b63f602aSPhilippe Charnier 			err(1, "%s", *argv);
63dea673e9SRodney W. Grimes 		break;
64dea673e9SRodney W. Grimes 	default:
65dea673e9SRodney W. Grimes 		usage();
66dea673e9SRodney W. Grimes 	}
67dea673e9SRodney W. Grimes 	exit(0);
68dea673e9SRodney W. Grimes }
69dea673e9SRodney W. Grimes 
70b63f602aSPhilippe Charnier static void
usage(void)719a958de5SEd Schouten usage(void)
72dea673e9SRodney W. Grimes {
73dea673e9SRodney W. Grimes 	(void)fprintf(stderr, "usage: accton [file]\n");
74dea673e9SRodney W. Grimes 	exit(1);
75dea673e9SRodney W. Grimes }
76