nuclear@0: #include nuclear@0: #include nuclear@0: #include "sgl.h" nuclear@0: nuclear@0: struct cbnode { nuclear@0: void (*func[SGL_NUM_CALLBACKS])(); nuclear@0: struct cbnode *next; nuclear@0: }; nuclear@0: nuclear@0: struct cbnode first_cbnode; nuclear@0: struct cbnode *cb = &first_cbnode; nuclear@0: nuclear@0: int sgl_push_callbacks(void) nuclear@0: { nuclear@0: struct cbnode *node; nuclear@0: nuclear@0: if(!(node = malloc(sizeof *node))) { nuclear@0: return -1; nuclear@0: } nuclear@0: node->next = cb; nuclear@0: cb = node; nuclear@0: sgl_clear_callbacks(); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: int sgl_pop_callbacks(void) nuclear@0: { nuclear@0: struct cbnode *node; nuclear@0: nuclear@0: if(!cb->next) { nuclear@0: return -1; nuclear@0: } nuclear@0: nuclear@0: node = cb; nuclear@0: cb = cb->next; nuclear@0: free(node); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void sgl_clear_callbacks(void) nuclear@0: { nuclear@0: memset(cb->func, 0, sizeof cb->func); nuclear@0: } nuclear@0: nuclear@0: void (*sgl_callback(int idx, void (*func)()))() nuclear@0: { nuclear@0: void (*prev)() = cb->func[idx]; nuclear@0: cb->func[idx] = func; nuclear@0: return prev; nuclear@0: }