version 1.63, 2009/08/17 15:07:49 |
version 1.64, 2009/08/17 16:17:46 |
|
|
} |
} |
if (in) { |
if (in) { |
rproc = rpipe_new(dev); |
rproc = rpipe_new(dev); |
rbuf = abuf_new(3125, &aparams_none); |
rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); |
aproc_setout(rproc, rbuf); |
aproc_setout(rproc, rbuf); |
aproc_setin(thrubox, rbuf); |
aproc_setin(thrubox, rbuf); |
} |
} |
if (out) { |
if (out) { |
wproc = wpipe_new(dev); |
wproc = wpipe_new(dev); |
wbuf = abuf_new(3125, &aparams_none); |
wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); |
aproc_setin(wproc, wbuf); |
aproc_setin(wproc, wbuf); |
aproc_setout(thrubox, wbuf); |
aproc_setout(thrubox, wbuf); |
if (in) { |
if (in) { |
|
|
midicat_main(int argc, char **argv) |
midicat_main(int argc, char **argv) |
{ |
{ |
int c, l_flag, unit, fd; |
int c, l_flag, unit, fd; |
struct farglist dfiles; |
struct farglist dfiles, ifiles, ofiles; |
char base[PATH_MAX], path[PATH_MAX]; |
char base[PATH_MAX], path[PATH_MAX]; |
char *input, *output; |
|
struct farg *fa; |
struct farg *fa; |
struct file *stdx, *f; |
struct file *stdx, *f; |
struct aproc *p; |
struct aproc *p; |
|
|
|
|
l_flag = 0; |
l_flag = 0; |
unit = -1; |
unit = -1; |
output = NULL; |
|
input = NULL; |
|
SLIST_INIT(&dfiles); |
SLIST_INIT(&dfiles); |
|
SLIST_INIT(&ifiles); |
|
SLIST_INIT(&ofiles); |
|
|
while ((c = getopt(argc, argv, "i:o:lf:U:")) != -1) { |
while ((c = getopt(argc, argv, "i:o:lf:U:")) != -1) { |
switch (c) { |
switch (c) { |
case 'i': |
case 'i': |
if (input != NULL) |
farg_add(&ifiles, &aparams_none, &aparams_none, |
errx(1, "only one -i allowed"); |
0, HDR_RAW, 0, optarg); |
input = optarg; |
|
break; |
break; |
case 'o': |
case 'o': |
if (output != NULL) |
farg_add(&ofiles, &aparams_none, &aparams_none, |
errx(1, "only one -o allowed"); |
0, HDR_RAW, 0, optarg); |
output = optarg; |
|
break; |
break; |
case 'f': |
case 'f': |
farg_add(&dfiles, &aparams_none, &aparams_none, |
farg_add(&dfiles, &aparams_none, &aparams_none, |
HDR_RAW, 0, 0, optarg); |
0, HDR_RAW, 0, optarg); |
break; |
break; |
case 'l': |
case 'l': |
l_flag = 1; |
l_flag = 1; |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
if (argc > 0 || (!input && !output && !l_flag)) { |
if (argc > 0 || (SLIST_EMPTY(&ifiles) && SLIST_EMPTY(&ofiles) && |
|
!l_flag)) { |
midicat_usage(); |
midicat_usage(); |
exit(1); |
exit(1); |
} |
} |
if (!l_flag && unit >= 0) |
if (!l_flag && unit >= 0) |
errx(1, "can't use -U without -l"); |
errx(1, "can't use -U without -l"); |
if (l_flag) { |
if (l_flag) { |
if (input || output) |
if (!SLIST_EMPTY(&ifiles) || !SLIST_EMPTY(&ofiles)) |
errx(1, "can't use -i or -o with -l"); |
errx(1, "can't use -i or -o with -l"); |
getbasepath(base, sizeof(path)); |
getbasepath(base, sizeof(path)); |
if (unit < 0) |
if (unit < 0) |
|
|
thrubox = thru_new("thru"); |
thrubox = thru_new("thru"); |
thrubox->refs++; |
thrubox->refs++; |
|
|
if ((input || output) && SLIST_EMPTY(&dfiles)) { |
if ((!SLIST_EMPTY(&ifiles) || !SLIST_EMPTY(&ofiles)) && |
|
SLIST_EMPTY(&dfiles)) { |
farg_add(&dfiles, &aparams_none, &aparams_none, |
farg_add(&dfiles, &aparams_none, &aparams_none, |
0, HDR_RAW, 0, NULL); |
0, HDR_RAW, 0, NULL); |
} |
} |
|
|
while (!SLIST_EMPTY(&dfiles)) { |
while (!SLIST_EMPTY(&dfiles)) { |
fa = SLIST_FIRST(&dfiles); |
fa = SLIST_FIRST(&dfiles); |
SLIST_REMOVE_HEAD(&dfiles, entry); |
SLIST_REMOVE_HEAD(&dfiles, entry); |
newmidi(fa, output || l_flag, input || l_flag); |
newmidi(fa, |
|
!SLIST_EMPTY(&ofiles) || l_flag, |
|
!SLIST_EMPTY(&ifiles) || l_flag); |
free(fa); |
free(fa); |
} |
} |
|
|
if (l_flag) { |
if (l_flag) { |
snprintf(path, sizeof(path), "%s/%s%u", base, |
snprintf(path, sizeof(path), "%s/%s%u", base, |
DEFAULT_MIDITHRU, unit); |
DEFAULT_MIDITHRU, unit); |
|
|
if (debug_level == 0 && daemon(0, 0) < 0) |
if (debug_level == 0 && daemon(0, 0) < 0) |
err(1, "daemon"); |
err(1, "daemon"); |
} |
} |
if (input) { |
while (!SLIST_EMPTY(&ifiles)) { |
if (strcmp(input, "-") == 0) { |
fa = SLIST_FIRST(&ifiles); |
|
SLIST_REMOVE_HEAD(&ifiles, entry); |
|
if (strcmp(fa->name, "-") == 0) { |
fd = STDIN_FILENO; |
fd = STDIN_FILENO; |
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) |
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) |
warn("stdin"); |
warn("stdin"); |
} else { |
} else { |
fd = open(input, O_RDONLY | O_NONBLOCK, 0666); |
fd = open(fa->name, O_RDONLY | O_NONBLOCK, 0666); |
if (fd < 0) |
if (fd < 0) |
err(1, "%s", input); |
err(1, "%s", fa->name); |
} |
} |
stdx = (struct file *)pipe_new(&pipe_ops, fd, "stdin"); |
stdx = (struct file *)pipe_new(&pipe_ops, fd, fa->name); |
p = rpipe_new(stdx); |
p = rpipe_new(stdx); |
buf = abuf_new(3125, &aparams_none); |
buf = abuf_new(MIDI_BUFSZ, &aparams_none); |
aproc_setout(p, buf); |
aproc_setout(p, buf); |
aproc_setin(thrubox, buf); |
aproc_setin(thrubox, buf); |
|
free(fa); |
} |
} |
if (output) { |
while (!SLIST_EMPTY(&ofiles)) { |
if (strcmp(output, "-") == 0) { |
fa = SLIST_FIRST(&ifiles); |
|
SLIST_REMOVE_HEAD(&ifiles, entry); |
|
if (strcmp(fa->name, "-") == 0) { |
fd = STDOUT_FILENO; |
fd = STDOUT_FILENO; |
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) |
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) |
warn("stdout"); |
warn("stdout"); |
} else { |
} else { |
fd = open(output, |
fd = open(fa->name, |
O_WRONLY | O_TRUNC | O_CREAT | O_NONBLOCK, 0666); |
O_WRONLY | O_TRUNC | O_CREAT | O_NONBLOCK, 0666); |
if (fd < 0) |
if (fd < 0) |
err(1, "%s", output); |
err(1, "%s", fa->name); |
} |
} |
stdx = (struct file *)pipe_new(&pipe_ops, fd, "stdout"); |
stdx = (struct file *)pipe_new(&pipe_ops, fd, fa->name); |
p = wpipe_new(stdx); |
p = wpipe_new(stdx); |
buf = abuf_new(3125, &aparams_none); |
buf = abuf_new(MIDI_BUFSZ, &aparams_none); |
aproc_setin(p, buf); |
aproc_setin(p, buf); |
aproc_setout(thrubox, buf); |
aproc_setout(thrubox, buf); |
|
free(fa); |
} |
} |
|
|
/* |
/* |