xref: /inferno-os/appl/lib/tcl_utils.b (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1implement Tcl_Utils;
2include "sys.m";
3include "draw.m";
4include "tk.m";
5include "tcl.m";
6include "tcllib.m";
7include "utils.m";
8
9break_it(s : string) : array of string {
10	argv:= array[200] of string;
11	buf : string;
12	argc := 0;
13	nc := 0;
14   outer:
15	for (i := 0; i < len s ; ) {
16		case int s[i] {
17		' ' or '\t' or '\n' =>
18			if (nc > 0) {	# end of a word?
19				argv[argc++] = buf;
20				buf = nil;
21				nc = 0;
22			}
23			i++;
24		'{' =>
25			if (s[i+1]=='}'){
26				argv[argc++] = nil;
27				buf = nil;
28				nc = 0;
29				i+=2;
30			}else{
31				nbra := 1;
32				for (i++; i < len s; i++) {
33					if (s[i] == '{')
34						nbra++;
35					else if (s[i] == '}') {
36						nbra--;
37					if (nbra == 0) {
38							i++;
39							continue outer;
40						}
41					}
42					buf[nc++] = s[i];
43				}
44			}
45		* =>
46			buf[nc++] = s[i++];
47		}
48	}
49	if (nc > 0)	# fix up last word if present
50		argv[argc++] = buf;
51	ret := array[argc] of string;
52	ret[0:] = argv[0:argc];
53	return ret;
54}
55
56arr_resize(argv : array of string) : array of string {
57	ret := array[len argv + 25] of string;
58	ret[0:]=argv;
59	return ret;
60}
61
62