Mercurial > mplayer.hg
comparison m_option.c @ 9913:88fe89b46786
Add suffix support to the object list type.
So now -vf-clr destroy the list -vf-add filer1=blah,filter append
these 2 filters, -vf-pre ... will 'prepend' them.
Finnaly -vf-del 2,3,-1 will delete the filters at at given indexs
It start from 0, negative number start from the end of the list
(so -1 is the last one).
author | albeu |
---|---|
date | Sat, 12 Apr 2003 13:45:43 +0000 |
parents | c616ebcda25a |
children | 4640f25fef12 |
comparison
equal
deleted
inserted
replaced
9912:39444d65c4cb | 9913:88fe89b46786 |
---|---|
265 if (tmp_off < opt->min) { | 265 if (tmp_off < opt->min) { |
266 mp_msg(MSGT_CFGPARSER, MSGL_ERR, | 266 mp_msg(MSGT_CFGPARSER, MSGL_ERR, |
267 (sizeof(off_t) == sizeof(int) ? | 267 (sizeof(off_t) == sizeof(int) ? |
268 "The %s option must be >= %d: %s\n" : | 268 "The %s option must be >= %d: %s\n" : |
269 "The %s option must be >= %lld: %s\n"), | 269 "The %s option must be >= %lld: %s\n"), |
270 (off_t) opt->min, param); | 270 name, (off_t) opt->min, param); |
271 return M_OPT_OUT_OF_RANGE; | 271 return M_OPT_OUT_OF_RANGE; |
272 } | 272 } |
273 | 273 |
274 if (opt->flags & M_OPT_MAX) | 274 if (opt->flags & M_OPT_MAX) |
275 if (tmp_off > opt->max) { | 275 if (tmp_off > opt->max) { |
276 mp_msg(MSGT_CFGPARSER, MSGL_ERR, | 276 mp_msg(MSGT_CFGPARSER, MSGL_ERR, |
277 (sizeof(off_t) == sizeof(int) ? | 277 (sizeof(off_t) == sizeof(int) ? |
278 "The %s option must be <= %d: %s\n" : | 278 "The %s option must be <= %d: %s\n" : |
279 "The %s option must be <= %lld: %s\n"), | 279 "The %s option must be <= %lld: %s\n"), |
280 (off_t) opt->max, param); | 280 name, (off_t) opt->max, param); |
281 return M_OPT_OUT_OF_RANGE; | 281 return M_OPT_OUT_OF_RANGE; |
282 } | 282 } |
283 | 283 |
284 if(dst) | 284 if(dst) |
285 VAL(dst) = tmp_off; | 285 VAL(dst) = tmp_off; |
444 free(del[i]); | 444 free(del[i]); |
445 continue; | 445 continue; |
446 } | 446 } |
447 free(del[i]); | 447 free(del[i]); |
448 if(idx < 0 || idx >= ln) { | 448 if(idx < 0 || idx >= ln) { |
449 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Index %d is out of range\n",idx); | 449 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Index %ld is out of range\n",idx); |
450 continue; | 450 continue; |
451 } else if(!lst[idx]) | 451 } else if(!lst[idx]) |
452 continue; | 452 continue; |
453 free(lst[idx]); | 453 free(lst[idx]); |
454 lst[idx] = NULL; | 454 lst[idx] = NULL; |
1258 | 1258 |
1259 *_ret = ret; | 1259 *_ret = ret; |
1260 return 1; | 1260 return 1; |
1261 } | 1261 } |
1262 | 1262 |
1263 static void free_obj_settings_list(void* dst); | |
1264 | |
1265 static int obj_settings_list_del(char *opt_name,char *param,void* dst, int src) { | |
1266 char** str_list = NULL; | |
1267 int r,i,idx_max = 0; | |
1268 char* rem_id = "_removed_marker_"; | |
1269 m_option_t list_opt = {opt_name , NULL, CONF_TYPE_STRING_LIST, | |
1270 0, 0, 0, NULL }; | |
1271 m_obj_settings_t* obj_list = dst ? VAL(dst) : NULL; | |
1272 | |
1273 if(dst && !obj_list) { | |
1274 mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %s: the list is empty.\n",opt_name); | |
1275 return 1; | |
1276 } else if(obj_list) { | |
1277 for(idx_max = 0 ; obj_list[idx_max].name != NULL ; idx_max++) | |
1278 /* NOP */; | |
1279 } | |
1280 | |
1281 r = m_option_parse(&list_opt,opt_name,param,&str_list,src); | |
1282 if(r < 0 || !str_list) | |
1283 return r; | |
1284 | |
1285 for(r = 0 ; str_list[r] ; r++) { | |
1286 int id; | |
1287 char* endptr; | |
1288 id = strtol(str_list[r],&endptr,0); | |
1289 if(endptr == str_list[r]) { | |
1290 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid parameter. We a list of integer wich are the index of the elements to remove\n",opt_name); | |
1291 m_option_free(&list_opt,&str_list); | |
1292 return M_OPT_INVALID; | |
1293 } | |
1294 if(!obj_list) continue; | |
1295 if(id >= idx_max || id < -idx_max) { | |
1296 mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %s: index %d is out of range\n",opt_name,id); | |
1297 continue; | |
1298 } | |
1299 if(id < 0) | |
1300 id = idx_max + id; | |
1301 free(obj_list[id].name); | |
1302 free_str_list(&(obj_list[id].attribs)); | |
1303 obj_list[id].name = rem_id; | |
1304 } | |
1305 | |
1306 if(!dst) { | |
1307 m_option_free(&list_opt,&str_list); | |
1308 return 1; | |
1309 } | |
1310 | |
1311 for(i = 0 ; obj_list[i].name ; i++) { | |
1312 while(obj_list[i].name == rem_id) { | |
1313 memmove(&obj_list[i],&obj_list[i+1],sizeof(m_obj_settings_t)*(idx_max - i)); | |
1314 idx_max--; | |
1315 } | |
1316 } | |
1317 obj_list = realloc(obj_list,sizeof(m_obj_settings_t)*(idx_max+1)); | |
1318 VAL(dst) = obj_list; | |
1319 | |
1320 return 1; | |
1321 } | |
1263 | 1322 |
1264 static int parse_obj_settings_list(m_option_t* opt,char *name, | 1323 static int parse_obj_settings_list(m_option_t* opt,char *name, |
1265 char *param, void* dst, int src) { | 1324 char *param, void* dst, int src) { |
1266 int n = 0,r; | 1325 int n = 0,r,len = strlen(opt->name); |
1267 char *str; | 1326 char *str; |
1268 char *ptr, *last_ptr; | 1327 char *ptr, *last_ptr; |
1269 m_obj_settings_t *res = NULL; | 1328 m_obj_settings_t *res = NULL,*queue = NULL,*head = NULL; |
1329 int op = OP_NONE; | |
1270 | 1330 |
1271 // We need the objects list | 1331 // We need the objects list |
1272 if(!opt->priv) | 1332 if(!opt->priv) |
1273 return M_OPT_INVALID; | 1333 return M_OPT_INVALID; |
1274 | 1334 |
1335 if(opt->name[len-1] == '*' && ((int)strlen(name) > len - 1)) { | |
1336 char* n = &name[len-1]; | |
1337 if(strcasecmp(n,"-add") == 0) | |
1338 op = OP_ADD; | |
1339 else if(strcasecmp(n,"-pre") == 0) | |
1340 op = OP_PRE; | |
1341 else if(strcasecmp(n,"-del") == 0) | |
1342 op = OP_DEL; | |
1343 else if(strcasecmp(n,"-clr") == 0) | |
1344 op = OP_CLR; | |
1345 else { | |
1346 char prefix[len]; | |
1347 strncpy(prefix,opt->name,len-1); | |
1348 prefix[len-1] = '\0'; | |
1349 mp_msg(MSGT_VFILTER,MSGL_ERR, "Option %s: unknow posfix %s\n" | |
1350 "Supported posfix are:\n" | |
1351 " %3$s-add\n" | |
1352 " Append the given list to the current list\n\n" | |
1353 " %3$s-pre\n" | |
1354 " Prepend the given list to the current list\n\n" | |
1355 " %3$s-del x,y,...\n" | |
1356 " Remove the given elements. Take the list element index (starting from 0).\n" | |
1357 " Neagtive index can be used (ie -1 is the last element)\n\n" | |
1358 " %3$s-clr\n" | |
1359 " Clear the cureent list.\n",name,n,prefix); | |
1360 | |
1361 return M_OPT_UNKNOW; | |
1362 } | |
1363 } | |
1364 | |
1365 // Clear the list ?? | |
1366 if(op == OP_CLR) { | |
1367 if(dst) | |
1368 free_obj_settings_list(dst); | |
1369 return 0; | |
1370 } | |
1371 | |
1275 if (param == NULL || strlen(param) == 0) | 1372 if (param == NULL || strlen(param) == 0) |
1276 return M_OPT_MISSING_PARAM; | 1373 return M_OPT_MISSING_PARAM; |
1374 | |
1375 switch(op) { | |
1376 case OP_ADD: | |
1377 if(dst) head = VAL(dst); | |
1378 break; | |
1379 case OP_PRE: | |
1380 if(dst) queue = VAL(dst); | |
1381 break; | |
1382 case OP_DEL: | |
1383 return obj_settings_list_del(name,param,dst,src); | |
1384 case OP_NONE: | |
1385 if(dst && VAL(dst)) | |
1386 free_obj_settings_list(dst); | |
1387 break; | |
1388 default: | |
1389 mp_msg(MSGT_VFILTER,MSGL_ERR, "Option %s: FIXME\n",name); | |
1390 return M_OPT_UNKNOW; | |
1391 } | |
1277 | 1392 |
1278 if(!strcmp(param,"help")) { | 1393 if(!strcmp(param,"help")) { |
1279 m_obj_list_t* ol = opt->priv; | 1394 m_obj_list_t* ol = opt->priv; |
1280 for(n = 0 ; ol->list[n] ; n++) | 1395 for(n = 0 ; ol->list[n] ; n++) |
1281 mp_msg(MSGT_VFILTER,MSGL_INFO," %-15s: %s\n", | 1396 mp_msg(MSGT_VFILTER,MSGL_INFO," %-15s: %s\n", |
1312 | 1427 |
1313 if( ((opt->flags & M_OPT_MIN) && (n < opt->min)) || | 1428 if( ((opt->flags & M_OPT_MIN) && (n < opt->min)) || |
1314 ((opt->flags & M_OPT_MAX) && (n > opt->max)) ) | 1429 ((opt->flags & M_OPT_MAX) && (n > opt->max)) ) |
1315 return M_OPT_OUT_OF_RANGE; | 1430 return M_OPT_OUT_OF_RANGE; |
1316 | 1431 |
1317 if(dst) | 1432 if(dst) { |
1433 if(queue) { | |
1434 int qsize; | |
1435 for(qsize = 0 ; queue[qsize].name ; qsize++) | |
1436 /* NOP */; | |
1437 res = realloc(res,(qsize+n+1)*sizeof(m_obj_settings_t)); | |
1438 memcpy(&res[n],queue,(qsize+1)*sizeof(m_obj_settings_t)); | |
1439 n += qsize; | |
1440 free(queue); | |
1441 } | |
1442 if(head) { | |
1443 int hsize; | |
1444 for(hsize = 0 ; head[hsize].name ; hsize++) | |
1445 /* NOP */; | |
1446 head = realloc(head,(hsize+n+1)*sizeof(m_obj_settings_t)); | |
1447 memcpy(&head[hsize],res,(n+1)*sizeof(m_obj_settings_t)); | |
1448 free(res); | |
1449 res = head; | |
1450 } | |
1318 VAL(dst) = res; | 1451 VAL(dst) = res; |
1319 | 1452 } |
1320 return 1; | 1453 return 1; |
1321 } | 1454 } |
1322 | 1455 |
1323 static void free_obj_settings_list(void* dst) { | 1456 static void free_obj_settings_list(void* dst) { |
1324 int n; | 1457 int n; |
1366 | 1499 |
1367 m_option_type_t m_option_type_obj_settings_list = { | 1500 m_option_type_t m_option_type_obj_settings_list = { |
1368 "Object settings list", | 1501 "Object settings list", |
1369 "", | 1502 "", |
1370 sizeof(m_obj_settings_t*), | 1503 sizeof(m_obj_settings_t*), |
1371 M_OPT_TYPE_DYNAMIC, | 1504 M_OPT_TYPE_DYNAMIC|M_OPT_TYPE_ALLOW_WILDCARD, |
1372 parse_obj_settings_list, | 1505 parse_obj_settings_list, |
1373 NULL, | 1506 NULL, |
1374 copy_obj_settings_list, | 1507 copy_obj_settings_list, |
1375 copy_obj_settings_list, | 1508 copy_obj_settings_list, |
1376 copy_obj_settings_list, | 1509 copy_obj_settings_list, |
1611 // A path/filename is given | 1744 // A path/filename is given |
1612 // check if it's not a trailing '/' | 1745 // check if it's not a trailing '/' |
1613 if( strlen(ptr2)>1 ) { | 1746 if( strlen(ptr2)>1 ) { |
1614 // copy the path/filename in the URL container | 1747 // copy the path/filename in the URL container |
1615 if(!m_option_list_find(desc->fields,"filename")) { | 1748 if(!m_option_list_find(desc->fields,"filename")) { |
1616 mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %s: this url doesn't have a hostname part part\n"); | 1749 mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %s: this url doesn't have a hostname part part\n",name); |
1617 // skip | 1750 // skip |
1618 } else { | 1751 } else { |
1619 if(dst) { | 1752 if(dst) { |
1620 r = m_struct_set(desc,dst,"filename",ptr2+1); | 1753 r = m_struct_set(desc,dst,"filename",ptr2+1); |
1621 if(r < 0) { | 1754 if(r < 0) { |
1622 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: error while setting filename\n"); | 1755 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: error while setting filename\n",name); |
1623 return r; | 1756 return r; |
1624 } | 1757 } |
1625 } | 1758 } |
1626 } | 1759 } |
1627 } | 1760 } |