int main(int argc, char **argv) { struct mixer *mixer; int card = 0; if ((argc > 2) && (strcmp(argv[1], "-D") == 0)) { argv++; if (argv[1]) { card = atoi(argv[1]); argv++; argc -= 2; } else { argc -= 1; } } mixer = mixer_open(card); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } if (argc == 1) { printf("Mixer name: '%s'\n", mixer_get_name(mixer)); tinymix_list_controls(mixer); } else if (argc == 2) { tinymix_detail_control(mixer, argv[1], 1); } else if (argc >= 3) { tinymix_set_value(mixer, argv[1], &argv[2], argc - 2); } else { printf("Usage: tinymix [-D card] [control id] [value to set]\n"); } mixer_close(mixer); return 0; }
int main(int argc, char **argv) { struct mixer *mixer; mixer = mixer_open(0); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } if (argc == 1) tinymix_list_controls(mixer); else if (argc == 2) tinymix_detail_control(mixer, atoi(argv[1]), 1); else if (argc == 3) tinymix_set_value(mixer, atoi(argv[1]), argv[2]); else printf("Usage: tinymix [control id] [value to set]\n"); mixer_close(mixer); return 0; }
int main(int argc, char **argv) { struct mixer *mixer; int card = 0; char *cmd; while (1) { static struct option long_options[] = { { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; /* getopt_long stores the option index here. */ int option_index = 0; int c = 0; c = getopt_long (argc, argv, "c:D:hv", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 'D': card = atoi(optarg); break; case 'h': usage(); return EXIT_SUCCESS; case 'v': version(); return EXIT_SUCCESS; } } mixer = mixer_open(card); if (!mixer) { fprintf(stderr, "Failed to open mixer\n"); return EXIT_FAILURE; } cmd = argv[optind]; if (cmd == NULL) { fprintf(stderr, "no command specified (see --help)\n"); mixer_close(mixer); return EXIT_FAILURE; } else if (strcmp(cmd, "get") == 0) { if ((optind + 1) >= argc) { fprintf(stderr, "no control specified\n"); mixer_close(mixer); return EXIT_FAILURE; } tinymix_detail_control(mixer, argv[optind + 1]); printf("\n"); } else if (strcmp(cmd, "set") == 0) { if ((optind + 1) >= argc) { fprintf(stderr, "no control specified\n"); mixer_close(mixer); return EXIT_FAILURE; } if ((optind + 2) >= argc) { fprintf(stderr, "no value(s) specified\n"); mixer_close(mixer); return EXIT_FAILURE; } tinymix_set_value(mixer, argv[optind + 1], &argv[optind + 2], argc - optind - 2); } else if (strcmp(cmd, "controls") == 0) { tinymix_list_controls(mixer, 0); } else if (strcmp(cmd, "contents") == 0) { tinymix_list_controls(mixer, 1); } else { fprintf(stderr, "unknown command '%s' (see --help)\n", cmd); mixer_close(mixer); return EXIT_FAILURE; } mixer_close(mixer); return EXIT_SUCCESS; }