ftp.nice.ch/pub/next/unix/communication/newam.0.1.s.tar.gz#/newam-0.1/src/amreset.c

This is amreset.c in view mode; [Download] [Up]

/*********************************************************************/
/*                                                                   */
/* Programmer:                                                       */
/*   Olaf Mueller <olaf@orest.escape.de>                             */
/*                                                                   */
/* Purpose:                                                          */
/*   Answering Machine                                               */
/*       a small program resetting the answering machine             */
/*       Normally you should not need this program.                  */
/*       But on my intel system playing sounds irritates the         */
/*       serial line                                                 */
/*                                                                   */
/* History:                                                          */
/*   29-08-96   Initial Release           Olaf Mueller               */
/*                                                                   */
/* Notes:                                                            */
/*                                                                   */
/*********************************************************************/

#include <libc.h>

#include "const.h"
#include "misc.h"
#include "device.h"
#include "iodev.h"



static void signalhandler (int sig)
{
}


static int dialogOnLine (int line,long msec,char *until,char *question,...)
{
	va_list		ap ;
	char		buffer [1000] ;
	long		usedtime ;
	char		sbuf [1000] , rbuf [1000] ;
	int			len , rc = -1 ;

	va_start (ap,question) ;
	vsprintf (buffer,question,ap) ;
	va_end (ap) ;

	debugsputs (sbuf,buffer) ; debugsputs (rbuf,until) ;
	printf ("send \"%s\" wait for \"%s\"\n",sbuf,rbuf) ;
	len = strlen (buffer) ;
	if (write(line,buffer,len) == len)
	{
		if ((usedtime = readUntil(line,msec,until)) >= 0L)
		{
			printf ("got it after %ld msec\n",usedtime) ;
			rc = 0 ;
		}
		else
			printf ("reading failed (Timeout after %ld msec)\n",msec) ;
	}
	else
		printf ("writing failed\n") ;
	return  rc ;
}



int main (int argc,char *argv[])
{
	int		rc , line ;
	char	port ;


	if (argc != 2)
	{
		printf ("usage: amreset <port>\n") ;
		return 1 ;
	}
	port = *argv[1] ;
	if (strlen(argv[1]) != 1  ||  (port != 'a'  &&  port != 'b'))
	{
		printf ("amreset: bad port description (use \'a\' or \'b\')\n") ;
		return  1 ;
	}

	signal (SIGALRM,signalhandler) ;
	siginterrupt (SIGALRM,1) ;

	if ((rc = lockDevice(DIALOUT,port)) == 0)
	{
		if ((line = openDevice(DIALOUT,port)) >= 0)
		{
			initDevice (line,B38400) ;
			rc = dialogOnLine (line,2000L,"OK\r\n","AT\r") ;
			sleep (2) ;
			closeDevice (line) ;
		}
		else
			printf ("cannot open dial out line\n") ;
		unlockDevice (DIALOUT,port) ;
	}
	else
		printf ("cannot lock dial out line\n") ;
	return  rc ;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.