[vorbis-dev] patch to add device-option to ogg123 rc file
Jeremy C. Reed
reed at reedmedia.net
Sat Mar 10 03:44:13 PST 2001
Below is a patch for vorbis-tools-1.0beta4 ogg123.
It adds support for using the rc file (like /etc/ogg123.rc) for
configuring the device-options. In addition, comments can be used (when
they start a line).
My ~/.ogg123rc:
default_device=oss
default_options=dsp:/dev/audio
Please share your comments.
Jeremy C. Reed
http://www.reedmedia.net/
diff -u vorbis-tools-1.0beta4/ogg123/ao_interface.c vorbis-tools-1.0beta4-modifdiff -u vorbis-tools-1.0beta4/ogg123/ao_interface.c vorbis-tools-1.0beta4-modified/ogg123/ao_interface.c
--- vorbis-tools-1.0beta4/ogg123/ao_interface.c Fri Feb 23 17:39:19 2001
+++ vorbis-tools-1.0beta4-modified/ogg123/ao_interface.c Sat Mar 10 03:28:28 2001
@@ -56,12 +56,13 @@
return (result);
}
-int get_default_device(void)
+int get_configs(ao_option_t ** op_h)
{
FILE *fp;
char filename[FILENAME_MAX];
char line[100];
char *device = NULL;
+ char *device_options = NULL;
char *homedir = getenv("HOME");
int i;
@@ -74,15 +75,41 @@
strcat(filename, "/.ogg123rc");
fp = fopen(filename, "r");
- /* if no ~/.ogg123rc can be found, try /etc/ogg123rc instead */
+ /* if no ~/.ogg123rc can be found, try /etc/ogg123.rc instead */
if (!fp) fp = fopen("/etc/ogg123.rc", "r");
/* This is a very simplistic parser. If more options are ever added,
it will need a serious overhaul. */
if (fp) {
- if (fgets(line, 100, fp)) {
+ while (fgets (line, 100, fp) != (char *) NULL) {
+ /* skip blank lines and comments */
+ if (*line == '#' || *line == '\n' || *line == '\0')
+ continue;
+
+ if (strncmp(line, "default_options=", 16) == 0) {
+ device_options = malloc (sizeof(line) + 1);
+ if (! device_options) {
+ fprintf (stderr, "malloc\n");
+ exit(1);
+ }
+ strncpy (device_options, &line[16], sizeof(line) - 1);
+ for (i = 0; i < strlen(device_options); i++)
+ if (device_options[i] == '\n' || device_options[i] == '\r')
+ device_options[i] = 0;
+
+ if (!add_option(op_h, device_options)) {
+ fprintf(stderr, "Incorrect option format in rc file: %s.\n",
+ device_options);
+ exit(1);
+ }
+ }
if (strncmp(line, "default_device=", 15) == 0) {
- device = &line[15];
+ device = malloc (sizeof(line) + 1);
+ if (! device) {
+ fprintf (stderr, "malloc\n");
+ exit(1);
+ }
+ strncpy (device, &line[15], sizeof(line));
for (i = 0; i < strlen(device); i++)
if (device[i] == '\n' || device[i] == '\r')
device[i] = 0;
diff -u vorbis-tools-1.0beta4/ogg123/ogg123.1 vorbis-tools-1.0beta4-modified/ogg123/ogg123.1
--- vorbis-tools-1.0beta4/ogg123/ogg123.1 Fri Feb 23 17:39:19 2001
+++ vorbis-tools-1.0beta4-modified/ogg123/ogg123.1 Sat Mar 10 03:27:22 2001
@@ -194,8 +194,8 @@
.SH FILES
.TP
-/etc/ogg123rc
-Can be used to set the default output device for
+/etc/ogg123.rc
+Can be used to set the default output device and device options for
.B ogg123.
See the included file
.B ogg123rc-example
diff -u vorbis-tools-1.0beta4/ogg123/ogg123.c vorbis-tools-1.0beta4-modified/ogg123/ogg123.c
--- vorbis-tools-1.0beta4/ogg123/ogg123.c Fri Feb 23 16:52:22 2001
+++ vorbis-tools-1.0beta4-modified/ogg123/ogg123.c Sat Mar 10 03:15:28 2001
@@ -168,7 +168,7 @@
/* Add last device to device list or use the default device */
if (temp_driver_id < 0) {
- temp_driver_id = get_default_device();
+ temp_driver_id = get_configs(current_options);
if(temp_driver_id < 0) {
temp_driver_id = ao_get_driver_id(NULL);
}
diff -u vorbis-tools-1.0beta4/ogg123/ogg123.h vorbis-tools-1.0beta4-modified/ogg123/ogg123.h
--- vorbis-tools-1.0beta4/ogg123/ogg123.h Wed Feb 21 18:49:12 2001
+++ vorbis-tools-1.0beta4-modified/ogg123/ogg123.h Sat Mar 10 03:21:12 2001
@@ -41,7 +41,7 @@
void devices_write(void *ptr, size_t size, devices_t * d);
void usage(void);
int add_option(ao_option_t ** op_h, const char *optstring);
-int get_default_device(void);
+int get_configs(ao_option_t ** op_h);
void play_file(ogg123_options_t opt);
int get_tcp_socket(void); /* Will be going soon. */
FILE *http_open(char *server, int port, char *path); /* ditto */
diff -u vorbis-tools-1.0beta4/ogg123/ogg123rc-example vorbis-tools-1.0beta4-modified/ogg123/ogg123rc-example
--- vorbis-tools-1.0beta4/ogg123/ogg123rc-example Mon Dec 25 13:24:25 2000
+++ vorbis-tools-1.0beta4-modified/ogg123/ogg123rc-example Sat Mar 10 03:29:36 2001
@@ -1,3 +1,3 @@
-# Copy this to ~/.ogg123rc and edit as necessary. The current
-# parser cannot handle comments, so remove these lines also.
+# Copy this to ~/.ogg123rc and edit as necessary.
default_device=oss
+default_options=dsp:/dev/audio
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis-dev
mailing list