[MPlayer-dev-eng] Test for extended dvd arguments

Carl Fûrstenberg azatoth at gmail.com
Sat Oct 16 01:48:42 CEST 2004


ok, c is not my maiden language, but here is my try,  I'm using pcre
because I do not want a to big mess with optional arguments, If you do
not like it, you can always rewrite it.

Because I'm not a c-guru, there is perhaps some memoryleaks I havn't
found (havn't thought of ie.).

But don't kill me :)


Index: libmpdemux/open.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/open.c,v
retrieving revision 1.99
diff -u -r1.99 open.c
--- libmpdemux/open.c	22 Aug 2004 18:47:48 -0000	1.99
+++ libmpdemux/open.c	15 Oct 2004 23:31:54 -0000
@@ -189,7 +189,53 @@
     ifo_handle_t *vmg_file;
     tt_srpt_t *tt_srpt;
     ifo_handle_t *vts_file;
-    dvd_title = filename[6] == '\0' ? 1 : strtol(filename + 6,NULL,0);
+
+#ifdef USE_EXTENDED_DVD_ARGUMENTS
+	/**
+	 * using:
+	 * dvd://title:chapter:angle@dvd-device
+	 * angle is optional
+	 * chapter is optional
+	 * dvd-device is also optional
+	 * ok, title is optional as well :)
+	 * example:
+	 * dvd://
+	 * dvd://1:1@/dev/dvd
+	 * dvd://2
+	 * dvd://2@/home/foo/bar.img
+	 * dvd:///dev/dvd
+	 * dvd://3mov.img
+	 * dvd://1:2:3@dev
+	 * dvd://1::2
+	 *
+	 * I think std is dvd://1:1:1@/dev/dvd
+	 *
+	 */
+#include <pcre.h>
+	const char *error;
+	pcre *pe;
+	int erroffset;
+	int rc;
+	int ovector[30];
+	pe = pcre_compile("dvd://(\\d+)?:?(\\d+)?:?(\\d*(?![\\w\\.]+))?@?(.*)",
+			PCRE_EXTENDED,&error,&erroffset,NULL);
+	rc = pcre_exec(pe,NULL,filename,strlen(filename),0,0,ovector,30);
+	const char **stringlist;
+	pcre_get_substring_list((char *)string, ovector, rc,&stringlist);
+
+	dvd_title = strlen(stringlist[1]) == 0 ? 1 : strtol(stringlist[1],NULL,0);
+	dvd_chapter = strlen(stringlist[2]) == 0 ? 1 : strtol(stringlist[2],NULL,0);
+	dvd_angle = strlen(stringlist[3]) == 0 ? 1 : strtol(stringlist[3],NULL,0);
+	dvd_device = strlen(stringlist[4]) == 0 ? strdup(DEFAULT_DVD_DEVICE)
: strdup(stringlist[4]);
+
+	pcre_free_substring_list(stringlist);
+	
+	// ok, done...
+
+#else	/* USE_EXTENDED_DVD_ARGUMENTS */	
+	dvd_title = filename[6] == '\0' ? 1 : strtol( filename + 6 , NULL , 0 );
+#endif
+
     /**
      * Open the disc.
      */




More information about the MPlayer-dev-eng mailing list