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