1: /* $Header$ */
2:
3: /*
4: * Author: Peter J. Nicklin
5: */
6: #include <ctype.h>
7: #include "null.h"
8: #include "path.h"
9: #include "yesno.h"
10:
11: /*
12: * ispdt() returns 1 if project directory type label is legal,
13: * otherwise zero.
14: */
15: ispdt(type)
16: char *type; /* type label */
17: {
18: register char *tp; /* type label pointer */
19: register int body = NO; /* does type label have a body? */
20:
21: for (tp = type; *tp != '\0' && *tp != '.'; tp++)
22: switch (*tp)
23: {
24: case ' ':
25: case '\t':
26: continue;
27: default:
28: body = YES;
29: break;
30: }
31: if (body == NO)
32: return(0);
33: if (*tp == '.')
34: {
35: tp++;
36: if (*tp == '-' || *tp == '+')
37: tp++;
38: while (isdigit(*tp))
39: tp++;
40: }
41: return((*tp == '\0') ? 1 : 0);
42: }
43:
44:
45:
46: /*
47: * pdtcpy() copies a project directory type pointed to by tb, to type.
48: * Returns type.
49: */
50: char *
51: pdtcpy(type, tb)
52: register char *type; /* receiving type buffer */
53: register char *tb; /* type pointer */
54: {
55: register int i; /* type buffer index */
56:
57: for (i = 0; *tb != _PDTSC && *tb != '\0'; i++)
58: type[i] = *tb++;
59: type[i] = '\0';
60: return(type);
61: }
62:
63:
64:
65: /*
66: * pdtfind() compares project directory type label type with the type
67: * labels stored in type label buffer tb and returns a pointer to the
68: * position of the type label in the buffer if found, otherwise NULL.
69: */
70: char *
71: pdtfind(type, tb)
72: char *type; /* type label */
73: register char *tb; /* type label buffer */
74: {
75: char *tskip(); /* skip to next type label */
76: int tcmp(); /* compare type labels */
77:
78: for (; *tb != '\0'; tb = tskip(tb))
79: {
80: if (tcmp(type, tb) == 0)
81: return(tb);
82: }
83: return(NULL);
84: }
85:
86:
87:
88: /*
89: * pdtinsert() inserts a type in type label buffer tb. The type labels
90: * within tb are assumed to be sorted into ascending order. tb must
91: * be big enough to hold type.
92: */
93: void
94: pdtinsert(type, tb)
95: register char *type; /* type label */
96: char *tb; /* type label buffer */
97: {
98: register char *tp; /* type label buffer pointer */
99: char *tskip(); /* skip to next type label */
100: char *strcpy(); /* string copy */
101: int strlen(); /* string length */
102: int typlen; /* type label length */
103: int tcmp(); /* compare type labels */
104: void tstretch(); /* stretch type label buffer */
105:
106: for (tp = tb; *tp != '\0'; tp = tskip(tp))
107: if (tcmp(type, tp) < 0)
108: break;
109: typlen = strlen(type);
110: if (*tp == '\0') /* append to the buffer */
111: if (tp > tb)
112: {
113: tstretch(tp, typlen+1);
114: *tp = _PDTSC;
115: strcpy(tp+1, type);
116: }
117: else { /* empty buffer */
118: tstretch(tp, typlen);
119: strcpy(tp, type);
120: }
121: else { /* insert in the buffer */
122: tstretch(tp, typlen+1);
123: strcpy(tp, type);
124: tp[typlen] = _PDTSC;
125: }
126: }
127:
128:
129:
130: /*
131: * pdtrm() removes type label type from type label buffer tb.
132: */
133: void
134: pdtrm(type, tb)
135: char *type; /* type label to be removed */
136: register char *tb; /* type label buffer */
137: {
138: register char *tp; /* type label buffer pointer */
139: char *tskip(); /* skip to next type label */
140: int tcmp(); /* compare type labels */
141: int tlen(); /* length of type label */
142: int typlen; /* type label length */
143: void tstretch(); /* stretch type label buffer */
144:
145: for (tp = tb; *tp != '\0'; tp = tskip(tp))
146: if (tcmp(type, tp) == 0)
147: {
148: typlen = tlen(tp);
149: if (tp[typlen] == _PDTSC)
150: tstretch(tp, -(typlen+1));
151: else
152: tstretch(tp, -typlen);
153: if (tp > tb && tp[0] == '\0' && tp[-1] == _PDTSC)
154: tp[-1] = '\0';
155: break;
156: }
157: }
158:
159:
160:
161: /*
162: * tcmp() compares project directory type labels and returns an integer
163: * greater than, equal to, or less than 0, depending on whether type is
164: * lexicographically greater than, equal to, or less than the type
165: * pointed to by tp.
166: */
167: static int
168: tcmp(type, tp)
169: register char *type; /* type label to be compared */
170: register char *tp; /* type pointer */
171: {
172: for (; *tp == *type && *type != '\0'; tp++, type++)
173: continue;
174: if (*type == '\0' && (*tp == _PDTSC || *tp == '.' || *tp == '\0'))
175: return(0);
176: return(*type - *tp);
177: }
178:
179:
180:
181: /*
182: * tlen() returns the length of the type label pointed to by type label
183: * buffer pointer tp.
184: */
185: static int
186: tlen(tp)
187: register char *tp; /* type label buffer pointer */
188: {
189: register int n; /* length counter */
190:
191: for (n = 0; *tp != _PDTSC && *tp != '\0'; tp++, n++)
192: continue;
193: return(n);
194: }
195:
196:
197:
198: /*
199: * tskip() advances type pointer, tp, to the next project directory type
200: * label.
201: */
202: static char *
203: tskip(tp)
204: register char *tp; /* type label pointer */
205: {
206: while (*tp != _PDTSC && *tp != '\0')
207: tp++;
208: if (*tp == _PDTSC)
209: tp++;
210: return(tp);
211: }
212:
213:
214:
215: /*
216: * tstretch() stretches type label buffer by n characters just before the point
217: * marked by type pointer tp. Negative n shrinks buffer by n characters.
218: */
219: static void
220: tstretch(tp, n)
221: register char *tp; /* type label buffer pointer */
222: int n; /* stretch amount */
223: {
224: register char *lowertp; /* lower roving type label buffer ptr */
225: register char *uppertp; /* upper roving type label buffer ptr */
226:
227: if (n > 0)
228: {
229: for (lowertp = tp; *lowertp != '\0'; lowertp++)
230: continue;
231: uppertp = lowertp + n;
232: while (lowertp >= tp)
233: *uppertp-- = *lowertp--;
234: }
235: else if (n < 0)
236: {
237: for (uppertp = tp; *uppertp != '\0'; uppertp++)
238: continue;
239: lowertp = tp - n;
240: if (lowertp >= uppertp)
241: *tp = '\0';
242: while (lowertp <= uppertp)
243: *tp++ = *lowertp++;
244: }
245: }
Defined functions
ispdt
defined in line
15;
never used
tcmp
defined in line
167; used 6 times
tlen
defined in line
185; used 2 times