148123Sbostic /*-
248123Sbostic  * %sccs.include.proprietary.c%
348123Sbostic  */
448123Sbostic 
510947Srrh #ifndef lint
6*62264Sbostic static char sccsid[] = "@(#)0.string.c	8.1 (Berkeley) 06/06/93";
748123Sbostic #endif /* not lint */
810947Srrh 
910947Srrh #include <stdio.h>
1010947Srrh #include "def.h"
1110947Srrh #include "1.defs.h"
1210947Srrh 
str_copy(s,ptr,length)1310947Srrh str_copy(s,ptr,length)	/* copy s at ptr, return length of s */
1410947Srrh char *s, *ptr;
1510947Srrh int length;
1610947Srrh 	{int i;
1710947Srrh 	for (i = 0; i < length; i++)
1810947Srrh 		{
1910947Srrh 		ptr[i] = s[i];
2010947Srrh 		if (ptr[i] == '\0')
2110947Srrh 			return(i + 1);
2210947Srrh 		}
2310947Srrh 	faterr("string too long to be copied at given address:\n",s,"");
2410947Srrh 	}
2510947Srrh 
2610947Srrh 
find(s,ar,size)2710947Srrh find(s,ar,size)
2810947Srrh char *s,*ar[];
2910947Srrh int size;
3010947Srrh 	{
3110947Srrh 	int i;
3210947Srrh 	for (i=0; i < size; i++)
3310947Srrh 		{if (str_eq(s, ar[i])) return(i);}
3410947Srrh 	return(-1);
3510947Srrh 	}
3610947Srrh 
3710947Srrh 
str_eq(s,t)3810947Srrh str_eq(s,t)
3910947Srrh char s[],t[];
4010947Srrh 	{int j;
4110947Srrh 	for (j = 0; s[j] == t[j]; j++)
4210947Srrh 		{if (s[j] == '\0') return(1);}
4310947Srrh 	return(0);
4410947Srrh 	}
4510947Srrh 
4610947Srrh 
classmatch(c,i)4710947Srrh classmatch(c,i)
4810947Srrh char c;
4910947Srrh int i;
5010947Srrh 	{switch(i)
5110947Srrh 		{case _digit:
5210947Srrh 			if ('0' <= c && c <= '9')  return(1);
5310947Srrh 			else return(0);
5410947Srrh 
5510947Srrh 		case _letter:
5610947Srrh 			if ( ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
5710947Srrh 				return(1);
5810947Srrh 			else return(0);
5910947Srrh 
6010947Srrh 		case _diglet:  return(classmatch(c,_digit)||classmatch(c,_letter) );
6110947Srrh 
6210947Srrh 		case _arith:
6310947Srrh 			if (050 <= c && c<= 057)  return(1);
6410947Srrh 			else return(0);
6510947Srrh 		case _nl:
6610947Srrh 			return(c=='\n');
6710947Srrh 		case _other:
6810947Srrh 			return(1);
6910947Srrh 		}
7010947Srrh 	}
7110947Srrh 
7210947Srrh 
copychars(cbeg,target,n)7310947Srrh copychars(cbeg,target,n)		/* copy n chars from cbeg to target */
7410947Srrh char *cbeg, *target;
7510947Srrh int n;
7610947Srrh 	{
7710947Srrh 	int i;
7810947Srrh 	for (i = 0; i < n; i++)
7910947Srrh 		target[i] = cbeg[i];
8010947Srrh 	}
8110947Srrh 
8210947Srrh 
8310947Srrh 
copycs(cbeg,target,n)8410947Srrh copycs(cbeg,target,n)			/* copy n chars from cbeg to target, add '\0' */
8510947Srrh char *cbeg, *target;
8610947Srrh int n;
8710947Srrh 	{
8810947Srrh 	copychars(cbeg,target,n);
8910947Srrh 	target[n] = '\0';
9010947Srrh 	}
9110947Srrh 
9210947Srrh 
slength(s)9310947Srrh slength(s)			/* return number of chars in s, not counting '\0' */
9410947Srrh char *s;
9510947Srrh 	{
9610947Srrh 	int i;
9710947Srrh 	if (!s) return(-1);
9810947Srrh 	for (i = 0; s[i] != '\0'; i++);
9910947Srrh 	return(i);
10010947Srrh 	}
10110947Srrh 
10210947Srrh 
concat(x,y)10310947Srrh concat(x,y)			/* allocate space, return xy */
10410947Srrh char *x, *y;
10510947Srrh 	{
10610947Srrh 	char *temp;
10710947Srrh 	int i,j;
10810947Srrh 	i = slength(x);
10910947Srrh 	j = slength(y);
11010947Srrh 	temp = galloc(i + j + 1);
11110947Srrh 	sprintf(temp,"%s",x);
11210947Srrh 	sprintf(&temp[i],"%s",y);
11310947Srrh 	return(temp);
11410947Srrh 	}
115