diff options
author | nagappan <nagappan> | 2005-09-28 05:57:37 +0000 |
---|---|---|
committer | nagappan <nagappan> | 2005-09-28 05:57:37 +0000 |
commit | 2b78819cb114a3784557fb1b157e147f359a40e2 (patch) | |
tree | e40f951d23a03b1f473b095bef503f709816ac8e | |
parent | 594f5278f29f4fe1f81857cd80cdd4ddbef01aee (diff) |
2005-09-23 Premkumar J <jpremkumar@novell.com>
* Rewritten code to generate appmap for making it complaint with the new
searching algorithm
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | appmap-gen.c | 833 | ||||
-rw-r--r-- | appmap-gen.h | 21 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | parser.c | 1705 | ||||
-rw-r--r-- | parser.h | 17 | ||||
-rw-r--r-- | utils.c | 9 |
8 files changed, 765 insertions, 1827 deletions
@@ -1,2 +1,5 @@ +2005-09-23 Premkumar J <jpremkumar@novell.com> + * Rewritten code to generate appmap for making it complaint with the new + searching algorithm 2005-07-28 Nagappan A <anagappan@novell.com> * Converted all asprintf to g_strdup_printf mainly to work with solaris platform diff --git a/Makefile.am b/Makefile.am index 7d455f0..6d2e215 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,8 +5,6 @@ bin_PROGRAMS = appmap appmap_SOURCES = \ appmap-gen.c \ appmap-gen.h \ - parser.c \ - parser.h \ utils.c \ utils.h diff --git a/appmap-gen.c b/appmap-gen.c index b98a9d7..4acae4f 100644 --- a/appmap-gen.c +++ b/appmap-gen.c @@ -3,6 +3,7 @@ * * Author: * Nagappan A <anagappan@novell.com> + * Premkumar J <jpremkumar@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,8 +147,8 @@ Accessible *accessible_app_handle (char *app_name) */ if (strchr (name, ' ')) g_strstrip (name); - - if (strcasecmp (name, app_name) == 0) + + if (g_ascii_strcasecmp (name, app_name) == 0) { /* Application name matched @@ -92,126 +165,700 @@ Accessible *accessible_app_handle (char *app_name) 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; + + g_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 (g_ascii_strcasecmp (obj_info->object_type, "separator" ) == 0 || + g_ascii_strcasecmp (obj_info->object_type, "table_cell" ) == 0) + return 0; + if (g_ascii_strcasecmp (label, "ukngrip" ) == 0) + return 0; + if (g_ascii_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 (g_ascii_strcasecmp (obj_info->object_type, "list_item") == 0) + return 0; + + if (g_ascii_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); + if (relation) + { + max_accessible = AccessibleRelation_getNTargets (*relation); + if (max_accessible > 0) + { + int relation_targets = 0; + for (i = 0; i < (relation_targets = 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) + { + int j = 0; + char *name = NULL; + Accessible *tmp_obj; + tmp_obj = AccessibleRelation_getTarget (relation[i], i); + name = Accessible_getName (tmp_obj); + if (g_ascii_strcasecmp (name, "") == 0) + { + SPI_freeString (name); + Accessible_unref (tmp_obj); + for (j = i; relation[j] != NULL; j++) + Accessible_unref (relation[j]); + return NULL; + } + label_by = g_strdup (name); + SPI_freeString (name); + Accessible_unref (tmp_obj); + for (j = i; relation[j] != NULL; j++) + Accessible_unref (relation[j]); + return label_by; + } + Accessible_unref (relation[i]); + } + } } + 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 = NULL; + 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_ascii_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 (strstr (label, " ")) + { + char *stripped_data = NULL; + stripped_data = strip_white_space (label); + if (g_ascii_strcasecmp (stripped_data, "") == 0) + { + g_free (label); + label = g_strdup (stripped_data); + g_free (stripped_data); + } + else + g_free (stripped_data); + } + + if (filter_appmap_data (accessible, cur_obj_info, name)) + { + if (g_ascii_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 + { + char *tmp; + if (strstr (label_by, ":")) + { + tmp = strip_delim (label_by, ':'); + g_free (label_by); + label_by = g_strdup (tmp); + g_free (tmp); + value = NULL; + } + 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); + label_by = NULL; + } + } + else + { + if (g_ascii_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 (label_by); + 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 (label_by); + 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"); + obj_info->instance_index = page_tab; + page_tab++; + obj_info->object_type = g_strdup ("page_tab"); + } + else if (role == SPI_ROLE_PAGE_TAB_LIST) + { + obj_info->prefix = g_strdup ("ptl"); + obj_info->instance_index = page_tab_list; + page_tab_list++; + obj_info->object_type = g_strdup ("page_tab_list"); + } + else if (role == SPI_ROLE_TABLE) + { + obj_info->prefix = g_strdup ("tbl"); + obj_info->instance_index = table; + table++; + obj_info->object_type = g_strdup ("table"); + } + else if (role == SPI_ROLE_COMBO_BOX) + { + obj_info->prefix = g_strdup ("cbo"); + obj_info->instance_index = combo_box; + combo_box++; + obj_info->object_type = g_strdup ("combo_box"); + } + else if (role == SPI_ROLE_SPIN_BUTTON) + { + obj_info->prefix = g_strdup ("sbtn"); + obj_info->instance_index = spin_button; + 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"); + obj_info->instance_index = radio_button; + radio_button++; + obj_info->object_type = g_strdup ("radio_button"); + } + else if (role == SPI_ROLE_TREE_TABLE) + { + obj_info->prefix = g_strdup ("ttbl"); + obj_info->instance_index = tree_table; + tree_table++; + obj_info->object_type = g_strdup ("tree_table"); + } + else if (role == SPI_ROLE_LAYERED_PANE) + { + obj_info->prefix = g_strdup ("pane"); + obj_info->instance_index = layered_pane; + 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"); + obj_info->instance_index = cal_view; + cal_view++; + obj_info->object_type = g_strdup ("calendar_view"); + } + else if (role == SPI_ROLE_PANEL) + { + obj_info->prefix = g_strdup ("pnl"); + obj_info->instance_index = panel; + panel++; + obj_info->object_type = g_strdup ("panel"); + } + else if (role == SPI_ROLE_LABEL) + { + obj_info->prefix = g_strdup ("lbl"); + obj_info->instance_index = label; + label++; + obj_info->object_type = g_strdup ("label"); + } + else if (role == SPI_ROLE_MENU_BAR) + { + obj_info->prefix = g_strdup ("mbr"); + obj_info->instance_index = menubar; + menubar++; + obj_info->object_type = g_strdup ("menu_bar"); + } + else if (role == SPI_ROLE_MENU) + { + obj_info->prefix = g_strdup ("mnu"); + obj_info->instance_index = menu; + menu++; + obj_info->object_type = g_strdup ("menu"); + } + else if (role == SPI_ROLE_MENU_ITEM) + { + obj_info->prefix = g_strdup ("mnu"); + obj_info->instance_index = menu; + 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"); + obj_info->instance_index = menu; + menu++; + obj_info->object_type = g_strdup ("check_menu_item"); + } + else if (role == SPI_ROLE_RADIO_MENU_ITEM) + { + obj_info->prefix = g_strdup ("mnu"); + obj_info->instance_index = menu; + menu++; + obj_info->object_type = g_strdup ("radio_menu_item"); + } + + else if (role == SPI_ROLE_PUSH_BUTTON) + { + obj_info->prefix = g_strdup ("btn"); + obj_info->instance_index = button; + button++; + obj_info->object_type = g_strdup ("push_button"); + } + else if (role == SPI_ROLE_TOGGLE_BUTTON) + { + obj_info->prefix = g_strdup ("btn"); + obj_info->instance_index = button; + button++; + obj_info->object_type = g_strdup ("toggle_button"); + } + else if (role == SPI_ROLE_SCROLL_BAR) + { + obj_info->prefix = g_strdup ("scbr"); + obj_info->instance_index = scroll_bar; + scroll_bar++; + obj_info->object_type = g_strdup ("scroll_bar"); + } + else if (role == SPI_ROLE_SCROLL_PANE) + { + obj_info->prefix = g_strdup ("scpn"); + obj_info->instance_index = scroll_pane; + scroll_pane++; + obj_info->object_type = g_strdup ("scroll_pane"); + } + else if (role == SPI_ROLE_TEXT) + { + obj_info->prefix = g_strdup ("txt"); + obj_info->instance_index = text; + text++; + obj_info->object_type = g_strdup ("text"); + } + else if (role == SPI_ROLE_PASSWORD_TEXT) + { + obj_info->prefix = g_strdup ("txt"); + obj_info->instance_index = text; + text++; + obj_info->object_type = g_strdup ("password_text"); + } + else if (role == SPI_ROLE_STATUS_BAR) + { + obj_info->prefix = g_strdup ("stat"); + obj_info->instance_index = status_bar; + status_bar++; + obj_info->object_type = g_strdup ("statusbar"); + } + else if (role == SPI_ROLE_TABLE_COLUMN_HEADER) + { + obj_info->prefix = g_strdup ("tch"); + obj_info->instance_index = status_bar; + column_header++; + obj_info->object_type = g_strdup ("table_column_header"); + } + else if (role == SPI_ROLE_SEPARATOR) + { + obj_info->prefix = g_strdup ("spr"); + obj_info->instance_index = separator; + separator++; + obj_info->object_type = g_strdup ("separator"); + } + else if (role == SPI_ROLE_FILLER) + { + obj_info->prefix = g_strdup ("flr"); + obj_info->instance_index = filler; + filler++; + obj_info->object_type = g_strdup ("filler"); + } + else if (role == SPI_ROLE_CANVAS) + { + obj_info->prefix = g_strdup ("cnvs"); + obj_info->instance_index = canvas; + canvas++; + obj_info->object_type = g_strdup ("canvas"); + } + else if (role == SPI_ROLE_SPLIT_PANE) + { + obj_info->prefix = g_strdup ("splt"); + obj_info->instance_index = split_pane; + split_pane++; + obj_info->object_type = g_strdup ("split_pane"); + } + else if (role == SPI_ROLE_SLIDER) + { + obj_info->prefix = g_strdup ("sldr"); + obj_info->instance_index = slider; + slider++; + obj_info->object_type = g_strdup ("slider"); + } + else if (role == SPI_ROLE_HTML_CONTAINER) + { + obj_info->prefix = g_strdup ("html"); + obj_info->instance_index = html_container; + html_container++; + obj_info->object_type = g_strdup ("html_container"); + } + else if (role == SPI_ROLE_PROGRESS_BAR) + { + obj_info->prefix = g_strdup ("pbar"); + obj_info->instance_index = progress_bar; + progress_bar++; + obj_info->object_type = g_strdup ("progree_bar"); + } + else if (role == SPI_ROLE_TOOL_BAR) + { + obj_info->prefix = g_strdup ("tbar"); + obj_info->instance_index = tool_bar; + tool_bar++; + obj_info->object_type = g_strdup ("tool_bar"); + } + else if (role == SPI_ROLE_CHECK_BOX) + { + obj_info->prefix = g_strdup ("chk"); + obj_info->instance_index = check_box; + 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"); + obj_info->instance_index = unknown; + 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); + if (fp) + { + create_appmap (fp, parent, app_name); + close_appmap (fp); + } + else + { + g_print ("Unable to open file for writing application map!!\n"); + } + 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 +872,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 +880,12 @@ int main (int argc, char *argv[]) appmap_main (application_name); - check_duplicate_entries (map_filename); - g_free (application_name); g_free (map_filename); leaked = SPI_exit (); - - if (leaked) - g_warning ("Leaked %d SPI handles", leaked); + g_print ("Leaked %d SPI handles\n", leaked); putenv ("AT_BRIDGE_SHUTDOWN=1"); + return 0; } diff --git a/appmap-gen.h b/appmap-gen.h index 7143a4c..7d868fe 100644 --- a/appmap-gen.h +++ b/appmap-gen.h @@ -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 diff --git a/configure.in b/configure.in index f1e867e..36e96dc 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ AC_INIT(appmap-gen.c) -AM_INIT_AUTOMAKE(appmap, 0.0.6) +AM_INIT_AUTOMAKE(appmap, 0.2.0) dnl Specify a header configuration file AM_CONFIG_HEADER(config.h) diff --git a/parser.c b/parser.c deleted file mode 100644 index 5fc3fbc..0000000 --- a/parser.c +++ /dev/null @@ -1,1705 +0,0 @@ -/* - * Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp - * - * Author: - * Nagappan A <anagappan@novell.com> - * - * Copyright 2004 Novell, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#define _GNU_SOURCE - -#include "appmap-gen.h" -#include "parser.h" -#include "utils.h" - -static char *application_name = NULL; -static char *dialog_name = NULL; - -int table = -1, - combo_box = -1, - page_tab_list = -1, - page_tab = -1, - spin_button = -1, - push_button = -1, - radio_button = -1, - tree_table = -1, - layered_pane = -1, - text = -1, - toggle_button = -1, - cal_view = -1, - panel = -1, - label = -1; - -void reset_count() -{ - table = -1; - combo_box = -1; - page_tab_list = -1; - page_tab = -1; - spin_button = -1; - push_button = -1; - radio_button = -1; - tree_table = -1; - layered_pane = -1; - text = -1; - toggle_button = -1; - cal_view = -1; - panel = -1; - label = -1; -} - -gchar *get_prefix (char *role) -{ - gchar *prefix = NULL; - if (strcasecmp(role, "page tab" ) == 0) - prefix = g_strdup_printf ("%s", "ptab"); - if (strcasecmp(role, "page tab list" ) == 0) - prefix = g_strdup_printf ("%s", "ptl"); - if (strcasecmp(role, "table" ) == 0) - prefix = g_strdup_printf ("%s", "tbl"); - if (strcasecmp(role, "combo box" ) == 0) - prefix = g_strdup_printf ("%s", "cbo"); - if (strcasecmp(role, "spin button" ) == 0) - prefix = g_strdup_printf ("%s", "sbtn"); - if (strcasecmp(role, "font chooser" ) == 0) - prefix = g_strdup_printf ("%s", "dlg"); - if (strcasecmp(role, "radio button" ) == 0) - prefix = g_strdup_printf ("%s", "rbtn"); - if (strcasecmp(role, "tree table" ) == 0) - prefix = g_strdup_printf ("%s", "ttbl"); - if (strcasecmp(role, "layered pane" ) == 0) - prefix = g_strdup_printf ("%s", "pane"); - if (strcasecmp(role, "frame" ) == 0) - prefix = g_strdup_printf ("%s", "frm"); - if (strcasecmp(role, "dialog" ) == 0) - prefix = g_strdup_printf ("%s", "dlg"); - if (strcasecmp(role, "Calendar view" ) == 0) - prefix = g_strdup_printf ("%s", "calview"); - if (strcasecmp(role, "panel" ) == 0) - prefix = g_strdup_printf ("%s", "pnl"); - if (strcasecmp(role, "label" ) == 0) - prefix = g_strdup_printf ("%s", "lbl"); - return prefix; -} - -char *get_parent_role (Accessible *child) -{ - char *role = NULL; - char *parent_role = NULL; - Accessible *parent; - - parent = Accessible_getParent (child); - role = Accessible_getRoleName (parent); - Accessible_unref (parent); - if (!role || strcmp (role, "") == 0) - { - if (role) - SPI_freeString (role); - return NULL; - } - parent_role = strdup (role); - SPI_freeString (role); - return parent_role; -} - -static int is_object_model_type (char *object_type) -{ - if (strcasecmp (object_type, "frame") == 0 || - strcasecmp (object_type, "dialog") == 0 || - strcasecmp (object_type, "fontchooser") == 0) - { -#ifdef DEBUG - printf ("Object type is a window model\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_model_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - reset_count(); - if (strcasecmp (object_type, "frame") == 0) - { - int size = 0; - char *str_format = NULL; - gchar *tmp_name = NULL; - gchar *tmp_app_name = NULL; - - tmp_name = g_ascii_strup (name, strlen (name)); - tmp_app_name = g_ascii_strup (application_name, strlen (application_name)); - if (strcmp (name, "") != 0 && strstr (tmp_name, tmp_app_name) == NULL) - { - int size = 0; - char *data = NULL; - char *str_format = NULL; - - if (strchr (name, ' ')) - data = strip_white_space (name); - else - data = strdup (name); - str_format = g_strdup_printf ("[%s]\n%s", - data, - data); - size = strlen (str_format); - free (data); -#ifdef DEBUG - printf ("%s", str_format); -#endif - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - } - else - { - int size = 0; - char *str_format = NULL; - - str_format = g_strdup_printf ("[%s]\n%s", - application_name, - application_name); - size = strlen (str_format); -#ifdef DEBUG - printf ("%s", str_format); -#endif - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - } - - g_free (tmp_name); - g_free (tmp_app_name); - str_format = g_strdup_printf ("={class=frame, app_name=%s}\n", - application_name); - size = strlen (str_format); - -#ifdef DEBUG - printf ("%s", str_format); -#endif - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - - return 0; - } - if (strcasecmp (object_type, "dialog") == 0) - { - int size = 0; - char *str_format = NULL; - - if (strchr (name, ' ')) - { - char *data = NULL; - char *stripped_data = NULL; - - stripped_data = data = strip_white_space (name); - if (strchr (stripped_data, '.')) - { - data = strip_delim (stripped_data, '.'); - free (stripped_data); - } - str_format = g_strdup_printf ("[dlg%s]\ndlg%s={class=dialog, label=%s, app_name=%s}\n", - data, data, - name, application_name); - size = strlen (str_format); - free (data); - if (dialog_name) - { - free (dialog_name); - dialog_name = NULL; - } - dialog_name = strdup (name); - } - else - { - char *data = NULL; - char *stripped_data = NULL; - - stripped_data = data = strip_white_space (name); - if (strchr (stripped_data, '.')) - { - data = strip_delim (stripped_data, '.'); - free (stripped_data); - } - else - data = strdup (name); - str_format = g_strdup_printf ("[dlg%s]\ndlg%s={class=dialog, label=%s, app_name=%s}\n", - data, data, - data, application_name); - size = strlen (str_format); - free (data); - if (dialog_name) - { - free (dialog_name); - dialog_name = NULL; - } - dialog_name = strdup (name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - if (strcasecmp (object_type, "fontchooser") == 0) - { - int size = 0; - char *str_format = NULL; - - if (strchr (name, ' ')) - { - char *data = NULL; - char *stripped_data = NULL; - - stripped_data = data = strip_white_space (name); - if (strchr (stripped_data, '.')) - { - data = strip_delim (stripped_data, '.'); - free (stripped_data); - } - str_format = g_strdup_printf ("[dlg%s]\ndlg%s={class=fontchooser, label=%s, app_name=%s}\n", - data, data, - name, application_name); - free (data); - if (dialog_name) - { - free (dialog_name); - dialog_name = NULL; - } - dialog_name = strdup (name); - } - else - { - str_format = g_strdup_printf ( - "[dlg%s]\ndlg%s={class=fontchooser, label=%s, app_name=%s}\n", - name, - name, - name, - application_name); - if (dialog_name) - { - free (dialog_name); - dialog_name = NULL; - } - dialog_name = strdup (name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } -#ifdef DEBUG - printf ("Window model type not implemented\n"); -#endif - return -1; -} - -static int is_object_menu_type (char *object_type) -{ - if (strcasecmp (object_type, "menu") == 0 || - strcasecmp (object_type, "menu item") == 0 || - strcasecmp (object_type, "check menu item") == 0 || - strcasecmp (object_type, "radio menu item") == 0 || - strcasecmp (object_type, "menu bar") == 0) - { -#ifdef DEBUG - printf ("Object type is a menu or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_menu_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "menu") == 0) - { - int size = 0; - char *str_format = NULL; - char *stripped_data = NULL; - - if (strchr (name, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - str_format = g_strdup_printf ("mnu%s={class=menu, label=%s}\n", - data, name); - size = strlen (str_format); - free (data); - } - else - { - if (strcmp (name, "") != 0) - { - str_format = g_strdup_printf ("mnu%s={class=menu, label=%s}\n", - name, name); - size = strlen (str_format); - } - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - if (strcasecmp (object_type, "menu item") == 0) - { - int size = 0; - char *data = NULL; - char *str_format = NULL; - char *stripped_data = NULL; - char *parent_name = NULL,*temp=NULL; - Accessible *parent ; - - while (temp == NULL || (strlen(temp) == 0)) - { - parent = Accessible_getParent (object); - temp = Accessible_getName (parent); - object = parent; - Accessible_unref(parent); - } - parent_name = strdup(temp); - if (strchr (temp, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - parent_name = strdup(data); - free (data); - } - - if (strchr (name, ' ')) - { - stripped_data = data = strip_white_space (name); - if (strchr (stripped_data, '.')) - { - data = strip_delim (stripped_data, '.'); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - } - else - { - if (strchr (name, '.')) - { - data = strip_delim (name, '.'); - } - else - data = strdup (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - } - str_format = g_strdup_printf ("mnu%s={class=menu_item, label=%s, parent=mnu%s}\n", - data, name, - parent_name); - free (data); -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - if (strcasecmp (object_type, "radio menu item") == 0) - { - int size = 0; - char *str_format = NULL; - char *stripped_data = NULL ; - char *parent_name = NULL,*temp=NULL; - Accessible *parent ; - - while (temp == NULL || (strlen(temp) == 0)) - { - parent = Accessible_getParent (object); - temp = Accessible_getName (parent); - Accessible_unref(parent); - object = parent; - } - parent_name = strdup(temp); - if (strchr (temp, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - parent_name = strdup(data); - free (data); - } - - if (strchr (name, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - str_format = g_strdup_printf ("mnu%s={class=radio_menu_item, label=%s, parent=mnu%s}\n", - data, name, parent_name); - free (data); - } - else - { - str_format = g_strdup_printf ("mnu%s={class=radio_menu_item, label=%s, parent=mnu%s}\n", - name, name, parent_name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - if (strcasecmp (object_type, "check menu item") == 0) - { - int size = 0; - char *str_format = NULL; - char *stripped_data = NULL; - char *parent_name = NULL,*temp=NULL; - Accessible *parent ; - - while (temp == NULL || (strlen(temp) == 0)) - { - parent = Accessible_getParent (object); - temp = Accessible_getName (parent); - Accessible_unref(parent); - object = parent; - } - parent_name = strdup(temp); - if (strchr (temp, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - parent_name = strdup(data); - free (data); - } - - if (strchr (name, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - str_format = g_strdup_printf ("mnu%s={class=check_menu_item, label=%s, parent=mnu%s}\n", - data, name, parent_name); - free (data); - } - else - { - str_format = g_strdup_printf ("mnu%s={class=check_menu_item, label=%s, parent=mnu%s}\n", - name, name, parent_name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } -#ifdef DEBUG - printf ("Menu type not implemented %s %s\n", name, object_type); -#endif - return -1; -} - -static int is_object_button_type (char *object_type) -{ - if (strcasecmp (object_type, "push button") == 0 || - strcasecmp (object_type, "check box") == 0 || - strcasecmp (object_type, "radio button") == 0 || - strcasecmp (object_type, "spin button") == 0) - { -#ifdef DEBUG - printf ("Object type is a button or its subset\n"); -#endif - return 1; - } - return 0; -} - -int generate_obj_info (FILE *fp, Accessible *object, char *obj_str, - char *obj_type, char *obj_name, char delim) -{ - int size = 0; - char *str_format = NULL; - - if (strchr (obj_name, ' ') && - strcasecmp (obj_type, "spin_button") != 0) - { - char *data = NULL; - char *stripped_data = NULL; - - stripped_data = data = strip_white_space (obj_name); - if (strchr (stripped_data, delim)) - { - data = strip_delim (stripped_data, delim); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label=%s}\n", - obj_str, data, - obj_type, obj_name); - size = strlen (str_format); - free (data); - } - else if (strlen (obj_name) == 0 || - strcasecmp (obj_type, "spin_button") == 0) - { - int i = 0; - AccessibleRelation **relation; - - relation = Accessible_getRelationSet (object); - if (AccessibleRelation_getNTargets (*relation) == -1) - { - AccessibleRelation_unref (*relation); - return -1; - } - 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 *data = NULL; - char *label = NULL; - Accessible *tmp_obj; - char *stripped_data = NULL; - - tmp_obj = AccessibleRelation_getTarget (relation[i], i); - label = Accessible_getName (tmp_obj); - Accessible_unref (tmp_obj); - if (strchr (label, ' ')) - { - stripped_data = data = strip_white_space (label); - if (strchr (stripped_data, delim)) - { - data = strip_delim (stripped_data, delim); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - } - else - { - if (strchr (label, delim)) - { - data = strip_delim (label, delim); - } - else - data = strdup (label); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - } - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label_by=%s}\n", - obj_str, data, - obj_type, label); - free (data); - SPI_freeString (label); - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - } - AccessibleRelation_unref (relation[i]); - } - Accessible_unref (*relation); - return 0; - } - else - { - char *data = NULL; - char *stripped_data = NULL; - - if (strchr (obj_name, delim)) - data = strip_delim (obj_name, delim); - else - data = strdup (obj_name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label=%s}\n", - obj_str, data, - obj_type, obj_name); - free (data); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; -} - -int generate_obj_info_index (FILE *fp, Accessible *object, char *obj_str, - char *obj_type, char *obj_name, char delim , int index) -{ - int size = 0, i = 0; - char *str_format = NULL; - char *parent_name = NULL; - char *prefix = NULL; - char *role = NULL, *temp = NULL; - Accessible *child = object; - - while (1) - { - char *name; - Accessible *parent; - parent = Accessible_getParent (child); - name = Accessible_getName (parent); - if (name && (strlen (name) > 0)) - { - role = Accessible_getRoleName (parent); - temp = g_strdup (name); - g_print ("Name: %s - Role: %s\n", name, role); - SPI_freeString (name); - if (child != object) - Accessible_unref (child); - prefix = get_prefix (role); - SPI_freeString (role); - Accessible_unref (parent); - break; - } - if (child != object) - Accessible_unref (child); - child = parent; - } - - if (temp && (strchr (temp, ' ') || strchr (temp, '(') || strchr (temp, '{'))) - { - char *data = NULL; - char *stripped_data = NULL; - - stripped_data = data = strip_white_space (temp); - g_free (temp); - if (strchr (stripped_data, delim)) - { - data = strip_delim (stripped_data, delim); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - parent_name = g_strdup (data); - free (data); - } - else - parent_name = temp; - - if (strchr (obj_name, ' ') && - strcasecmp (obj_type, "spinstrip_button") != 0) - { - char *data = NULL; - char *stripped_data = NULL; - stripped_data = data = strip_white_space (obj_name); - if (strchr (stripped_data, delim)) - { - data = strip_delim (stripped_data, delim); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label=%s}\n", - obj_str, data, - obj_type, obj_name); - size = strlen (str_format); - free (data); - } - else if (strlen (obj_name) == 0 || - strcasecmp (obj_type, "spin_button") == 0) - { - int i = 0; - AccessibleRelation **relation; - relation = Accessible_getRelationSet (object); - if (AccessibleRelation_getNTargets (*relation) == -1) - { - AccessibleRelation_unref (*relation); - str_format = g_strdup_printf ("%s%d={class=%s, instance_index=%d, parent=%s%s}\n", - obj_str, index, obj_type, - index, prefix, parent_name); - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - g_free (str_format); - g_free (prefix); - g_free (parent_name); - return 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 *data = NULL; - char *label = NULL; - Accessible *tmp_obj; - char *stripped_data = NULL; - - tmp_obj = AccessibleRelation_getTarget (relation[i], i); - label = Accessible_getName (tmp_obj); - Accessible_unref (tmp_obj); - if (strchr (label, ' ')) - { - stripped_data = data = strip_white_space (label); - if (strchr (stripped_data, delim)) - { - data = strip_delim (stripped_data, delim); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - } - else - { - if (strchr (label, delim)) - { - data = strip_delim (label, delim); - } - else - data = strdup (label); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - - } - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label_by=%s}\n", - obj_str, data, - obj_type, label); - free (data); - SPI_freeString (label); - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - } - AccessibleRelation_unref (relation[i]); - } - Accessible_unref (*relation); - return 0; - } - else - { - char *data = NULL; - char *stripped_data = NULL; - if (strchr (obj_name, delim)) - data = strip_delim (obj_name, delim); - else - data = strdup (obj_name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - stripped_data = data; - if (strchr (stripped_data, '{')) - { - data = strip_delim (stripped_data, '{'); - free (stripped_data); - } - if (strcasecmp (obj_type, "push_button") == 0 && - strchr (stripped_data, ':')) - { - data = strip_delim (stripped_data, ':'); - free (stripped_data); - } - str_format = g_strdup_printf ("%s%s={class=%s, label=%s}\n", - obj_str, data, - obj_type, obj_name); - free (data); - } - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; -} - -static int add_object_button_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "push button") == 0) - { - push_button++; - generate_obj_info_index (fp, object, "btn", "push_button", name, '.', push_button); - // if (strcasecmp (name, "close") == 0 || - // strcasecmp (name, "cancel") == 0) - // do_action (name, object, 2); - return 0; - } - if (strcasecmp (object_type, "spin button") == 0) - { - spin_button++; - generate_obj_info_index (fp, object, "sbtn", "spin_button", name, ':',spin_button); - return 0; - } - if (strcasecmp (object_type, "check box") == 0) - { - generate_obj_info (fp, object, "chk", "check_box", name, ':'); - return 0; - } - if (strcasecmp (object_type, "radio button") == 0) - { - radio_button++; - generate_obj_info_index (fp, object, "rdo", "radio_button", name, ':', radio_button); - return 0; - } -#ifdef DEBUG - printf ("Button type %s not implemented\n", object_type); -#endif - return -1; -} - -static int is_object_page_tab_type (char *object_type) -{ - if (strcasecmp (object_type, "page tab list") == 0 || - strcasecmp (object_type, "page tab") == 0) - { -#ifdef DEBUG - printf ("Object type is a page tab list or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "page tab list") == 0) - { - - page_tab_list++; - int size = 0; - char *str_format = NULL; - char *stripped_data = NULL; - char *parent_name = NULL,*temp=NULL; - Accessible *parent ; - /* if (!dialog_name) - { - printf("****page\n"); - return -1; - }*/ - while (temp == NULL || (strlen(temp) == 0)) - { - parent = Accessible_getParent (object); - temp = Accessible_getName (parent); - object = parent; - Accessible_unref(parent); - } - parent_name=strip_white_space (temp); - //parent_name = strdup(temp); - - - if (strlen(name) !=0) - { - if (strchr (dialog_name, ' ')) - { - char *data = NULL; - data = strip_white_space (dialog_name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - str_format = g_strdup_printf ("ptl%s={class=page_tab_list}\n", - dialog_name); - free (data); - } - else - { - str_format = g_strdup_printf ("ptl%s={class=page_tab_list}\n", - dialog_name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - else - { - if(dialog_name) - { - str_format = g_strdup_printf ("ptl%s%d={class=%s, instance_index=%d, parent=%s}\n", - parent_name, - page_tab_list, - "page_tab_list", - page_tab_list,parent_name); - } - else - { - str_format = g_strdup_printf ("ptl%d={class=%s, instance_index=%d}\n", - page_tab_list, - "page_tab_list", - page_tab_list); - } - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - - } - } - if (strcasecmp (object_type, "page tab") == 0) - { - page_tab++; - int size = 0; - char *str_format = NULL; - char *stripped_data = NULL; - char *parent_name = NULL,*temp=NULL; - Accessible *parent ; - - /* if (!dialog_name) - { - printf("****page\n"); - return -1; - }*/ - while (temp == NULL || (strlen(temp) == 0)) - { - parent = Accessible_getParent (object); - temp = Accessible_getName (parent); - object = parent; - Accessible_unref(parent); - } - parent_name=strip_white_space (temp); - if (strlen(name) !=0) - { - if (strchr (name, ' ')) - { - char *data = NULL; - - data = strip_white_space (name); - stripped_data = data; - if (strchr (stripped_data, '(')) - { - data = strip_delim (stripped_data, '('); - free (stripped_data); - } - str_format = g_strdup_printf ("ptab%s={class=page_tab, label=%s}\n", - data, name); - free (data); - } - else - { - str_format = g_strdup_printf ("ptab%s={class=page_tab, label=%s}\n", - name, name); - } -#ifdef DEBUG - printf ("%s", str_format); -#endif - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - } - - else - { - if(dialog_name) - { - str_format = g_strdup_printf ("ptb%d={class=%s, instance_index=%d, parent=%s }\n", - page_tab, - "page_tab", - page_tab, - parent_name); - size = strlen (str_format); - } - else - str_format = g_strdup_printf ("ptb%d={class=%s, instance_index=%d}\n", - page_tab, - "page_tab", - page_tab); - size = strlen (str_format); - fwrite (str_format, sizeof (char), size, fp); - free (str_format); - return 0; - - } - - } -#ifdef DEBUG - printf ("Page tab type not implemented\n"); -#endif - return -1; -} - -static int is_object_table_type (char *object_type) -{ - if (strcasecmp (object_type, "table") == 0) - { -#ifdef DEBUG - printf ("Object type is a table or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_table_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "table") == 0) - { - table++; - generate_obj_info_index (fp, object, "tbl", "table", name, ':', table); - //generate_obj_info (fp, object, "tbl", "table", name, ':'); - return 0; - } -#ifdef DEBUG - printf ("Table type not implemented\n"); -#endif - return -1; -} - -static int is_object_tree_table_type (char *object_type) -{ - if (strcasecmp (object_type, "tree table") == 0) - { -#ifdef DEBUG - printf ("Object type is a tree table or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_tree_table_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "tree table") == 0) - { - tree_table++; - generate_obj_info_index (fp, object, "ttbl", "tree_table", name, ':',tree_table); - return 0; - } -#ifdef DEBUG - printf ("Tree Table type not implemented\n"); -#endif - return -1; -} - - -static int is_object_layered_pane_type (char *object_type) -{ - if (strcasecmp (object_type, "layered pane") == 0) - { -#ifdef DEBUG - printf ("Object type is a layered pane or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_layered_pane_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "layered pane") == 0) - { - layered_pane++; - generate_obj_info_index (fp, object, "pane", "layered_pane", name, ':',layered_pane); - return 0; - } -#ifdef DEBUG - printf ("Layered pane type not implemented\n"); -#endif - return -1; -} - -static int is_object_text_type (char *object_type) -{ - if (strcasecmp (object_type, "text") == 0) - { -#ifdef DEBUG - printf ("Object type is a text or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_text_type (FILE *fp, char *name, char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "text") == 0) - { - text++; - generate_obj_info_index (fp, object, "txt", "text", name, ':',text); - return 0; - } -#ifdef DEBUG - printf ("Text type not implemented\n"); -#endif - return -1; -} - -static int is_object_toggle_button_type (char *object_type) -{ - if (strcasecmp (object_type, "toggle button") == 0) - { -#ifdef DEBUG - printf ("Object type is a toggle button or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_toggle_button_type (FILE *fp, char *name, - char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "toggle button") == 0) - { - toggle_button++; - generate_obj_info_index (fp, object, "tbtn", "toggle_button", name, ':',toggle_button); - return 0; - } -#ifdef DEBUG - printf ("Toggle button type not implemented\n"); -#endif - return -1; -} - -static int is_object_calendar_view_type (char *object_type) -{ - if (strcasecmp (object_type, "Calendar View") == 0) - { -#ifdef DEBUG - printf ("Object type is a calendar view or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_calendar_view_type (FILE *fp, char *name, - char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "Calendar View") == 0) - { - cal_view++; - generate_obj_info_index (fp, object, "calView", "calendar_view", name, ':',cal_view); - return 0; - } -#ifdef DEBUG - printf ("Calendar View type not implemented\n"); -#endif - return -1; -} - -static int is_object_combo_box_type (char *object_type) -{ - if (strcasecmp (object_type, "combo box") == 0) - { -#ifdef DEBUG - printf ("Object type is a combo box or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_combo_box_type (FILE *fp, char *name, - char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "combo box") == 0) - { - combo_box++; - generate_obj_info_index (fp, object, "cbo", "combo_box", name, ':',combo_box); - return 0; - } -#ifdef DEBUG - printf ("combo box type not implemented\n"); -#endif - return -1; -} - -static int is_object_panel_type (char *object_type) -{ - if (strcasecmp (object_type, "panel") == 0) - { -#ifdef DEBUG - printf ("Object type is a panel or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_panel_type (FILE *fp, char *name, - char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "panel") == 0) - { - panel++; - generate_obj_info_index (fp, object, "pnl", "panel", name, ':',panel); - return 0; - } -#ifdef DEBUG - printf ("panel type not implemented\n"); -#endif - return -1; -} - -static int is_object_label_type (char *object_type) -{ - if (strcasecmp (object_type, "label") == 0) - { -#ifdef DEBUG - printf ("Object type is a label or its subset\n"); -#endif - return 1; - } - return 0; -} - -static int add_object_label_type (FILE *fp, char *name, - char *object_type, Accessible *object) -{ - if (strcasecmp (object_type, "label") == 0) - { - label++; - generate_obj_info_index (fp, object, "lbl", "label", name, ':',label); - return 0; - } -#ifdef DEBUG - printf ("label type not implemented\n"); -#endif - return -1; -} - - -int add_appmap_data (FILE *fp, Accessible *object) -{ - char *name = NULL; - char *object_type = NULL; - static int window_model_count = 0; - - name = Accessible_getName (object); - object_type = Accessible_getRoleName (object); - if (is_object_model_type (object_type)) - { - - if (window_model_count) - { - window_model_count++; - fwrite ("\n", sizeof (char), strlen ("\n"), fp); - } - else - window_model_count++; - add_object_model_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_menu_type (object_type)) - { - - add_object_menu_type (fp, name, object_type, object); - if ( strcasecmp (object_type, "menu item") == 0 ) - { - if (strcasecmp (name, "exit") != 0 && - strcasecmp (name, "close") != 0 && - strcasecmp (name, "quit") != 0 && - strcasecmp (name, "help") != 0 && - strcasecmp (name, "contents") != 0) - { - int combo_box = 0; - Accessible *parent = object; - - while (1) - { - char *parent_role = NULL; - Accessible *child = parent; - parent_role = get_parent_role (child); - if (!parent_role) - { - if (parent != object) - Accessible_unref (parent); - break; - } - if (strcasecmp (parent_role, "invalid") == 0) - { - if (parent != object) - Accessible_unref (parent); - break; - } - if (strcasecmp (parent_role, "combo box") == 0) - { - if (parent != object) - Accessible_unref (parent); - combo_box = 1; - break; - } - child = Accessible_getParent (parent); - if (parent && parent != object) - Accessible_unref (parent); - else - { - if (child != object) - Accessible_unref (child); - break; - } - parent = child; - } - // if (combo_box == 0) - // do_action (name, object, 1); - } - } - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_button_type (object_type)) - { - add_object_button_type (fp, name, object_type, object); - - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_page_tab_type (object_type)) - { - add_object_page_tab_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_table_type (object_type)) - { - add_object_table_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_layered_pane_type (object_type)) - { - add_object_layered_pane_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_text_type (object_type)) - { - add_object_text_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_toggle_button_type (object_type)) - { - add_object_toggle_button_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_calendar_view_type (object_type)) - { - add_object_calendar_view_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_combo_box_type (object_type)) - { - add_object_combo_box_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_tree_table_type (object_type)) - { - add_object_tree_table_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_panel_type (object_type)) - { - add_object_panel_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - if (is_object_label_type (object_type)) - { - add_object_label_type (fp, name, object_type, object); - SPI_freeString (name); - SPI_freeString (object_type); - return 0; - } - SPI_freeString (name); - SPI_freeString (object_type); - return 0; -} - -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) - { - g_free (appmap_file); - return NULL; - } - application_name = strdup (app_name); - free (app_name); - g_free (appmap_file); - return fp; -} - -int close_appmap (FILE *fp) -{ - if (fp) - fclose (fp); - if (application_name) - { - free (application_name); - application_name = NULL; - } - free (application_name); - if (dialog_name) - { - free (dialog_name); - dialog_name = NULL; - } - return 0; -} - -int do_action (char *name, Accessible *object, int skip) -{ - int status = 0; - FILE *tempfp; - char *tmp = NULL; - char *data = NULL; - char *dir_name = NULL; - char *file_name = NULL; - AccessibleAction *action; - Accessible *parent; - - tmp = g_get_current_dir (); - dir_name = g_strdup_printf ("%s/tmpmapdir", tmp); - free (tmp); - - status = mkdir (dir_name, S_IRWXU | S_IRUSR | S_IXUSR | S_IROTH | S_IXOTH); - printf ("STATUS: %d - Dir: %s\n", status, dir_name); - - data = strdup (name); - if (strchr (name, ' ')) - { - free (data); - data = strip_white_space (name); - } - if (strchr (name, '.')) - { - char *tmp; - tmp = strip_delim (data, '.'); - free (data); - data = tmp; - } - - file_name = g_strdup_printf ("%s/%s.map", dir_name, data); - free (data); - free (dir_name); - - tempfp = fopen (file_name, "w"); - if (tempfp == NULL) - { - free (dir_name); - return -1; - } - - action = Accessible_getAction (object); - AccessibleAction_doAction (action, 0); - Accessible_unref (action); - parent = accessible_app_handle (application_name); - accessible_object_handle (tempfp, parent, skip); - Accessible_unref (parent); - fclose (tempfp); - - { - /* - If file size is zero just delete the file - */ - struct stat buf; - stat(file_name, &buf); - if (buf.st_size == 0) - unlink (file_name); - } - free (file_name); - return 0; -} /* end of do action*/ diff --git a/parser.h b/parser.h deleted file mode 100644 index d483438..0000000 --- a/parser.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - File: parser.h -*/ - -#ifndef _PARSER_H_ -#define _PARSER_H_ - -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -FILE *open_appmap (char *app_name); -int close_appmap (FILE *fp); -int add_appmap_data (FILE *fp, Accessible *object); -int do_action (char *name, Accessible *object,int skip); - -#endif @@ -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 delim) 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) { |