alsa-utils/alsactl/alsactl.c

126 lines
3.6 KiB
C
Raw Normal View History

1998-10-29 23:45:59 +01:00
/*
* Advanced Linux Sound Architecture Control Program
2000-08-25 16:34:26 +02:00
* Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
* Jaroslav Kysela <perex@perex.cz>
1998-10-29 23:45:59 +01:00
*
*
* 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; if not, write to the Free Software
2001-12-30 10:32:53 +01:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1998-10-29 23:45:59 +01:00
*
*/
1998-10-31 20:50:16 +01:00
#include "aconfig.h"
1999-01-30 20:12:34 +01:00
#include "version.h"
1998-10-29 23:45:59 +01:00
#include <getopt.h>
#include <stdarg.h>
2000-08-25 16:34:26 +02:00
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <alsa/asoundlib.h>
#include "alsactl.h"
1998-10-29 23:45:59 +01:00
2001-05-15 14:10:22 +02:00
#define SYS_ASOUNDRC "/etc/asound.state"
#define SYS_ASOUNDNAMES "/etc/asound.names"
1998-10-29 23:45:59 +01:00
int debugflag = 0;
int force_restore = 0;
2000-08-25 16:34:26 +02:00
char *command;
1998-10-29 23:45:59 +01:00
1998-11-27 16:13:57 +01:00
static void help(void)
1998-10-29 23:45:59 +01:00
{
1998-11-27 16:13:57 +01:00
printf("Usage: alsactl <options> command\n");
printf("\nAvailable options:\n");
printf(" -h,--help this help\n");
printf(" -f,--file # configuration file (default " SYS_ASOUNDRC " or " SYS_ASOUNDNAMES ")\n");
printf(" -F,--force try to restore the matching controls as much as possible\n");
printf(" -d,--debug debug mode\n");
printf(" -v,--version print version of this program\n");
1998-11-27 16:13:57 +01:00
printf("\nAvailable commands:\n");
printf(" store <card #> save current driver setup for one or each soundcards\n");
printf(" to configuration file\n");
printf(" restore <card #> load current driver setup for one or each soundcards\n");
printf(" from configuration file\n");
printf(" names <card #> dump information about all the known present (sub-)devices\n");
printf(" into configuration file (DEPRECATED)\n");
2000-08-25 16:34:26 +02:00
}
1998-11-27 16:13:57 +01:00
int main(int argc, char *argv[])
1998-10-29 23:45:59 +01:00
{
1998-11-27 16:13:57 +01:00
struct option long_option[] =
{
2000-08-25 16:34:26 +02:00
{"help", 0, NULL, 'h'},
{"file", 1, NULL, 'f'},
{"force", 0, NULL, 'F'},
2000-08-25 16:34:26 +02:00
{"debug", 0, NULL, 'd'},
{"version", 0, NULL, 'v'},
1998-11-27 16:13:57 +01:00
{NULL, 0, NULL, 0},
};
2000-08-25 16:34:26 +02:00
char *cfgfile = SYS_ASOUNDRC;
2002-12-04 15:41:32 +01:00
int res;
1998-11-27 16:13:57 +01:00
2000-08-25 16:34:26 +02:00
command = argv[0];
1998-11-27 16:13:57 +01:00
while (1) {
int c;
2003-01-07 14:44:08 +01:00
if ((c = getopt_long(argc, argv, "hf:Fdv", long_option, NULL)) < 0)
1998-11-27 16:13:57 +01:00
break;
switch (c) {
case 'h':
help();
return EXIT_SUCCESS;
1998-11-27 16:13:57 +01:00
case 'f':
2000-08-25 16:34:26 +02:00
cfgfile = optarg;
1998-11-27 16:13:57 +01:00
break;
case 'F':
force_restore = 1;
break;
1998-11-27 16:13:57 +01:00
case 'd':
debugflag = 1;
break;
case 'v':
1999-01-30 20:12:34 +01:00
printf("alsactl version " SND_UTIL_VERSION_STR "\n");
2001-09-26 18:05:03 +02:00
return EXIT_SUCCESS;
2002-12-04 15:41:32 +01:00
case '?': // error msg already printed
help();
return EXIT_FAILURE;
2002-12-04 15:41:32 +01:00
break;
default: // should never happen
fprintf(stderr,
"Invalid option '%c' (%d) not handled??\n", c, c);
1998-11-27 16:13:57 +01:00
}
}
if (argc - optind <= 0) {
fprintf(stderr, "alsactl: Specify command...\n");
return 0;
}
2002-12-04 15:41:32 +01:00
1998-11-27 16:13:57 +01:00
if (!strcmp(argv[optind], "store")) {
2002-12-04 15:41:32 +01:00
res = save_state(cfgfile,
argc - optind > 1 ? argv[optind + 1] : NULL);
1998-11-27 16:13:57 +01:00
} else if (!strcmp(argv[optind], "restore")) {
2002-12-04 15:41:32 +01:00
res = load_state(cfgfile,
argc - optind > 1 ? argv[optind + 1] : NULL);
} else if (!strcmp(argv[optind], "names")) {
if (!strcmp(cfgfile, SYS_ASOUNDRC))
cfgfile = SYS_ASOUNDNAMES;
res = generate_names(cfgfile);
1998-11-27 16:13:57 +01:00
} else {
2002-12-04 15:41:32 +01:00
fprintf(stderr, "alsactl: Unknown command '%s'...\n",
argv[optind]);
res = -ENODEV;
1998-11-27 16:13:57 +01:00
}
return res < 0 ? res : 0;
1998-10-29 23:45:59 +01:00
}