annotate libmenu/menu_cmdlist.c @ 8201:31bda85aeb11

configure has problems detecting the latest ffmpeg libavcodec.so. The MBR and MBC defines are now removed from the header. patch by Alexander.Gottwald@s1999.tu-chemnitz.de
author arpi
date Sat, 16 Nov 2002 02:54:26 +0000
parents b31caec933e9
children 440301fef3fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
2 #include "../config.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
4 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <ctype.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include "img_format.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
9 #include "mp_image.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
10
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
11 #include "../m_option.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
12 #include "../m_struct.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
13 #include "../asxparser.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
14 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
15 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
16
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17 #include "../libvo/font_load.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19 #include "../input/input.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20 #include "../version.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 char* ok;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 char* cancel;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
32 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
33 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 MENU_LIST_PRIV_DFLT
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 if(mpriv->p.current->ok) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 if(c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 } break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 if(mpriv->p.current->cancel) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59 if(c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 static void read_key(menu_t* menu,int c){
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 menu_list_read_key(menu,c,0);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 if(entry->ok)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 free(entry->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 if(entry->cancel)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 free(entry->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 static void close(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 static int parse_args(menu_t* menu,char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 char *element,*body, **attribs, *name, *ok, *cancel;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 list_entry_t* m = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 ASX_Parser_t* parser = asx_parser_new();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 r = asx_get_element(parser,&args,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 if(r < 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 printf("Syntax error at line %d\n",parser->line);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 return -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 } else if(r == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 if(!m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 printf("No entry found in the menu definition\n");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 return m ? 1 : 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 // Has it a name ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 name = asx_get_attrib("name",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 if(!name) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 printf("List menu entry definitions need a name (line %d)\n",parser->line);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 ok = asx_get_attrib("ok",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 cancel = asx_get_attrib("cancel",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 m = calloc(1,sizeof(struct list_entry_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 m->p.txt = name;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 m->ok = ok;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 m->cancel = cancel;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 menu_list_add_entry(menu,m);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 static int open(menu_t* menu, char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 menu->close = close;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 if(!args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 printf("List menu need an argument\n");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
134 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 if(!parse_args(menu,args))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 const menu_info_t menu_info_cmdlist = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 "Command list menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145 "cmdlist",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 "cmdlist_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 open
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 };