Mercurial > mplayer.hg
annotate parser-mpcmd.c @ 12816:fba780800efe
-use-stdin renamed to -noconsolecontrols.
| author | diego |
|---|---|
| date | Wed, 14 Jul 2004 09:27:04 +0000 |
| parents | 2cbc9f1f728f |
| children | 07dadc3066f3 |
| rev | line source |
|---|---|
| 8164 | 1 #include "config.h" |
| 2 | |
| 3 #include <stdio.h> | |
| 4 #include <stdlib.h> | |
| 5 #include <string.h> | |
| 6 #include <errno.h> | |
| 7 | |
| 8 #ifdef MP_DEBUG | |
| 9 #include <assert.h> | |
| 10 #endif | |
| 11 | |
| 12 #include "mp_msg.h" | |
| 13 #include "m_option.h" | |
| 14 #include "m_config.h" | |
| 15 #include "playtree.h" | |
| 16 | |
| 17 static int recursion_depth = 0; | |
| 18 static int mode = 0; | |
| 19 | |
| 20 #define GLOBAL 0 | |
| 21 #define LOCAL 1 | |
| 22 #define DROP_LOCAL 2 | |
| 23 | |
|
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
24 #define dvd_range(a) (a>0 && a<256) |
| 8164 | 25 #define UNSET_GLOBAL (mode = LOCAL) |
| 26 // Use this 1 if you want to have only global option (no per file option) | |
| 27 // #define UNSET_GLOBAL (mode = GLOBAL) | |
| 28 | |
| 29 | |
| 30 static int is_entry_option(char *opt, char *param, play_tree_t** ret) { | |
| 31 play_tree_t* entry = NULL; | |
| 32 | |
| 33 *ret = NULL; | |
| 34 | |
| 35 if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here | |
| 36 if(!param) | |
| 37 return M_OPT_MISSING_PARAM; | |
| 12267 | 38 |
| 8164 | 39 entry = parse_playlist_file(param); |
| 40 if(!entry) | |
| 12267 | 41 return -1; |
| 42 else { | |
| 43 *ret=entry; | |
| 44 return 1; | |
| 45 } | |
| 8164 | 46 } |
| 47 return 0; | |
| 48 } | |
| 49 | |
|
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
50 static inline void add_entry(play_tree_t **last_parentp, |
|
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
51 play_tree_t **last_entryp, play_tree_t *entry) { |
|
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
52 if(*last_entryp == NULL) |
|
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
53 play_tree_set_child(*last_parentp,entry); |
| 10513 | 54 else |
|
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
55 play_tree_append_entry(*last_entryp,entry); |
|
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
56 *last_entryp = entry; |
| 10513 | 57 } |
| 58 | |
| 8164 | 59 play_tree_t* |
| 60 m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) | |
| 61 { | |
|
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
62 int i,j,start_title=-1,end_title=-1; |
| 8164 | 63 int tmp = 0; |
|
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
64 char *opt,*splitpos=NULL; |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
65 char entbuf[10]; |
| 8164 | 66 int no_more_opts = 0; |
| 67 play_tree_t *last_parent, *last_entry = NULL, *root; | |
| 68 | |
| 69 #ifdef MP_DEBUG | |
| 70 assert(config != NULL); | |
| 71 assert(argv != NULL); | |
| 72 assert(argc >= 1); | |
| 73 #endif | |
| 74 | |
| 75 config->mode = M_COMMAND_LINE; | |
| 76 mode = GLOBAL; | |
| 77 last_parent = root = play_tree_new(); | |
| 78 /* in order to work recursion detection properly in parse_config_file */ | |
| 79 ++recursion_depth; | |
| 80 | |
| 81 for (i = 1; i < argc; i++) { | |
| 82 //next: | |
| 83 opt = argv[i]; | |
| 84 /* check for -- (no more options id.) except --help! */ | |
| 85 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h')) | |
| 86 { | |
| 87 no_more_opts = 1; | |
| 88 if (i+1 >= argc) | |
| 89 { | |
| 90 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n"); | |
| 91 goto err_out; | |
| 92 } | |
| 93 continue; | |
| 94 } | |
| 95 if((opt[0] == '{') && (opt[1] == '\0')) | |
| 96 { | |
| 97 play_tree_t* entry = play_tree_new(); | |
| 98 UNSET_GLOBAL; | |
| 8175 | 99 if(last_parent->flags & PLAY_TREE_RND) |
| 100 entry->flags |= PLAY_TREE_RND; | |
| 8164 | 101 if(last_entry == NULL) { |
| 102 play_tree_set_child(last_parent,entry); | |
| 103 } else { | |
| 104 play_tree_append_entry(last_entry,entry); | |
| 105 last_entry = NULL; | |
| 106 } | |
| 107 last_parent = entry; | |
| 108 continue; | |
| 109 } | |
| 110 | |
| 111 if((opt[0] == '}') && (opt[1] == '\0')) | |
| 112 { | |
| 113 if( ! last_parent || ! last_parent->parent) { | |
| 114 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); | |
| 115 goto err_out; | |
| 116 } | |
| 117 last_entry = last_parent; | |
| 118 last_parent = last_entry->parent; | |
| 119 continue; | |
| 120 } | |
| 121 | |
| 122 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
| 123 { | |
| 124 /* remove trailing '-' */ | |
| 125 opt++; | |
| 126 | |
| 127 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
| 128 // We handle here some specific option | |
| 129 if(strcasecmp(opt,"list-options") == 0) { | |
| 130 m_config_print_option_list(config); | |
| 131 exit(1); | |
| 132 // Loop option when it apply to a group | |
| 133 } else if(strcasecmp(opt,"loop") == 0 && | |
| 134 (! last_entry || last_entry->child) ) { | |
| 135 int l; | |
| 136 char* end; | |
| 8400 | 137 l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0; |
| 9106 | 138 if(*end != '\0') { |
| 139 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The loop option must be an integer: %s\n",argv[i+1]); | |
| 8164 | 140 tmp = ERR_OUT_OF_RANGE; |
| 9106 | 141 } else { |
| 8164 | 142 play_tree_t* pt = last_entry ? last_entry : last_parent; |
| 143 l = l <= 0 ? -1 : l; | |
| 144 pt->loop = l; | |
| 145 tmp = 1; | |
| 146 } | |
| 8452 | 147 } else if(strcasecmp(opt,"shuffle") == 0) { |
| 8175 | 148 if(last_entry && last_entry->child) |
| 149 last_entry->flags |= PLAY_TREE_RND; | |
| 150 else | |
| 151 last_parent->flags |= PLAY_TREE_RND; | |
| 8452 | 152 } else if(strcasecmp(opt,"noshuffle") == 0) { |
| 8175 | 153 if(last_entry && last_entry->child) |
| 154 last_entry->flags &= ~PLAY_TREE_RND; | |
| 155 else | |
| 156 last_parent->flags &= ~PLAY_TREE_RND; | |
| 8164 | 157 } else { |
| 158 m_option_t* mp_opt = NULL; | |
| 159 play_tree_t* entry = NULL; | |
| 160 | |
| 8458 | 161 tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry); |
| 8164 | 162 if(tmp > 0) { // It's an entry |
| 163 if(entry) { | |
|
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
164 add_entry(&last_parent,&last_entry,entry); |
| 8175 | 165 if((last_parent->flags & PLAY_TREE_RND) && entry->child) |
| 166 entry->flags |= PLAY_TREE_RND; | |
| 8164 | 167 UNSET_GLOBAL; |
| 168 } else if(mode == LOCAL) // Entry is empty we have to drop his params | |
| 169 mode = DROP_LOCAL; | |
| 170 } else if(tmp == 0) { // 'normal' options | |
| 171 mp_opt = m_config_get_option(config,opt); | |
| 172 if (mp_opt != NULL) { // Option exist | |
| 173 if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL)) | |
| 8426 | 174 tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1]) |
| 175 : m_config_set_option(config, opt, NULL); | |
| 8164 | 176 else { |
| 8458 | 177 tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL); |
| 8164 | 178 if(tmp >= 0 && mode != DROP_LOCAL) { |
| 179 play_tree_t* pt = last_entry ? last_entry : last_parent; | |
| 180 play_tree_set_param(pt,opt, argv[i + 1]); | |
| 181 } | |
| 182 } | |
| 183 } else { | |
|
10595
522afd56703c
100l to albeu for his english grammar, and 10l to me becouse I noticed that lately (my backward compatibilty macro uses M_OPT_UNKNOWN)
alex
parents:
10594
diff
changeset
|
184 tmp = M_OPT_UNKNOWN; |
| 10397 | 185 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown option on the command line: %s\n",opt); |
| 8164 | 186 } |
| 187 } | |
| 188 } | |
| 189 | |
| 9792 | 190 if (tmp < 0) { |
| 191 if (tmp == M_OPT_EXIT) | |
| 192 exit(0); | |
| 8164 | 193 goto err_out; |
| 9792 | 194 } |
| 8164 | 195 i += tmp; |
| 196 } | |
| 197 else /* filename */ | |
| 198 { | |
| 199 play_tree_t* entry = play_tree_new(); | |
| 200 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); | |
|
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
201 // if required expand DVD filename entries like dvd://1-3 into component titles |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
202 if ( strstr(argv[i],"dvd://") != NULL ) |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
203 { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
204 splitpos=strstr(argv[i]+6,"-"); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
205 if(splitpos != NULL) |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
206 { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
207 start_title=strtol(argv[i]+6,NULL,10); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
208 if (start_title<0) { //entries like dvd://-2 start title implied 1 |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
209 end_title=abs(start_title); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
210 start_title=1; |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
211 } else { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
212 end_title=strtol(splitpos+1,NULL,10); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
213 } |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
214 |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
215 if (dvd_range(start_title) && dvd_range(end_title) && (start_title<end_title)) |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
216 { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
217 for (j=start_title;j<=end_title;j++) |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
218 { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
219 if (j!=start_title) |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
220 entry=play_tree_new(); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
221 snprintf(entbuf,9,"dvd://%d",j); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
222 play_tree_add_file(entry,entbuf); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
223 add_entry(&last_parent,&last_entry,entry); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
224 last_entry = entry; |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
225 } |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
226 } else { |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
227 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Invalid play entry %s\n",argv[i]); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
228 } |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
229 |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
230 } else { // dvd:// or dvd://x entry |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
231 play_tree_add_file(entry,argv[i]); |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
232 } |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
233 } else { |
| 8164 | 234 play_tree_add_file(entry,argv[i]); |
|
12543
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
235 } |
|
2cbc9f1f728f
Support dvd://start_title-end_title as requested on wishlist
rtognimp
parents:
12267
diff
changeset
|
236 |
| 8164 | 237 // Lock stdin if it will be used as input |
| 238 if(strcasecmp(argv[i],"-") == 0) | |
| 12816 | 239 m_config_set_option(config,"noconsolecontrols",NULL); |
|
10542
928c02fa9949
fix the bug where only the last file of the command line is found
pl
parents:
10513
diff
changeset
|
240 add_entry(&last_parent,&last_entry,entry); |
| 8164 | 241 UNSET_GLOBAL; // We start entry specific options |
| 242 | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 --recursion_depth; | |
| 247 if(last_parent != root) | |
| 248 mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); | |
| 249 return root; | |
| 250 | |
| 251 err_out: | |
| 252 --recursion_depth; | |
| 253 play_tree_free(root,1); | |
| 254 return NULL; | |
| 255 } |
