accton.c revision 8857
181588Sru/*
257260Sjasone * Copyright (c) 1988, 1993
379754Sdd *	The Regents of the University of California.  All rights reserved.
457260Sjasone *
557260Sjasone * Redistribution and use in source and binary forms, with or without
657260Sjasone * modification, are permitted provided that the following conditions
757260Sjasone * are met:
857260Sjasone * 1. Redistributions of source code must retain the above copyright
957260Sjasone *    notice, this list of conditions and the following disclaimer.
1057260Sjasone * 2. Redistributions in binary form must reproduce the above copyright
1157260Sjasone *    notice, this list of conditions and the following disclaimer in the
1257260Sjasone *    documentation and/or other materials provided with the distribution.
1357260Sjasone * 3. All advertising materials mentioning features or use of this software
1457260Sjasone *    must display the following acknowledgement:
1579754Sdd *	This product includes software developed by the University of
1657260Sjasone *	California, Berkeley and its contributors.
1757260Sjasone * 4. Neither the name of the University nor the names of its contributors
1857260Sjasone *    may be used to endorse or promote products derived from this software
1957260Sjasone *    without specific prior written permission.
2057260Sjasone *
2157260Sjasone * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2257260Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2357260Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2457260Sjasone * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2557260Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2657260Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2779754Sdd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2857260Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29131465Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3057260Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3157260Sjasone * SUCH DAMAGE.
3257260Sjasone */
3357260Sjasone
3457260Sjasone#ifndef lint
3557260Sjasonestatic char copyright[] =
3659501Sphantom"@(#) Copyright (c) 1988, 1993\n\
37124530Sru	The Regents of the University of California.  All rights reserved.\n";
3857260Sjasone#endif /* not lint */
3984306Sru
4057260Sjasone#ifndef lint
41104492Smikestatic char sccsid[] = "@(#)accton.c	8.1 (Berkeley) 6/6/93";
4257260Sjasone#endif /* not lint */
4357260Sjasone
4457260Sjasone#include <sys/types.h>
4557260Sjasone#include <errno.h>
4657260Sjasone#include <unistd.h>
4757260Sjasone#include <stdlib.h>
4857260Sjasone#include <stdio.h>
4957260Sjasone#include <string.h>
5057260Sjasone
5157260Sjasonevoid usage __P((void));
5257260Sjasone
5381352Syarint
5457260Sjasonemain(argc, argv)
55112542Scharnier	int argc;
5657260Sjasone	char *argv[];
57112542Scharnier{
5857260Sjasone	int ch;
5957260Sjasone
60131465Sru	while ((ch = getopt(argc, argv, "")) != EOF)
6157260Sjasone		switch(ch) {
62131465Sru		case '?':
6357260Sjasone		default:
6457260Sjasone			usage();
6557260Sjasone		}
6657260Sjasone	argc -= optind;
6763352Sjasone	argv += optind;
68109220Stjr
69109220Stjr	switch(argc) {
7057260Sjasone	case 0:
71112542Scharnier		if (acct(NULL)) {
7257260Sjasone			(void)fprintf(stderr,
73112542Scharnier			    "accton: %s\n", strerror(errno));
7473093Sru			exit(1);
7557260Sjasone		}
7657260Sjasone		break;
77131465Sru	case 1:
78131465Sru		if (acct(*argv)) {
79131465Sru			(void)fprintf(stderr,
8057260Sjasone			    "accton: %s: %s\n", *argv, strerror(errno));
8157260Sjasone			exit(1);
82		}
83		break;
84	default:
85		usage();
86	}
87	exit(0);
88}
89
90void
91usage()
92{
93	(void)fprintf(stderr, "usage: accton [file]\n");
94	exit(1);
95}
96