[LDTP-Dev] [PATCH] New Appmap generation code

jpremkumar jpremkumar at novell.com
Fri Sep 23 02:09:38 PDT 2005


Hi All,

Change in searching algorithm in pyldtp requires change in the appmap
generation code as we need to generate the child index for every object
with respect to its parent. I have attached patch for achieving the
same. I have also removed the instance index and relevant index values
from appmap generation as they are no longer used by the new searching
algorithm implementation. Also the files 'parser.c' and 'parser.h' can
be removed as all the appmap generation code has been moved to
'appmap-gen.c' file.

Please review the patch.

Thanks
Premkumar J

Index: AUTHORS
===================================================================
RCS file: /cvs/appmap/AUTHORS,v
retrieving revision 1.1
diff -u -p -r1.1 AUTHORS
--- AUTHORS	15 Jun 2005 18:38:41 -0000	1.1
+++ AUTHORS	23 Sep 2005 16:13:09 -0000
@@ -1,2 +1,3 @@
 Nagappan A <anagappan at novell.com>
 Bhargavi K <kbhargavi_83 at yahoo.co.in>
+Premkumar J <jpremkumar at novell.com>
Index: ChangeLog
===================================================================
RCS file: /cvs/appmap/ChangeLog,v
retrieving revision 1.2
diff -u -p -r1.2 ChangeLog
--- ChangeLog	28 Jul 2005 16:06:57 -0000	1.2
+++ ChangeLog	23 Sep 2005 16:13:09 -0000
@@ -1,2 +1,5 @@
+2005-09-23 Premkumar J <jpremkumar at novell.com>
+  * Rewritten code to generate appmap for making it complaint with the
new
+  searching algorithm
 2005-07-28 Nagappan A <anagappan at novell.com>
   * Converted all asprintf to g_strdup_printf mainly to work with
solaris platform
Index: Makefile.am
===================================================================
RCS file: /cvs/appmap/Makefile.am,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile.am
--- Makefile.am	15 Jun 2005 18:38:41 -0000	1.1
+++ Makefile.am	23 Sep 2005 16:13:09 -0000
@@ -5,8 +5,6 @@ bin_PROGRAMS = appmap
 appmap_SOURCES =	\
 	appmap-gen.c	\
 	appmap-gen.h	\
-	parser.c	\
-	parser.h	\
 	utils.c		\
 	utils.h
 
Index: appmap-gen.c
===================================================================
RCS file: /cvs/appmap/appmap-gen.c,v
retrieving revision 1.8
diff -u -p -r1.8 appmap-gen.c
--- appmap-gen.c	2 Aug 2005 12:13:56 -0000	1.8
+++ appmap-gen.c	23 Sep 2005 16:13:09 -0000
@@ -3,6 +3,7 @@
  *
  * Author:
  *    Nagappan A <anagappan at novell.com>
+ *    Premkumar J <jpremkumar at novell.com>
  *
  * Copyright 2004 Novell, Inc.
  *
@@ -25,12 +26,84 @@
 #define _GNU_SOURCE
 
 #include "appmap-gen.h"
-#include "parser.h"
 #include "utils.h"
 
 typedef GHashTable Appmap;
-char *application_name;
-char *map_filename;
+
+int table = 0,
+  canvas = 0,
+  column_header = 0,
+  combo_box = 0,
+  page_tab_list = 0,
+  page_tab = 0,
+  spin_button = 0,
+  button = 0,
+  radio_button = 0,
+  check_box = 0,
+  tree_table = 0,
+  layered_pane = 0,
+  text = 0,
+  cal_view = 0,
+  panel = 0,
+  filler = 0,
+  menubar = 0,
+  menu = 0,
+  separator = 0,
+  scroll_bar = 0,
+  scroll_pane = 0,
+  split_pane = 0,
+  slider = 0,
+  html_container = 0,
+  password_text = 0,
+  progress_bar = 0,
+  status_bar = 0,
+  tool_bar = 0,
+  label = 0,
+  unknown = 0;
+
+void reset_count()
+{
+  table = 0;
+  canvas = 0;
+  column_header = 0;
+  combo_box = 0;
+  page_tab_list = 0;
+  page_tab = 0;
+  spin_button = 0;
+  button = 0;
+  radio_button = 0;
+  tree_table = 0;
+  layered_pane = 0;
+  text = 0;
+  cal_view = 0;
+  panel = 0;
+  filler = 0;
+  menubar = 0;
+  menu = 0;
+  separator = 0;
+  scroll_bar = 0;
+  scroll_pane = 0;
+  split_pane = 0;
+  slider = 0;
+  html_container = 0;
+  password_text = 0;
+  progress_bar = 0;
+  status_bar = 0;
+  tool_bar = 0;
+  label = 0;
+  check_box = 0;
+  unknown = 0;
+}
+
+/*
+ *GDestroyNotify function for the hashtable used
+ */
+void free_element (gpointer data)
+{
+    char *val;
+    val = (char *) data;
+    g_free (val);
+}
 
 /*
   Get accessible handle of the given application
@@ -74,7 +147,7 @@ Accessible *accessible_app_handle (char 
       */
       if (strchr (name, ' '))
 	g_strstrip (name);
-
+      
       if (strcasecmp (name, app_name) == 0)
 	{
 	  /*
@@ -92,126 +165,662 @@ Accessible *accessible_app_handle (char 
   return NULL;
 }
 
+
+FILE *open_appmap (char *app_name)
+{
+  FILE *fp = NULL;
+  char *appmap_file = NULL;
+  appmap_file = g_strdup_printf ("%s.map", app_name);
+  fp = fopen (appmap_file, "w");
+
+  if (fp == NULL)
+    return NULL;
+  
+  free (appmap_file);
+  return fp;
+}
+
+int close_appmap (FILE *fp)
+{
+  if (fp)
+    fclose (fp);
+  return 0;
+}
+
 /*
-  Get accessible handle of the given object
-*/
-void accessible_object_handle (FILE *fp, Accessible *accessible, int
skip_level)
+ * This function filters the appmap entries
+ */
+int filter_appmap_data (Accessible *accessible, OBJECT_INFO *obj_info,
char *label)
 {
-  int i, num_child;
-  Accessible *child, *parent;
-  num_child = Accessible_getChildCount (accessible);
+    if (strcasecmp (obj_info->object_type, "label" ) == 0 ||
+	strcasecmp (obj_info->object_type, "separator" ) == 0 ||
+	strcasecmp (obj_info->object_type, "table_cell" ) == 0)
+	return 0;
+    if (strcasecmp (label, "ukngrip" ) == 0)
+	return 0;
+    if (strcasecmp (obj_info->object_type, "menu_item" ) == 0)
+    {
+	Accessible *parent;
+	Accessible *grand_parent;
+	int parent_type;
+	parent = Accessible_getParent (accessible);
+	grand_parent = Accessible_getParent (parent);
+	parent_type = Accessible_getRole (grand_parent);
+	if (parent_type == SPI_ROLE_COMBO_BOX)
+	{
+	    Accessible_unref (parent);
+	    Accessible_unref (grand_parent);
+	    return 0;
+	}
+	else
+	{
+	    Accessible_unref (parent);
+	    Accessible_unref (grand_parent);
+	    return 1;
+	}
+    }
 
-  for (i = 0; i < num_child; i++)
+    if (strcasecmp (obj_info->object_type, "list_item") == 0)
+      return 0;
+
+    if (strcasecmp (obj_info->object_type, "unknown" ) == 0)
     {
-      if (skip_level)
+	Accessible *parent;
+	int parent_type;
+	parent = Accessible_getParent (accessible);
+	parent_type = Accessible_getRole (parent);
+	if (parent_type == SPI_ROLE_TABLE || 
+	    parent_type == SPI_ROLE_TREE_TABLE )
 	{
-	  skip_level--;
-	  continue;
+	    Accessible_unref (parent);
+	    return 0;
 	}
-      child = Accessible_getChildAtIndex (accessible, i);
-      if (!child)
-	  continue;
-      add_appmap_data (fp, child);
+	else
+	{
+	    Accessible_unref (parent);
+	    return 1;
+	}
+    }
 
-      /*
-	Call this function recursively, until we reach the end of
-	depth first search in all the given object handle
-      */
-      accessible_object_handle (fp, child, skip_level);
-      Accessible_unref (child);
+    return 1;
+}
+
+char *get_relation_name (Accessible *object)
+{
+  int i;
+  int max_accessible = 0;
+  char *label_by = NULL;
+  AccessibleRelation **relation;
+
+  relation = Accessible_getRelationSet (object);
+  max_accessible = AccessibleRelation_getNTargets (*relation);
+  if (max_accessible > 0)
+    {
+      for (i = 0; i < AccessibleRelation_getNTargets (relation[i]); i
++)
+	{
+	  AccessibleRelationType relation_type;
+	  relation_type = AccessibleRelation_getRelationType (relation[i]);
+	  if (relation_type == SPI_RELATION_LABELED_BY ||
+	      relation_type == SPI_RELATION_CONTROLLED_BY ||
+	      relation_type == SPI_RELATION_LABEL_FOR)
+	    {
+	      char *name = NULL;
+	      Accessible *tmp_obj;
+	      tmp_obj = AccessibleRelation_getTarget (relation[i], i);
+	      name = Accessible_getName (tmp_obj);
+	      if (g_strcasecmp (name, "") == 0)
+		{
+		  SPI_freeString (name);
+		  Accessible_unref (tmp_obj);
+		  Accessible_unref (*relation);
+		  return NULL;
+		}
+	      label_by = g_strdup (name);
+	      SPI_freeString (name);
+	      Accessible_unref (tmp_obj);
+	      Accessible_unref (*relation);
+	      return label_by;
+	    }
+	}
     }
+  Accessible_unref (*relation);
+  return NULL;
 }
 
-int appmap_main (char *app_name)
+/*
+ * This function creates entry in the Appmap file corresponding to the
object passed to it
+ */
+char *add_appmap_data (FILE *fp, Accessible *accessible, char
*parent_name, int child_index, GHashTable *current_context)
 {
-  FILE *fp = NULL;
-  Accessible *parent;
+    char *name;
+    char *label_by;
+    char *label = NULL;
+    char *object_record;
+    char *key;
+    char *value;
+    int size;
+    char *accessible_name;
+    OBJECT_INFO *cur_obj_info = NULL;
+    
+    cur_obj_info = get_object_info (accessible);
+    accessible_name = Accessible_getName (accessible);
+    label_by = get_relation_name (accessible);
+    if (label_by)
+      {
+	if (g_strcasecmp (label_by,"") == 0)
+	  label = g_strdup (accessible_name);
+	else
+	  label = g_strdup (label_by);
+      }
+    else
+      label = g_strdup (accessible_name);
 
-  parent = accessible_app_handle (app_name);
-  if (!parent)
+    if (strcmp (label, "") != 0)
     {
-      printf ("Application %s seems to be not running !!!\n",
app_name);
-      return -1;
+	char *stripped_data = NULL;
+	char *value = NULL;
+	if (strchr (label, ' '))
+	    stripped_data = strip_white_space (label);
+	else
+	    stripped_data = g_strdup (label);
+	if (strstr (stripped_data, "."))
+	{
+	    value = strip_delim (stripped_data, '.');
+	    g_free (stripped_data);
+	    stripped_data = g_strdup (value);
+	    g_free (value);
+	    value = NULL;
+	}
+	if (strstr (stripped_data, ":"))
+	{
+	    value = strip_delim (stripped_data, ':');
+	    g_free (stripped_data);
+	    stripped_data = g_strdup (value);
+	    g_free (value);
+	    value = NULL;
+	}
+	name = g_strdup_printf ("%s%s", cur_obj_info->prefix, stripped_data);
+	
+	value = g_hash_table_lookup (current_context, name);
+	if (value)
+	{
+	    if (name)
+	      g_free (name);
+	    name = g_strdup_printf ("%s%s%d", cur_obj_info->prefix,
stripped_data, cur_obj_info->instance_index);
+	}
+	g_free (stripped_data);
+    }
+    else
+	name = g_strdup_printf ("%s%d", cur_obj_info->prefix,
cur_obj_info->instance_index);
+
+    g_free (label);
+    label = g_strdup (accessible_name);
+    SPI_freeString (accessible_name);
+
+    if (filter_appmap_data (accessible, cur_obj_info, name))
+    {
+      if (g_strcasecmp (label, "") == 0)
+	{
+	  if (!label_by)
+	    object_record = g_strdup_printf ("%s={class=%s,parent=%
s,child_index=%d}\n", name, 
+					     cur_obj_info->object_type, parent_name, child_index);
+	  else
+	    {
+	      object_record = g_strdup_printf ("%s={class=%s,parent=%
s,child_index=%d,label_by=%s}\n", name, 
+					       cur_obj_info->object_type, parent_name, child_index,
label_by);
+	      g_free (label_by);
+	    }
+	}
+      else
+	{
+	  if (g_strcasecmp (cur_obj_info->object_type, "combo_box") != 0)
+	    object_record = g_strdup_printf ("%s={class=%s,parent=%
s,child_index=%d,label=%s}\n", name, 
+					     cur_obj_info->object_type, parent_name, child_index, label);
+	  else
+	    object_record = g_strdup_printf ("%s={class=%s,parent=%
s,child_index=%d}\n", name, 
+					     cur_obj_info->object_type, parent_name, child_index);
+	}
+      size = strlen (object_record);
+      fwrite (object_record, sizeof (char), size, fp);
+      key = g_strdup (name);
+      value = g_strdup ("ADDED");
+      if (current_context)
+	g_hash_table_insert (current_context, key, value);	
+      else
+	g_print ("Hashtable is NULL!!\n");
+      g_free (label);
+      g_free (object_record);
+      g_free (cur_obj_info->object_type);
+      g_free (cur_obj_info->prefix);
+      g_free (cur_obj_info);
+      return name;
+    }
+    else
+    {
+	g_free (name);
+	g_free (label);
+	g_free (cur_obj_info->object_type);
+	g_free (cur_obj_info->prefix);
+	g_free (cur_obj_info);
+	return NULL;
     }
-  fp = open_appmap (app_name);
-  accessible_object_handle (fp, parent, 0);
-  Accessible_unref (parent);
-  close_appmap (fp);  
-  return 0;
 }
 
-void print_entries (char *key, char *value, char *userdata)
+/*
+ * This function returns the information about the accessible object
passed
+ */
+OBJECT_INFO *get_object_info (Accessible *accessible)
 {
-  printf ("%s = %s\n", key, value);
+  OBJECT_INFO *obj_info;
+  int role;
+
+  obj_info = (OBJECT_INFO *) malloc (sizeof (OBJECT_INFO));
+  role = Accessible_getRole (accessible);
+
+  if (role == SPI_ROLE_PAGE_TAB) 
+    {
+      obj_info->prefix = g_strdup ("ptab");
+      page_tab++;
+      obj_info->instance_index = page_tab;
+      obj_info->object_type = g_strdup ("page_tab");
+    }
+  else if (role == SPI_ROLE_PAGE_TAB_LIST) 
+    {
+      obj_info->prefix = g_strdup ("ptl");
+      page_tab_list++;
+      obj_info->instance_index = page_tab_list;
+      obj_info->object_type = g_strdup ("page_tab_list");
+    }
+  else if (role == SPI_ROLE_TABLE) 
+    {
+      obj_info->prefix = g_strdup ("tbl");
+      table++;
+      obj_info->instance_index = table;
+      obj_info->object_type = g_strdup ("table");
+    }
+  else if (role == SPI_ROLE_COMBO_BOX) 
+    {
+      obj_info->prefix = g_strdup ("cbo");
+      combo_box++;
+      obj_info->instance_index = combo_box;
+      obj_info->object_type = g_strdup ("combo_box");
+    }
+  else if (role == SPI_ROLE_SPIN_BUTTON) 
+    {
+      obj_info->prefix = g_strdup ("sbtn");
+      spin_button++;
+      obj_info->instance_index = spin_button;
+      obj_info->object_type = g_strdup ("spin_button");
+    }
+  else if (role == SPI_ROLE_FONT_CHOOSER) 
+    {
+      obj_info->prefix = g_strdup ("dlg");
+      obj_info->instance_index = -1; /* Value -1 signifies not
applicable  */
+      obj_info->object_type = g_strdup ("font_chooser");
+    }
+  else if (role == SPI_ROLE_RADIO_BUTTON) 
+    {
+      obj_info->prefix = g_strdup ("rbtn");
+      radio_button++;
+      obj_info->instance_index = radio_button;
+      obj_info->object_type = g_strdup ("radio_button");
+    }
+  else if (role == SPI_ROLE_TREE_TABLE) 
+    {
+      obj_info->prefix = g_strdup ("ttbl");
+      tree_table++;
+      obj_info->instance_index = tree_table;
+      obj_info->object_type = g_strdup ("tree_table");
+    }
+  else if (role == SPI_ROLE_LAYERED_PANE) 
+    {
+      obj_info->prefix = g_strdup ("pane");
+      layered_pane++;
+      obj_info->instance_index = layered_pane;
+      obj_info->object_type = g_strdup ("layered_pane");
+    }
+  else if (role == SPI_ROLE_FRAME) 
+    {
+      obj_info->prefix = g_strdup ("frm");
+      obj_info->instance_index = -1;
+      obj_info->object_type = g_strdup ("frame");
+    }
+  else if (role == SPI_ROLE_DIALOG) 
+    {
+      obj_info->prefix = g_strdup ("dlg");
+      obj_info->instance_index = -1;
+      obj_info->object_type = g_strdup ("dialog");
+    }
+  else if (role == SPI_ROLE_ALERT) 
+    {
+      obj_info->prefix = g_strdup ("dlg");
+      obj_info->instance_index = -1;
+      obj_info->object_type = g_strdup ("alert");
+    }
+  else if (role == SPI_ROLE_CALENDAR) 
+    {
+      obj_info->prefix = g_strdup ("calview");
+      cal_view++;
+      obj_info->instance_index = cal_view;
+      obj_info->object_type = g_strdup ("calendar_view");
+    }
+  else if (role == SPI_ROLE_PANEL) 
+    {
+      obj_info->prefix = g_strdup ("pnl");
+      panel++;
+      obj_info->instance_index = panel;
+      obj_info->object_type = g_strdup ("panel");
+    }
+  else if (role == SPI_ROLE_LABEL) 
+    {
+      obj_info->prefix = g_strdup ("lbl");
+      label++;
+      obj_info->instance_index = label;
+      obj_info->object_type = g_strdup ("label");
+    }
+  else if (role == SPI_ROLE_MENU_BAR) 
+    {
+      obj_info->prefix = g_strdup ("mbr");
+      menubar++;
+      obj_info->instance_index = menubar;
+      obj_info->object_type = g_strdup ("menu_bar");
+    }
+  else if (role == SPI_ROLE_MENU) 
+    {
+      obj_info->prefix = g_strdup ("mnu");
+      menu++;
+      obj_info->instance_index = menu;
+      obj_info->object_type = g_strdup ("menu");
+    }
+  else if (role == SPI_ROLE_MENU_ITEM) 
+    {
+      obj_info->prefix = g_strdup ("mnu");
+      menu++;
+      obj_info->instance_index = menu;
+      obj_info->object_type = g_strdup ("menu_item");
+    }
+  else if (role == SPI_ROLE_LIST_ITEM) 
+    {
+      obj_info->prefix = g_strdup ("lst");
+      obj_info->instance_index = -1;
+      obj_info->object_type = g_strdup ("list_item");
+    }
+  else if (role == SPI_ROLE_CHECK_MENU_ITEM) 
+    {
+      obj_info->prefix = g_strdup ("mnu");
+      menu++;
+      obj_info->instance_index = menu;
+      obj_info->object_type = g_strdup ("check_menu_item");
+    }
+  else if (role == SPI_ROLE_RADIO_MENU_ITEM)
+    {
+      obj_info->prefix = g_strdup ("mnu");
+      menu++;
+      obj_info->instance_index = menu;
+      obj_info->object_type = g_strdup ("radio_menu_item");
+    }
+
+  else if (role == SPI_ROLE_PUSH_BUTTON) 
+    {
+      obj_info->prefix = g_strdup ("btn");
+      button++;
+      obj_info->instance_index = button;
+      obj_info->object_type = g_strdup ("push_button");
+    }
+  else if (role == SPI_ROLE_TOGGLE_BUTTON) 
+    {
+      obj_info->prefix = g_strdup ("btn");
+      button++;
+      obj_info->instance_index = button;
+      obj_info->object_type = g_strdup ("toggle_button");
+    }
+  else if (role == SPI_ROLE_SCROLL_BAR) 
+    {
+      obj_info->prefix = g_strdup ("scbr");
+      scroll_bar++;
+      obj_info->instance_index = scroll_bar;
+      obj_info->object_type = g_strdup ("scroll_bar");
+    }
+  else if (role == SPI_ROLE_SCROLL_PANE) 
+    {
+      obj_info->prefix = g_strdup ("scpn");
+      scroll_pane++;
+      obj_info->instance_index = scroll_pane;
+      obj_info->object_type = g_strdup ("scroll_pane");
+    }
+  else if (role == SPI_ROLE_TEXT) 
+    {
+      obj_info->prefix = g_strdup ("txt");
+      text++;
+      obj_info->instance_index = text;
+      obj_info->object_type = g_strdup ("text");
+    }
+  else if (role == SPI_ROLE_PASSWORD_TEXT) 
+    {
+      obj_info->prefix = g_strdup ("txt");
+      text++;
+      obj_info->instance_index = text;
+      obj_info->object_type = g_strdup ("password_text");
+    }
+  else if (role == SPI_ROLE_STATUS_BAR) 
+    {
+      obj_info->prefix = g_strdup ("stat");
+      status_bar++;
+      obj_info->instance_index = status_bar;
+      obj_info->object_type = g_strdup ("statusbar");
+    }
+  else if (role == SPI_ROLE_TABLE_COLUMN_HEADER) 
+    {
+      obj_info->prefix = g_strdup ("tch");
+      column_header++;
+      obj_info->instance_index = status_bar;
+      obj_info->object_type = g_strdup ("table_column_header");
+    }
+  else if (role == SPI_ROLE_SEPARATOR) 
+    {
+      obj_info->prefix = g_strdup ("spr");
+      separator++;
+      obj_info->instance_index = separator;
+      obj_info->object_type = g_strdup ("separator");
+    }
+  else if (role == SPI_ROLE_FILLER) 
+    {
+      obj_info->prefix = g_strdup ("flr");
+      filler++;
+      obj_info->instance_index = filler;
+      obj_info->object_type = g_strdup ("filler");
+    }
+  else if (role == SPI_ROLE_CANVAS) 
+    {
+      obj_info->prefix = g_strdup ("cnvs");
+      canvas++;
+      obj_info->instance_index = canvas;
+      obj_info->object_type = g_strdup ("canvas");
+    }
+  else if (role == SPI_ROLE_SPLIT_PANE) 
+    {
+      obj_info->prefix = g_strdup ("splt");
+      split_pane++;
+      obj_info->instance_index = split_pane;
+      obj_info->object_type = g_strdup ("split_pane");
+    }
+  else if (role == SPI_ROLE_SLIDER) 
+    {
+      obj_info->prefix = g_strdup ("sldr");
+      slider++;
+      obj_info->instance_index = slider;
+      obj_info->object_type = g_strdup ("slider");
+    }
+  else if (role == SPI_ROLE_HTML_CONTAINER) 
+    {
+      obj_info->prefix = g_strdup ("html");
+      html_container++;
+      obj_info->instance_index = html_container;
+      obj_info->object_type = g_strdup ("html_container");
+    }
+  else if (role == SPI_ROLE_PROGRESS_BAR) 
+    {
+      obj_info->prefix = g_strdup ("pbar");
+      progress_bar++;
+      obj_info->instance_index = progress_bar;
+      obj_info->object_type = g_strdup ("progree_bar");
+    }
+  else if (role == SPI_ROLE_TOOL_BAR) 
+    {
+      obj_info->prefix = g_strdup ("tbar");
+      tool_bar++;
+      obj_info->instance_index = tool_bar;
+      obj_info->object_type = g_strdup ("tool_bar");
+    }
+  else if (role == SPI_ROLE_CHECK_BOX) 
+    {
+      obj_info->prefix = g_strdup ("chk");
+      check_box++;
+      obj_info->instance_index = check_box;
+      obj_info->object_type = g_strdup ("check_box");
+    }
+  else if (role == SPI_ROLE_TABLE_CELL) 
+    {
+      obj_info->prefix = g_strdup ("tblc");
+      obj_info->instance_index = -1;
+      obj_info->object_type = g_strdup ("table_cell");
+    }
+  else 
+    {
+      obj_info->prefix = g_strdup ("ukn");
+      unknown++;
+      obj_info->instance_index = unknown;
+      obj_info->object_type = g_strdup ("unknown");
+    }
+  return obj_info;
+}
+
+void insert_context_header (FILE *fp, Accessible *accessible)
+{
+    char *name;
+    char *label;
+    char *object_record;
+    int size;
+    char *accessible_name;
+    OBJECT_INFO *cur_obj_info = NULL;
+    
+    cur_obj_info = get_object_info (accessible);
+    accessible_name = Accessible_getName (accessible);
+    label = g_strdup (accessible_name);
+    SPI_freeString (accessible_name);
+    if (strcmp (label, "") != 0)
+    {
+	char *stripped_data = NULL;
+	if (strchr (label, ' '))
+	    stripped_data = strip_white_space (label);
+	else
+	    stripped_data = g_strdup (label);
+	name = g_strdup_printf ("%s%s", cur_obj_info->prefix, stripped_data);
+	g_free (stripped_data);
+    }
+    object_record = g_strdup_printf ("[%s]\n", name);
+    size = strlen (object_record);
+    fwrite (object_record, sizeof (char), size, fp);
+    
+    g_free (label);
+    g_free (name);
+    g_free (object_record);
+    g_free (cur_obj_info->object_type);
+    g_free (cur_obj_info->prefix);
+    g_free (cur_obj_info);
 }
 
-int check_duplicate_entries (char *gui_map_filename)
+void create_appmap (FILE *fp, Accessible *accessible, char
*application_name)
 {
-  int fd, line_no = 0;
-  FILE *fp;
-  GHashTable *appmap;
-  appmap = g_hash_table_new (&g_str_hash, &g_str_equal);
+    int i, num_child;
+    char *name;
+    char *label;
+    Accessible *child;
+    GHashTable *current_context = NULL;
+    
+    label = Accessible_getName (accessible);
+    if (strchr (label, ' '))
+	name = g_strdup_printf ("[%s]\n", strip_white_space (label));
+    else
+	name =  g_strdup_printf ("[%s]\n", label);
 
-  fp = fopen (gui_map_filename, "r");
-  if (fp ==NULL)
+    num_child = Accessible_getChildCount (accessible);
+    for (i = 0; i < num_child; i++)
     {
-      g_print ("Unable to open appmap %s file\n", gui_map_filename);
-      return 0;
+	reset_count ();
+	current_context = g_hash_table_new_full (&g_str_hash, &g_str_equal,
&free_element, &free_element);
+	child = Accessible_getChildAtIndex (accessible, i);
+	insert_context_header (fp, child);
+	if (!child)
+	    continue;
+	accessible_object_handle (fp, child, application_name, i,
current_context);
+	fwrite ("\n", sizeof (char), 1, fp);
+	g_hash_table_destroy (current_context);
+	current_context = NULL;
     }
-  fd = fileno (fp);
+    g_free (name);
+    SPI_freeString (label);
+    Accessible_unref (accessible);
+}
 
+/*
+  Get accessible handle of the given object
+*/
+void accessible_object_handle (FILE *fp, Accessible *accessible, char*
parent_name, 
+			       int child_index, GHashTable *current_context)
+{
+  int i, num_child;
+  Accessible *child;
+  char *current_parent = NULL;
+  char *temp_parent = NULL;
+
+  num_child = Accessible_getChildCount (accessible);
+  temp_parent = add_appmap_data (fp, accessible, parent_name,
child_index, current_context);
+  if (temp_parent)
   {
-    char *data;
-    char *entry = NULL;
-    char *char_line=NULL;
-    while (1)
+      current_parent = g_strdup_printf ("%s", temp_parent);
+      g_free (temp_parent);
+      for (i = 0; i < num_child; i++)
       {
-	data = read_line (fd);line_no++;
-	if (data == NULL)
-	     break;
-	if (data[0] == '['||data [0] == '\n')
-	    continue;
-	else
-	  {
-	    char *token;
-	    int offset;
-	    gchar orig_key[256];
-	    gchar value[256];
-	    token = strtok (strdup (data), "=");
-	    if (token)
-	      {
-	      entry  = strdup (token);
-	      char_line = g_strdup_printf ("%d", line_no);
-            if (!g_hash_table_lookup_extended (appmap, entry,
-					       (gpointer) &orig_key, (gpointer) &value))
-		{
-		  g_hash_table_insert (appmap, entry, char_line);
-		  continue;
-		}
-	      else
-		{
-		  g_print ("DUPLICATE : Line no:%s :%s", char_line, data);
-		  continue;
-		}
-	      }
-	  }
-	g_free (data);
+	  child = Accessible_getChildAtIndex (accessible, i);
+	  if (!child)
+	      continue;
+	  /*
+	    Call this function recursively, until we reach the end of
+	    depth first search in all the given object handle
+	  */
+	  accessible_object_handle (fp, child, current_parent, i,
current_context);
       }
+      g_free (current_parent);
   }
-
-  // g_hash_table_foreach (appmap, (GHFunc)&print_entries, NULL);
-  /*
-    Print all the data in hash table
-  */
-  return 1;
+  Accessible_unref (accessible);
 }
 
+int appmap_main (char *app_name)
+{
+  FILE *fp = NULL;
+  Accessible *parent;
+
+  parent = accessible_app_handle (app_name);
+  if (!parent)
+    {
+      printf ("Application %s seems to be not running !!!\n",
app_name);
+      return -1;
+    }
+  fp = open_appmap (app_name);
+  create_appmap (fp, parent, app_name);
+  close_appmap (fp);  
+  return 0;
+}
 
 int main (int argc, char *argv[])
 {
   int leaked;
   int init_error;
 
+  char *application_name;
+  char *map_filename;
+
   if (argc < 2)
     {
       printf("Syntax: appmap <application name>\n");
@@ -225,7 +834,6 @@ int main (int argc, char *argv[])
   if (init_error)
     {
       g_warning ("Error: SPI Init\n");
-      g_free (map_filename);
       return init_error;
     }
 
@@ -234,15 +842,19 @@ int main (int argc, char *argv[])
 
   appmap_main (application_name);
 
-  check_duplicate_entries (map_filename);
+/*  check_duplicate_entries (map_filename); */
 
   g_free (application_name);
   g_free (map_filename);
 
   leaked = SPI_exit ();
-
+  g_print ("Leaked %d SPI handles\n", leaked);
+#ifdef DEBUG
   if (leaked)
-    g_warning ("Leaked %d SPI handles", leaked);
+    fprintf (stderr, "Leaked %d SPI handles\n", leaked);
+#endif
+  
   putenv ("AT_BRIDGE_SHUTDOWN=1");
+ 
   return 0;
 }
Index: appmap-gen.h
===================================================================
RCS file: /cvs/appmap/appmap-gen.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 appmap-gen.h
--- appmap-gen.h	6 May 2005 19:29:02 -0000	1.1.1.1
+++ appmap-gen.h	23 Sep 2005 16:13:09 -0000
@@ -19,7 +19,26 @@
 // Accessibility headers
 #include <cspi/spi.h>
 
+struct object_info
+{
+    char *object_type;
+    char *prefix;
+    int instance_index;
+};
+
+typedef struct object_info OBJECT_INFO;
+
 Accessible *accessible_app_handle (char *app_name);
-void accessible_object_handle (FILE *fp, Accessible *accessible, int
skip_level);
+void reset_count ();
+FILE *open_appmap (char *app_name);
+int close_appmap (FILE *fp);
+char *add_appmap_data (FILE *fp, Accessible *accessible, char
*parent_name, int child_index, GHashTable *context); 
+void create_appmap (FILE *fp, Accessible *accessible, char
*parent_name); 
+void accessible_object_handle (FILE *fp, Accessible *accessible, char
*parent_name, int child_index, GHashTable *context); 
+int appmap_main (char *);
+OBJECT_INFO *get_object_info (Accessible *accessible);
+void insert_context_header (FILE *fp, Accessible *accessible);
+int filter_appmap_data (Accessible *accessible, OBJECT_INFO *cur_obj,
char *label);
+char *get_relation_name (Accessible *accessible);
 
 #endif
Index: utils.c
===================================================================
RCS file: /cvs/appmap/utils.c,v
retrieving revision 1.3
diff -u -p -r1.3 utils.c
--- utils.c	2 Aug 2005 12:13:56 -0000	1.3
+++ utils.c	23 Sep 2005 16:13:09 -0000
@@ -33,10 +33,7 @@ char *strip_white_space (char *data)
   int j = 0;
   char *stripped_data = NULL;
 
-  if (!data)
-    return NULL;
-
-  stripped_data = (char *) calloc (sizeof (char) * strlen (data) + 1,
1);
+  stripped_data = (char *) malloc (sizeof (char) * strlen (data) + 1);
 
   for (i = 0; i < strlen (data); i++)
     {
@@ -53,7 +50,7 @@ char *strip_delim (char *data, char deli
   int j = 0;
   char *stripped_data = NULL;
 
-  stripped_data = (char *) calloc (sizeof (char) * strlen (data) + 1,
1);
+  stripped_data = (char *) malloc (sizeof (char) * strlen (data) + 1);
 
   for (i = 0; i < strlen (data); i++)
     {
@@ -78,7 +75,7 @@ char *read_line (int fd )
     {
       if (!data)
 	{
-	  data = (char *) calloc (sizeof (char)*len, 1);
+	  data = (char *) malloc (sizeof (char)*len);
 	}
       if (size%len == 0)
 	{





More information about the Ldtp-dev mailing list