8164
|
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;
|
9096
|
104 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "%s is not an MEncoder option\n",opt);
|
8164
|
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 }
|
8893
|
122 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
|
8164
|
123 tmp = m_config_set_option(config, opt, argv[i + 1]);
|
8893
|
124 if(tmp < 0){
|
|
125 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
|
|
126 goto err_out;
|
|
127 }
|
|
128 } else {
|
8164
|
129 tmp = m_config_check_option(config, opt, argv[i + 1]);
|
|
130 if(tmp >= 0) {
|
|
131 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
|
|
132 entry->opts[2*no] = strdup(opt);
|
|
133 entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL;
|
|
134 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL;
|
|
135 no++;
|
8893
|
136 } else {
|
|
137 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
|
|
138 goto err_out;
|
8164
|
139 }
|
|
140 }
|
|
141 i += tmp;
|
|
142 } else /* filename */
|
|
143 add_file(argv[i]);
|
|
144 }
|
|
145
|
|
146 if(nf == 0) {
|
|
147 m_entry_list_free(lst);
|
|
148 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n");
|
|
149 return NULL;
|
|
150 }
|
|
151 return lst;
|
|
152
|
|
153 err_out:
|
|
154 m_entry_list_free(lst);
|
|
155 return NULL;
|
|
156 }
|
|
157
|
|
158 #endif
|