nuclear@1: #include nuclear@7: #include nuclear@7: #include nuclear@1: #include "wsys.h" nuclear@31: #include "log.h" nuclear@1: nuclear@3: static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2); nuclear@3: static struct wsys_module *msort(struct wsys_module *list, int count); nuclear@3: nuclear@3: nuclear@7: struct wsys_module *wslist, *sel; nuclear@1: int wscount; nuclear@1: nuclear@1: int sgl_register_module(struct wsys_module *ws) nuclear@1: { nuclear@1: ws->next = wslist; nuclear@1: wslist = ws; nuclear@1: wscount++; nuclear@1: return 0; nuclear@1: } nuclear@1: nuclear@3: void sgl_sort_modules(void) nuclear@3: { nuclear@3: wslist = msort(wslist, wscount); nuclear@3: } nuclear@3: nuclear@7: void sgl_print_modules(void) nuclear@7: { nuclear@7: struct wsys_module *ws = wslist; nuclear@7: nuclear@31: sgl_log("window system modules:\n"); nuclear@7: while(ws) { nuclear@31: sgl_log("- %s\n", ws->name); nuclear@7: ws = ws->next; nuclear@7: } nuclear@7: } nuclear@7: nuclear@3: struct wsys_module *sgl_wsys_module(void) nuclear@3: { nuclear@7: if(!sel) { nuclear@7: char *modname; nuclear@7: if((modname = getenv("SGL_MODULE"))) { nuclear@7: struct wsys_module *ws = wslist; nuclear@7: while(ws) { nuclear@7: if(strcmp(ws->name, modname) == 0) { nuclear@7: sel = ws; nuclear@7: break; nuclear@7: } nuclear@7: ws = ws->next; nuclear@7: } nuclear@7: if(!sel) { nuclear@7: sel = wslist; nuclear@7: } nuclear@7: } else { nuclear@7: sel = wslist; nuclear@7: } nuclear@7: } nuclear@7: return sel; nuclear@3: } nuclear@3: nuclear@1: #define APPEND(node) \ nuclear@1: do { \ nuclear@1: if(!res) { \ nuclear@1: res = tail = node; \ nuclear@1: } else { \ nuclear@1: tail->next = (node); \ nuclear@1: tail = (node); \ nuclear@1: } \ nuclear@1: (node) = (node)->next; \ nuclear@1: tail->next = 0; \ nuclear@1: } while(0) nuclear@1: nuclear@1: static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2) nuclear@1: { nuclear@1: struct wsys_module *res, *tail; nuclear@1: nuclear@1: res = tail = 0; nuclear@1: nuclear@1: while(list1 || list2) { nuclear@1: if(list1 && list2) { nuclear@1: if(list1->prio <= list2->prio) { nuclear@1: APPEND(list1); nuclear@1: } else { nuclear@1: APPEND(list2); nuclear@1: } nuclear@1: } else if(list1) { nuclear@1: APPEND(list1); nuclear@1: } else { nuclear@1: APPEND(list2); nuclear@1: } nuclear@1: } nuclear@1: return res; nuclear@1: } nuclear@1: nuclear@1: static struct wsys_module *msort(struct wsys_module *list, int count) nuclear@1: { nuclear@1: int i, mid = count / 2; nuclear@1: struct wsys_module *prev, *list2 = list; nuclear@1: nuclear@1: if(!list->next) { nuclear@1: return list; nuclear@1: } nuclear@1: for(i=0; inext; nuclear@1: } nuclear@1: prev->next = 0; nuclear@1: nuclear@1: list = msort(list, mid); nuclear@1: list2 = msort(list2, count - mid); nuclear@1: return merge(list, list2); nuclear@1: }