mirror of https://github.com/ericonr/sndio.git
Revert "midicat: Move midi write its own routine."
This reverts commit ea55b2c67d
.
This commit is contained in:
parent
2799f8975e
commit
10777e2260
|
@ -21,59 +21,23 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "bsd-compat.h"
|
#include "bsd-compat.h"
|
||||||
|
|
||||||
#define MIDI_BUFSZ 1024
|
|
||||||
|
|
||||||
char usagestr[] = "usage: midicat [-d] [-i in-file] [-o out-file] "
|
char usagestr[] = "usage: midicat [-d] [-i in-file] [-o out-file] "
|
||||||
"[-q in-port] [-q out-port]\n";
|
"[-q in-port] [-q out-port]\n";
|
||||||
|
|
||||||
char *port0, *port1, *ifile, *ofile;
|
|
||||||
struct mio_hdl *ih, *oh;
|
|
||||||
unsigned char buf[MIDI_BUFSZ];
|
|
||||||
int buf_used = 0;
|
|
||||||
int ifd = -1, ofd = -1;
|
|
||||||
int dump;
|
|
||||||
|
|
||||||
static int
|
|
||||||
midi_flush(void)
|
|
||||||
{
|
|
||||||
int i, n, sep;
|
|
||||||
|
|
||||||
if (buf_used == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (ofile != NULL) {
|
|
||||||
n = write(ofd, buf, buf_used);
|
|
||||||
if (n != buf_used) {
|
|
||||||
fprintf(stderr, "%s: short write\n", ofile);
|
|
||||||
buf_used = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
n = mio_write(oh, buf, buf_used);
|
|
||||||
if (n != buf_used) {
|
|
||||||
fprintf(stderr, "%s: port disconnected\n",
|
|
||||||
ih == oh ? port0 : port1);
|
|
||||||
buf_used = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dump) {
|
|
||||||
for (i = 0; i < buf_used; i++) {
|
|
||||||
sep = (i % 16 == 15 || i == buf_used - 1) ?
|
|
||||||
'\n' : ' ';
|
|
||||||
fprintf(stderr, "%02x%c", buf[i], sep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buf_used = 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, mode;
|
#define MIDI_BUFSZ 1024
|
||||||
|
unsigned char buf[MIDI_BUFSZ];
|
||||||
|
struct mio_hdl *ih, *oh;
|
||||||
|
char *port0, *port1, *ifile, *ofile;
|
||||||
|
int ifd, ofd;
|
||||||
|
int dump, c, i, len, n, sep, mode;
|
||||||
|
|
||||||
|
dump = 0;
|
||||||
|
port0 = port1 = ifile = ofile = NULL;
|
||||||
|
ih = oh = NULL;
|
||||||
|
ifd = ofd = -1;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "di:o:q:")) != -1) {
|
while ((c = getopt(argc, argv, "di:o:q:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -180,23 +144,39 @@ main(int argc, char **argv)
|
||||||
/* transfer until end-of-file or error */
|
/* transfer until end-of-file or error */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (ifile != NULL) {
|
if (ifile != NULL) {
|
||||||
buf_used = read(ifd, buf, sizeof(buf));
|
len = read(ifd, buf, sizeof(buf));
|
||||||
if (buf_used < 0) {
|
if (len == 0)
|
||||||
|
break;
|
||||||
|
if (len < 0) {
|
||||||
perror("stdin");
|
perror("stdin");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (buf_used == 0)
|
|
||||||
break;
|
|
||||||
if (!midi_flush())
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
buf_used = mio_read(ih, buf, sizeof(buf));
|
len = mio_read(ih, buf, sizeof(buf));
|
||||||
if (buf_used == 0) {
|
if (len == 0) {
|
||||||
fprintf(stderr, "%s: disconnected\n", port0);
|
fprintf(stderr, "%s: disconnected\n", port0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!midi_flush())
|
}
|
||||||
|
if (ofile != NULL) {
|
||||||
|
n = write(ofd, buf, len);
|
||||||
|
if (n != len) {
|
||||||
|
fprintf(stderr, "%s: short write\n", ofile);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
n = mio_write(oh, buf, len);
|
||||||
|
if (n != len) {
|
||||||
|
fprintf(stderr, "%s: disconnected\n", port1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dump) {
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
sep = (i % 16 == 15 || i == len - 1) ?
|
||||||
|
'\n' : ' ';
|
||||||
|
fprintf(stderr, "%02x%c", buf[i], sep);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue