Something went wrong. Try again.
a less like pager but for fun
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107#include "queue.h"
queue q_new() { queue q = {0}; q.front = q.rear = Q_EMPTY_IDX; return q;}
// check if q is emptybool q_is_empty(queue *q) { return q->front == Q_EMPTY_IDX;}
// check if q is fullbool q_is_full(queue *q) { return (q->rear + 1) % Q_MAX_SIZE == q->front;}
// enqueue item to q// RETURNS Q_FULL if q is full// RETURNS Q_DONE if successfulint q_enqueue(queue *q, void *item) { if (q_is_full(q)) return Q_FULL;
if (q->front == Q_EMPTY_IDX) q->front = 0;
q->rear = (q->rear + 1) % Q_MAX_SIZE; q->items[q->rear] = item; return Q_DONE;}
// dequeue q// RETURNS NULL pointer if q is emptyvoid *q_dequeue(queue *q) { if (q_is_empty(q)) return Q_NULL;
void *item = q->items[q->front];
if (q->front == q->rear) q->front = q->rear = Q_EMPTY_IDX; else q->front = (q->front + 1) % Q_MAX_SIZE;
return item;}
// peek at q// RETURNS NULL pointer if q is emptyvoid *q_peek(queue *q) { if (q_is_empty(q)) return Q_NULL; return q->items[q->front];}
#ifdef KK_DEBUG_
#include <stdio.h>#include "draw.h"
void q_print_type_enum(int e) { switch (e) { case DRAW: printf("DRAW"); break; case MOVEV: printf("MOVEV"); break; case MOVEH: printf("MOVEH"); break; case SETL: printf("SETL"); break; case SETX: printf("SETX"); break; case SWITCH: printf("SWITCH"); break; case AUTO_PAGING: printf("AUTO_PAGING"); break; case POPULATE_W: printf("POPULATE_W"); break; } printf(" ");}
void q_debug(queue *q) { printf("[Q: "); if (q_is_empty(q)) goto end; int i = q->front; while (i != q->rear) { if (q->items[i] == NULL) { printf("NULL "); } else { int v = ((dtask *) q->items[i])->type; q_print_type_enum(v); } i = (i + 1) % Q_MAX_SIZE; } int v = ((dtask *) q->items[i])->type; q_print_type_enum(v);end: printf("]"); fflush(stdout);}#endif // KK_DEBUG_