Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / pdisk / errors.c
blobe3e57739de37e4a3a96b7c753ca107e126da42d8
1 //
2 // errors.c - error & help routines
3 //
4 // Written by Eryk Vershen
5 //
7 /*
8 * Copyright 1996,1997,1998 by Apple Computer, Inc.
9 * All Rights Reserved
11 * Permission to use, copy, modify, and distribute this software and
12 * its documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appears in all copies and
14 * that both the copyright notice and this permission notice appear in
15 * supporting documentation.
17 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE.
21 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
22 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
24 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 // for *printf()
29 #include <stdio.h>
30 #include <errno.h>
32 // for exit()
33 #ifndef __linux__
34 #include <stdlib.h>
35 #endif
36 // for strrchr
37 #include <string.h>
39 // for va_start(), etc.
40 #include <stdarg.h>
42 #include "errors.h"
46 // Defines
51 // Types
56 // Global Constants
61 // Global Variables
63 char *program_name;
64 #ifdef NeXT
65 extern int errno;
66 extern int sys_nerr;
67 extern const char * const sys_errlist[];
68 #endif
72 // Forward declarations
77 // Routines
79 void
80 init_program_name(char **argv)
82 #if defined(__linux__) || defined(__unix__)
83 if ((program_name = strrchr(argv[0], '/')) != (char *)NULL) {
84 program_name++;
85 } else {
86 program_name = argv[0];
88 #else
89 program_name = "pdisk";
90 #endif
94 void
95 do_help()
97 printf("\t%s [-h|--help]\n", program_name);
98 printf("\t%s [-v|--version]\n", program_name);
99 #ifdef __linux__
100 printf("\t%s [-l|--list [name]] [...]\n", program_name);
101 #else
102 printf("\t%s [-l|--list] name [...]\n", program_name);
103 #endif
104 printf("\t%s [-r|--readonly] name ...\n", program_name);
105 printf("\t%s [-i|--interactive]\n", program_name);
106 printf("\t%s name [...]\n", program_name);
108 {"debug", no_argument, 0, 'd'},
109 {"abbr", no_argument, 0, 'a'},
110 {"fs", no_argument, 0, 'f'},
111 {"logical", no_argument, 0, kLogicalOption},
112 {"compute_size", no_argument, 0, 'c'},
117 void
118 usage(const char *kind)
120 error(-1, "bad usage - %s\n", kind);
121 hflag = 1;
126 // Print a message on standard error and exit with value.
127 // Values in the range of system error numbers will add
128 // the perror(3) message.
130 void
131 fatal(int value, const char *fmt, ...)
133 va_list ap;
135 fprintf(stderr, "%s: ", program_name);
136 va_start(ap, fmt);
137 vfprintf(stderr, fmt, ap);
138 va_end(ap);
140 #if defined(__linux__) || defined(NeXT) || defined(__unix__)
141 if (value > 0 && value < sys_nerr) {
142 fprintf(stderr, " (%s)\n", sys_errlist[value]);
143 } else {
144 fprintf(stderr, "\n");
146 #else
147 fprintf(stderr, "\n");
148 printf("Processing stopped: Choose 'Quit' from the file menu to quit.\n\n");
149 #endif
150 exit(value);
155 // Print a message on standard error.
156 // Values in the range of system error numbers will add
157 // the perror(3) message.
159 void
160 error(int value, const char *fmt, ...)
162 va_list ap;
164 fprintf(stderr, "%s: ", program_name);
165 va_start(ap, fmt);
166 vfprintf(stderr, fmt, ap);
167 va_end(ap);
169 #if defined(__linux__) || defined(NeXT) || defined(__unix__)
170 if (value > 0 && value < sys_nerr) {
171 fprintf(stderr, " (%s)\n", sys_errlist[value]);
172 } else {
173 fprintf(stderr, "\n");
175 #else
176 fprintf(stderr, "\n");
177 #endif