Mercurial > mplayer.hg
comparison parser-mecmd.c @ 8164:487cfc28525d
New config system + cleanup of header inter dependency
author | albeu |
---|---|
date | Tue, 12 Nov 2002 01:56:42 +0000 |
parents | |
children | 268b3fbc35b7 |
comparison
equal
deleted
inserted
replaced
8163:51e5033ee687 | 8164:487cfc28525d |
---|---|
1 | |
2 #include "config.h" | |
3 | |
4 #ifdef NEW_CONFIG | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <errno.h> | |
10 | |
11 #ifdef MP_DEBUG | |
12 #include <assert.h> | |
13 #endif | |
14 | |
15 #include "mp_msg.h" | |
16 #include "m_option.h" | |
17 #include "m_config.h" | |
18 #include "parser-mecmd.h" | |
19 | |
20 | |
21 void | |
22 m_entry_list_free(m_entry_t* lst) { | |
23 int i,j; | |
24 | |
25 for(i = 0 ; lst[i].name != NULL ; i++){ | |
26 free(lst[i].name); | |
27 for(j = 0 ; lst[i].opts[2*j] != NULL ; j++) { | |
28 free(lst[i].opts[2*j]); | |
29 free(lst[i].opts[2*j+1]); | |
30 } | |
31 free(lst[i].opts); | |
32 } | |
33 free(lst); | |
34 } | |
35 | |
36 int | |
37 m_entry_set_options(m_config_t *config, m_entry_t* entry) { | |
38 int i,r; | |
39 | |
40 for(i = 0 ; entry->opts[2*i] != NULL ; i++){ | |
41 r = m_config_set_option(config,entry->opts[2*i],entry->opts[2*i+1]); | |
42 if(r < 0) | |
43 return 0; | |
44 } | |
45 return 1; | |
46 } | |
47 | |
48 | |
49 | |
50 | |
51 m_entry_t* | |
52 m_config_parse_me_command_line(m_config_t *config, int argc, char **argv) | |
53 { | |
54 int i,nf = 0,no = 0; | |
55 int tmp; | |
56 char *opt; | |
57 int no_more_opts = 0; | |
58 m_entry_t *lst = NULL, *entry = NULL; | |
59 void add_file(char* file) { | |
60 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); | |
61 lst = realloc(lst,(nf+2)*sizeof(m_entry_t)); | |
62 lst[nf].name = strdup(file); | |
63 lst[nf].opts = calloc(2,sizeof(char*)); | |
64 entry = &lst[nf]; | |
65 no = 0; | |
66 memset(&lst[nf+1],0,sizeof(m_entry_t)); | |
67 nf++; | |
68 } | |
69 | |
70 #ifdef MP_DEBUG | |
71 assert(config != NULL); | |
72 assert(argv != NULL); | |
73 assert(argc >= 1); | |
74 #endif | |
75 | |
76 config->mode = M_COMMAND_LINE; | |
77 | |
78 lst = calloc(1,sizeof(m_entry_t)); | |
79 | |
80 for (i = 1; i < argc; i++) { | |
81 //next: | |
82 opt = argv[i]; | |
83 /* check for -- (no more options id.) except --help! */ | |
84 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h')) | |
85 { | |
86 no_more_opts = 1; | |
87 if (i+1 >= argc) | |
88 { | |
89 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n"); | |
90 goto err_out; | |
91 } | |
92 continue; | |
93 } | |
94 | |
95 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
96 { | |
97 m_option_t* mp_opt = NULL; | |
98 /* remove trailing '-' */ | |
99 opt++; | |
100 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
101 mp_opt = m_config_get_option(config,opt); | |
102 if(!mp_opt) { | |
103 tmp = M_OPT_UNKNOW; | |
104 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "%s in not an MEncoder option\n",opt); | |
105 goto err_out; | |
106 } | |
107 // Hack for the -vcd ... options | |
108 if(strcasecmp(opt,"vcd") == 0) | |
109 add_file("VCD Track"); | |
110 if(strcasecmp(opt,"dvd") == 0) | |
111 add_file("DVD Title"); | |
112 if(strcasecmp(opt,"tv") == 0 && argv[i + 1]) { // TV is a bit more tricky | |
113 char* param = argv[i + 1]; | |
114 char* on = strstr(param,"on"); | |
115 for( ; on ; on = strstr(on + 1,"on")) { | |
116 if(on[2] != ':' && on[2] != '\0') continue; | |
117 if(on != param && *(on - 1) != ':') continue; | |
118 add_file("TV Channel"); | |
119 break; | |
120 } | |
121 } | |
122 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)) | |
123 tmp = m_config_set_option(config, opt, argv[i + 1]); | |
124 else { | |
125 tmp = m_config_check_option(config, opt, argv[i + 1]); | |
126 if(tmp >= 0) { | |
127 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*)); | |
128 entry->opts[2*no] = strdup(opt); | |
129 entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL; | |
130 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL; | |
131 no++; | |
132 } | |
133 } | |
134 if (tmp < 0) | |
135 goto err_out; | |
136 i += tmp; | |
137 } else /* filename */ | |
138 add_file(argv[i]); | |
139 } | |
140 | |
141 if(nf == 0) { | |
142 m_entry_list_free(lst); | |
143 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n"); | |
144 return NULL; | |
145 } | |
146 return lst; | |
147 | |
148 err_out: | |
149 m_entry_list_free(lst); | |
150 return NULL; | |
151 } | |
152 | |
153 #endif |