
#include "bbscdef.h"
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>

strfill(buf,fillchar,length)	/* fill a string with fillchar */
char	*buf;			/*  for length -1 */
int	fillchar,
	length;
	{
	while(--length)		/* really is length -1 */
		{
		*buf++ = fillchar;
		}
	*buf++ = '\0';		/* need room for this */
	}
#ifndef ATT3B1

substr(from,to,start,length)	/* moves chars from "from" to "to" */
char	*from, *to ;		/*  starting at "start" for */
	    			/*  "length" number of chars */
int	start, length ;		/* for beginning of string use 1, not 0 */
	{
	int	cnt;

	cnt = 0;

	while(--start)		/* adjust sending field pointer */
		{
		from++;		
		}

	while((cnt < length) && (*to++ = *from++))	/* do the moving */
		{
		cnt++;		
		}
	
	*to = '\0';

	}
#endif

#ifdef ATT3B1

substr(from,to,start,length)
char *from,*to;
int start,length;
{
   int cnt, i;

   cnt = 0;
   while(--start)
       from++;

   i=0;
   while(cnt < length)
      if (from[i] == NULL)
         break;
      else {
         to[i] = from[i];
         i++;
         cnt++;
     }

   to[i] = NULL;
}

#endif

itoa(str,n)		/* taken from float.c */
char *str;
	{
	sprintf(str,"%d",n) ;
	}
/*	end of function		*/

seek(fildes,posit,dummy) int fildes,posit,dummy ;
	{
long	pos;
	pos = posit * 128L ;
/*	return(lseek(fildes,posit << 7,0)) ;    */
	return(lseek(fildes,pos,0)) ;
	}
/*	end of function		*/

char *basename(x)  char *x;
{
	char *ptr;
	ptr = strrchr(x, '/');
	if ( ptr == (char *)NULL )
		return(x);
	else
		return(++ptr);
}

int legalname( co, strg )
char *co, *strg;
{
	char *ptr, *indx;
	int i;
	ptr = co;
	while ( *ptr ) {
		i = (int) *ptr++;
		indx = strchr(strg, i);
		if ( indx != NULL )
			return(0);
	}
	return(1);
}

int asciicheck(fne)
char *fne;
{
	FILE *tbuf;
	int datar;
	if((tbuf = fopen(fne, "r")) == NULL )
		return(0);
	while ((datar = getc(tbuf)) != EOF ) {
		if(isprint(datar) == 0 && isspace(datar) == 0) {
			fclose(tbuf);
			return(0);
		}
	}
	fclose(tbuf);
	return(1);
}
	
	
/*	end of program  	*/
