1: /* brkstring.c - break string into an array of strings */
2:
3: #include "../h/mh.h"
4:
5:
6: static char *broken[MAXARGS+1]; /* array of substring start addresses */
7:
8: char **brkstring (strg, brksep, brkterm)
9: register char *strg;
10: register char *brksep,
11: *brkterm;
12: {
13: register int bi;
14: register char c,
15: *sp;
16:
17: sp = strg; /* scan string, replacing separators with
18: zeroes */
19:
20: for (bi = 0; bi < MAXARGS; bi++) {
21: /* and entering start addrs in "broken" */
22: while (brkany (c = *sp, brksep))
23: *sp++ = 0;
24: if (!c || brkany (c, brkterm)) {
25: *sp = 0;
26: broken[bi] = 0;
27: return broken; /* terminator found, finish up */
28: }
29:
30: broken[bi] = sp; /* set next start addr */
31: while ((c = *++sp) && !brkany (c, brksep) && !brkany (c, brkterm))
32: continue;
33: }
34: broken[MAXARGS] = 0; /* reached limit of MAXARGS substrings */
35:
36: return broken;
37: }
38:
39:
40: static brkany (chr, strg) /* returns 1 if chr in strg, 0 otherwise */
41: register char chr,
42: *strg;
43: {
44: register char *sp;
45:
46: if (strg)
47: for (sp = strg; *sp; sp++)
48: if (chr == *sp)
49: return 1;
50: return 0;
51: }
Defined functions
Defined variables
broken
defined in line
6; used 5 times