1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _MDB_IO_H 28 #define _MDB_IO_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #ifdef _MDB 37 38 #include <sys/types.h> 39 #include <setjmp.h> 40 #include <stdarg.h> 41 #include <stdio.h> 42 43 typedef struct mdb_iob mdb_iob_t; /* I/O buffer */ 44 typedef struct mdb_io mdb_io_t; /* I/O implementation */ 45 struct mdb_arg; /* Argument structure */ 46 47 #define MDB_IOB_DEFTAB 8 /* Default tabstop */ 48 #define MDB_IOB_DEFMARGIN 16 /* Default margin width */ 49 #define MDB_IOB_DEFROWS 24 /* Default rows */ 50 #define MDB_IOB_DEFCOLS 80 /* Default columns */ 51 52 #define MDB_IOB_RDONLY 0x0001 /* Buffer is for reading */ 53 #define MDB_IOB_WRONLY 0x0002 /* Buffer is for writing */ 54 #define MDB_IOB_EOF 0x0004 /* Read buffer has reached EOF */ 55 #define MDB_IOB_ERR 0x0008 /* Underlying i/o error occurred */ 56 #define MDB_IOB_INDENT 0x0010 /* Lines are auto-indented */ 57 #define MDB_IOB_PGENABLE 0x0020 /* Pager enabled */ 58 #define MDB_IOB_PGSINGLE 0x0040 /* Line-at-a-time pager active */ 59 #define MDB_IOB_PGCONT 0x0080 /* Continue paging until next reset */ 60 #define MDB_IOB_AUTOWRAP 0x0100 /* Auto-wrap if next chunk won't fit */ 61 #define MDB_IOB_TTYLIKE 0x0200 /* Input is interactive like a tty */ 62 63 typedef struct mdb_iob_stack { 64 mdb_iob_t *stk_top; /* Topmost stack element */ 65 size_t stk_size; /* Number of stack elements */ 66 } mdb_iob_stack_t; 67 68 typedef struct mdb_iob_ctx { 69 jmp_buf ctx_rpcb; /* Read-side context label */ 70 jmp_buf ctx_wpcb; /* Write-side context label */ 71 void *ctx_rptr; /* Read-side client data */ 72 void *ctx_wptr; /* Write-side client data */ 73 void *ctx_data; /* Pointer to client data */ 74 mdb_iob_t *ctx_iob; /* Storage for iob save/restore */ 75 } mdb_iob_ctx_t; 76 77 #define MDB_IOB_RDIOB 0 /* Index for pipe's read-side iob */ 78 #define MDB_IOB_WRIOB 1 /* Index for pipe's write-side iob */ 79 80 typedef void mdb_iobsvc_f(mdb_iob_t *, mdb_iob_t *, mdb_iob_ctx_t *); 81 82 #define MDBIOC (('m' << 24) | ('d' << 16) | ('b' << 8)) 83 84 #define MDB_IOC_CTTY (MDBIOC | 0x01) /* Clear child tty settings */ 85 #define MDB_IOC_TSET (MDBIOC | 0x02) /* Set terminal type */ 86 #define MDB_IOC_GETFD (MDBIOC | 0x04) /* Get file descriptor (if any) */ 87 88 89 typedef void mdb_table_print_f(void *); 90 91 #define MDB_TBL_DONE 0 92 #define MDB_TBL_PRNT 1 93 #define MDB_TBL_FUNC 2 94 95 extern mdb_io_t *mdb_io_hold(mdb_io_t *); 96 extern void mdb_io_rele(mdb_io_t *); 97 extern void mdb_io_destroy(mdb_io_t *); 98 99 extern mdb_iob_t *mdb_iob_create(mdb_io_t *, uint_t); 100 extern void mdb_iob_pipe(mdb_iob_t **, mdb_iobsvc_f *, mdb_iobsvc_f *); 101 extern void mdb_iob_destroy(mdb_iob_t *); 102 103 extern void mdb_iob_flush(mdb_iob_t *); 104 extern void mdb_iob_nlflush(mdb_iob_t *); 105 extern void mdb_iob_discard(mdb_iob_t *); 106 107 extern void mdb_iob_push_io(mdb_iob_t *, mdb_io_t *); 108 extern mdb_io_t *mdb_iob_pop_io(mdb_iob_t *); 109 110 extern void mdb_iob_resize(mdb_iob_t *, size_t, size_t); 111 extern void mdb_iob_setpager(mdb_iob_t *, mdb_io_t *); 112 extern void mdb_iob_clearlines(mdb_iob_t *); 113 extern void mdb_iob_tabstop(mdb_iob_t *, size_t); 114 extern void mdb_iob_margin(mdb_iob_t *, size_t); 115 extern void mdb_iob_setbuf(mdb_iob_t *, void *, size_t); 116 117 extern void mdb_iob_setflags(mdb_iob_t *, uint_t); 118 extern void mdb_iob_clrflags(mdb_iob_t *, uint_t); 119 extern uint_t mdb_iob_getflags(mdb_iob_t *); 120 121 extern void mdb_iob_vprintf(mdb_iob_t *, const char *, va_list); 122 extern void mdb_iob_aprintf(mdb_iob_t *, const char *, const struct mdb_arg *); 123 extern void mdb_iob_printf(mdb_iob_t *, const char *, ...); 124 125 extern size_t mdb_iob_vsnprintf(char *, size_t, const char *, va_list); 126 extern size_t mdb_iob_asnprintf(char *, size_t, const char *, 127 const struct mdb_arg *); 128 extern size_t mdb_iob_snprintf(char *, size_t, const char *, ...); 129 130 extern void mdb_iob_nputs(mdb_iob_t *, const char *, size_t); 131 extern void mdb_iob_puts(mdb_iob_t *, const char *); 132 extern void mdb_iob_putc(mdb_iob_t *, int); 133 134 extern void mdb_iob_fill(mdb_iob_t *, int, size_t); 135 extern void mdb_iob_ws(mdb_iob_t *, size_t); 136 extern void mdb_iob_tab(mdb_iob_t *); 137 extern void mdb_iob_nl(mdb_iob_t *); 138 139 extern ssize_t mdb_iob_ngets(mdb_iob_t *, char *, size_t); 140 extern int mdb_iob_getc(mdb_iob_t *); 141 extern int mdb_iob_ungetc(mdb_iob_t *, int); 142 extern int mdb_iob_eof(mdb_iob_t *); 143 extern int mdb_iob_err(mdb_iob_t *); 144 145 extern ssize_t mdb_iob_read(mdb_iob_t *, void *, size_t); 146 extern ssize_t mdb_iob_write(mdb_iob_t *, const void *, size_t); 147 extern int mdb_iob_ctl(mdb_iob_t *, int, void *); 148 extern const char *mdb_iob_name(mdb_iob_t *); 149 extern size_t mdb_iob_lineno(mdb_iob_t *); 150 extern size_t mdb_iob_gettabstop(mdb_iob_t *); 151 extern size_t mdb_iob_getmargin(mdb_iob_t *); 152 153 extern void mdb_iob_stack_create(mdb_iob_stack_t *); 154 extern void mdb_iob_stack_destroy(mdb_iob_stack_t *); 155 extern void mdb_iob_stack_push(mdb_iob_stack_t *, mdb_iob_t *, size_t); 156 extern mdb_iob_t *mdb_iob_stack_pop(mdb_iob_stack_t *); 157 extern size_t mdb_iob_stack_size(mdb_iob_stack_t *); 158 159 extern const char *mdb_iob_format2str(const char *); 160 161 /* 162 * Available i/o backend constructors for common MDB code. These are 163 * implemented in the corresponding .c files. 164 */ 165 extern mdb_io_t *mdb_logio_create(mdb_io_t *); 166 extern mdb_io_t *mdb_fdio_create_path(const char **, const char *, int, mode_t); 167 extern mdb_io_t *mdb_fdio_create_named(int fd, const char *); 168 extern mdb_io_t *mdb_fdio_create(int); 169 extern mdb_io_t *mdb_strio_create(const char *); 170 extern mdb_io_t *mdb_termio_create(const char *, mdb_io_t *, mdb_io_t *); 171 extern mdb_io_t *mdb_pipeio_create(mdb_iobsvc_f *, mdb_iobsvc_f *); 172 extern mdb_io_t *mdb_nullio_create(void); 173 174 /* 175 * Functions for testing whether the given iob is of a given backend type: 176 */ 177 extern int mdb_iob_isastr(mdb_iob_t *); 178 extern int mdb_iob_isatty(mdb_iob_t *); 179 extern int mdb_iob_isapipe(mdb_iob_t *); 180 181 extern void mdb_table_print(uint_t, const char *, ...); 182 183 extern int mdb_setupterm(const char *, mdb_io_t *, int *); 184 185 #endif /* _MDB */ 186 187 #ifdef __cplusplus 188 } 189 #endif 190 191 #endif /* _MDB_IO_H */ 192