Mercurial > mplayer.hg
annotate parser-mecmd.c @ 10198:5c773d4f3a60
Accept Helix as a valid Real server
author | rtognimp |
---|---|
date | Tue, 27 May 2003 19:58:28 +0000 |
parents | 4c34dc17e43d |
children | 57bdcdb061d7 |
rev | line source |
---|---|
8164 | 1 |
2 #include "config.h" | |
3 | |
4 #ifdef NEW_CONFIG | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <errno.h> | |
10 | |
11 #ifdef MP_DEBUG | |
12 #include <assert.h> | |
13 #endif | |
14 | |
15 #include "mp_msg.h" | |
16 #include "m_option.h" | |
17 #include "m_config.h" | |
18 #include "parser-mecmd.h" | |
19 | |
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; | |
58 m_entry_t *lst = NULL, *entry = NULL; | |
59 | |
60 #ifdef MP_DEBUG | |
61 assert(config != NULL); | |
62 assert(argv != NULL); | |
63 assert(argc >= 1); | |
64 #endif | |
65 | |
66 config->mode = M_COMMAND_LINE; | |
67 | |
68 lst = calloc(1,sizeof(m_entry_t)); | |
69 | |
70 for (i = 1; i < argc; i++) { | |
71 //next: | |
72 opt = argv[i]; | |
73 /* check for -- (no more options id.) except --help! */ | |
74 if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h')) | |
75 { | |
76 no_more_opts = 1; | |
77 if (i+1 >= argc) | |
78 { | |
79 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n"); | |
80 goto err_out; | |
81 } | |
82 continue; | |
83 } | |
84 | |
85 if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ | |
86 { | |
87 m_option_t* mp_opt = NULL; | |
88 /* remove trailing '-' */ | |
89 opt++; | |
90 mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); | |
91 mp_opt = m_config_get_option(config,opt); | |
92 if(!mp_opt) { | |
93 tmp = M_OPT_UNKNOW; | |
9096 | 94 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "%s is not an MEncoder option\n",opt); |
8164 | 95 goto err_out; |
96 } | |
8893 | 97 if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){ |
8164 | 98 tmp = m_config_set_option(config, opt, argv[i + 1]); |
8893 | 99 if(tmp < 0){ |
100 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp); | |
101 goto err_out; | |
102 } | |
103 } else { | |
8164 | 104 tmp = m_config_check_option(config, opt, argv[i + 1]); |
105 if(tmp >= 0) { | |
106 entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*)); | |
107 entry->opts[2*no] = strdup(opt); | |
108 entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL; | |
109 entry->opts[2*no+2] = entry->opts[2*no+3] = NULL; | |
110 no++; | |
8893 | 111 } else { |
112 // mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp); | |
9792 | 113 if(tmp == M_OPT_EXIT) |
114 exit(0); | |
8893 | 115 goto err_out; |
8164 | 116 } |
117 } | |
118 i += tmp; | |
9747
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
119 } else {/* filename */ |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
120 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
|
121 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
|
122 lst[nf].name = strdup(argv[i]); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
123 lst[nf].opts = calloc(2,sizeof(char*)); |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
124 entry = &lst[nf]; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
125 no = 0; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
126 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
|
127 nf++; |
264cb5f03131
Remove the hack used to pass -dvd, etc into the playlist
albeu
parents:
9096
diff
changeset
|
128 } |
8164 | 129 } |
130 | |
131 if(nf == 0) { | |
132 m_entry_list_free(lst); | |
133 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n"); | |
134 return NULL; | |
135 } | |
136 return lst; | |
137 | |
138 err_out: | |
139 m_entry_list_free(lst); | |
140 return NULL; | |
141 } | |
142 | |
143 #endif |