xref: /netbsd/sys/arch/atari/stand/tostools/aptck/aptck.in (revision bf9ec67e)
1/*	$NetBSD: aptck.in,v 1.1.1.1 1996/01/07 21:54:17 leo Exp $	*/
2
3/*
4 * Copyright (c) 1995 Waldi Ravens.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *        This product includes software developed by Waldi Ravens.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/types.h>
34#include <stdlib.h>
35#include <unistd.h>
36#include "libtos.h"
37#include "aptck.h"
38
39int		main    PROTO((int, char **));
40
41static void	version PROTO((void)) NORETURN;
42static void	usage   PROTO((void)) NORETURN;
43
44static void
45version()
46{
47	eprintf("%s\n", "$Revision: 1.1.1.1 $");
48	xexit(EXIT_SUCCESS);
49}
50
51static void
52usage()
53{
54	eprintf("Usage: aptck [OPTIONS] DISK..\n"
55		"where OPTIONS are:\n"
56		"\t-V         display version information and exit\n"
57		"\t-h         display this help and exit\n"
58		"\t-o FILE    send output to FILE instead of stdout\n"
59		"\t-w         wait for key press before exiting\n\n"
60		"DISK is the concatenation of BUS, TARGET and LUN.\n"
61		"BUS is one of `i' (IDE), `a' (ACSI) or `s' (SCSI).\n"
62		"TARGET and LUN are one decimal digit each. LUN must\n"
63		"not be specified for IDE devices and is optional for\n"
64		"ACSI/SCSI devices (if omitted, LUN defaults to 0).\n\n"
65		"Examples:  a0  refers to ACSI target 0 lun 0\n"
66		"           s21 refers to SCSI target 2 lun 1\n"
67		);
68	xexit(EXIT_SUCCESS);
69}
70
71int
72main(argc, argv)
73	int		argc;
74	char		**argv;
75{
76	extern int	optind;
77	extern char	*optarg;
78
79	disk_t		*dd;
80	int		rv, c;
81
82	init_toslib(*argv);
83
84	while ((c = getopt(argc, argv, "Vho:w")) != -1) {
85		switch (c) {
86		  case 'o':
87			redirect_output(optarg);
88			break;
89		  case 'w':
90		  	set_wait_for_key();
91			break;
92		  case 'V':
93			version();
94			/* NOT REACHED */
95		  case 'h':
96		  default:
97			usage();
98			/* NOT REACHED */
99		}
100	}
101	argv += optind;
102
103	if (!*argv) {
104		error(-1, "missing DISK argument");
105		usage();
106		/* NOT REACHED */
107	}
108
109	c  = isatty(STDOUT_FILENO);
110	rv = EXIT_SUCCESS;
111	while (*argv) {
112		dd = disk_open(*argv++);
113		if (dd) {
114			if (readdisklabel(dd))
115				rv = EXIT_FAILURE;
116			disk_close(dd);
117			if (c)
118				press_any_key();
119		}
120		else rv = EXIT_FAILURE;
121	}
122	return(rv);
123}
124