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 * ===============================
33 *----------------------------------------------------------------------------*/
50 #include<i4b/i4b_tel_ioctl.h>
54 #define MAXBLOCKS_DEFAULT 23
59 int maxbytes = (BUFLEN * MAXBLOCKS_DEFAULT);
61 int xfd = -1, xact = 0;
62 int ifd = -1, iact = 0;
68 struct timeval timeout;
69 char nambuf[PATH_MAX];
76 void dbg( char *fmt, ... );
79 int main (int argc, char **argv) {
84 while( ( ch = getopt( argc, argv, "x:i:o:b:D:")) != -1 ){
88 maxbytes = x * BUFLEN;
91 ifd = open( optarg, O_RDONLY );
95 ofd = open( optarg, O_WRONLY|O_TRUNC|O_CREAT );
98 xfd = open( optarg, O_RDWR );
103 if( (dfp = fopen( optarg, "w" )) < 0) {
105 dbg("Err for opening %s\n", optarg);
115 if( ( xfd < 0 ) || ( ifd < 0 ) || ( ofd < 0 ) ) {
116 dbg("Err opening one ore more Files.\n");
117 dbg("xfd: %d, ifd: %d, ofd: %d\n", xfd, ifd, ofd );
121 if((x = ioctl(xfd, I4B_TEL_EMPTYINPUTQUEUE, &dummy)) < 0){
122 dbg("Err I4B_TEL_EMPTYINPUTQUEUE\n");
125 while( (iact == 1) || ( (obytes < maxbytes) && (xact == 1) ) ){
139 x=select( maxfd+1, &set, NULL, NULL, NULL);
141 if( (iact == 1) && FD_ISSET( ifd, &set) ){
144 if( (xact == 1) && FD_ISSET( xfd, &set) ){
153 void ifd_hdlr( void) {
155 unsigned char buf[BUFLEN];
157 x = read( ifd, buf, BUFLEN);
158 dbg("ifd read %d bytes\n", x);
162 dbg("xfd %d bytes written to %d\n", x, ibytes);
168 void xfd_hdlr( void) {
170 unsigned char buf[BUFLEN];
172 x = read( xfd, buf, BUFLEN);
173 dbg("xfd read %d bytes\n", x);
177 dbg("ofd %d bytes written to %d\n", x, obytes);
184 fprintf(dfp, "isdntelmux V.1\n");
185 fprintf(dfp, "usage: isdntelmux -x device -i ifile -o ofile [-b blocks]\n");
189 void dbg( char *fmt, ... ) {
195 vfprintf( dfp, fmt, ap);