Something went wrong. Try again.
various tools I have been using throughout the years
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#define _POSIX_C_SOURCE 200809L
#include "mpd_common.h"
#include <string.h>#include <unistd.h>
static void usage(FILE *file, const char *program) { fprintf(file, "Usage: %s [--verbose] [FILE|-]\n", program);}
int main(int argc, char **argv) { bool verbose = false; const char *path = NULL; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { usage(stdout, argv[0]); return 0; } if (strcmp(argv[i], "--verbose") == 0) { verbose = true; } else if ((argv[i][0] == '-' && strcmp(argv[i], "-") != 0) || path != NULL) { usage(stderr, argv[0]); return 2; } else { path = argv[i]; } }
bool close_input; FILE *input = mt_open_input(path, &close_input); if (input == NULL) return 1; if (path == NULL && isatty(STDIN_FILENO)) fprintf(stderr, "Reading tracks from stdin; press Ctrl-D to finish.\n");
struct mpd_connection *connection = mt_connect(); if (connection == NULL) { if (close_input) fclose(input); return 1; } size_t count = 0U; bool ok = mt_add_queue_stream(connection, input, verbose, &count); if (close_input && fclose(input) != 0) { perror("mpd: close input"); ok = false; } if (ok) printf("Added %zu track%s.\n", count, count == 1U ? "" : "s"); mpd_connection_free(connection); return ok ? 0 : 1;}