17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
247c478bdstevel@tonic-gate * All rights reserved.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#ifndef	_MDB_IO_IMPL_H
287c478bdstevel@tonic-gate#define	_MDB_IO_IMPL_H
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#include <mdb/mdb_io.h>
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#ifdef	__cplusplus
357c478bdstevel@tonic-gateextern "C" {
367c478bdstevel@tonic-gate#endif
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate#ifdef _MDB
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gatetypedef struct mdb_io_ops {
417c478bdstevel@tonic-gate	ssize_t (*io_read)(mdb_io_t *, void *, size_t);
427c478bdstevel@tonic-gate	ssize_t (*io_write)(mdb_io_t *, const void *, size_t);
437c478bdstevel@tonic-gate	off64_t (*io_seek)(mdb_io_t *, off64_t, int);
447c478bdstevel@tonic-gate	int (*io_ctl)(mdb_io_t *, int, void *);
457c478bdstevel@tonic-gate	void (*io_close)(mdb_io_t *);
467c478bdstevel@tonic-gate	const char *(*io_name)(mdb_io_t *);
477c478bdstevel@tonic-gate	void (*io_link)(mdb_io_t *, mdb_iob_t *);
487c478bdstevel@tonic-gate	void (*io_unlink)(mdb_io_t *, mdb_iob_t *);
497c478bdstevel@tonic-gate	int (*io_setattr)(mdb_io_t *, int, uint_t);
507c478bdstevel@tonic-gate	void (*io_suspend)(mdb_io_t *);
517c478bdstevel@tonic-gate	void (*io_resume)(mdb_io_t *);
527c478bdstevel@tonic-gate} mdb_io_ops_t;
537c478bdstevel@tonic-gate
547c478bdstevel@tonic-gate#define	IOP_READ(io, buf, len) ((io)->io_ops->io_read((io), (buf), (len)))
557c478bdstevel@tonic-gate#define	IOP_WRITE(io, buf, len) ((io)->io_ops->io_write((io), (buf), (len)))
567c478bdstevel@tonic-gate#define	IOP_SEEK(io, off, whence) ((io)->io_ops->io_seek((io), (off), (whence)))
577c478bdstevel@tonic-gate#define	IOP_CTL(io, req, arg) ((io)->io_ops->io_ctl((io), (req), (arg)))
587c478bdstevel@tonic-gate#define	IOP_CLOSE(io) ((io)->io_ops->io_close((io)))
597c478bdstevel@tonic-gate#define	IOP_NAME(io) ((io)->io_ops->io_name((io)))
607c478bdstevel@tonic-gate#define	IOP_LINK(io, iob) ((io)->io_ops->io_link((io), (iob)))
617c478bdstevel@tonic-gate#define	IOP_UNLINK(io, iob) ((io)->io_ops->io_unlink((io), (iob)))
627c478bdstevel@tonic-gate#define	IOP_SETATTR(io, r, a) ((io)->io_ops->io_setattr((io), (r), (a)))
637c478bdstevel@tonic-gate#define	IOP_SUSPEND(io) ((io)->io_ops->io_suspend((io)))
647c478bdstevel@tonic-gate#define	IOP_RESUME(io) ((io)->io_ops->io_resume((io)))
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gate#define	IOPF_READ(io)	\
677c478bdstevel@tonic-gate	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_read)
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gate#define	IOPF_WRITE(io)	\
707c478bdstevel@tonic-gate	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_write)
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#define	ATT_STANDOUT	0x01		/* Standout mode */
737c478bdstevel@tonic-gate#define	ATT_UNDERLINE	0x02		/* Underline mode */
747c478bdstevel@tonic-gate#define	ATT_REVERSE	0x04		/* Reverse video mode */
757c478bdstevel@tonic-gate#define	ATT_BOLD	0x08		/* Bold text mode */
767c478bdstevel@tonic-gate#define	ATT_DIM		0x10		/* Dim text mode */
777c478bdstevel@tonic-gate#define	ATT_ALTCHARSET	0x20		/* Alternate character set mode */
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate#define	ATT_ALL		0x3f		/* Mask of all valid attributes */
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate#define	ATT_OFF		0		/* Turn attributes off */
827c478bdstevel@tonic-gate#define	ATT_ON		1		/* Turn attributes on */
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gatestruct mdb_io {
857c478bdstevel@tonic-gate	const mdb_io_ops_t *io_ops;	/* I/O type-specific operations */
867c478bdstevel@tonic-gate	void *io_data;			/* I/O type-specific data pointer */
877c478bdstevel@tonic-gate	mdb_io_t *io_next;		/* Link to next i/o object on stack */
887c478bdstevel@tonic-gate	size_t io_refcnt;		/* Reference count */
897c478bdstevel@tonic-gate};
907c478bdstevel@tonic-gate
917c478bdstevel@tonic-gatestruct mdb_iob {
927c478bdstevel@tonic-gate	char *iob_buf;			/* Input/output buffer */
937c478bdstevel@tonic-gate	size_t iob_bufsiz;		/* Size of iob_buf in bytes */
947c478bdstevel@tonic-gate	char *iob_bufp;			/* Current buffer location */
957c478bdstevel@tonic-gate	size_t iob_nbytes;		/* Number of bytes in io_buf */
967c478bdstevel@tonic-gate	size_t iob_nlines;		/* Lines output on current page */
977c478bdstevel@tonic-gate	size_t iob_lineno;		/* Storage for saved yylineno */
987c478bdstevel@tonic-gate	size_t iob_rows;		/* Terminal height */
997c478bdstevel@tonic-gate	size_t iob_cols;		/* Terminal width */
1007c478bdstevel@tonic-gate	size_t iob_tabstop;		/* Tab stop width */
1017c478bdstevel@tonic-gate	size_t iob_margin;		/* Margin width */
1027c478bdstevel@tonic-gate	uint_t iob_flags;		/* Flags (see <mdb/mdb_io.h>) */
1037c478bdstevel@tonic-gate	mdb_io_t *iob_iop;		/* I/o implementation pointer */
1047c478bdstevel@tonic-gate	mdb_io_t *iob_pgp;		/* Pager i/o implementation pointer */
1057c478bdstevel@tonic-gate	mdb_iob_t *iob_next;		/* Stack next pointer */
1067c478bdstevel@tonic-gate};
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate/*
1097c478bdstevel@tonic-gate * Stub functions for i/o backend implementors: these stubs either act as
1107c478bdstevel@tonic-gate * pass-through no-ops or return ENOTSUP as appropriate.
1117c478bdstevel@tonic-gate */
1127c478bdstevel@tonic-gateextern ssize_t no_io_read(mdb_io_t *, void *, size_t);
1137c478bdstevel@tonic-gateextern ssize_t no_io_write(mdb_io_t *, const void *, size_t);
1147c478bdstevel@tonic-gateextern off64_t no_io_seek(mdb_io_t *, off64_t, int);
1157c478bdstevel@tonic-gateextern int no_io_ctl(mdb_io_t *, int, void *);
1167c478bdstevel@tonic-gateextern void no_io_close(mdb_io_t *);
1177c478bdstevel@tonic-gateextern const char *no_io_name(mdb_io_t *);
1187c478bdstevel@tonic-gateextern void no_io_link(mdb_io_t *, mdb_iob_t *);
1197c478bdstevel@tonic-gateextern void no_io_unlink(mdb_io_t *, mdb_iob_t *);
1207c478bdstevel@tonic-gateextern int no_io_setattr(mdb_io_t *, int, uint_t);
1217c478bdstevel@tonic-gateextern void no_io_suspend(mdb_io_t *);
1227c478bdstevel@tonic-gateextern void no_io_resume(mdb_io_t *);
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gate#endif	/* _MDB */
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gate#ifdef	__cplusplus
1277c478bdstevel@tonic-gate}
1287c478bdstevel@tonic-gate#endif
1297c478bdstevel@tonic-gate
1307c478bdstevel@tonic-gate#endif	/* _MDB_IO_IMPL_H */
131