Mercurial > mplayer.hg
annotate parser-mecmd.c @ 19945:15ae9558e41e
Fix audio stream switching with demux_mkv:
return value of demuxer_switch_audio is new stream number for
-aid, the index in a_streams array is in demuxer->audio->id instead.
author | reimar |
---|---|
date | Sat, 23 Sep 2006 11:07:58 +0000 |
parents | 1a14fde7680d |
children | d78e7d5bc6d5 |
rev | line source |
---|---|
18265 | 1 |
2 /// \file | |
3 /// \ingroup ConfigParsers MEntry | |
4 | |
8164 | 5 #include "config.h" |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <errno.h> | |
11 | |
12 #ifdef MP_DEBUG | |
13 #include <assert.h> | |
14 #endif | |
15 | |
16 #include "mp_msg.h" | |
17 #include "m_option.h" | |
18 #include "m_config.h" | |
19 #include "parser-mecmd.h" | |
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; | |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
58 int opt_exit = 0; |
8164 | 59 m_entry_t *lst = NULL, *entry = NULL; |
60 | |
61 #ifdef MP_DEBUG | |
62 assert(config != NULL); | |
63 assert(argv != NULL); | |
64 assert(argc >= 1); | |
65 #endif | |
66 | |
67 config->mode = M_COMMAND_LINE; | |
68 | |
69 lst = calloc(1,sizeof(m_entry_t)); | |
70 | |
71 for (i = 1; i < argc; i++) { | |
72 //next: | |
73 opt = argv[i]; | |
74 /* check for -- (no more options id.) except --help! */ | |
15245
4fdfe0860cc5
Make "mplayer -- --a" play the file --a instead of bailing out with a useless
reimar
parents:
14541
diff
changeset
|
75 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0)) |
8164 | 76 { |
77 no_more_opts = 1; | |
78 if (i+1 >= argc) | |
79 { | |
14541 | 80 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n"); |
8164 | 81 goto err_out; |
82 } | |
83 continue; | |
84 } | |
85 | |
86 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
87 { | |
88 m_option_t* mp_opt = NULL; | |
89 /* remove trailing '-' */ | |
90 opt++; | |
91 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
92 mp_opt = m_config_get_option(config,opt); | |
93 if(!mp_opt) { | |
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
|
94 tmp = M_OPT_UNKNOWN; |
15742
55cbf0c204bc
when somebody specifies e.g. --loop, the message says that a -loop option
reimar
parents:
15245
diff
changeset
|
95 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "-%s is not an MEncoder option\n",opt); |
8164 | 96 goto err_out; |
97 } | |
8893 | 98 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){ |
8164 | 99 tmp = m_config_set_option(config, opt, argv[i + 1]); |
17467
d631b3c09c53
Fix multiple help clauses on the command line with mencoder.
albeu
parents:
16345
diff
changeset
|
100 if (tmp <= M_OPT_EXIT) { |
d631b3c09c53
Fix multiple help clauses on the command line with mencoder.
albeu
parents:
16345
diff
changeset
|
101 opt_exit = 1; |
d631b3c09c53
Fix multiple help clauses on the command line with mencoder.
albeu
parents:
16345
diff
changeset
|
102 tmp = M_OPT_EXIT - tmp; |
d631b3c09c53
Fix multiple help clauses on the command line with mencoder.
albeu
parents:
16345
diff
changeset
|
103 } |
18148
280f93388ac3
also print an error when parsing fails with M_OPT_INVALID or M_OPT_PARSER_ERR.
reimar
parents:
17467
diff
changeset
|
104 else |
8893 | 105 if(tmp < 0){ |
106 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp); | |
18209 | 107 mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "Error parsing option on the command line: -%s\n",opt); |
8893 | 108 goto err_out; |
109 } | |
110 } else { | |
8164 | 111 tmp = m_config_check_option(config, opt, argv[i + 1]); |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
112 if (tmp <= M_OPT_EXIT) { |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
113 opt_exit = 1; |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
114 tmp = M_OPT_EXIT - tmp; |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
115 } |
8164 | 116 if(tmp >= 0) { |
117 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*)); | |
118 entry->opts[2*no] = strdup(opt); | |
119 entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL; | |
120 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL; | |
121 no++; | |
8893 | 122 } else { |
123 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp); | |
124 goto err_out; | |
8164 | 125 } |
126 } | |
127 i += tmp; | |
9747
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
128 } else {/* filename */ |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
129 mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
130 lst = realloc(lst,(nf+2)*sizeof(m_entry_t)); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
131 lst[nf].name = strdup(argv[i]); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
132 lst[nf].opts = calloc(2,sizeof(char*)); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
133 entry = &lst[nf]; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
134 no = 0; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
135 memset(&lst[nf+1],0,sizeof(m_entry_t)); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
136 nf++; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
137 } |
8164 | 138 } |
139 | |
16345
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
140 if (opt_exit) |
feb16d0117c8
allow multiple help clauses on the command line, Patch by kiriuja " mplayer-patches AH en-directo POUM net "
gpoirier
parents:
15742
diff
changeset
|
141 exit(0); |
8164 | 142 if(nf == 0) { |
143 m_entry_list_free(lst); | |
144 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n"); | |
145 return NULL; | |
146 } | |
147 return lst; | |
148 | |
149 err_out: | |
150 m_entry_list_free(lst); | |
151 return NULL; | |
152 } |