Example #1
0
func DumpZObjectsTree(mem *gork.ZMemory, header *gork.ZHeader) {

	fmt.Print("\n    **** Object tree ****\n\n")

	total, err := gork.ZObjectsCount(mem, header)
	if err != nil {
		panic(err)
	}

	var printObject func(obj *gork.ZObject, depth int)
	printObject = func(obj *gork.ZObject, depth int) {
		for {

			for j := 0; j < depth; j++ {
				fmt.Print(" . ")
			}
			fmt.Printf("[%3d] ", obj.Id())
			fmt.Printf("\"%s\"\n", obj.Name())

			if obj.ChildId() != 0 {
				childobj, err := gork.NewZObject(mem, obj.ChildId(), header)
				if err != nil {
					panic(err)
				}
				printObject(childobj, depth+1)
			}

			if obj.SiblingId() == 0 {
				break
			}
			obj, err = gork.NewZObject(mem, obj.SiblingId(), header)
			if err != nil {
				panic(err)
			}
		}
	}

	for i := uint8(1); i <= total; i++ {
		zobj, err := gork.NewZObject(mem, i, header)
		if err != nil {
			panic(err)
		}

		// root
		if zobj.ParentId() == 0 {
			printObject(zobj, 0)
			break
		}
	}
}
Example #2
0
func DumpAllZObjects(mem *gork.ZMemory, header *gork.ZHeader) {
	total, err := gork.ZObjectsCount(mem, header)
	if err != nil {
		panic(err)
	}

	fmt.Print("\n    **** Objects ****\n\n")
	fmt.Printf("  Object count = %d\n\n", total)

	for i := uint8(1); i <= total; i++ {
		obj, err := gork.NewZObject(mem, i, header)
		if err != nil {
			panic(err)
		}
		fmt.Printf("%3d. %s", i, obj)
	}
}