printf(" -i,--inactive show also inactive controls\n");
printf(" -a,--abstract L select abstraction level (none or basic)\n");
printf(" -s,--stdin Read and execute commands from stdin sequentially\n");
+ printf(" -f,--file FILE Read and execute commands from file sequentially\n");
printf(" -R,--raw-volume Use the raw value (default)\n");
printf(" -M,--mapped-volume Use the mapped volume\n");
printf("\nAvailable commands:\n");
#define MAX_ARGS 32
-static int exec_stdin(void)
+static int exec_file(FILE *file)
{
int narg;
char *buf = NULL, *args[MAX_ARGS];
/* quiet = 1; */
ignore_error = 1;
- while (getline(&buf, &size, stdin) > 0) {
+ while (getline(&buf, &size, file) > 0) {
narg = split_line(buf, args, MAX_ARGS);
if (narg > 0) {
if (!strcmp(args[0], "sset") || !strcmp(args[0], "set"))
{
int badopt, retval, level = 0;
int read_stdin = 0;
+ int read_file = 0;
+ char filename[256] = { 0 };
static const struct option long_option[] =
{
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'},
{"abstract", 1, NULL, 'a'},
{"stdin", 0, NULL, 's'},
+ {"file", 1, NULL, 'f'},
{"raw-volume", 0, NULL, 'R'},
{"mapped-volume", 0, NULL, 'M'},
{NULL, 0, NULL, 0},
while (1) {
int c;
- if ((c = getopt_long(argc, argv, "hc:D:qidnva:sRM", long_option, NULL)) < 0)
+ if ((c = getopt_long(argc, argv, "hc:D:qidnva:sf:RM", long_option, NULL)) < 0)
break;
switch (c) {
case 'h':
case 's':
read_stdin = 1;
break;
+ case 'f':
+ read_file = 1;
+ strncpy(filename, optarg, sizeof(filename)-1);
+ filename[sizeof(filename)-1] = '\0';
+ break;
case 'R':
std_vol_type = VOL_RAW;
break;
smixer_options.device = card;
if (read_stdin) {
- retval = exec_stdin();
+ retval = exec_file(stdin);
+ goto finish;
+ }
+
+ if (read_file) {
+ FILE *file;
+ file = fopen(filename, "r");
+ if (!file) {
+ retval = errno;
+ perror("fopen");
+ goto finish;
+ }
+
+ retval = exec_file(file);
+ fclose(file);
goto finish;
}