xref: /csrg-svn/games/trek/utility.c (revision 34205)
121297Sdist /*
221297Sdist  * Copyright (c) 1980 Regents of the University of California.
3*34205Sbostic  * All rights reserved.
4*34205Sbostic  *
5*34205Sbostic  * Redistribution and use in source and binary forms are permitted
6*34205Sbostic  * provided that this notice is preserved and that due credit is given
7*34205Sbostic  * to the University of California at Berkeley. The name of the University
8*34205Sbostic  * may not be used to endorse or promote products derived from this
9*34205Sbostic  * software without specific prior written permission. This software
10*34205Sbostic  * is provided ``as is'' without express or implied warranty.
1121297Sdist  */
1221297Sdist 
1311702Smckusick #ifndef lint
14*34205Sbostic static char sccsid[] = "@(#)utility.c	5.2 (Berkeley) 05/05/88";
15*34205Sbostic #endif /* not lint */
1611702Smckusick 
1711702Smckusick /*
1811702Smckusick **  ASSORTED UTILITY ROUTINES
1911702Smckusick */
2011702Smckusick 
2111702Smckusick /*
2211702Smckusick **  BLOCK MOVE
2311702Smckusick **
2411702Smckusick **	Moves a block of storage of length `l' bytes from the data
2511702Smckusick **	area pointed to by `a' to the area pointed to by `b'.
2611702Smckusick **	Returns the address of the byte following the `b' field.
2711702Smckusick **	Overflow of `b' is not tested.
2811702Smckusick */
2911702Smckusick 
3011702Smckusick char *bmove(a, b, l)
3111702Smckusick char	*a, *b;
3211702Smckusick int	l;
3311702Smckusick {
3411702Smckusick 	register int		n;
3511702Smckusick 	register char		*p, *q;
3611702Smckusick 
3711702Smckusick 	p = a;
3811702Smckusick 	q = b;
3911702Smckusick 	n = l;
4011702Smckusick 	while (n--)
4111702Smckusick 		*q++ = *p++;
4211702Smckusick 	return (q);
4311702Smckusick }
4411702Smckusick 
4511702Smckusick 
4611702Smckusick /*
4711702Smckusick **  STRING EQUALITY TEST
4811702Smckusick **	null-terminated strings `a' and `b' are tested for
4911702Smckusick **	absolute equality.
5011702Smckusick **	returns one if equal, zero otherwise.
5111702Smckusick */
5211702Smckusick 
5311702Smckusick sequal(a, b)
5411702Smckusick char	*a, *b;
5511702Smckusick {
5611702Smckusick 	register char		*p, *q;
5711702Smckusick 
5811702Smckusick 	p = a;
5911702Smckusick 	q = b;
6011702Smckusick 	while (*p || *q)
6111702Smckusick 		if (*p++ != *q++)
6211702Smckusick 			return(0);
6311702Smckusick 	return(1);
6411702Smckusick }
6511702Smckusick 
6611702Smckusick 
6711702Smckusick /*
6811702Smckusick **  STRING CONCATENATE
6911702Smckusick **
7011702Smckusick **	The strings `s1' and `s2' are concatenated and stored into
7111702Smckusick **	`s3'.  It is ok for `s1' to equal `s3', but terrible things
7211702Smckusick **	will happen if `s2' equals `s3'.  The return value is is a
7311702Smckusick **	pointer to the end of `s3' field.
7411702Smckusick */
7511702Smckusick 
7611702Smckusick char *concat(s1, s2, s3)
7711702Smckusick char	*s1, *s2, *s3;
7811702Smckusick {
7911702Smckusick 	register char		*p;
8011702Smckusick 	register char		*q;
8111702Smckusick 
8211702Smckusick 	p = s3;
8311702Smckusick 	q = s1;
8411702Smckusick 	while (*q)
8511702Smckusick 		*p++ = *q++;
8611702Smckusick 	q = s2;
8711702Smckusick 	while (*q)
8811702Smckusick 		*p++ = *q++;
8911702Smckusick 	*p = 0;
9011702Smckusick 	return (p);
9111702Smckusick }
9211702Smckusick 
9311702Smckusick 
9411702Smckusick /*
9511702Smckusick **  FIND STRING LENGTH
9611702Smckusick **
9711702Smckusick **	The length of string `s' (excluding the null byte which
9811702Smckusick **		terminates the string) is returned.
9911702Smckusick */
10011702Smckusick 
10111702Smckusick length(s)
10211702Smckusick char	*s;
10311702Smckusick {
10411702Smckusick 	register int	l;
10511702Smckusick 	register char	*p;
10611702Smckusick 
10711702Smckusick 	l = 0;
10811702Smckusick 	p = s;
10911702Smckusick 	while (*p++)
11011702Smckusick 		l++;
11111702Smckusick 	return(l);
11211702Smckusick }
11311702Smckusick 
11411702Smckusick 
11511702Smckusick /*
11611702Smckusick **  SYSTEM ERROR
11711702Smckusick */
11811702Smckusick 
11911702Smckusick syserr(p0, p1, p2, p3, p4, p5)
12011702Smckusick {
12111702Smckusick 	extern int	errno;
12211702Smckusick 
12311702Smckusick 	printf("\n\07TREK SYSERR: ");
12411702Smckusick 	printf(p0, p1, p2, p3, p4, p5);
12511702Smckusick 	printf("\n");
12611702Smckusick 	if (errno)
12711702Smckusick 		printf("\tsystem error %d\n", errno);
12811702Smckusick 	exit(-1);
12911702Smckusick }
130