+ return i_start <= i_num && i_num <= i_stop ? true : false;
+}
+
+static bool ESSelected( es_format_t *fmt, char *psz_select )
+{
+ char *psz_dup;
+ char *psz;
+
+ /* We have tri-state variable : no tested (-1), failed(0), succeed(1) */
+ int i_cat = -1;
+ int i_es = -1;
+ int i_prgm= -1;
+
+ /* If empty all es are selected */
+ if( psz_select == NULL || *psz_select == '\0' )
+ {
+ return true;
+ }
+ psz_dup = strdup( psz_select );
+ psz = psz_dup;
+
+ /* If non empty, parse the selection:
+ * We have selection[,selection[,..]] where following selection are recognized:
+ * (no(-))audio
+ * (no(-))spu
+ * (no(-))video
+ * (no(-))es=[start]-[end] or es=num
+ * (no(-))prgm=[start]-[end] or prgm=num (program works too)
+ * if a negative test failed we exit directly
+ */
+ while( psz && *psz )
+ {
+ char *p;
+
+ /* Skip space */
+ while( *psz == ' ' || *psz == '\t' ) psz++;
+
+ /* Search end */
+ p = strchr( psz, ',' );
+ if( p == psz )
+ {
+ /* Empty */
+ psz = p + 1;
+ continue;
+ }
+ if( p )
+ {
+ *p++ = '\0';
+ }
+
+ if( !strncmp( psz, "no-audio", strlen( "no-audio" ) ) ||
+ !strncmp( psz, "noaudio", strlen( "noaudio" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat != AUDIO_ES ? 1 : 0;
+ }
+ }
+ else if( !strncmp( psz, "no-video", strlen( "no-video" ) ) ||
+ !strncmp( psz, "novideo", strlen( "novideo" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat != VIDEO_ES ? 1 : 0;
+ }
+ }
+ else if( !strncmp( psz, "no-spu", strlen( "no-spu" ) ) ||
+ !strncmp( psz, "nospu", strlen( "nospu" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat != SPU_ES ? 1 : 0;
+ }
+ }
+ else if( !strncmp( psz, "audio", strlen( "audio" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat == AUDIO_ES ? 1 : 0;
+ }
+ }
+ else if( !strncmp( psz, "video", strlen( "video" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat == VIDEO_ES ? 1 : 0;
+ }
+ }
+ else if( !strncmp( psz, "spu", strlen( "spu" ) ) )
+ {
+ if( i_cat == -1 )
+ {
+ i_cat = fmt->i_cat == SPU_ES ? 1 : 0;
+ }
+ }
+ else if( strchr( psz, '=' ) != NULL )
+ {
+ char *psz_arg = strchr( psz, '=' );
+ *psz_arg++ = '\0';
+
+ if( !strcmp( psz, "no-es" ) || !strcmp( psz, "noes" ) )
+ {
+ if( i_es == -1 )
+ {
+ i_es = NumInRange( psz_arg, fmt->i_id ) ? 0 : -1;
+ }
+ }
+ else if( !strcmp( psz, "es" ) )
+ {
+ if( i_es == -1 )
+ {
+ i_es = NumInRange( psz_arg, fmt->i_id) ? 1 : -1;
+ }
+ }
+ else if( !strcmp( psz, "no-prgm" ) || !strcmp( psz, "noprgm" ) ||
+ !strcmp( psz, "no-program" ) || !strcmp( psz, "noprogram" ) )
+ {
+ if( fmt->i_group >= 0 && i_prgm == -1 )
+ {
+ i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 0 : -1;
+ }
+ }
+ else if( !strcmp( psz, "prgm" ) || !strcmp( psz, "program" ) )
+ {
+ if( fmt->i_group >= 0 && i_prgm == -1 )
+ {
+ i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 1 : -1;
+ }
+ }
+ }
+ else
+ {
+ fprintf( stderr, "unknown args (%s)\n", psz );
+ }
+ /* Next */
+ psz = p;
+ }
+
+ free( psz_dup );
+
+ if( i_cat == 1 || i_es == 1 || i_prgm == 1 )
+ {
+ return true;
+ }
+ return false;