Commit | Line | Data |
---|---|---|
520d5775 EA |
1 | /* |
2 | ** ASSORTED UTILITY ROUTINES | |
3 | */ | |
4 | ||
5 | /* | |
6 | ** BLOCK MOVE | |
7 | ** | |
8 | ** Moves a block of storage of length `l' bytes from the data | |
9 | ** area pointed to by `a' to the area pointed to by `b'. | |
10 | ** Returns the address of the byte following the `b' field. | |
11 | ** Overflow of `b' is not tested. | |
12 | */ | |
13 | ||
14 | char *bmove(a, b, l) | |
15 | char *a, *b; | |
16 | int l; | |
17 | { | |
18 | register int n; | |
19 | register char *p, *q; | |
20 | ||
21 | p = a; | |
22 | q = b; | |
23 | n = l; | |
24 | while (n--) | |
25 | *q++ = *p++; | |
26 | return (q); | |
27 | } | |
28 | ||
29 | ||
30 | /* | |
31 | ** STRING EQUALITY TEST | |
32 | ** null-terminated strings `a' and `b' are tested for | |
33 | ** absolute equality. | |
34 | ** returns one if equal, zero otherwise. | |
35 | */ | |
36 | ||
37 | sequal(a, b) | |
38 | char *a, *b; | |
39 | { | |
40 | register char *p, *q; | |
41 | ||
42 | p = a; | |
43 | q = b; | |
44 | while (*p || *q) | |
45 | if (*p++ != *q++) | |
46 | return(0); | |
47 | return(1); | |
48 | } | |
49 | ||
50 | ||
51 | /* | |
52 | ** STRING CONCATENATE | |
53 | ** | |
54 | ** The strings `s1' and `s2' are concatenated and stored into | |
55 | ** `s3'. It is ok for `s1' to equal `s3', but terrible things | |
56 | ** will happen if `s2' equals `s3'. The return value is is a | |
57 | ** pointer to the end of `s3' field. | |
58 | */ | |
59 | ||
60 | char *concat(s1, s2, s3) | |
61 | char *s1, *s2, *s3; | |
62 | { | |
63 | register char *p; | |
64 | register char *q; | |
65 | ||
66 | p = s3; | |
67 | q = s1; | |
68 | while (*q) | |
69 | *p++ = *q++; | |
70 | q = s2; | |
71 | while (*q) | |
72 | *p++ = *q++; | |
73 | *p = 0; | |
74 | return (p); | |
75 | } | |
76 | ||
77 | ||
78 | /* | |
79 | ** FIND STRING LENGTH | |
80 | ** | |
81 | ** The length of string `s' (excluding the null byte which | |
82 | ** terminates the string) is returned. | |
83 | */ | |
84 | ||
85 | length(s) | |
86 | char *s; | |
87 | { | |
88 | register int l; | |
89 | register char *p; | |
90 | ||
91 | l = 0; | |
92 | p = s; | |
93 | while (*p++) | |
94 | l++; | |
95 | return(l); | |
96 | } | |
97 | ||
98 | ||
99 | /* | |
100 | ** SYSTEM ERROR | |
101 | */ | |
102 | ||
103 | syserr(p0, p1, p2, p3, p4, p5) | |
104 | { | |
105 | extern int errno; | |
106 | ||
107 | printf("\n\07TREK SYSERR: "); | |
108 | printf(p0, p1, p2, p3, p4, p5); | |
109 | printf("\n"); | |
110 | if (errno) | |
111 | printf("\tsystem error %d\n", errno); | |
112 | exit(-1); | |
113 | } |