Lines Matching refs:cq
92 GlCharQueue *cq; /* The object to be returned */ in _new_GlCharQueue() local
96 cq = malloc(sizeof(GlCharQueue)); in _new_GlCharQueue()
97 if(!cq) { in _new_GlCharQueue()
106 cq->err = NULL; in _new_GlCharQueue()
107 cq->bufmem = NULL; in _new_GlCharQueue()
108 cq->buffers.head = NULL; in _new_GlCharQueue()
109 cq->buffers.tail = NULL; in _new_GlCharQueue()
110 cq->nflush = cq->ntotal = 0; in _new_GlCharQueue()
114 cq->err = _new_ErrMsg(); in _new_GlCharQueue()
115 if(!cq->err) in _new_GlCharQueue()
116 return _del_GlCharQueue(cq); in _new_GlCharQueue()
120 cq->bufmem = _new_FreeList(sizeof(CqCharBuff), 1); in _new_GlCharQueue()
121 if(!cq->bufmem) in _new_GlCharQueue()
122 return _del_GlCharQueue(cq); in _new_GlCharQueue()
123 return cq; in _new_GlCharQueue()
134 GlCharQueue *_del_GlCharQueue(GlCharQueue *cq) in _del_GlCharQueue() argument
136 if(cq) { in _del_GlCharQueue()
137 cq->err = _del_ErrMsg(cq->err); in _del_GlCharQueue()
138 cq->bufmem = _del_FreeList(cq->bufmem, 1); in _del_GlCharQueue()
139 free(cq); in _del_GlCharQueue()
161 int _glq_append_chars(GlCharQueue *cq, const char *chars, int n, in _glq_append_chars() argument
168 if(!cq || !chars) { in _glq_append_chars()
184 int boff = cq->ntotal % GL_CQ_SIZE; in _glq_append_chars()
198 if(boff == 0 && _idle_FreeListNodes(cq->bufmem) == 0) { in _glq_append_chars()
199 switch(_glq_flush_queue(cq, write_fn, data)) { in _glq_append_chars()
208 boff = cq->ntotal % GL_CQ_SIZE; in _glq_append_chars()
220 CqCharBuff *node = (CqCharBuff *) _new_FreeListNode(cq->bufmem); in _glq_append_chars()
222 _err_record_msg(cq->err, "Insufficient memory to buffer output.", in _glq_append_chars()
233 if(cq->buffers.tail) in _glq_append_chars()
234 cq->buffers.tail->next = node; in _glq_append_chars()
236 cq->buffers.head = node; in _glq_append_chars()
237 cq->buffers.tail = node; in _glq_append_chars()
254 memcpy(cq->buffers.tail->bytes + boff, chars + ndone, nnew); in _glq_append_chars()
255 cq->ntotal += nnew; in _glq_append_chars()
270 void _glq_empty_queue(GlCharQueue *cq) in _glq_empty_queue() argument
272 if(cq) { in _glq_empty_queue()
276 _rst_FreeList(cq->bufmem); in _glq_empty_queue()
280 cq->buffers.head = cq->buffers.tail = NULL; in _glq_empty_queue()
281 cq->nflush = cq->ntotal = 0; in _glq_empty_queue()
293 int _glq_char_count(GlCharQueue *cq) in _glq_char_count() argument
295 return (cq && cq->buffers.head) ? (cq->ntotal - cq->nflush) : 0; in _glq_char_count()
321 GlqFlushState _glq_flush_queue(GlCharQueue *cq, GlWriteFn *write_fn, in _glq_flush_queue() argument
327 if(!cq) { in _glq_flush_queue()
335 while(cq->buffers.head) { in _glq_flush_queue()
339 int is_tail = cq->buffers.head == cq->buffers.tail; in _glq_flush_queue()
344 int nmodulo = cq->ntotal % GL_CQ_SIZE; in _glq_flush_queue()
358 int nbuff = nhead - (cq->nflush % GL_CQ_SIZE); in _glq_flush_queue()
362 int nnew = write_fn(data, cq->buffers.head->bytes + in _glq_flush_queue()
363 cq->nflush % GL_CQ_SIZE, nbuff); in _glq_flush_queue()
372 cq->nflush += nnew; in _glq_flush_queue()
383 _glq_empty_queue(cq); in _glq_flush_queue()
388 CqCharBuff *node = cq->buffers.head; in _glq_flush_queue()
392 cq->buffers.head = node->next; in _glq_flush_queue()
396 node = (CqCharBuff *) _del_FreeListNode(cq->bufmem, node); in _glq_flush_queue()
409 _err_record_msg(cq->err, "Error writing to terminal", END_ERR_MSG); in _glq_flush_queue()
430 const char *_glq_last_error(GlCharQueue *cq) in _glq_last_error() argument
432 return cq ? _err_get_msg(cq->err) : "NULL GlCharQueue argument"; in _glq_last_error()