removed support for -r, -h, and rmail
[unix-history] / usr / src / games / trek / utility.c
CommitLineData
bb0cfa24
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
e9fb6bea
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
bb0cfa24
DF
11 */
12
713e2710 13#ifndef lint
e9fb6bea
KB
14static char sccsid[] = "@(#)utility.c 5.2 (Berkeley) %G%";
15#endif /* not lint */
713e2710
KM
16
17/*
18** ASSORTED UTILITY ROUTINES
19*/
20
21/*
22** BLOCK MOVE
23**
24** Moves a block of storage of length `l' bytes from the data
25** area pointed to by `a' to the area pointed to by `b'.
26** Returns the address of the byte following the `b' field.
27** Overflow of `b' is not tested.
28*/
29
30char *bmove(a, b, l)
31char *a, *b;
32int l;
33{
34 register int n;
35 register char *p, *q;
36
37 p = a;
38 q = b;
39 n = l;
40 while (n--)
41 *q++ = *p++;
42 return (q);
43}
44
45
46/*
47** STRING EQUALITY TEST
48** null-terminated strings `a' and `b' are tested for
49** absolute equality.
50** returns one if equal, zero otherwise.
51*/
52
53sequal(a, b)
54char *a, *b;
55{
56 register char *p, *q;
57
58 p = a;
59 q = b;
60 while (*p || *q)
61 if (*p++ != *q++)
62 return(0);
63 return(1);
64}
65
66
67/*
68** STRING CONCATENATE
69**
70** The strings `s1' and `s2' are concatenated and stored into
71** `s3'. It is ok for `s1' to equal `s3', but terrible things
72** will happen if `s2' equals `s3'. The return value is is a
73** pointer to the end of `s3' field.
74*/
75
76char *concat(s1, s2, s3)
77char *s1, *s2, *s3;
78{
79 register char *p;
80 register char *q;
81
82 p = s3;
83 q = s1;
84 while (*q)
85 *p++ = *q++;
86 q = s2;
87 while (*q)
88 *p++ = *q++;
89 *p = 0;
90 return (p);
91}
92
93
94/*
95** FIND STRING LENGTH
96**
97** The length of string `s' (excluding the null byte which
98** terminates the string) is returned.
99*/
100
101length(s)
102char *s;
103{
104 register int l;
105 register char *p;
106
107 l = 0;
108 p = s;
109 while (*p++)
110 l++;
111 return(l);
112}
113
114
115/*
116** SYSTEM ERROR
117*/
118
119syserr(p0, p1, p2, p3, p4, p5)
120{
121 extern int errno;
122
123 printf("\n\07TREK SYSERR: ");
124 printf(p0, p1, p2, p3, p4, p5);
125 printf("\n");
126 if (errno)
127 printf("\tsystem error %d\n", errno);
128 exit(-1);
129}