]> git.alsa-project.org Git - alsa-utils.git/commitdiff
Updates for write path..
authorJaroslav Kysela <perex@perex.cz>
Sat, 30 Jan 1999 17:28:44 +0000 (17:28 +0000)
committerJaroslav Kysela <perex@perex.cz>
Sat, 30 Jan 1999 17:28:44 +0000 (17:28 +0000)
amixer/amain.cpp
amixer/amixer.1

index 8c9b67a3968dfaaa1e119187465798b02b9c0d73..1324bf0c4aca33691f82e96736e250603380b03e 100644 (file)
@@ -50,7 +50,7 @@ void usage()
        printf("\n"
               "Usage: amixer [-c card] [-d dev] device [vol|L:R] [mute|unmute] [rec|norec]\n\n"
               "       amixer [-p path] -r\tRead %s or <path> settings\n"
-              "       amixer -w\t\tWrite %s settings\n"
+              "       amixer [-p path] -w\tWrite %s or <path> settings\n"
               "       amixer -q ...\t\tQuiet mode\n"
               "       amixer -h\t\tHelp\n\n"
               "Example: amixer line-out 80:50 unmute rec\n\n", rc_file(), rc_file());
@@ -68,7 +68,9 @@ void read_config(Mixer * mix, const char *path)
        int count = 0;
        int flags;
 
-       if ((rc = fopen(path ? path : rc_file(), "r")) == NULL) {
+       if (path && strcmp(path, "-") == 0)
+               rc = stdin;
+       else if ((rc = fopen(path ? path : rc_file(), "r")) == NULL) {
                printf("Mixer values not read\n");
                return;
        }
@@ -93,16 +95,19 @@ void read_config(Mixer * mix, const char *path)
                mix->Write(left, right, flags);
        }
 
-       fclose(rc);
+       if (rc != stdin)
+               fclose(rc);
        return;
 }
 
-void write_config(Mixer * mix)
+void write_config(Mixer * mix, const char *path)
 {
        FILE *rc;
        int32 left, right, flags;
 
-       if ((rc = fopen(rc_file(), "w+")) == NULL) {
+       if (path && strcmp(path, "-") == 0)
+               rc = stdout;
+       else if ((rc = fopen(path ? path : rc_file(), "w+")) == NULL) {
                printf("Mixer values not written\n");
                return;
        }
@@ -113,7 +118,8 @@ void write_config(Mixer * mix)
                mix->Read(&left, &right, &flags);
                fprintf(rc, "%d %d:%d %d %d\n", i, mix->Left(), mix->Right(), flags & E_MIXER_MUTE ? 1 : 0, flags & E_MIXER_RECORD ? 1 : 0);
        }
-       fclose(rc);
+       if (rc != stdout)
+               fclose(rc);
        return;
 }
 
@@ -165,7 +171,7 @@ int main(int argc, char **argv)
                        } else if (argv[add][1] == 'w') {
                                the_mixer = new Mixer(card, device);
                                if (the_mixer && the_mixer->Init())
-                                       write_config(the_mixer);
+                                       write_config(the_mixer, pathind ? argv[pathind] : (const char *) NULL);
                                delete the_mixer;
                                return 0;
                        } else if (argv[add][1] == 'q') {
index 0944c4aa974b7223bb6ca8794960ff3c829de056..49694719bc7b53569f544a84c02991bffdb23259 100644 (file)
@@ -48,10 +48,12 @@ than I do. :)
 Help: show syntax.
 .TP
 [\fI-p\fP path] \fI-r\fP 
-Read settings from $HOME/.amixerrc or from optional <path>.
+Read settings from $HOME/.amixerrc or from optional <path>. If <path>
+is ``\-'', reads from the standard input.
 .TP
-\fI-w\fP 
-Write the current mixer settings into $HOME/.amixerrc 
+[\fI-p\fP path] \fI-w\fP 
+Write the current mixer settings into $HOME/.amixerrc or optional <path>.
+If <path> is ``\-'', writes to the standard output.
 .TP
 \fI-q\fP
 Quiet mode. Do not show results of changes.