/*
* ximp3 A simple mp3 player
*
* Copyright (C) 2001 Mats Peterson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Please send any comments/bug reports to
*
[email protected] (Mats Peterson)
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include "ximp3.h"
static void usage(void)
{
fprintf(stderr, "%s v%s\n", PACKAGE, VERSION);
fprintf(stderr, "usage: %s [-d device] [-b buffers] [-r] <file ...>\n", PACKAGE);
exit(0);
}
void init(int argc, char **argv)
{
int c, tmp;
if (! (v = malloc(sizeof(VARS)))) {
fprintf(stderr, "Couldn't allocate global variables\n");
exit(1);
}
v->flist = NULL;
v->flist_size = 0;
v->shuffle_ord = NULL;
strcpy(v->device, "/dev/dsp");
v->tot_playbufs = TOT_PLAYBUFS;
v->shuffle = 0;
v->loop = 0;
v->verbose = 0;
v->remote = 0;
while ((c = getopt(argc, argv, "d:b:slvr")) != -1) {
switch (c) {
case 'd':
strcpy(v->device, optarg);
break;
case 'b':
tmp = atoi(optarg);
if (tmp < 2) {
fprintf(stderr,
"Error: Number of buffers must be at least 2\n");
exit(1);
}
v->tot_playbufs = tmp;
break;
case 's':
v->shuffle = 1;
break;
case 'l':
v->loop = 1;
break;
case 'v':
v->verbose = 1;
break;
case 'r':
v->remote = 1;
break;
case '?':
default:
usage();
}
}
if ((argc - optind) < 1)
usage();
if (pipe(v->pfds) < 0) {
fprintf(stderr, "Couldn't create pipe\n");
exit(1);
}
v->playbufs = (PLAYBUF*)malloc(sizeof(PLAYBUF) * v->tot_playbufs);
if (! v->playbufs) {
fprintf(stderr, "Couldn't allocate play buffers\n");
exit(1);
}
v->playbuf = v->addbuf = 0;
v->n_playbufs = 0;
v->playing = 0;
if (v->remote) {
setlinebuf(stdout);
setlinebuf(stderr);
}
/*
if (! fork_audio())
exit(1);
*/
}