annotate libmenu/menu_param.c @ 9373:e1e2177841ef

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