comparison m_option.c @ 19973:02a18c52a42a

after a long time, finally i could add -endpos option to mplayer executable. as oded told me on 1006 02 24, i applied it, blame me if some problem occurs, i hope not, since i tried it for a while....
author ptt
date Mon, 25 Sep 2006 16:47:56 +0000
parents 41bcb2309c9c
children 9f256c4066ff
comparison
equal deleted inserted replaced
19972:6e103c537e6d 19973:02a18c52a42a
1173 NULL, 1173 NULL,
1174 NULL 1174 NULL
1175 }; 1175 };
1176 1176
1177 1177
1178 // Time or size (-endpos)
1179
1180 static int parse_time_size(m_option_t* opt,char *name, char *param, void* dst, int src) {
1181
1182 if (dst == NULL)
1183 return 0;
1184
1185 m_time_size_t* ts = dst;
1186 ts->pos=0;
1187
1188 char unit[4];
1189 int a,b;
1190 float d;
1191 double end_at;
1192
1193 if (param == NULL || strlen(param) == 0)
1194 return M_OPT_MISSING_PARAM;
1195
1196 /* End at size parsing */
1197 if(sscanf(param, "%lf%3s", &end_at, unit) == 2) {
1198 ts->type = END_AT_SIZE;
1199 if(!strcasecmp(unit, "b"))
1200 ;
1201 else if(!strcasecmp(unit, "kb"))
1202 end_at *= 1024;
1203 else if(!strcasecmp(unit, "mb"))
1204 end_at *= 1024*1024;
1205 else if(!strcasecmp(unit, "gb"))
1206 end_at *= 1024*1024*1024;
1207 else
1208 ts->type = END_AT_NONE;
1209
1210 if (ts->type == END_AT_SIZE) {
1211 ts->pos = end_at;
1212 return 1;
1213 }
1214 }
1215
1216 /* End at time parsing. This has to be last because of
1217 * sscanf("%f", ...) below */
1218 if (sscanf(param, "%d:%d:%f", &a, &b, &d) == 3)
1219 end_at = 3600*a + 60*b + d;
1220 else if (sscanf(param, "%d:%f", &a, &d) == 2)
1221 end_at = 60*a + d;
1222 else if (sscanf(param, "%f", &d) == 1)
1223 end_at = d;
1224 else {
1225 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time or size: '%s'\n",
1226 name,param);
1227 return M_OPT_INVALID;
1228 }
1229
1230 ts->type = END_AT_TIME;
1231 ts->pos = end_at;
1232
1233 return 1;
1234 }
1235
1236 m_option_type_t m_option_type_time_size = {
1237 "Time or size",
1238 "",
1239 sizeof(m_time_size_t),
1240 0,
1241 parse_time_size,
1242 NULL,
1243 copy_opt,
1244 copy_opt,
1245 NULL,
1246 NULL
1247 };
1248
1249
1178 //// Objects (i.e. filters, etc) settings 1250 //// Objects (i.e. filters, etc) settings
1179 1251
1180 #include "m_struct.h" 1252 #include "m_struct.h"
1181 1253
1182 #undef VAL 1254 #undef VAL