xref: /titanic_44/usr/src/lib/libtecla/common/chrqueue.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate #ifndef chrqueue_h
2*7c478bd9Sstevel@tonic-gate #define chrqueue_h
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate /*
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * All rights reserved.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * Permission is hereby granted, free of charge, to any person obtaining a
10*7c478bd9Sstevel@tonic-gate  * copy of this software and associated documentation files (the
11*7c478bd9Sstevel@tonic-gate  * "Software"), to deal in the Software without restriction, including
12*7c478bd9Sstevel@tonic-gate  * without limitation the rights to use, copy, modify, merge, publish,
13*7c478bd9Sstevel@tonic-gate  * distribute, and/or sell copies of the Software, and to permit persons
14*7c478bd9Sstevel@tonic-gate  * to whom the Software is furnished to do so, provided that the above
15*7c478bd9Sstevel@tonic-gate  * copyright notice(s) and this permission notice appear in all copies of
16*7c478bd9Sstevel@tonic-gate  * the Software and that both the above copyright notice(s) and this
17*7c478bd9Sstevel@tonic-gate  * permission notice appear in supporting documentation.
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20*7c478bd9Sstevel@tonic-gate  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21*7c478bd9Sstevel@tonic-gate  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22*7c478bd9Sstevel@tonic-gate  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23*7c478bd9Sstevel@tonic-gate  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24*7c478bd9Sstevel@tonic-gate  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25*7c478bd9Sstevel@tonic-gate  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26*7c478bd9Sstevel@tonic-gate  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27*7c478bd9Sstevel@tonic-gate  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28*7c478bd9Sstevel@tonic-gate  *
29*7c478bd9Sstevel@tonic-gate  * Except as contained in this notice, the name of a copyright holder
30*7c478bd9Sstevel@tonic-gate  * shall not be used in advertising or otherwise to promote the sale, use
31*7c478bd9Sstevel@tonic-gate  * or other dealings in this Software without prior written authorization
32*7c478bd9Sstevel@tonic-gate  * of the copyright holder.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate /*-----------------------------------------------------------------------
38*7c478bd9Sstevel@tonic-gate  * This module implements a queue of characters to be processed in some
39*7c478bd9Sstevel@tonic-gate  * way. It is used by gl_get_line() to maintain a queue of characters
40*7c478bd9Sstevel@tonic-gate  * to be sent to a remote terminal. Characters are recorded in a
41*7c478bd9Sstevel@tonic-gate  * dynamically extensible list of fixed sized buffers.
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate typedef struct GlCharQueue GlCharQueue;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate  * Create a new character queue.
48*7c478bd9Sstevel@tonic-gate  */
49*7c478bd9Sstevel@tonic-gate GlCharQueue *_new_GlCharQueue(void);
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * Delete a redundant character queue.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate GlCharQueue *_del_GlCharQueue(GlCharQueue *cq);
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate  * Append an array of n characters to a character queue.
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate int _glq_append_chars(GlCharQueue *cq, const char *chars, int n,
60*7c478bd9Sstevel@tonic-gate 		      GlWriteFn *write_fn, void *data);
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  * Clear a character queue.
64*7c478bd9Sstevel@tonic-gate  */
65*7c478bd9Sstevel@tonic-gate void _glq_empty_queue(GlCharQueue *cq);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * Return a count of the number of characters in the queue.
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate int _glq_char_count(GlCharQueue *cq);
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * A structure of the following type is used by _glq_peek_chars() to
74*7c478bd9Sstevel@tonic-gate  * return characters at the start of the queue.
75*7c478bd9Sstevel@tonic-gate  */
76*7c478bd9Sstevel@tonic-gate typedef struct {
77*7c478bd9Sstevel@tonic-gate   const char *buff;  /* A pointer to the first undeleted byte in the */
78*7c478bd9Sstevel@tonic-gate                      /*  first buffer of the queue. */
79*7c478bd9Sstevel@tonic-gate   int nbuff;         /* The number of characters in buff[] */
80*7c478bd9Sstevel@tonic-gate } GlCharQueueBuff;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * Enumerator values of the following type are returned by
84*7c478bd9Sstevel@tonic-gate  * _glq_flush_queue() to indicate the status of the flush operation.
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate typedef enum {
87*7c478bd9Sstevel@tonic-gate   GLQ_FLUSH_DONE,   /* The flush operation completed successfully */
88*7c478bd9Sstevel@tonic-gate   GLQ_FLUSH_AGAIN,  /* The flush operation couldn't be completed on this */
89*7c478bd9Sstevel@tonic-gate                     /*  call. Call this function again when the output */
90*7c478bd9Sstevel@tonic-gate                     /*  channel can accept further output. */
91*7c478bd9Sstevel@tonic-gate   GLQ_FLUSH_ERROR   /* Unrecoverable error. */
92*7c478bd9Sstevel@tonic-gate } GlqFlushState;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate  * Transfer as much of the contents of a character queue to an output
96*7c478bd9Sstevel@tonic-gate  * channel as possible, returning before the queue is empty if the
97*7c478bd9Sstevel@tonic-gate  * write_fn() callback says that it can't currently write anymore.
98*7c478bd9Sstevel@tonic-gate  */
99*7c478bd9Sstevel@tonic-gate GlqFlushState _glq_flush_queue(GlCharQueue *cq, GlWriteFn *write_fn,
100*7c478bd9Sstevel@tonic-gate 			       void *data);
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * Provide information about the last error that occurred while calling
104*7c478bd9Sstevel@tonic-gate  * any of the above functions.
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate const char *_glq_last_error(GlCharQueue *cq);
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #endif
109