2 * Copyright (c) 1999 Michael Reifenberger (Michael@Reifenberger.com).
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 *---------------------------------------------------------------------------
28 * i4btemux - record while playing
29 * ===============================
31 * $FreeBSD: src/share/examples/isdn/contrib/isdntelmux.c,v 1.1.2.1 2001/08/10 14:59:48 obrien Exp $
32 * $DragonFly: src/share/examples/isdn/contrib/isdntelmux.c,v 1.2 2003/06/17 04:36:57 dillon Exp $
34 *----------------------------------------------------------------------------*/
51 #include<machine/i4b_tel_ioctl.h>
55 #define MAXBLOCKS_DEFAULT 23
60 int maxbytes = (BUFLEN * MAXBLOCKS_DEFAULT);
62 int xfd = -1, xact = 0;
63 int ifd = -1, iact = 0;
69 struct timeval timeout;
70 char nambuf[PATH_MAX];
77 void dbg( char *fmt, ... );
80 int main (int argc, char **argv) {
85 while( ( ch = getopt( argc, argv, "x:i:o:b:D:")) != -1 ){
89 maxbytes = x * BUFLEN;
92 ifd = open( optarg, O_RDONLY );
96 ofd = open( optarg, O_WRONLY|O_TRUNC|O_CREAT );
99 xfd = open( optarg, O_RDWR );
104 if( (dfp = fopen( optarg, "w" )) < 0) {
106 dbg("Err for opening %s\n", optarg);
116 if( ( xfd < 0 ) || ( ifd < 0 ) || ( ofd < 0 ) ) {
117 dbg("Err opening one ore more Files.\n");
118 dbg("xfd: %d, ifd: %d, ofd: %d\n", xfd, ifd, ofd );
122 if((x = ioctl(xfd, I4B_TEL_EMPTYINPUTQUEUE, &dummy)) < 0){
123 dbg("Err I4B_TEL_EMPTYINPUTQUEUE\n");
126 while( (iact == 1) || ( (obytes < maxbytes) && (xact == 1) ) ){
140 x=select( maxfd+1, &set, NULL, NULL, NULL);
142 if( (iact == 1) && FD_ISSET( ifd, &set) ){
145 if( (xact == 1) && FD_ISSET( xfd, &set) ){
154 void ifd_hdlr( void) {
156 unsigned char buf[BUFLEN];
158 x = read( ifd, buf, BUFLEN);
159 dbg("ifd read %d bytes\n", x);
163 dbg("xfd %d bytes written to %d\n", x, ibytes);
169 void xfd_hdlr( void) {
171 unsigned char buf[BUFLEN];
173 x = read( xfd, buf, BUFLEN);
174 dbg("xfd read %d bytes\n", x);
178 dbg("ofd %d bytes written to %d\n", x, obytes);
185 fprintf(dfp, "isdntelmux V.1\n");
186 fprintf(dfp, "usage: isdntelmux -x device -i ifile -o ofile [-b blocks]\n");
190 void dbg( char *fmt, ... ) {
196 vfprintf( dfp, fmt, ap);