4.11. Print a Widget Tree Summary

#!/usr/cogent/bin/phgamma

/*
 * This example reads a widget file and prints the widget level,
 * type, and name in hierarchical order. You can use the test file
 * QNX4-WidgetFiles/wgt/colortest.wgtw for QNX 4 or
 * QNX6-WidgetFiles/wgt/colortest.wgtw for QNX 6 by entering its
 * name as the first argument on the command line.
 */

PtInit(nil);
require_lisp("PhotonWidgets.lsp");
require_lisp("PhabTemplate.lsp");

if (cadr(argv))
{
  /*
   * Read the widget definitions, and access them.
   */
  file = string(cadr(argv));
  defs = PhabReadWidgetFile(file);
  treewin = car(defs);
  
  /*
   * Make a function that walks a widget tree, and finds
   * and prints the level, name, and type of its widgets.
   */
  function PhabInfoTree(tree)
	{
	  local return = nil;
	  local trees;
	  if (car(tree))
		princ(caar(tree)," ",cadar(tree),"\t\t ",caddr(car(tree)),"\n");
	  for (trees = cdr(tree); trees; trees = cdr(trees)){
		return = PhabInfoTree(car(trees));
	  }
	  return;
	}
  
  /*
   * Call the function.
   */
  PhabInfoTree(treewin);
}

else princ("Please enter a command-line argument, such as: \n",
		   "QNX4-WidgetFiles/wgt/colortest.wgtw in QNX 4, or\n",
		   "QNX6-WidgetFiles/wgt/colortest.wgtw in QNX 6.\n");