Lines Matching defs:cq
94 GlCharQueue *cq; /* The object to be returned */
98 cq = malloc(sizeof(GlCharQueue));
99 if(!cq) {
108 cq->err = NULL;
109 cq->bufmem = NULL;
110 cq->buffers.head = NULL;
111 cq->buffers.tail = NULL;
112 cq->nflush = cq->ntotal = 0;
116 cq->err = _new_ErrMsg();
117 if(!cq->err)
118 return _del_GlCharQueue(cq);
122 cq->bufmem = _new_FreeList(sizeof(CqCharBuff), 1);
123 if(!cq->bufmem)
124 return _del_GlCharQueue(cq);
125 return cq;
132 * cq GlCharQueue * The object to be deleted.
136 GlCharQueue *_del_GlCharQueue(GlCharQueue *cq)
138 if(cq) {
139 cq->err = _del_ErrMsg(cq->err);
140 cq->bufmem = _del_FreeList(cq->bufmem, 1);
141 free(cq);
150 * cq GlCharQueue * The queue to append to.
163 int _glq_append_chars(GlCharQueue *cq, const char *chars, int n,
170 if(!cq || !chars) {
180 int nleft; /* The amount of space remaining in cq->buffers.tail */
181 int nnew; /* The number of characters to append to cq->buffers.tail */
186 int boff = cq->ntotal % GL_CQ_SIZE;
200 if(boff == 0 && _idle_FreeListNodes(cq->bufmem) == 0) {
201 switch(_glq_flush_queue(cq, write_fn, data)) {
210 boff = cq->ntotal % GL_CQ_SIZE;
222 CqCharBuff *node = (CqCharBuff *) _new_FreeListNode(cq->bufmem);
224 _err_record_msg(cq->err, "Insufficient memory to buffer output.",
235 if(cq->buffers.tail)
236 cq->buffers.tail->next = node;
238 cq->buffers.head = node;
239 cq->buffers.tail = node;
256 memcpy(cq->buffers.tail->bytes + boff, chars + ndone, nnew);
257 cq->ntotal += nnew;
270 * cq GlCharQueue * The queue to clear.
272 void _glq_empty_queue(GlCharQueue *cq)
274 if(cq) {
278 _rst_FreeList(cq->bufmem);
282 cq->buffers.head = cq->buffers.tail = NULL;
283 cq->nflush = cq->ntotal = 0;
291 * cq GlCharQueue * The queue of interest.
295 int _glq_char_count(GlCharQueue *cq)
297 return (cq && cq->buffers.head) ? (cq->ntotal - cq->nflush) : 0;
306 * cq GlCharQueue * The queue to write characters from.
323 GlqFlushState _glq_flush_queue(GlCharQueue *cq, GlWriteFn *write_fn,
329 if(!cq) {
337 while(cq->buffers.head) {
341 int is_tail = cq->buffers.head == cq->buffers.tail;
346 int nmodulo = cq->ntotal % GL_CQ_SIZE;
360 int nbuff = nhead - (cq->nflush % GL_CQ_SIZE);
364 int nnew = write_fn(data, cq->buffers.head->bytes +
365 cq->nflush % GL_CQ_SIZE, nbuff);
374 cq->nflush += nnew;
385 _glq_empty_queue(cq);
390 CqCharBuff *node = cq->buffers.head;
394 cq->buffers.head = node->next;
398 node = (CqCharBuff *) _del_FreeListNode(cq->bufmem, node);
411 _err_record_msg(cq->err, "Error writing to terminal", END_ERR_MSG);
427 * cq GlCharQueue * The container of the history list.
432 const char *_glq_last_error(GlCharQueue *cq)
434 return cq ? _err_get_msg(cq->err) : "NULL GlCharQueue argument";