Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
2
Indexable
Never
GET "libhdr.h"

MANIFEST
{	len = 0
	cnt = 1
	data = 2
	upb = 3
}

LET start() = VALOF
{	LET arr = "*x01*x05*x00*x07*x02*x09*x00*x04"
	AND out = getarr(5)

	FOR i = 1 TO arr%0 DO
	{ TEST arr%i = '*x00' THEN
		{	IF out!data!(out!cnt)!cnt > 0 DO
			{	out!cnt +:= 1
				IF out!cnt = out!len DO grwarr(out, out!len*2)
				out!data!(out!cnt)!data := getarr(5)
			}
		}
	  ELSE
		{	LET p = out!data!(out!cnt)
			TEST p = 0 THEN { p := getarr(5); out!data!(out!cnt) := p }
			ELSE IF p!cnt = p!len DO grwarr((p!cnt)-1, out!data!len*2)
			p!data!(p!cnt) := arr%i
			p!cnt +:= 1
		}
	}

	FOR i = 0 TO out!cnt DO
	{	FOR j = 0 TO out!data!i!cnt-1 DO writef("%n ",out!data!i!data!j)
		wrch('*n')
	}

	cleanup(out)

	RESULTIS 0
}

AND getarr(n) = VALOF
{	LET new = getvec(upb)
	new!len := n
	new!cnt := 0
	new!data := getvec(n)
	FOR i = 0 TO n-1 DO new!data!i := 0
	RESULTIS new
}

AND grwarr(a, n) BE
{	LET new = getvec(n)
	FOR i = 0 TO a!len-1 DO new!data!i := a!data!i
	freevec(a!data)
	a!data := new
	a!len := n
}

AND cleanup(a) BE
{	FOR i = 0 TO a!cnt DO freevec(a!data!i)
	freevec(a!data)
}
Leave a Comment