1 // $FreeBSD: src/share/examples/isdn/contrib/answer.c,v 1.1.2.1 2001/08/10 14:59:47 obrien Exp $
2 // changed ".g711a" to ".al" (-hm)
3 // Tue Mar 3 02:42:14 MET 1998 dave@turbocat.de
7 #define SOX "/usr/local/bin/sox"
8 #define ALAWULAW "/usr/local/bin/alaw2ulaw"
18 char tmpBuf[1024] = "";
21 void writeToPhone (char *path)
28 srcfile = fopen(path,"r");
30 for (i=0;i<BLK_SIZE;i++) {
36 readcount = fread(buf,1, BLK_SIZE, srcfile);
37 fwrite(buf, 1, readcount, device);
39 // fprintf(logfile,"%d read (%d)\n",i,readcount);
40 } while (readcount == BLK_SIZE);
44 fprintf(logfile,"Can't open file '%s'\n",path);
48 void readFromPhone (char *path)
55 destfile = fopen(path,"a");
57 for (i=0;i<BLK_SIZE;i++) {
63 readcount = fread(buf,1, BLK_SIZE, device);
64 fwrite(buf, 1, readcount, destfile);
66 // fprintf(logfile,"%d read (%d)\n",i,readcount);
67 } while (readcount == BLK_SIZE);
71 fprintf(logfile,"Can't open file '%s'\n",path);
77 fprintf(stderr,"Usage: answer -D device -d destination -s source\n");
81 const char * argWithName (const char* aName)
83 // '-D /dev/null -d 82834 -s 3305682834'
88 for (i = 0; i < sizeof(tmpBuf);i++) {
92 for (i = 0; i<strlen(argbuf);i++) {
94 for (;(i<strlen(argbuf) && (argbuf[i] != ' '));i++) {
99 for (;(i<strlen(argbuf) && (argbuf[i] != ' '));i++) {
101 strncpy(tmpBuf,&argbuf[startpos], i-startpos);
105 if (0 == strncmp(aName,&argbuf[i], strlen(aName))) {
114 int main (int argc, const char *argv[]) {
121 char outfileName[1024] = "";
122 char cmdStr[2048] = "";
127 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
129 logfile = fopen("/var/log/answer.log","a");
131 fprintf(logfile,"%s Started\n",timeStr);
134 for (i=1;i<argc;i++) {
135 sprintf(&argbuf[strlen(argbuf)],"%s ",argv[i]);
137 if (strlen(argbuf) > 2) {
138 argbuf[strlen(argbuf)-1] = '\0';
142 device = fopen(argWithName("-D"),"r+");
143 strcpy(destNum, argWithName("-d"));
144 strcpy(srcNum, argWithName("-s"));
146 fprintf(logfile,"device '%s'\n", argWithName("-D"));
147 fprintf(logfile,"srcNum '%s'\n", srcNum);
148 fprintf(logfile,"destNum '%s'\n", destNum);
153 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
155 sprintf(outfileName,"/var/isdn/%s_%s_%s", timeStr, srcNum, destNum);
157 writeToPhone ("/usr/local/lib/isdn/msg.al");
158 readFromPhone (outfileName);
160 sprintf(cmdStr,"/bin/cat %s | %s | %s -t raw -U -b -r 8000 - -t .au %s.snd", outfileName, ALAWULAW, SOX, outfileName);
161 fprintf(logfile,"%s\n",cmdStr);
167 fprintf(logfile,"Can't open file '%s'\n",argWithName("-D"));
172 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
174 fprintf(logfile,"%s Done\n",timeStr);
176 exit(0); // insure the process exit status is 0
177 return 0; // ...and make main fit the ANSI spec.