Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / format / misc.h
blob784c2d05e478da938fbbdc8fbe7aa87d38bb85c9
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _MISC_H
26 #define _MISC_H
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
33 * This file contains declarations pertaining to the miscellaneous routines.
35 #include <setjmp.h>
36 #include <termios.h>
39 * Define macros bzero and bcopy for convenience
41 #ifndef bzero
42 #define bzero(p, n) (void) memset((p), 0, (n))
43 #endif
44 #ifndef bcopy
45 #define bcopy(src, dst, n) (void) memcpy((dst), (src), (n))
46 #endif
47 #ifndef bcmp
48 #define bcmp(p1, p2, n) memcmp((p1), (p2), (n))
49 #endif
52 * Minimum and maximum macros
54 #ifndef min
55 #define min(x, y) ((x) < (y) ? (x) : (y))
56 #endif /* min */
57 #ifndef max
58 #define max(x, y) ((x) > (y) ? (x) : (y))
59 #endif /* max */
62 * This defines the structure of a saved environment. It consists of the
63 * environment itself, a pointer to the next environment on the stack, and
64 * flags to tell whether the environment is active, etc.
66 struct env {
67 jmp_buf env; /* environment buf */
68 struct env *ptr; /* ptr to next on list */
69 char flags; /* flags */
71 extern struct env *current_env;
73 * This macro saves the current environment in the given structure and
74 * pushes the structure onto our enivornment stack. It initializes the
75 * flags to zero (inactive).
77 #define saveenv(x) { \
78 x.ptr = current_env; \
79 current_env = &x; \
80 (void) setjmp(x.env); \
81 x.flags = 0; \
84 * This macro marks the environment on the top of the stack active. It
85 * assumes that there is an environment on the stack.
87 #define useenv() (current_env->flags |= ENV_USE)
89 * This macro marks the environment on the top of the stack inactive. It
90 * assumes that there is an environment on the stack.
92 #define unuseenv() (current_env->flags &= ~ENV_USE)
94 * This macro pops an environment off the top of the stack. It
95 * assumes that there is an environment on the stack.
97 #define clearenv() (current_env = current_env->ptr)
99 * These are the flags for the environment struct.
101 #define ENV_USE 0x01 /* active */
102 #define ENV_CRITICAL 0x02 /* in critical zone */
103 #define ENV_ABORT 0x04 /* abort pending */
106 * This structure is used to keep track of the state of the tty. This
107 * is necessary because some of the commands turn off echoing.
109 struct ttystate {
110 struct termios ttystate; /* buffer for ioctls */
111 int ttyflags; /* changes to tty state */
112 int ttyfile; /* file for ioctls */
113 int vmin; /* min read satisfier */
114 int vtime; /* read timing */
118 * ttyflags - changes we can make to the tty state.
120 #define TTY_ECHO_OFF 0x01 /* turned echo off */
121 #define TTY_CBREAK_ON 0x02 /* turned cbreak on */
124 * This is the number lines assumed for the tty. It is designed to work
125 * on terminals as well as sun monitors.
127 #define TTY_LINES 24
130 * format parameter to dump()
132 #define HEX_ONLY 0 /* print hex only */
133 #define HEX_ASCII 1 /* hex and ascii */
137 * Prototypes for ANSI C
139 void *zalloc(int count);
140 void *rezalloc(void *ptr, int count);
141 void destroy_data(char *data);
142 int check(char *question);
143 void cmdabort(int sig);
144 void onsusp(int sig);
145 void onalarm(int sig);
146 void fullabort(void) __NORETURN;
147 void enter_critical(void);
148 void exit_critical(void);
149 void echo_off(void);
150 void echo_on(void);
151 void charmode_on(void);
152 void charmode_off(void);
153 char *alloc_string(char *s);
154 char **build_argvlist(char **, int *, int *, char *);
155 int conventional_name(char *name);
156 #ifdef i386
157 int emcpower_name(char *name);
158 #endif
161 #if defined(_FIRMWARE_NEEDS_FDISK)
162 int fdisk_physical_name(char *name);
163 #endif /* defined(_FIRMWARE_NEEDS_FDISK) */
165 int whole_disk_name(char *name);
166 int canonical_name(char *name);
167 int canonical4x_name(char *name);
168 void canonicalize_name(char *dst, char *src);
169 int match_substr(char *s1, char *s2);
170 void dump(char *, caddr_t, int, int);
171 float bn2mb(uint64_t);
172 diskaddr_t mb2bn(float);
173 float bn2gb(uint64_t);
174 float bn2tb(uint64_t);
175 diskaddr_t gb2bn(float);
176 int get_tty_lines();
180 * Macro to handle internal programming errors that
181 * should "never happen".
183 #define impossible(msg) {err_print("Internal error: file %s, line %d: %s\n", \
184 __FILE__, __LINE__, msg); \
185 fullabort(); }
188 extern char *confirm_list[];
191 * This defines the size of the blind selection verfication prompt
194 #define BLIND_SELECT_VER_PROMPT (43 + MAXNAMELEN)
196 #ifdef __cplusplus
198 #endif
200 #endif /* _MISC_H */