[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123rc-example ogg123.c

Kenneth C. Arnold kcarnold at arnoldnet.net
Mon Oct 30 17:16:10 PST 2000



On Mon, Oct 30, 2000 at 05:06:22PM -0800, Jack Moffitt wrote:
> jack        00/10/30 17:06:22
> 
>   Modified:    ogg123   ogg123.c
>   Added:       ogg123   ogg123rc-example
>   Log:
>   added support for a .ogg123rc file so that you can specify a default device :)
>   an example is provided.

very good. one less thing that I could easily botch up trying to implement :)

>   jack.
[...]
> @@ -169,6 +169,39 @@
>    fprintf (o, "  -z, --shuffle  shuffle play\n");
>  }
>  
> +int get_default_device(void)
> +{
> +	FILE *fp;
> +	char filename[NAME_MAX];

Is that constant guaranteed to be there? curious.

> +	char line[100];
> +	char *device = NULL;
> +	int i;
> +
> +	strncpy(filename, getenv("HOME"), NAME_MAX);
> +	strcat(filename, "/.ogg123rc");

Remember, ogg123's goal is not to be Unix-specific. This should be ifdef'ed
or something (yes, the horror!)

> +
> +	fp = fopen(filename, "r");
> +	if (fp) {
> +		if (fgets(line, 100, fp)) {
> +			if (strncmp(line, "default_device=", 15) == 0) {

This should be more extensible... I don't know what to, though. Perhaps if
libao is going to be used in other projects, it should be managing its own
default device in an rc file?

> +				device = &line[15];
> +				for (i = 0; i < strlen(device); i++)
> +					if (device[i] == '\n' || device[i] == '\r')
> +						device[i] = 0;
> +			}
> +		}
> +		fclose(fp);
> +	}
> +
> +	if (device) {
> +		fprintf(stderr, "device short name = %s\n", device);
> +		fprintf(stderr, "device_id is = %d\n", ao_get_driver_id(device));
> +		return ao_get_driver_id(device);

It's not clear here ... are you checking the return value of this function?

> +	}
> +
> +	return -1;

Ditto... but there should be at least 2 return values: one for an invalid
default device, and one for no default device.

> +}
> +
>  int
>  main (int argc, char **argv)
>  {
> @@ -182,6 +215,8 @@
>    int bits, rate, channels;
>  
>    ao_initialize();
> +
> +  temp_driver_id = get_default_device();
>  
>    while (-1 != (ret = getopt_long (argc, argv, "d:hqk:o:vV:z",
>  				   long_options, &option_index)))
> 
> 
> 
> 1.1                  vorbis-tools/ogg123/ogg123rc-example
> 
> Index: ogg123rc-example
> ===================================================================
> default_device=oss

-- 
Kenneth Arnold <ken at arnoldnet.net> / kcarnold / Linux user #180115
http://arnoldnet.net/~kcarnold/

--- >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 'cvs-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 commits mailing list