diff options
author | sshaik <sshaik> | 2005-05-26 11:07:51 +0000 |
---|---|---|
committer | sshaik <sshaik> | 2005-05-26 11:07:51 +0000 |
commit | 2f3d68c3597ef75474ec2c39dc4b24679bc6f988 (patch) | |
tree | 26f7c57a17eddc27cbbcdb252a1d1e0dc5d99025 | |
parent | 54169185c909caa57540847b4805c24a65d6314a (diff) |
Modified function: check for duplicate entries in appmap using hash table by shagan
-rw-r--r-- | appmap-gen.c | 78 | ||||
-rw-r--r-- | parser.c | 500 |
2 files changed, 551 insertions, 27 deletions
diff --git a/appmap-gen.c b/appmap-gen.c index 9be3396..0a3236d 100644 --- a/appmap-gen.c +++ b/appmap-gen.c @@ -26,8 +26,11 @@ #include "appmap-gen.h" #include "parser.h" +#include "utils.h" +typedef GHashTable Appmap; char *application_name; +char *appln_name; /* Get accessible handle of the given application @@ -124,7 +127,6 @@ int appmap_main (char *app_name) FILE *fp = NULL; Accessible *parent; - g_strstrip (app_name); parent = accessible_app_handle (app_name); if (!parent) { @@ -134,10 +136,75 @@ int appmap_main (char *app_name) fp = open_appmap (app_name); accessible_object_handle (fp, parent, 0); Accessible_unref (parent); - close_appmap (fp); + close_appmap (fp); return 0; } +void print_entries (char *key, char *value, char *userdata) +{ + printf ("%s = %s\n", key, value); +} +int check_duplicate_entries (char *gui_map_filename) +{ + int fd,line_no=0; + FILE *fp; + GHashTable *appmap; + appmap = g_hash_table_new (&g_str_hash, &g_str_equal); + + fp = fopen (gui_map_filename, "r"); + if (fp ==NULL) + { + g_print ("Unable to open appmap %s file\n", gui_map_filename); + return 0; + } + fd = fileno (fp); + + { + char *data; + char *entry = NULL; + char *char_line=NULL; + while (1) + { + 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); + asprintf(&char_line,"%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 + { + printf("DUPLICATE : Line no:%s :%s",char_line,data); + continue; + } + } + } + free(data); + } + } + + // g_hash_table_foreach (appmap, (GHFunc)&print_entries, NULL); + /* + Print all the data in hash table + */ + return 1; +} + + int main (int argc, char *argv[]) { int leaked; @@ -148,8 +215,10 @@ int main (int argc, char *argv[]) printf("Syntax: ldtp <application name>\n"); exit(0); } - application_name = strdup (argv[1]); + application_name = strdup (argv[1]); + appln_name = strdup (argv[1]); + init_error = SPI_init (); if (init_error) { @@ -161,7 +230,7 @@ int main (int argc, char *argv[]) putenv ("GNOME_ACCESSIBILITY=1"); appmap_main (application_name); - + check_duplicate_entries(appln_name); free (application_name); leaked = SPI_exit (); @@ -173,5 +242,6 @@ int main (int argc, char *argv[]) #endif putenv ("AT_BRIDGE_SHUTDOWN=1"); + return 0; } @@ -31,6 +31,73 @@ 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; +} + +char *get_prefix(char *role) +{ + char *prefix = NULL; + if (strcasecmp(role, "page tab" ) == 0) + asprintf(&prefix, "%s","ptab"); + if (strcasecmp(role, "page tab list" ) == 0) + asprintf(&prefix, "%s","ptl"); + if (strcasecmp(role, "table" ) == 0) + asprintf(&prefix, "%s","tbl"); + if (strcasecmp(role, "combo box" ) == 0) + asprintf(&prefix, "%s","cbo"); + if (strcasecmp(role, "spin button" ) == 0) + asprintf(&prefix, "%s","sbtn"); + if (strcasecmp(role, "font chooser" ) == 0) + asprintf(&prefix, "%s","dlg"); + if (strcasecmp(role, "radio button" ) == 0) + asprintf(&prefix, "%s","rbtn"); + if (strcasecmp(role, "tree table" ) == 0) + asprintf(&prefix, "%s","ttbl"); + if (strcasecmp(role, "layered pane" ) == 0) + asprintf(&prefix, "%s","pane"); + if (strcasecmp(role, "frame" ) == 0) + asprintf(&prefix, "%s",""); + if (strcasecmp(role, "dialog" ) == 0) + asprintf(&prefix, "%s","dlg"); + if (strcasecmp(role, "Calendar view" ) == 0) + asprintf(&prefix, "%s","calview"); + if (strcasecmp(role, "panel" ) == 0) + asprintf(&prefix, "%s","pnl"); + if (strcasecmp(role, "label" ) == 0) + asprintf(&prefix, "%s","lbl"); + return prefix; +} + char *get_parent_role (Accessible *child) { char *role = NULL; @@ -67,6 +134,7 @@ static int is_object_model_type (char *object_type) 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; @@ -302,6 +370,31 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access 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); + 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, ' ')) { @@ -334,9 +427,10 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access } } size = asprintf (&str_format, - "mnu%s={class=menu_item, label=%s}\n", + "mnu%s={class=menu_item, label=%s, parent=mnu%s}\n", data, - name); + name, + parent_name); free (data); #ifdef DEBUG printf ("%s", str_format); @@ -349,7 +443,32 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access { int size = 0; char *str_format = NULL; - char *stripped_data = 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, ' ')) { @@ -363,17 +482,17 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access free (stripped_data); } size = asprintf (&str_format, - "mnu%s={class=radio_menu_item, label=%s}\n", + "mnu%s={class=radio_menu_item, label=%s, parent=mnu%s}\n", data, - name); + name,parent_name); free (data); } else { size = asprintf (&str_format, - "mnu%s={class=radio_menu_item, label=%s}\n", + "mnu%s={class=radio_menu_item, label=%s, parent=mnu%s}\n", name, - name); + name,parent_name); } #ifdef DEBUG printf ("%s", str_format); @@ -386,7 +505,32 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access { int size = 0; char *str_format = NULL; - char *stripped_data = 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, ' ')) { @@ -400,17 +544,17 @@ static int add_object_menu_type (FILE *fp, char *name, char *object_type, Access free (stripped_data); } size = asprintf (&str_format, - "mnu%s={class=check_menu_item, label=%s}\n", + "mnu%s={class=check_menu_item, label=%s, parent=mnu%s}\n", data, - name); + name,parent_name); free (data); } else { size = asprintf (&str_format, - "mnu%s={class=check_menu_item, label=%s}\n", + "mnu%s={class=check_menu_item, label=%s, parent=mnu%s}\n", name, - name); + name,parent_name); } #ifdef DEBUG printf ("%s", str_format); @@ -619,11 +763,240 @@ int generate_obj_info (FILE *fp, Accessible *object, char *obj_str, 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; + char *str_format = NULL , *parent_name = NULL , *prefix = NULL ,*role = NULL, *temp = NULL; ; + + while (temp == NULL || (strlen (temp) == 0) ) + { + Accessible *parent; + parent = Accessible_getParent (object); + temp = Accessible_getName (parent); + role = Accessible_getRoleName(parent); + object = parent; + Accessible_unref(parent); + } + prefix = get_prefix(role); + parent_name = strdup(temp); + if (strchr (temp, ' ')) + { + char *data = NULL; + char *stripped_data = NULL; + + stripped_data = data = strip_white_space (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 = strdup(data); + free (data); + } + + 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); + } + size = asprintf (&str_format, + "%s%s={class=%s, label=%s}\n", + obj_str, + data, + obj_type, + obj_name); + 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); + size = asprintf (&str_format, + "%s%d={class=%s, instance_index=%d,parent=%s%s}\n", + obj_str, + index, + obj_type, + index,prefix,parent_name); + fwrite (str_format, sizeof (char), size, fp); + free (str_format); + 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); + } + size = asprintf (&str_format, + "%s%s={class=%s, label_by=%s}\n", + obj_str, + data, + obj_type, + label); + free (data); + SPI_freeString (label); + 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); + } + size = asprintf (&str_format, + "%s%s={class=%s, label=%s}\n", + obj_str, + data, + obj_type, + obj_name); + free (data); + } +#ifdef DEBUG + printf ("%s", str_format); +#endif + 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) { - generate_obj_info (fp, object, "btn", "push_button", name, '.'); + 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); @@ -631,7 +1004,8 @@ static int add_object_button_type (FILE *fp, char *name, char *object_type, Acce } if (strcasecmp (object_type, "spin button") == 0) { - generate_obj_info (fp, object, "sbtn", "spin_button", name, ':'); + spin_button++; + generate_obj_info_index (fp, object, "sbtn", "spin_button", name, ':',spin_button); return 0; } if (strcasecmp (object_type, "check box") == 0) @@ -641,7 +1015,8 @@ static int add_object_button_type (FILE *fp, char *name, char *object_type, Acce } if (strcasecmp (object_type, "radio button") == 0) { - generate_obj_info (fp, object, "rdo", "radio_button", name, ':'); + radio_button++; + generate_obj_info_index (fp, object, "rdo", "radio_button", name, ':', radio_button); return 0; } #ifdef DEBUG @@ -667,6 +1042,7 @@ static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Ac { if (strcasecmp (object_type, "page tab list") == 0) { + page_tab_list++; int size = 0; char *str_format = NULL; char *stripped_data = NULL; @@ -675,6 +1051,8 @@ static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Ac { return -1; } + if (strlen(name) !=0) + { if (strchr (dialog_name, ' ')) { char *data = NULL; @@ -703,9 +1081,23 @@ static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Ac fwrite (str_format, sizeof (char), size, fp); free (str_format); return 0; + } + else + { + size = asprintf (&str_format, + "ptl%d={class=%s, instance_index=%d}\n", + page_tab_list, + object_type, + page_tab_list); + 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; @@ -714,6 +1106,8 @@ static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Ac { return -1; } + if (strlen(name) !=0) + { if (strchr (name, ' ')) { char *data = NULL; @@ -745,6 +1139,21 @@ static int add_object_page_tab_type (FILE *fp, char *name, char *object_type, Ac free (str_format); return 0; } + + else + { + size = asprintf (&str_format, + "ptl%d={class=%s, instance_index=%d}\n", + page_tab_list, + object_type, + page_tab_list); + fwrite (str_format, sizeof (char), size, fp); + free (str_format); + return 0; + + } + + } #ifdef DEBUG printf ("Page tab type not implemented\n"); #endif @@ -767,7 +1176,9 @@ static int add_object_table_type (FILE *fp, char *name, char *object_type, Acces { if (strcasecmp (object_type, "table") == 0) { - generate_obj_info (fp, object, "tbl", "table", name, ':'); + table++; + generate_obj_info_index (fp, object, "tbl", "table", name, ':', table); + //generate_obj_info (fp, object, "tbl", "table", name, ':'); return 0; } #ifdef DEBUG @@ -792,7 +1203,8 @@ static int add_object_tree_table_type (FILE *fp, char *name, char *object_type, { if (strcasecmp (object_type, "tree table") == 0) { - generate_obj_info (fp, object, "trtbl", "tree_table", name, ':'); + tree_table++; + generate_obj_info_index (fp, object, "ttbl", "tree_table", name, ':',tree_table); return 0; } #ifdef DEBUG @@ -818,7 +1230,8 @@ static int add_object_layered_pane_type (FILE *fp, char *name, char *object_type { if (strcasecmp (object_type, "layered pane") == 0) { - generate_obj_info (fp, object, "pane", "layered_pane", name, ':'); + layered_pane++; + generate_obj_info_index (fp, object, "pane", "layered_pane", name, ':',layered_pane); return 0; } #ifdef DEBUG @@ -843,7 +1256,8 @@ static int add_object_text_type (FILE *fp, char *name, char *object_type, Access { if (strcasecmp (object_type, "text") == 0) { - generate_obj_info (fp, object, "txt", "text", name, ':'); + text++; + generate_obj_info_index (fp, object, "txt", "text", name, ':',text); return 0; } #ifdef DEBUG @@ -869,7 +1283,8 @@ static int add_object_toggle_button_type (FILE *fp, char *name, { if (strcasecmp (object_type, "toggle button") == 0) { - generate_obj_info (fp, object, "tbtn", "toggle_button", name, ':'); + toggle_button++; + generate_obj_info_index (fp, object, "tbtn", "toggle_button", name, ':',toggle_button); return 0; } #ifdef DEBUG @@ -895,7 +1310,8 @@ static int add_object_calendar_view_type (FILE *fp, char *name, { if (strcasecmp (object_type, "Calendar View") == 0) { - generate_obj_info (fp, object, "calView", "calendar_view", name, ':'); + cal_view++; + generate_obj_info_index (fp, object, "calView", "calendar_view", name, ':',cal_view); return 0; } #ifdef DEBUG @@ -921,7 +1337,8 @@ static int add_object_combo_box_type (FILE *fp, char *name, { if (strcasecmp (object_type, "combo box") == 0) { - generate_obj_info (fp, object, "cmb", "combo_box", name, ':'); + combo_box++; + generate_obj_info_index (fp, object, "cbo", "combo_box", name, ':',combo_box); return 0; } #ifdef DEBUG @@ -947,7 +1364,8 @@ static int add_object_panel_type (FILE *fp, char *name, { if (strcasecmp (object_type, "panel") == 0) { - generate_obj_info (fp, object, "pnl", "panel", name, ':'); + panel++; + generate_obj_info_index (fp, object, "pnl", "panel", name, ':',panel); return 0; } #ifdef DEBUG @@ -956,6 +1374,34 @@ static int add_object_panel_type (FILE *fp, char *name, 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; @@ -964,6 +1410,7 @@ int add_appmap_data (FILE *fp, Accessible *object) name = Accessible_getName (object); object_type = Accessible_getRoleName (object); + if (is_object_model_type (object_type)) { if (window_model_count) @@ -1106,6 +1553,13 @@ int add_appmap_data (FILE *fp, Accessible *object) 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; |