annotate parser-mecmd.c @ 9528:565015128767

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