These programs extract information from the GTK widget classes, some of which is used by gtkwidget2docs.g program, which makes a call to GGUT_IvarStringList.
/*
* Gtk Gamma Utilities (GGUT)
*
*/
// Returns the Gtk type for the specified gamma class (must be a Gtk... class).
function GGUT_ClassType(klass)
{
gtk_type_from_name(string(class_name(klass)));
}
// Returns list of type parentage, from given type to the root.
function GGUT_TypeParentList (type)
{
local parent = gtk_type_parent (type);
if (parent != 0)
cons (type, GGUT_TypeParentList (parent));
else
cons(type, nil);
}
// Writes the type parentage list as a single line, using the '->' symbol.
function GGUT_TypeParentWrite (type, fp?=stdout)
{
local l = reverse(GGUT_TypeParentList(type));
for (; cdr(l); l = cdr(l))
{
writec(fp, gtk_type_name(car(l)), " -> ");
}
writec(fp, gtk_type_name(car(l)));
}
// Converts the gtk type info flag into a string.
function GGUT_FlagsString (flags)
{
((flags>K_ARG_READABLE)!=0 ?
((flags>K_ARG_WRITABLE)!=0 ? "Read / Write" : "Read") :
((flags>K_ARG_WRITABLE)!=0 ? "Write" : "Unaccesible"));
}
// Generates a list of (ivar_name, ivar_type, ivar_flags) for attributes of klass.
function GGUT_Ivars (klass, only_gtk?=nil)
{
local ivararray, pivararray, ivars, i, result;
local klass_type = GGUT_ClassType(klass);
local type, flags;
// Get the instance vars for the class.
ivararray = instance_vars(klass);
// Remove instance vars not unique to class, i.e., inherited,
// & build a list of names as strings.
if (parent_class(klass))
pivararray = instance_vars(parent_class(klass));
with i in ivararray do
{
if (!pivararray || !find(i,pivararray))
ivars = cons (string(i), ivars);
}
ivars = reverse(ivars); // list of names
// Build a list of (ivar_name, ivar_type, ivar_flags) lists.
with i in ivars do
{
info = gtk_object_arg_get_info(klass_type, i);
if (instance_p(info))
{
result = cons (list(info.name, info.type, info.arg_flags), result);
}
else if (!only_gtk)
{
/* gtk has no info about this variable */
result = cons (list(i), result);
}
}
result = reverse(result);
result;
}
// Converts the type and flag of a (name, type, flag) list into strings.
function GGUT_IvarString (info)
{
local info_string=list();
local name = car(info);
local type = cadr(info);
local flags = caddr(info);
{
if (name)
{
info_string = cons(name, info_string);
if (cadr(info))
{
info_string = cons(gtk_type_name(cadr(info)), info_string);
if(caddr(info))
{
info_string = cons(string(GGUT_FlagsString(caddr(info))), info_string);
}
else info_string = append(list(string("")), info_string);
}
else info_string = append(list(string(""), string("")), info_string);
}
else info_string = list(string(""), string(""), string(""));
}
reverse(info_string);
}
// Makes a list of all ivar strings of a class.
function GGUT_IvarStringList (klass)
{
local ivar_list = list ();
local orig_list = GGUT_Ivars(klass);
with i in orig_list do
{
list_item = GGUT_IvarString(i);
ivar_list = cons(list_item, ivar_list);
}
reverse(ivar_list);
}
// Converts a (name, type, flag) list into a string, with specified padding.
function GGUT_IvarFormattedString (info, namelen, typelen, flagslen)
{
local res="";
local name = car(info);
local type = cadr(info);
local flags = caddr(info);
if (name)
{
res = format(string("%-", namelen,"s"), name);
if (type)
{
res = format(string("%s%-", typelen,"s"),
res, gtk_type_name(type));
if (flags)
{
res = format(string("%s : %-", flagslen, "s"),
res, GGUT_FlagsString(flags));
}
}
}
res;
}
function GGUT_IvarsWrite(klass, fp?=stdout)
{
local i;
//local l = GGUT_Ivars(klass, t); // pick up ivars known to gtk only
local l = GGUT_Ivars(klass); // pick up all ivars seen by gamma
// Determine maximum length of ivar and type names.
local ivarlen = 0;
local typelen = 0;
with i in l do
{
local name = car(i);
local type = cadr(i);
if (name && strlen(name) > ivarlen) ivarlen = strlen(name);
if (type && (type=gtk_type_name(type))!=0 && strlen(type) > typelen)
typelen = strlen(type);
}
if (fp == stdout)
princ (class_name(klass), " ivars are: \n");
with i in l do
{
writec(fp, GGUT_IvarFormattedString(i, ivarlen+2, typelen+2, 0));
// If you want to see the ivar type tree...
if (t && (type=cadr(i)) && gtk_type_parent(type)!=0)
{
terpri(fp);
writec(fp, format(string("%", ivarlen + 2, "s"), " "));
GGUT_TypeParentWrite (type, fp);
}
terpri(fp);
}
if (fp == stdout)
princ ("\n");
}
Copyright © 1995-2004 by Cogent Real-Time Systems, Inc. All rights reserved.