Lines Matching refs:cq

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