Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=xbdmenu.git;a=commitdiff;h=21bdb9e7fc69d17350e1445eec0c96eb5a92da6f
commit 21bdb9e7fc69d17350e1445eec0c96eb5a92da6f Author: James Buren <[email protected]> Date: Sun Mar 15 16:59:39 2009 -0500 menu.c * implement internals diff --git a/menu.c b/menu.c index 3123864..d6df1e3 100644 --- a/menu.c +++ b/menu.c @@ -1,13 +1,81 @@ +#include <stdlib.h> +#include <ctype.h> #include <gd.h> +#include "mem.h" #include "env.h" +#include "str.h" #include "menu.h" -extern void menu_init(void) +#define MBUF 256 + +static int mn; + +static int menu_parse_line(const char *line) { +#define MSIZE sizeof(struct menu_t)*(mn+1) + char name[MBUF] = {0},cmd[MBUF] = {0},icon[MBUF] = {0}; + int ret = 1; + sscanf(line,"%[^\n:]:%[^\n:]:%[^\n:]",name,cmd,icon); + strtrim(name); + strtrim(cmd); + strtrim(icon); + if(isprint(name[0])&&isprint(cmd[0])&&isprint(icon[0])) + { + menu = (mn>0) ? realloc(menu,MSIZE) : zmalloc(MSIZE); + menu[mn].name = zstrdup(name); + menu[mn].cmd = zstrdup(cmd); + menu[mn].iconpath = strcmb(env->menudir,icon); + if((menu[mn].icon=load_image(menu[mn].iconpath))==NULL) + ret = 0; + ++mn; + } + else + ret = 0; + return(ret); +#undef MSIZE +} +extern void menu_init(void) +{ + char buf[MBUF] = {0}; + FILE *file = zfopen(env->menufile,"r"); + int ln = 0; + if(file==NULL) + exit(EXIT_FAILURE); + for(;;) + { + fgets(buf,sizeof(buf),file); + if(feof(file)) + break; + ++ln; + if(buf[0]=='\0'||buf[0]=='\n'||buf[0]=='#') + continue; + if(!menu_parse_line(buf)) + { + printf("Error while reading file '%s' at line %d.\n",env->menufile,ln); + zfclose(file); + exit(EXIT_FAILURE); + } + } + zfclose(file); } extern void menu_end(void) { - + if(menu) + { + int i; + for(i=0;i<mn;++i) + { + if(menu[i].name) + zfree(menu[i].name); + if(menu[i].cmd) + zfree(menu[i].cmd); + if(menu[i].iconpath) + zfree(menu[i].iconpath); + if(menu[i].icon) + free_image(menu[i].icon); + } + zfree(menu); + } } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
