Commit af527ca4 authored by ogg.k.ogg.k's avatar ogg.k.ogg.k Committed by conrad

codecs can be displayed by their name or MIME type, and on separate lines or on a single line.

parent ec1ff860
......@@ -4,7 +4,7 @@ oggz-info \(em Display a list of codecs found in one or more Ogg files and their
.SH "SYNOPSIS"
.PP
\fBoggz-codecs\fR [\-a | \-\-all ] [\-m | \-\-mime ] filename \&...
\fBoggz-codecs\fR [\-a | \-\-all ] [\-m | \-\-mime ] [\-1 | \-\-one\-per\-line] filename \&...
.PP
\fBoggz-codecs\fR [\-h | \-\-help ] [\-v | \-\-version ]
.SH "Description"
......@@ -21,6 +21,8 @@ Ogg files and their bitstreams.
Display an entry for every bitstream, rather than displaying each codec once, even if present more than once.
.IP "\-m, \-\-mime" 10
Display each codec's MIME type, instead of its name.
.IP "\-1, \-\-one\-per\-line" 10
Display each entries on a separate line.
.SS "Miscellaneous options"
.IP "\-h, \-\-help" 10
Display usage information and exit.
......
......@@ -35,6 +35,7 @@
#include <string.h>
#include <limits.h> /* LONG_MAX */
#include <math.h>
#include <ctype.h>
#include <getopt.h>
#include <errno.h>
......@@ -53,6 +54,7 @@
static int show_all = 0;
static int show_as_mime = 0;
static int show_one_per_line = 0;
/* Assumes UNKNOWN is last - fair assumption I think */
static int codecs_count[OGGZ_CONTENT_UNKNOWN+1] = {0};
......@@ -64,7 +66,8 @@ usage (const char * progname)
printf ("Display codecs used in one or more Ogg files and their bitstreams\n");
printf ("\nDisplay options\n");
printf (" -a, --all Display an entry for all bitstreams, rather than collapsing codecs used more than once\n");
printf (" -m, --mime Displays entries on a single line, separated by commas\n");
printf (" -m, --mime Displays MIME types rather than codec names\n");
printf (" -1, --one-per-line Displays one entry per line\n");
printf ("\nMiscellaneous options\n");
printf (" -h, --help Display this help and exit\n");
printf (" -v, --version Output version information and exit\n");
......@@ -100,20 +103,26 @@ oggz_info_apply (OI_TrackFunc func, OI_Info * info)
static void
print_codec_name (OI_Info * info, long serialno)
{
static int displayed_once = 0;
OggzStreamContent content = oggz_stream_get_content(info->oggz, serialno);
if (!codecs_count[content]++ || show_all) {
if (displayed_once && !show_one_per_line) {
printf(", ");
}
if (show_as_mime) {
const char *mime_type = NULL;
if (content >= 0 && content < OGGZ_CONTENT_UNKNOWN)
mime_type = mime_type_names[content];
if (!mime_type) mime_type = "application/octet-stream";
printf("%s\n", mime_type);
printf("%s%s", mime_type, show_one_per_line?"\n":"");
}
else {
const char *codec_name = oggz_content_type (content);
const char *codec_name = oggz_content_type (content), *ptr;
if (!codec_name) codec_name = "unknown";
printf("%s\n", codec_name);
for (ptr = codec_name; *ptr; ++ptr) putchar(tolower(*ptr));
if (show_one_per_line) putchar('\n');
}
displayed_once = 1;
}
}
......@@ -159,7 +168,7 @@ main (int argc, char ** argv)
OGGZ * oggz;
OI_Info info;
char * optstring = "hvam";
char * optstring = "hvam1";
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
......@@ -167,6 +176,7 @@ main (int argc, char ** argv)
{"version", no_argument, 0, 'v'},
{"all", no_argument, 0, 'a'},
{"mime", no_argument, 0, 'm'},
{"one-line", no_argument, 0, '1'},
{NULL,0,0,0}
};
#endif
......@@ -212,6 +222,9 @@ main (int argc, char ** argv)
case 'm':
show_as_mime = 1;
break;
case '1':
show_one_per_line = 1;
break;
default:
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