#
/*
*	SCCS File Type - 
*
* 	What identification string
*/
static char *_S_editroutc =   "@(#)Ned_rout.c	1.8";
#include "KERcalls.h"
#include "NKSRdefs.h"
#include "NKedit.h"


/* scaner in UNIX */

scaner(string)
register char    string[];
{
	register int     i = 0;          /* position pointer */

	while(((string[i++]=getchar()) != '\n') && (i <= LINELENGTH));
	string[--i] = ENDSTRING;
	printf("\n");

	return;
}



/* strcopy copies string for a given length
 * or to the end of the string
 * given char pointers and length
 * returns number of characters copied
 * assumes length >= 0
 */

strcopy(as,at,length)
char *as,*at;
int  length;
{
	register char *s, *t;
	register int l = 1;
	s = as; t = at;
	while( l <= length && *t )
	{
		l++;
		*s++ = *t++;
	}
	return(l - 1);
}

/*
 *      Fill the named string with null characters.
 */
blankout(string,length)
register char    string[];
register int     length;
{
	register int     i;

	for (i=0; i < length; string[i++] = 0);
	return;
}


/*
 *       read response to a yes or no question.
 *       return char only after a y or n received
 */
char yesorno()
{
	register char    answer[LINELENGTH];             /* response */

	while(FOREVER)
	{
		scaner( answer);

		if ((answer[0] == 'y') || (answer[0] == 'Y'))
			return (YES);
		else if ((answer[0] == 'n') || (answer[0] == 'N'))
			return(NO);
		else
			printf ("Please type y or n : ");
	}
}
/*
 * get decimal number from standard input
 * called by getcompart
 * calls none
 */
int getdec(number,cc)
int     *number;
char    *cc;
{
	char    result = OFF;
	register char    input[LINELENGTH];
	register int     i;

	for(i=0; i<=LINELENGTH; i++)
	{
		/* if input is not a digit, assign char to cc and end getchar */
		if(((input[i] = getchar()) < '0') || input[i] > '9')
		{
			*cc = input[i];
			break;
		}
	}

	/* if there has been a number entered, then convert it and set flag */
	if(i>0)
	{
		input[i] = ENDSTRING;
		*number = atoi(input);
		result = ON;
	}

	return(result);
}

/*
 *        Check for non printable characters
 *        in string.
 */
int prtable(string,length)
char    string[];
int     length;
{
	int     i = 0;          /* counter */
	int     error = OFF;    /* error flag */

	while ((i <= length) && (string[i] != ENDSTRING) && (error == OFF))

		if (string[i++] < ASCIPRTABLE)
			error = ON;

	return(error);
}

toupcase(string,length)
register char *string;
int      length;
{
	register char    nc;             /* char of string named */
	register int     i;              /* index through string */

	/* convert any lowercase char to uppercase */
	for (i = 0; (i <= length) && ((nc = string[i]) != ENDSTRING); i++)
		if (nc >= 'a' && nc <= 'z')
			string[i] -= CASEDIFF;
	return;
}

/*
 *     ascii to integer conversion routine
 */
atoi(ap)
char *ap;
{
	register n, c;
	register char *p;
	int f;

	p = ap;
	n = 0;
	f = 0;
loop:
	while(*p == ' ' || *p == '	')
		p++;
	if(*p == '-') {
		f++;
		p++;
		goto loop;
	}
	while(*p >= '0' && *p <= '9')
		n = n*10 + *p++ - '0';
	if(f)
		n = -n;
	return(n);
}


long
atol(ap)                /* ascii to long conversion routine */
char *ap;
{
	register c;
	register char *p;
	int f;
	long	l;

	p = ap;
	l = 0;
	f = 0;
loop:
	while(*p == ' ' || *p == '	')
		p++;
	if(*p == '-') {
		f++;
		p++;
		goto loop;
	}
	while(*p >= '0' && *p <= '9')
		l = l*10 + *p++ - '0';
	if(f)
		l = -l;
	return(l);
}
