xref: /csrg-svn/games/trek/utility.c (revision 60859)
121297Sdist /*
2*60859Sbostic  * Copyright (c) 1980, 1993
3*60859Sbostic  *	The Regents of the University of California.  All rights reserved.
434205Sbostic  *
542606Sbostic  * %sccs.include.redist.c%
621297Sdist  */
721297Sdist 
811702Smckusick #ifndef lint
9*60859Sbostic static char sccsid[] = "@(#)utility.c	8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111702Smckusick 
1211702Smckusick /*
1311702Smckusick **  ASSORTED UTILITY ROUTINES
1411702Smckusick */
1511702Smckusick 
1611702Smckusick /*
1711702Smckusick **  BLOCK MOVE
1811702Smckusick **
1911702Smckusick **	Moves a block of storage of length `l' bytes from the data
2011702Smckusick **	area pointed to by `a' to the area pointed to by `b'.
2111702Smckusick **	Returns the address of the byte following the `b' field.
2211702Smckusick **	Overflow of `b' is not tested.
2311702Smckusick */
2411702Smckusick 
bmove(a,b,l)2511702Smckusick char *bmove(a, b, l)
2611702Smckusick char	*a, *b;
2711702Smckusick int	l;
2811702Smckusick {
2911702Smckusick 	register int		n;
3011702Smckusick 	register char		*p, *q;
3111702Smckusick 
3211702Smckusick 	p = a;
3311702Smckusick 	q = b;
3411702Smckusick 	n = l;
3511702Smckusick 	while (n--)
3611702Smckusick 		*q++ = *p++;
3711702Smckusick 	return (q);
3811702Smckusick }
3911702Smckusick 
4011702Smckusick 
4111702Smckusick /*
4211702Smckusick **  STRING EQUALITY TEST
4311702Smckusick **	null-terminated strings `a' and `b' are tested for
4411702Smckusick **	absolute equality.
4511702Smckusick **	returns one if equal, zero otherwise.
4611702Smckusick */
4711702Smckusick 
sequal(a,b)4811702Smckusick sequal(a, b)
4911702Smckusick char	*a, *b;
5011702Smckusick {
5111702Smckusick 	register char		*p, *q;
5211702Smckusick 
5311702Smckusick 	p = a;
5411702Smckusick 	q = b;
5511702Smckusick 	while (*p || *q)
5611702Smckusick 		if (*p++ != *q++)
5711702Smckusick 			return(0);
5811702Smckusick 	return(1);
5911702Smckusick }
6011702Smckusick 
6111702Smckusick 
6211702Smckusick /*
6311702Smckusick **  STRING CONCATENATE
6411702Smckusick **
6511702Smckusick **	The strings `s1' and `s2' are concatenated and stored into
6611702Smckusick **	`s3'.  It is ok for `s1' to equal `s3', but terrible things
6711702Smckusick **	will happen if `s2' equals `s3'.  The return value is is a
6811702Smckusick **	pointer to the end of `s3' field.
6911702Smckusick */
7011702Smckusick 
concat(s1,s2,s3)7111702Smckusick char *concat(s1, s2, s3)
7211702Smckusick char	*s1, *s2, *s3;
7311702Smckusick {
7411702Smckusick 	register char		*p;
7511702Smckusick 	register char		*q;
7611702Smckusick 
7711702Smckusick 	p = s3;
7811702Smckusick 	q = s1;
7911702Smckusick 	while (*q)
8011702Smckusick 		*p++ = *q++;
8111702Smckusick 	q = s2;
8211702Smckusick 	while (*q)
8311702Smckusick 		*p++ = *q++;
8411702Smckusick 	*p = 0;
8511702Smckusick 	return (p);
8611702Smckusick }
8711702Smckusick 
8811702Smckusick 
8911702Smckusick /*
9011702Smckusick **  FIND STRING LENGTH
9111702Smckusick **
9211702Smckusick **	The length of string `s' (excluding the null byte which
9311702Smckusick **		terminates the string) is returned.
9411702Smckusick */
9511702Smckusick 
length(s)9611702Smckusick length(s)
9711702Smckusick char	*s;
9811702Smckusick {
9911702Smckusick 	register int	l;
10011702Smckusick 	register char	*p;
10111702Smckusick 
10211702Smckusick 	l = 0;
10311702Smckusick 	p = s;
10411702Smckusick 	while (*p++)
10511702Smckusick 		l++;
10611702Smckusick 	return(l);
10711702Smckusick }
10811702Smckusick 
10911702Smckusick 
11011702Smckusick /*
11111702Smckusick **  SYSTEM ERROR
11211702Smckusick */
11311702Smckusick 
syserr(p0,p1,p2,p3,p4,p5)11411702Smckusick syserr(p0, p1, p2, p3, p4, p5)
11511702Smckusick {
11611702Smckusick 	extern int	errno;
11711702Smckusick 
11811702Smckusick 	printf("\n\07TREK SYSERR: ");
11911702Smckusick 	printf(p0, p1, p2, p3, p4, p5);
12011702Smckusick 	printf("\n");
12111702Smckusick 	if (errno)
12211702Smckusick 		printf("\tsystem error %d\n", errno);
12311702Smckusick 	exit(-1);
12411702Smckusick }
125