xref: /plan9/sys/src/cmd/tbl/ts.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
1 /* ts.c: minor string processing subroutines */
2 #include "t.h"
3 
4 int
match(char * s1,char * s2)5 match (char *s1, char *s2)
6 {
7 	while (*s1 == *s2)
8 		if (*s1++ == '\0')
9 			return(1);
10 		else
11 			s2++;
12 	return(0);
13 }
14 
15 
16 int
prefix(char * small,char * big)17 prefix(char *small, char *big)
18 {
19 	int	c;
20 
21 	while ((c = *small++) == *big++)
22 		if (c == 0)
23 			return(1);
24 	return(c == 0);
25 }
26 
27 
28 int
letter(int ch)29 letter (int ch)
30 {
31 	if (ch >= 'a' && ch <= 'z')
32 		return(1);
33 	if (ch >= 'A' && ch <= 'Z')
34 		return(1);
35 	return(0);
36 }
37 
38 
39 int
numb(char * str)40 numb(char *str)
41 {
42 				/* convert to integer */
43 	int	k;
44 	for (k = 0; *str >= '0' && *str <= '9'; str++)
45 		k = k * 10 + *str - '0';
46 	return(k);
47 }
48 
49 
50 int
digit(int x)51 digit(int x)
52 {
53 	return(x >= '0' && x <= '9');
54 }
55 
56 
57 int
max(int a,int b)58 max(int a, int b)
59 {
60 	return( a > b ? a : b);
61 }
62 
63 
64 void
tcopy(char * s,char * t)65 tcopy (char *s, char *t)
66 {
67 	while (*s++ = *t++)
68 		;
69 }
70 
71 
72