Makefile: Rebuild FFmpeg libraries when .asm and .o files change
[mplayer/glamo.git] / libmenu / menu_cmdlist.c
blob5b450ef6f1484580756ed632661a77fc00e79249
2 #include "config.h"
3 #include "mp_msg.h"
4 #include "help_mp.h"
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <string.h>
11 #include "libmpcodecs/img_format.h"
12 #include "libmpcodecs/mp_image.h"
14 #include "m_option.h"
15 #include "m_struct.h"
16 #include "asxparser.h"
17 #include "menu.h"
18 #include "menu_list.h"
20 #include "libvo/font_load.h"
22 #include "input/input.h"
26 struct list_entry_s {
27 struct list_entry p;
29 char* ok;
30 char* cancel;
31 char* left;
32 char* right;
35 struct menu_priv_s {
36 menu_list_priv_t p;
39 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
41 static struct menu_priv_s cfg_dflt = {
42 MENU_LIST_PRIV_DFLT,
45 static m_option_t cfg_fields[] = {
46 MENU_LIST_PRIV_FIELDS,
47 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
48 { NULL, NULL, NULL, 0,0,0,NULL }
51 #define mpriv (menu->priv)
53 static void read_cmd(menu_t* menu,int cmd) {
54 switch(cmd) {
55 case MENU_CMD_RIGHT:
56 if(mpriv->p.current->right) {
57 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->right);
58 break;
59 } // fallback on ok if right is not defined
60 case MENU_CMD_OK:
61 if (mpriv->p.current->ok)
62 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->ok);
63 break;
64 case MENU_CMD_LEFT:
65 if(mpriv->p.current->left) {
66 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->left);
67 break;
68 } // fallback on cancel if left is not defined
69 case MENU_CMD_CANCEL:
70 if(mpriv->p.current->cancel) {
71 mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->cancel);
72 break;
74 default:
75 menu_list_read_cmd(menu,cmd);
79 static void free_entry(list_entry_t* entry) {
80 if(entry->ok)
81 free(entry->ok);
82 if(entry->cancel)
83 free(entry->cancel);
84 if(entry->left)
85 free(entry->left);
86 if(entry->right)
87 free(entry->right);
88 free(entry->p.txt);
89 free(entry);
92 static void close_menu(menu_t* menu) {
93 menu_list_uninit(menu,free_entry);
96 static int parse_args(menu_t* menu,char* args) {
97 char *element,*body, **attribs, *name;
98 list_entry_t* m = NULL;
99 int r;
100 ASX_Parser_t* parser = asx_parser_new(menu->mconfig);
102 while(1) {
103 r = asx_get_element(parser,&args,&element,&body,&attribs);
104 if(r < 0) {
105 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
106 asx_parser_free(parser);
107 return -1;
108 } else if(r == 0) {
109 asx_parser_free(parser);
110 if(!m)
111 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition);
112 return m ? 1 : 0;
114 // Has it a name ?
115 name = asx_get_attrib("name",attribs);
116 if(!name) {
117 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName,parser->line);
118 free(element);
119 if(body) free(body);
120 asx_free_attribs(attribs);
121 continue;
123 m = calloc(1,sizeof(struct list_entry_s));
124 m->p.txt = name;
125 m->ok = asx_get_attrib("ok",attribs);
126 m->cancel = asx_get_attrib("cancel",attribs);
127 m->left = asx_get_attrib("left",attribs);
128 m->right = asx_get_attrib("right",attribs);
129 menu_list_add_entry(menu,m);
131 free(element);
132 if(body) free(body);
133 asx_free_attribs(attribs);
137 static int open_cmdlist(menu_t* menu, char* args) {
138 menu->draw = menu_list_draw;
139 menu->read_cmd = read_cmd;
140 menu->close = close_menu;
142 if(!args) {
143 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ListMenuNeedsAnArgument);
144 return 0;
147 menu_list_init(menu);
148 if(!parse_args(menu,args))
149 return 0;
150 return 1;
153 const menu_info_t menu_info_cmdlist = {
154 "Command list menu",
155 "cmdlist",
156 "Albeu",
159 "cmdlist_cfg",
160 sizeof(struct menu_priv_s),
161 &cfg_dflt,
162 cfg_fields
164 open_cmdlist