1: #ifndef lint
2: static char sccsid[] = "@(#)0.string.c 4.1 (Berkeley) 2/11/83";
3: #endif not lint
4:
5: #include <stdio.h>
6: #include "def.h"
7: #include "1.defs.h"
8:
9: str_copy(s,ptr,length) /* copy s at ptr, return length of s */
10: char *s, *ptr;
11: int length;
12: {int i;
13: for (i = 0; i < length; i++)
14: {
15: ptr[i] = s[i];
16: if (ptr[i] == '\0')
17: return(i + 1);
18: }
19: faterr("string too long to be copied at given address:\n",s,"");
20: }
21:
22:
23: find(s,ar,size)
24: char *s,*ar[];
25: int size;
26: {
27: int i;
28: for (i=0; i < size; i++)
29: {if (str_eq(s, ar[i])) return(i);}
30: return(-1);
31: }
32:
33:
34: str_eq(s,t)
35: char s[],t[];
36: {int j;
37: for (j = 0; s[j] == t[j]; j++)
38: {if (s[j] == '\0') return(1);}
39: return(0);
40: }
41:
42:
43: classmatch(c,i)
44: char c;
45: int i;
46: {switch(i)
47: {case _digit:
48: if ('0' <= c && c <= '9') return(1);
49: else return(0);
50:
51: case _letter:
52: if ( ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
53: return(1);
54: else return(0);
55:
56: case _diglet: return(classmatch(c,_digit)||classmatch(c,_letter) );
57:
58: case _arith:
59: if (050 <= c && c<= 057) return(1);
60: else return(0);
61: case _nl:
62: return(c=='\n');
63: case _other:
64: return(1);
65: }
66: }
67:
68:
69: copychars(cbeg,target,n) /* copy n chars from cbeg to target */
70: char *cbeg, *target;
71: int n;
72: {
73: int i;
74: for (i = 0; i < n; i++)
75: target[i] = cbeg[i];
76: }
77:
78:
79:
80: copycs(cbeg,target,n) /* copy n chars from cbeg to target, add '\0' */
81: char *cbeg, *target;
82: int n;
83: {
84: copychars(cbeg,target,n);
85: target[n] = '\0';
86: }
87:
88:
89: slength(s) /* return number of chars in s, not counting '\0' */
90: char *s;
91: {
92: int i;
93: if (!s) return(-1);
94: for (i = 0; s[i] != '\0'; i++);
95: return(i);
96: }
97:
98:
99: concat(x,y) /* allocate space, return xy */
100: char *x, *y;
101: {
102: char *temp;
103: int i,j;
104: i = slength(x);
105: j = slength(y);
106: temp = galloc(i + j + 1);
107: sprintf(temp,"%s",x);
108: sprintf(&temp[i],"%s",y);
109: return(temp);
110: }
Defined functions
find
defined in line
23; used 1 times
Defined variables
sccsid
defined in line
2;
never used