/* * This code demonstrates the use of some liblincks routines, * in particular the use of "mapfn" (map functions). * It can be incorporated in the xaim module aimcommand.c, * and invoked in one of the button (command) functions * like this: * * if (currentinfonode == NULL) * printf("no current item\n"); * else * demo_liblincks(¤tinfonode->obj); * * To use lint on this file: * lint -I/usr/local/X11R5/include xxx.c * because some X stuff is included via nested .h's. */ #include "aimtypes.h" static int mapfn_group_name(); static int mapfn_field_name(); /* This struct is for passing multiple parameters to a * mapfn with one pointer. */ struct demo_extra { label *Plabel; char *Pgroup_tag; };
/************************************************************ * Function: static void demo_liblincks(label *Plabel) * * INPUT: a pointer to a node label. * OUTPUT: printfs of the nodes's image, attribute tags, * values, etc. */ static void demo_liblincks(Plabel) label *Plabel; { attrval attr; if (GI_GETIMAGE(Plabel,&attr) != NO_ERROR) { printf("GI_ failed\n"); return; } printf("Image of selected node:\n%s\n", attr.attvalue); /* * liblincks allocated some memory, which is pointed to by * attr.attvalue. * We have the responsibility for freeing that memory when * we're finished with it. */ free(attr.attvalue); /* we use the "extra" parameter to pass Plabel to the mapfn */ if (GAGN_GETATTRGROUPNAMES(Plabel,mapfn_group_name, (void *) Plabel) != NO_ERROR) { printf("GAGN_ failed\n"); return; } } /* end demo_liblincks() */
/************************************************************ * Function: static int mapfn_group_name(FOUR PARAMETERS) * Parameters: * label *Plabel * char *Pgroup_tag; * int count * int length * * mapfn for a group. * Will be called by GAGN_ once for "initialization", then once * for each attribute group. */ static int mapfn_group_name(Plabel,Pgroup_tag,count,length) label *Plabel; /* using the "extra" parameter */ char *Pgroup_tag; int count; int length; { struct demo_extra demo_parms; if (count == 0) { /* this is the first time we've been called for this node * ("initialization") */ printf("This node has %d group(s).\n", length); } else { /* we're being called for a particular group */ printf("\tGroup %d group tag: %s\n", count, Pgroup_tag); /* we store some information in a special block, so it * can be passed to the map function */ demo_parms.Plabel = Plabel; demo_parms.Pgroup_tag = Pgroup_tag; if (GAN_GETATTRNAMES(Plabel,Pgroup_tag,mapfn_field_name, (void *) &demo_parms) != NO_ERROR) { printf("GAN_ failed\n"); return (!0); /* what GAGN_ wants for failure */ } } return (0); /* this is what GAGN_ wants */ } /* end mapfn_group_name() */
/************************************************************ * Function: static int mapfn_field_name(FOUR PARAMETERS) * Parameters: * struct demo_extra *Pdemo * char *Pfield_tag * int count * int length * * mapfn for a field. * Will be called by GAN_ once for "initialization", then once * for each attribute field within a group. */ static int mapfn_field_name(Pdemo,Pfield_tag,count,length) struct demo_extra *Pdemo; char *Pfield_tag; int count; int length; { attrval attr; if (count == 0) { /* this is the first time we've been called for this group * ("initialization") */ printf("\tThis group has %d field(s).\n", length); } else { /* we're being called for a particular field */ printf("\t\tField %d field tag: %s\n", count, Pfield_tag); if (GA_GETATTR(Pdemo->Plabel,Pdemo->Pgroup_tag, Pfield_tag,&attr) != NO_ERROR) { printf("GA_ failed\n"); return (!0); /* what GAN_ wants for failure */ } printf("\t\tField value: %s\n", attr.attvalue); /* liblincks allocated some memory, which is pointed to by * attr.attvalue. * We have the responsibility for freeing that memory when * we're finished with it. */ free(attr.attvalue); } return (0); /* this is what GAN_ wants */ } /* end mapfn_field_name() */