annotate parser-mecmd.c @ 17902:578074a74d4e

sync to x264 r476 (subq=7)
author lorenm
date Mon, 20 Mar 2006 23:13:37 +0000
parents d631b3c09c53
children 280f93388ac3
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 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
2
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
3 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
4 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
5 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
6 #include <errno.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
7
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
8 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
9 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
10 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
11
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
12 #include "mp_msg.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
13 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
14 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
15 #include "parser-mecmd.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
16
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
17 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
18 m_entry_list_free(m_entry_t* lst) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
19 int i,j;
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 for(i = 0 ; lst[i].name != NULL ; i++){
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
22 free(lst[i].name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23 for(j = 0 ; lst[i].opts[2*j] != NULL ; j++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 free(lst[i].opts[2*j]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 free(lst[i].opts[2*j+1]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
27 free(lst[i].opts);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
28 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
29 free(lst);
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
32 int
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
33 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
34 int i,r;
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 for(i = 0 ; entry->opts[2*i] != NULL ; i++){
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
37 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
38 if(r < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 return 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
41 return 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
42 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
43
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
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 m_entry_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
48 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
49 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
50 int i,nf = 0,no = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
51 int tmp;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 char *opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
53 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
54 int opt_exit = 0;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55 m_entry_t *lst = NULL, *entry = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
56
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
57 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 assert(argv != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
60 assert(argc >= 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
62
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
63 config->mode = M_COMMAND_LINE;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
64
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
65 lst = calloc(1,sizeof(m_entry_t));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
67 for (i = 1; i < argc; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
68 //next:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
69 opt = argv[i];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
70 /* 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
71 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
73 no_more_opts = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 if (i+1 >= argc)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75 {
14541
bef9d6dc2333 Clarify confusing error message.
diego
parents: 10595
diff changeset
76 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n");
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
77 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
78 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
79 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
82 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
83 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84 m_option_t* mp_opt = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
85 /* remove trailing '-' */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
86 opt++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87 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
88 mp_opt = m_config_get_option(config,opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
89 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
90 tmp = M_OPT_UNKNOWN;
15742
55cbf0c204bc when somebody specifies e.g. --loop, the message says that a -loop option
reimar
parents: 15245
diff changeset
91 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
92 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
93 }
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
94 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
95 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
96 if (tmp <= M_OPT_EXIT) {
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
97 opt_exit = 1;
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
98 tmp = M_OPT_EXIT - tmp;
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
99 }
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
100 if(tmp < 0){
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
101 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
102 goto err_out;
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
103 }
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
104 } else {
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
105 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
106 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
107 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
108 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
109 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
110 if(tmp >= 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
112 entry->opts[2*no] = strdup(opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
113 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
114 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 no++;
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
116 } else {
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
117 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
118 goto err_out;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
119 }
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 i += tmp;
9747
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
122 } else {/* filename */
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
123 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
124 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
125 lst[nf].name = strdup(argv[i]);
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
126 lst[nf].opts = calloc(2,sizeof(char*));
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
127 entry = &lst[nf];
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
128 no = 0;
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
129 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
130 nf++;
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
131 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
132 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
133
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
134 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
135 exit(0);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
136 if(nf == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
137 m_entry_list_free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
138 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n");
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139 return NULL;
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 return lst;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
142
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 err_out:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
144 m_entry_list_free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
145 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
146 }