annotate parser-mecmd.c @ 32404:2f42741403a8

ignore debhelper generated debug logfiles
author siretart
date Thu, 14 Oct 2010 08:43:19 +0000
parents c1a3f1bbba26
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
3 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
17 */
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 18209
diff changeset
18
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 18209
diff changeset
19 /// \file
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 18209
diff changeset
20 /// \ingroup ConfigParsers MEntry
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 18209
diff changeset
21
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
22 #include "config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
23
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
24 #include <stdio.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
25 #include <stdlib.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
26 #include <string.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
27 #include <errno.h>
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 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
30 #include <assert.h>
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
31 #endif
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 #include "mp_msg.h"
21312
d78e7d5bc6d5 localization of parser-m*cmd.c messages
ptt
parents: 18265
diff changeset
34 #include "help_mp.h"
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
35 #include "m_option.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
36 #include "m_config.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
37 #include "parser-mecmd.h"
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
38
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
39 void
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
40 m_entry_list_free(m_entry_t* lst) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
41 int i,j;
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 for(i = 0 ; lst[i].name != NULL ; i++){
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
44 free(lst[i].name);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
45 for(j = 0 ; lst[i].opts[2*j] != NULL ; j++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
46 free(lst[i].opts[2*j]);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
47 free(lst[i].opts[2*j+1]);
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 free(lst[i].opts);
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 free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
52 }
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
55 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
56 int i,r;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
57
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
58 for(i = 0 ; entry->opts[2*i] != NULL ; i++){
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
59 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
60 if(r < 0)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
61 return 0;
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 return 1;
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
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
66
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25227
diff changeset
67
8164
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 m_entry_t*
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
70 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
71 {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
72 int i,nf = 0,no = 0;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
73 int tmp;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
74 char *opt;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
75 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
76 int opt_exit = 0;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
77 m_entry_t *lst = NULL, *entry = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25227
diff changeset
78
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
79 #ifdef MP_DEBUG
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
80 assert(config != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
81 assert(argv != NULL);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
82 assert(argc >= 1);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
83 #endif
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
84
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
85 config->mode = M_COMMAND_LINE;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
86
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
87 lst = calloc(1,sizeof(m_entry_t));
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 for (i = 1; i < argc; i++) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
90 //next:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
91 opt = argv[i];
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
92 /* 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
93 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
8164
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 no_more_opts = 1;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
96 if (i+1 >= argc)
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
97 {
21312
d78e7d5bc6d5 localization of parser-m*cmd.c messages
ptt
parents: 18265
diff changeset
98 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGivenOnCommandLine);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
99 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
100 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
101 continue;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
102 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25227
diff changeset
103
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
104 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
105 {
25227
75837c33484b Mark more m_option_t uses as const
reimar
parents: 21312
diff changeset
106 const m_option_t* mp_opt = NULL;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
107 /* remove trailing '-' */
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
108 opt++;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
109 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
110 mp_opt = m_config_get_option(config,opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
111 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
112 tmp = M_OPT_UNKNOWN;
21312
d78e7d5bc6d5 localization of parser-m*cmd.c messages
ptt
parents: 18265
diff changeset
113 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NotAnMEncoderOption, opt);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
114 goto err_out;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
115 }
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
116 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
117 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
118 if (tmp <= M_OPT_EXIT) {
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
119 opt_exit = 1;
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
120 tmp = M_OPT_EXIT - tmp;
d631b3c09c53 Fix multiple help clauses on the command line with mencoder.
albeu
parents: 16345
diff changeset
121 }
18148
280f93388ac3 also print an error when parsing fails with M_OPT_INVALID or M_OPT_PARSER_ERR.
reimar
parents: 17467
diff changeset
122 else
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
123 if(tmp < 0){
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
124 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
21312
d78e7d5bc6d5 localization of parser-m*cmd.c messages
ptt
parents: 18265
diff changeset
125 mp_msg(MSGT_CFGPARSER, MSGL_FATAL, MSGTR_ErrorParsingOptionOnCommandLine, opt);
8893
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]);
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
130 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
131 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
132 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
133 }
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
134 if(tmp >= 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
135 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
136 entry->opts[2*no] = strdup(opt);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
137 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
138 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
139 no++;
8893
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
140 } else {
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
141 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
268b3fbc35b7 cosmetics
arpi
parents: 8164
diff changeset
142 goto err_out;
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
143 }
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 i += tmp;
9747
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
146 } else {/* filename */
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
147 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
148 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
149 lst[nf].name = strdup(argv[i]);
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
150 lst[nf].opts = calloc(2,sizeof(char*));
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
151 entry = &lst[nf];
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
152 no = 0;
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
153 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
154 nf++;
264cb5f03131 Remove the hack used to pass -dvd, etc into the playlist
albeu
parents: 9096
diff changeset
155 }
8164
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
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
158 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
159 exit(0);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
160 if(nf == 0) {
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
161 m_entry_list_free(lst);
21312
d78e7d5bc6d5 localization of parser-m*cmd.c messages
ptt
parents: 18265
diff changeset
162 mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGiven);
8164
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
163 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
164 }
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
165 return lst;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
166
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
167 err_out:
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
168 m_entry_list_free(lst);
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
169 return NULL;
487cfc28525d New config system + cleanup of header inter dependency
albeu
parents:
diff changeset
170 }