Mercurial > mplayer.hg
annotate libmenu/menu_param.c @ 11070:ede278d59026
10l
author | michael |
---|---|
date | Thu, 09 Oct 2003 23:45:04 +0000 |
parents | a2537e7d2d76 |
children | 931bdbc37ee0 |
rev | line source |
---|---|
8197 | 1 |
2 #include <stdlib.h> | |
3 #include <stdio.h> | |
4 #include <dirent.h> | |
5 #include <errno.h> | |
6 #include <string.h> | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
9 #include <ctype.h> | |
10 | |
11 | |
12 #include "../config.h" | |
13 | |
14 #include "../m_struct.h" | |
15 #include "../m_option.h" | |
16 #include "../m_config.h" | |
17 #include "../asxparser.h" | |
18 | |
19 #include "img_format.h" | |
20 #include "mp_image.h" | |
21 | |
22 #include "menu.h" | |
23 #include "menu_list.h" | |
24 #include "../input/input.h" | |
9380 | 25 #include "../osdep/keycodes.h" |
8197 | 26 |
27 struct list_entry_s { | |
28 struct list_entry p; | |
29 m_option_t* opt; | |
30 }; | |
31 | |
32 struct menu_priv_s { | |
33 menu_list_priv_t p; | |
34 char* edit; | |
35 int edit_len; | |
36 /// Cfg fields | |
37 }; | |
38 | |
39 static struct menu_priv_s cfg_dflt = { | |
40 MENU_LIST_PRIV_DFLT, | |
41 NULL, | |
42 0 | |
43 }; | |
44 | |
45 static m_option_t cfg_fields[] = { | |
46 MENU_LIST_PRIV_FIELDS, | |
47 { "title", M_ST_OFF(menu_list_priv_t,title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
48 { NULL, NULL, NULL, 0,0,0,NULL } | |
49 }; | |
50 | |
51 #define mpriv (menu->priv) | |
52 | |
53 extern m_config_t* mconfig; | |
54 | |
55 static int parse_args(menu_t* menu,char* args) { | |
56 char *element,*body, **attribs, *name, *ok, *cancel; | |
57 list_entry_t* m = NULL; | |
58 int r; | |
59 m_option_t* opt; | |
60 ASX_Parser_t* parser = asx_parser_new(); | |
61 | |
62 | |
63 while(1) { | |
64 r = asx_get_element(parser,&args,&element,&body,&attribs); | |
65 if(r < 0) { | |
66 printf("Syntax error at line %d\n",parser->line); | |
67 asx_parser_free(parser); | |
68 return -1; | |
69 } else if(r == 0) { | |
70 asx_parser_free(parser); | |
71 if(!m) | |
72 printf("No entry found in the menu definition\n"); | |
73 return m ? 1 : 0; | |
74 } | |
75 // Has it a name ? | |
76 name = asx_get_attrib("name",attribs); | |
77 opt = name ? m_config_get_option(mconfig,name) : NULL; | |
78 if(!opt) { | |
79 printf("Pref menu entry definitions need a valid name attribut (line %d)\n",parser->line); | |
80 free(element); | |
81 if(name) free(name); | |
82 if(body) free(body); | |
83 asx_free_attribs(attribs); | |
84 continue; | |
85 } | |
86 m = calloc(1,sizeof(struct list_entry_s)); | |
87 m->p.txt = name; | |
88 m->opt = opt; | |
89 menu_list_add_entry(menu,m); | |
90 | |
91 free(element); | |
92 if(body) free(body); | |
93 asx_free_attribs(attribs); | |
94 } | |
95 } | |
96 | |
97 static void read_key(menu_t* menu,int c) { | |
98 menu_list_read_key(menu,c,0); | |
99 } | |
100 | |
101 static void free_entry(list_entry_t* entry) { | |
102 free(entry->p.txt); | |
103 free(entry); | |
104 } | |
105 | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
106 static void closeMenu(menu_t* menu) { |
8197 | 107 menu_list_uninit(menu,free_entry); |
108 if(mpriv->edit) | |
109 free(mpriv->edit); | |
110 } | |
111 | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
112 static int openMenu(menu_t* menu, char* args) { |
8197 | 113 list_entry_t* e; |
114 | |
115 menu->draw = menu_list_draw; | |
116 menu->read_cmd = menu_list_read_cmd; | |
117 menu->read_key = read_key; | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
118 menu->close = closeMenu; |
8197 | 119 |
120 | |
121 if(!args) { | |
122 printf("Pref menu need an argument\n"); | |
123 return 0; | |
124 } | |
125 | |
126 menu_list_init(menu); | |
127 if(!parse_args(menu,args)) | |
128 return 0; | |
129 | |
130 for(e = mpriv->p.menu ; e ; e = e->p.next) { | |
131 int l; | |
132 char* val = m_option_print(e->opt,e->opt->p); | |
133 if((int)val == -1) { | |
134 printf("Can't get value of option %s\n",e->opt->name); | |
135 continue; | |
136 } else if(!val) | |
137 val = strdup("NULL"); | |
138 l = strlen(e->opt->name) + 2 + strlen(val) + 1; | |
139 e->p.txt = malloc(l); | |
140 sprintf(e->p.txt,"%s: %s",e->opt->name,val); | |
141 free(val); | |
142 } | |
143 | |
144 return 1; | |
145 } | |
146 | |
147 const menu_info_t menu_info_pref = { | |
148 "Preferences menu", | |
149 "pref", | |
150 "Albeu", | |
151 "", | |
152 { | |
153 "pref_cfg", | |
154 sizeof(struct menu_priv_s), | |
155 &cfg_dflt, | |
156 cfg_fields | |
157 }, | |
10864
a2537e7d2d76
make menu work on mingw (run command is still disabled), based on patch by Christophe Perinaud
faust3
parents:
9380
diff
changeset
|
158 openMenu |
8197 | 159 }; |