summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--appmap-gen.c231
-rw-r--r--appmap-gen.h2
-rw-r--r--utils.c99
-rw-r--r--utils.h3
5 files changed, 311 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 09e961c..ea77d02 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-10-24 Premkumar J <jpremkumar@novell.com>
+ * Fixed name generation for objects to avoid spaces and ':'
+2005-10-21 Nagappan A <anagappan@novell.com>
+ * Modified delimiter parsing in appmap-gen.c
+2005-10-19 Nagappan A <anagappan@novell.com>
+ * Fixed utf8 string comparisons
+2005-10-18 Nagappan A <anagappan@novell.com>
+ * Added label and label_by to have _ if keybindings are present
+2005-10-14 Nagappan A <anagappan@novell.com>
+ * Fixed indexing of label in add_appmap_data function (g_hash_table_lookup for unique label)
2005-10-12 Prashanth <prashmohan@gmail.com>
* Fixed crash, when dialog name is empty
2005-10-11 Nagappan A <anagappan@novell.com>
@@ -13,7 +23,6 @@
2005-09-28 Veerapuram Varadhan <vvaradhan@novell.com>
* autogen.sh has been modified to take available automake and aclocal
2005-09-23 Premkumar J <jpremkumar@novell.com>
- * Rewritten code to generate appmap for making it complaint with the new
- searching algorithm
+ * 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
+ * Converted all asprintf to g_strdup_printf mainly to work in solaris platform
diff --git a/appmap-gen.c b/appmap-gen.c
index e9e5671..88a1446 100644
--- a/appmap-gen.c
+++ b/appmap-gen.c
@@ -5,7 +5,7 @@
* Nagappan A <anagappan@novell.com>
* Premkumar J <jpremkumar@novell.com>
*
- * Copyright 2004 Novell, Inc.
+ * Copyright 2004 - 2005 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -23,8 +23,6 @@
* Boston, MA 02111-1307, USA.
*/
-#define _GNU_SOURCE
-
#include "appmap-gen.h"
#include "utils.h"
@@ -149,7 +147,7 @@ Accessible *accessible_app_handle (char *app_name)
Incase of OO.o due to spaces, string compare gives different result.
Found because of extra spaces. Now stripped it ;)
*/
- if (strchr (name, ' '))
+ if (g_utf8_strchr (name, strlen (name), ' '))
g_strstrip (name);
if (g_ascii_strcasecmp (name, app_name) == 0)
@@ -237,7 +235,108 @@ int filter_appmap_data (Accessible *accessible, OBJECT_INFO *obj_info, char *lab
return 1;
}
-char *get_relation_name (Accessible *object)
+static char *get_keybinding (Accessible *object)
+{
+ if (Accessible_isAction (object))
+ {
+ AccessibleAction *action = NULL;
+
+ action = Accessible_getAction (object);
+ if (action)
+ {
+ char *binding = NULL;
+ binding = AccessibleAction_getKeyBinding (action, 0l);
+ Accessible_unref (action);
+ if (g_utf8_collate (binding, "") == 0)
+ return NULL;
+
+ if (binding)
+ {
+ gchar *key_binding = NULL;
+
+ key_binding = search_forward (binding, ';');
+ SPI_freeString (binding);
+ binding = NULL;
+
+ if (key_binding && g_utf8_collate (key_binding, "") == 0)
+ return binding;
+ else if (!key_binding)
+ return key_binding;
+
+ binding = key_binding;
+ if (g_utf8_strchr (binding, strlen (binding), '>') == NULL)
+ return binding;
+ key_binding = search_reverse (binding, '>');
+
+ if (key_binding && g_utf8_collate (key_binding, "") == 0)
+ {
+ g_free (binding);
+ return NULL;
+ }
+ else if (!key_binding)
+ return binding;
+ g_free (binding);
+ return key_binding;
+ }
+ }
+ }
+ return NULL;
+}
+
+char *insert_underscore (gchar *text, gchar *binding)
+{
+ GString *str;
+ GString *tmp;
+ gint length;
+ const gchar *p;
+ const gchar *end;
+ gboolean flag = FALSE;
+
+ g_return_val_if_fail (text != NULL, NULL);
+
+ length = strlen (text);
+
+ str = g_string_sized_new (length);
+ tmp = g_string_sized_new (length);
+
+ p = text;
+ end = text + length;
+
+ while (p != end)
+ {
+ const gchar *next;
+ next = g_utf8_next_char (p);
+
+ if (*p == g_unichar_toupper (*binding))
+ {
+ g_string_append (tmp, "_");
+ flag = TRUE;
+ }
+ else if (flag != TRUE && g_unichar_tolower (*p) == g_unichar_tolower (*binding))
+ {
+ g_string_append (str, "_");
+ flag = TRUE;
+ }
+ g_string_append_len (str, p, next - p);
+ g_string_append_len (tmp, p, next - p);
+
+ p = next;
+ }
+
+ if (g_utf8_collate (str->str, tmp->str) == 0)
+ g_free (tmp->str);
+ else if (g_utf8_strchr (tmp->str, tmp->len, '_'))
+ {
+ g_free (str->str);
+ str = tmp;
+ }
+ else
+ g_free (tmp->str);
+
+ return g_string_free (str, FALSE);
+}
+
+char *get_relation_name (Accessible *object, long *len)
{
int i = 0, j = 0;
int max_accessible = 0;
@@ -273,7 +372,7 @@ char *get_relation_name (Accessible *object)
Accessible_unref (*relation);
return NULL;
}
- if (g_ascii_strcasecmp (name, "") == 0)
+ if (g_utf8_collate (name, "") == 0)
{
SPI_freeString (name);
Accessible_unref (tmp_obj);
@@ -285,6 +384,30 @@ char *get_relation_name (Accessible *object)
g_print ("Relation name: %s\n", name);
label_by = g_strdup (name);
SPI_freeString (name);
+ if (label_by)
+ {
+ gchar *key_binding = NULL;
+
+ key_binding = get_keybinding (tmp_obj);
+ if (key_binding)
+ {
+ gchar *tmp = NULL;
+ tmp = insert_underscore (label_by, key_binding);
+ g_free (key_binding);
+ if (tmp)
+ {
+ g_free (label_by);
+ label_by = tmp;
+ }
+ }
+ }
+ if (Accessible_isText (tmp_obj))
+ {
+ AccessibleText *text = NULL;
+ text = Accessible_getText (tmp_obj);
+ *len = AccessibleText_getCharacterCount (text);
+ Accessible_unref (text);
+ }
Accessible_unref (tmp_obj);
for (k = j; relation[k] != NULL; k++)
Accessible_unref (relation[k]);
@@ -304,38 +427,44 @@ char *get_relation_name (Accessible *object)
*/
char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int child_index, GHashTable *current_context)
{
- char *name;
- char *label_by = NULL;
+ int size;
+ long length = -1;
+ long text_len = -1;
+ char *name = NULL;
+ char *key = NULL;
+ char *value = NULL;
char *label = NULL;
+ char *label_by = 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);
+ label_by = get_relation_name (accessible, &length);
if (label_by)
{
- if (g_ascii_strcasecmp (label_by, "") == 0)
+ if (g_utf8_collate (label_by, "") == 0)
label = g_strdup (accessible_name);
else
- label = g_strdup (label_by);
+ {
+ label = g_strdup (label_by);
+ text_len = length;
+ }
}
else
label = g_strdup (accessible_name);
-
- if (strcmp (label, "") != 0)
+ if (g_utf8_collate (label, "") != 0)
{
- char *stripped_data = NULL;
+ long label_index = 1;
char *value = NULL;
- if (strchr (label, ' '))
+ char *stripped_data = NULL;
+
+ if (g_utf8_strchr (label, text_len, ' '))
stripped_data = strip_white_space (label);
else
stripped_data = g_strdup (label);
- if (strstr (stripped_data, "."))
+ if (g_utf8_strchr (stripped_data, text_len, '.'))
{
value = strip_delim (stripped_data, '.');
g_free (stripped_data);
@@ -343,7 +472,7 @@ char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int
g_free (value);
value = NULL;
}
- if (strstr (stripped_data, ":"))
+ if (g_utf8_strchr (stripped_data, text_len, ':'))
{
value = strip_delim (stripped_data, ':');
g_free (stripped_data);
@@ -351,14 +480,32 @@ char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int
g_free (value);
value = NULL;
}
+ if (g_utf8_strchr (stripped_data, text_len, '\n'))
+ {
+ value = strip_delim (stripped_data, '\n');
+ g_free (stripped_data);
+ stripped_data = g_strdup (value);
+ g_free (value);
+ value = NULL;
+ }
+ if (g_utf8_strchr (stripped_data, text_len, '_'))
+ {
+ value = remove_char (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)
+ while (value)
{
if (name)
g_free (name);
- name = g_strdup_printf ("%s%s%d", cur_obj_info->prefix, stripped_data, cur_obj_info->instance_index);
+ name = g_strdup_printf ("%s%s%ld", cur_obj_info->prefix, stripped_data, label_index);
+ label_index++;
+ value = g_hash_table_lookup (current_context, name);
}
g_free (stripped_data);
}
@@ -367,16 +514,34 @@ char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int
g_free (label);
label = g_strdup (accessible_name);
+ if (label)
+ {
+ gchar *key_binding = NULL;
+
+ key_binding = get_keybinding (accessible);
+ if (key_binding)
+ {
+ gchar *tmp = NULL;
+ tmp = insert_underscore (label, key_binding);
+ g_free (key_binding);
+ if (tmp)
+ {
+ g_free (label);
+ label = tmp;
+ }
+ }
+ }
+
SPI_freeString (accessible_name);
/*
* Following code is for limiting appmap from generating
* label with value as string made of only space character
*/
- if (strchr (label, ' '))
+ if (g_utf8_strchr (label, strlen (label), ' '))
{
char *stripped_data = NULL;
stripped_data = strip_white_space (label);
- if (g_ascii_strcasecmp (stripped_data, "") == 0)
+ if (g_utf8_collate (stripped_data, "") == 0)
{
g_free (label);
label = g_strdup (stripped_data);
@@ -386,7 +551,7 @@ char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int
if (filter_appmap_data (accessible, cur_obj_info, name))
{
- if (g_ascii_strcasecmp (label, "") == 0)
+ if (g_utf8_collate (label, "") == 0)
{
if (!label_by)
object_record = g_strdup_printf ("%s={class=%s,parent=%s,child_index=%d}\n", name,
@@ -415,7 +580,7 @@ char *add_appmap_data (FILE *fp, Accessible *accessible, char *parent_name, int
if (current_context)
g_hash_table_insert (current_context, key, value);
else
- g_print ("Hashtable is NULL!!\n");
+ g_print ("Hashtable is NULL\n");
g_free (label);
g_free (label_by);
g_free (object_record);
@@ -738,15 +903,15 @@ void insert_context_header (FILE *fp, Accessible *accessible)
accessible_name = Accessible_getName (accessible);
label = g_strdup (accessible_name);
SPI_freeString (accessible_name);
- if (strcmp (label, "") != 0)
+ if (g_utf8_collate (label, "") != 0)
{
char *stripped_data = NULL;
char *tmp_data = NULL;
- if (strchr (label, ' '))
+ if (g_utf8_strchr (label, strlen (label), ' '))
stripped_data = strip_white_space (label);
else
stripped_data = g_strdup (label);
- if (strchr (stripped_data, '.'))
+ if (g_utf8_strchr (stripped_data, strlen (stripped_data), '.'))
tmp_data = strip_delim (stripped_data, '.');
else
tmp_data = g_strdup (stripped_data);
@@ -763,7 +928,7 @@ void insert_context_header (FILE *fp, Accessible *accessible)
/*
* TODO: Handle the case of window label being NULL
*/
- g_print ("Found window with label value as NULL!!");
+ g_print ("Found window with label value as NULL");
g_free (label);
g_free (object_record);
g_free (cur_obj_info->object_type);
@@ -787,7 +952,7 @@ void create_appmap (FILE *fp, Accessible *accessible, char *application_name)
GHashTable *current_context = NULL;
label = Accessible_getName (accessible);
- if (strchr (label, ' '))
+ if (g_utf8_strchr (label, strlen (label), ' '))
name = g_strdup_printf ("[%s]\n", strip_white_space (label));
else
name = g_strdup_printf ("[%s]\n", label);
@@ -866,7 +1031,7 @@ int appmap_main (char *app_name)
parent = accessible_app_handle (app_name);
if (!parent)
{
- printf ("Application %s seems to be not running !!!\n", app_name);
+ printf ("Application %s seems to be not running\n", app_name);
return -1;
}
fp = open_appmap (app_name);
@@ -876,7 +1041,7 @@ int appmap_main (char *app_name)
close_appmap (fp);
}
else
- g_print ("Unable to open file for writing application map!!\n");
+ g_print ("Unable to open file for writing application map\n");
return 0;
}
diff --git a/appmap-gen.h b/appmap-gen.h
index 7d868fe..cac98fa 100644
--- a/appmap-gen.h
+++ b/appmap-gen.h
@@ -39,6 +39,6 @@ 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);
+char *get_relation_name (Accessible *accessible, long *length);
#endif
diff --git a/utils.c b/utils.c
index b304600..e99329e 100644
--- a/utils.c
+++ b/utils.c
@@ -22,8 +22,6 @@
* Boston, MA 02111-1307, USA.
*/
-#define _GNU_SOURCE
-
#include "appmap-gen.h"
#include "utils.h"
@@ -94,3 +92,100 @@ char *read_line (int fd )
}
return NULL;
}
+
+gchar *remove_char (const gchar *text, gchar delimiter)
+{
+ gint length;
+ GString *str;
+ const gchar *p;
+ const gchar *end;
+
+ g_return_val_if_fail (text != NULL, NULL);
+
+ length = strlen (text);
+ str = g_string_sized_new (length);
+
+ p = text;
+ end = text + length;
+
+ while (p != end)
+ {
+ const gchar *next;
+ next = g_utf8_next_char (p);
+
+ if (*p != delimiter)
+ g_string_append_len (str, p, next - p);
+
+ p = next;
+ }
+ return g_string_free (str, FALSE);
+}
+
+gchar *search_forward (const gchar *text, gchar delimiter)
+{
+ gint length;
+ GString *str;
+ const gchar *p;
+ const gchar *end;
+
+ g_return_val_if_fail (text != NULL, NULL);
+
+ length = strlen (text);
+ str = g_string_sized_new (length);
+
+ p = text;
+ end = text + length;
+
+ while (p != end)
+ {
+ const gchar *next;
+ next = g_utf8_next_char (p);
+
+ if (*p == delimiter)
+ break;
+ else
+ g_string_append_len (str, p, next - p);
+
+ p = next;
+ }
+ return g_string_free (str, FALSE);
+}
+
+gchar *search_reverse (const gchar *text, gchar delimiter)
+{
+ gint length;
+ GString *str;
+ const gchar *p;
+ const gchar *end;
+ gboolean flag = FALSE;
+
+ g_return_val_if_fail (text != NULL, NULL);
+
+ length = strlen (text);
+ str = g_string_sized_new (length);
+
+ p = text;
+ end = text + length;
+
+ while (p != end)
+ {
+ const gchar *next;
+ next = g_utf8_next_char (p);
+
+ if (!flag && *p != delimiter)
+ {
+ p = next;
+ continue;
+ }
+ else if (!flag)
+ {
+ flag = TRUE;
+ p = next;
+ continue;
+ }
+ g_string_append_len (str, p, next - p);
+
+ p = next;
+ }
+ return g_string_free (str, FALSE);
+}
diff --git a/utils.h b/utils.h
index 5345556..5e5d6d2 100644
--- a/utils.h
+++ b/utils.h
@@ -8,5 +8,8 @@
char *strip_white_space (char *data);
char *strip_delim (char *data, char delim);
char *read_line (int fd);
+gchar *remove_char (const gchar *text, gchar delimiter);
+gchar *search_forward (const gchar *text, gchar delimiter);
+gchar *search_reverse (const gchar *text, gchar delimiter);
#endif