Commit 1354b657 authored by conrad's avatar conrad

remove MAX_FILTER limits -- switch from fixed-length arrays to OggzTables


git-svn-id: http://svn.annodex.net/liboggz/trunk@1075 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 742edaf1
...@@ -64,12 +64,9 @@ typedef struct { ...@@ -64,12 +64,9 @@ typedef struct {
int numwrite; int numwrite;
OggzTable *streams; OggzTable *streams;
int verbose; int verbose;
int num_serialnos; OggzTable *serialno_table;
long serialnos[MAX_FILTER]; OggzTable *stream_index_table;
int num_streamids; OggzTable *content_types_table;
long streamids[MAX_FILTER];
int num_content_types;
const char *content_types[MAX_FILTER];
} ORData; } ORData;
typedef struct { typedef struct {
...@@ -117,6 +114,15 @@ ordata_new () ...@@ -117,6 +114,15 @@ ordata_new ()
ordata->streams = oggz_table_new (); ordata->streams = oggz_table_new ();
assert (ordata->streams != NULL); assert (ordata->streams != NULL);
ordata->serialno_table = oggz_table_new();
assert (ordata->serialno_table != NULL);
ordata->stream_index_table = oggz_table_new();
assert (ordata->stream_index_table != NULL);
ordata->content_types_table = oggz_table_new();
assert (ordata->content_types_table != NULL);
return ordata; return ordata;
} }
...@@ -125,6 +131,9 @@ static void ...@@ -125,6 +131,9 @@ static void
ordata_delete (ORData *ordata) ordata_delete (ORData *ordata)
{ {
oggz_table_delete (ordata->streams); oggz_table_delete (ordata->streams);
oggz_table_delete (ordata->serialno_table);
oggz_table_delete (ordata->stream_index_table);
oggz_table_delete (ordata->content_types_table);
if (ordata->reader) if (ordata->reader)
oggz_close (ordata->reader); oggz_close (ordata->reader);
...@@ -138,23 +147,21 @@ static int ...@@ -138,23 +147,21 @@ static int
filter_stream_p (const ORData *ordata, ORStream *stream, filter_stream_p (const ORData *ordata, ORStream *stream,
const ogg_page *og, long serialno) const ogg_page *og, long serialno)
{ {
int i; int i, n;
for (i = 0; i < ordata->num_serialnos; i++) { if (oggz_table_lookup (ordata->serialno_table, serialno) != NULL)
if (ordata->serialnos[i] == serialno) return 1;
return 1;
}
if (stream == NULL) if (stream == NULL)
return 0; return 0;
for (i = 0; i < ordata->num_streamids; i++) {
if (ordata->streamids[i] == stream->streamid)
return 1;
}
for (i = 0; i < ordata->num_content_types; i++) { if (oggz_table_lookup (ordata->stream_index_table, (long)stream->streamid) != NULL)
if (strcmp (ordata->content_types[i], stream->content_type) == 0) return 1;
n = oggz_table_size (ordata->content_types_table);
for (i = 0; i < n; i++) {
char * c = oggz_table_nth (ordata->content_types_table, i, NULL);
if (strcmp (c, stream->content_type) == 0)
return 1; return 1;
} }
...@@ -295,7 +302,8 @@ main (int argc, char * argv[]) ...@@ -295,7 +302,8 @@ main (int argc, char * argv[])
FILE * infile = NULL; FILE * infile = NULL;
const char *currentopt = argv[1]; const char *currentopt = argv[1];
ORData * ordata; ORData * ordata;
int i; long l;
int i, n;
#ifdef _WIN32 #ifdef _WIN32
/* We need to set stdin/stdout to binary mode */ /* We need to set stdin/stdout to binary mode */
...@@ -352,31 +360,19 @@ main (int argc, char * argv[]) ...@@ -352,31 +360,19 @@ main (int argc, char * argv[])
ordata->verbose = 1; ordata->verbose = 1;
break; break;
case 's': /* serialno */ case 's': /* serialno */
if (ordata->num_serialnos >= MAX_FILTER) { if (or_get_long (optarg, currentopt, &l))
fprintf (stderr, "ERROR: too many serialnos on command line\n");
goto exit_err;
}
if (or_get_long (optarg, currentopt,
&ordata->serialnos[ordata->num_serialnos++]))
goto exit_err; goto exit_err;
oggz_table_insert (ordata->serialno_table, l, (void *)0x7);
break; break;
case 'i': /* stream index */ case 'i': /* stream index */
if (ordata->num_streamids >= MAX_FILTER) { if (or_get_long (optarg, currentopt, &l))
fprintf (stderr, "ERROR: too many stream indexes on command line\n");
goto exit_err;
}
if (or_get_long (optarg, currentopt,
&ordata->streamids[ordata->num_streamids++]))
goto exit_err; goto exit_err;
oggz_table_insert (ordata->stream_index_table, l, (void *)0x7);
break;
case 'c': /* content-type */ case 'c': /* content-type */
if (ordata->num_content_types >= MAX_FILTER) { n = oggz_table_size (ordata->content_types_table);
fprintf (stderr, "ERROR: too many content-types on command line\n"); oggz_table_insert (ordata->content_types_table, (long)n, optarg);
goto exit_err;
}
ordata->content_types[ordata->num_content_types++] = optarg;
break; break;
default: default:
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment