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

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

/*********************************************************************/
/*                                                                   */
/* Programmer:                                                       */
/*   Olaf Mueller <olaf@orest.escape.de>                             */
/*                                                                   */
/* Purpose:                                                          */
/*   Answering Machine                                               */
/*       some IO on a device                                         */
/*                                                                   */
/* History:                                                          */
/*   29-08-96   Initial Release           Olaf Mueller               */
/*                                                                   */
/* Notes:                                                            */
/*                                                                   */
/*********************************************************************/

#include <libc.h>

#include "timer.h"
#include "iodev.h"


long readUntil (int line,long msec,char *until)
{
	int		untillength = strlen (until) ;
	char	buffer [untillength] ;
	int		untilpos = 0 , buflen = 0 , ii ;

	setTimer (ITIMER_REAL,msec) ;
	while (untilpos < untillength)
	{
		if ((buflen = read(line,buffer,untillength-untilpos)) > 0)
		{
			for (ii = 0 ; ii < buflen ; ii++)
			{
//printf ("readUntil: %c (%02x)\n",buffer[ii]<32?' ':buffer[ii],buffer[ii]) ;
				if (*(until+untilpos) == buffer[ii])
					untilpos++ ;
				else if (*until == buffer[ii])
					untilpos = 1 ;
				else
					untilpos = 0 ;
			}
		}
		else
			break ;
	}
	return  (buflen > 0) ? msec - setTimer(ITIMER_REAL,0L) : -1L ;
}


long readAnswerUntil (int line,long msec,char *answer,int answerlength,char *until)
{
	int		untillength = strlen (until) ;
	char	buffer [untillength] ;
	int		answerpos = 0 , untilpos = 0 , buflen = 0 , ii ;

	setTimer (ITIMER_REAL,msec) ;
	while (untilpos < untillength)
	{
		if ((buflen = read(line,buffer,untillength-untilpos)) > 0)
		{
			for (ii = 0 ; ii < buflen ; ii++)
			{
//printf ("readAnswerUntil: %c (%02x)\n",buffer[ii]<32?' ':buffer[ii],buffer[ii]) ;
				if (answerpos < answerlength)
					*(answer+answerpos++) = buffer[ii] ;
				if (*(until+untilpos) == buffer[ii])
					untilpos++ ;
				else if (*until == buffer[ii])
					untilpos = 1 ;
				else
					untilpos = 0 ;
			}
		}
		else
			break ;
	}
	if (buflen > 0)
	{
		*(answer+answerpos-untillength) = '\0' ;
		return  msec - setTimer(ITIMER_REAL,0L) ;
	}
	else
		return  -1L ;
}

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