menu.c (974B)
1 #include <sys/types.h> 2 #include <err.h> 3 #include <stdarg.h> 4 #include <stdint.h> 5 #include <time.h> 6 7 #include <kcgi.h> 8 #include <kcgihtml.h> 9 10 #include "page.h" 11 #include "html.h" 12 13 #include "menu.h" 14 15 enum kcgi_err 16 htmlmenuitem(struct pagedata *pd, struct menuitem *item) 17 { 18 switch (item->type) { 19 case MenuURL: 20 return htmllink(pd, item->u.url, item->u.url); 21 case MenuFunc: 22 return item->u.func(pd); 23 default: 24 err(1, "Invalid menu item type"); 25 } 26 } 27 28 enum kcgi_err 29 htmlmenu(struct pagedata *pd, struct menuitem *items, 30 unsigned int len) 31 { 32 enum kcgi_err status; 33 unsigned int i; 34 35 if ((status = khtml_attr(&pd->html, KELEM_UL, 36 KATTR_CLASS, "menu", KATTR__MAX)) != KCGI_OK) 37 return KCGI_OK; 38 39 for (i = 0; i < len; ++i) { 40 if ((status = khtml_elem(&pd->html, KELEM_LI)) != KCGI_OK || 41 (status = htmlmenuitem(pd, &items[i])) != KCGI_OK || 42 (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) 43 return status; 44 } 45 46 return khtml_closeelem(&pd->html, 1); 47 }