Re: TEST : Peter's Patch



On 31.01.2002 15:52 Peter Bloomfield wrote:
> Well, it *seemed* that highlighting had been restored--I'm sure I saw it 
> yesterday--but today it's gone again!

Same here, no highlight after applying snake-oil patch.
I also posted 2 patches, one against cvs+snake_oil patch from you and 
another one porting the whole thing (ie snake_oil+my clean-ups) to 1.2.4. 
I didn't notice this was too big for the list (about 50 Ko) so here is the 
cvs patch, next one will follow.
Bye
Manu
--- libbalsa/address-entry.c	Thu Jan 31 11:30:03 2002
+++ ../../balsa-1.2.4-peter/libbalsa/address-entry.c	Wed Jan 30 19:34:16 2002
@@ -403,6 +403,7 @@
     g_return_if_fail(data != NULL);
 
     g_list_foreach(data->list, (GFunc) libbalsa_emailData_free, NULL);
+    g_list_free(data->list);
     g_free(data);
 }
 
@@ -473,36 +474,25 @@
 libbalsa_strsplit(const gchar *str, gchar delimiter)
 {
     GList *glist;
-    gchar *data;
     const gchar *old, *current;
-    gint i, previous;
     gboolean quoted;
 
-    g_return_val_if_fail(str != NULL, NULL);
+    if (!str) return NULL;
 
     quoted = FALSE;
     glist = NULL;
-    previous = 0;
-    old = current = str;
-    for (i = 0; str[i]; i++) {
-	if (str[i] == '"') quoted = !quoted;
-	if ( (!quoted) && (str[i] == delimiter) ) {
-	    data = g_strndup(old, i - previous);
-	    glist = g_list_append(glist, data);
-	    previous = i + 1;
-	    old = current;
-	    old++;
+    old = str;
+    for (current=str;*current;current++) {
+	if (*current == '"') quoted = !quoted;
+	else if ( (!quoted) && (*current == delimiter) ) {
+	    glist = g_list_append(glist, g_strndup(old, current-old));
+	    old=current+1;
 	}
-	current++;
-    }
-    if (str) {
-	data = g_strndup(old, i - previous);
-	glist = g_list_append(glist, data);
     }
+    glist = g_list_append(glist, g_strndup(old, current-old));
     return glist;
 }
 
-
 /*************************************************************
  * libbalsa_length_of_address:
  *     Calculated how long an address would be when it is
@@ -641,7 +631,7 @@
 static inputData *
 libbalsa_fill_input(LibBalsaAddressEntry *address_entry)
 {
-    gint cursor = 0, size = 0, prev = 0;
+    gint cursor, size, prev=0;
     gchar *typed = NULL;
     GList *el, *current;
     GList *list = NULL;
@@ -658,30 +648,28 @@
     input = libbalsa_inputData_new();
     cursor = (gint) gtk_editable_get_position(GTK_EDITABLE(address_entry));
     typed = gtk_editable_get_chars(GTK_EDITABLE(address_entry), 0, -1);
-    if (typed == NULL)
+    if (!typed)
 	typed = g_strdup("");
 
     /*
      * Split the input string by comma, and store the result in
      * input->list.
      * str contains a list of e-mail addresses seperated by ','.
-     *
-     * FIXME: Breaks for '"Doe, John" <john@doe.com>'
      */
     el = libbalsa_strsplit(typed, ',');
     g_free(typed);
     /*
      * Store it all in a glist.
      */
-    if (el != NULL) {
+    if (el) {
 	for (current = el;
-	     current != NULL;
+	     current;
 	     current = g_list_next(current)) {
 	    addy = libbalsa_emailData_new();
-	    addy->user = g_strdup((gchar *)current->data);
+	    addy->user = (gchar *)current->data;
 	    input->list = g_list_append(input->list, addy);
 	}
-	g_list_foreach(el, (GFunc)g_free, NULL);
+	g_list_free(el);
     } else {
        addy = libbalsa_emailData_new();
        addy->user = g_strdup("");
@@ -693,26 +681,30 @@
      * We have to match the cursor in GtkEntry to the list.
      */
     g_assert(input->list != NULL);
-    size = prev = 0;
-    for (list = g_list_first(input->list);
-	 list != NULL;
-	 list = g_list_next(list)) {
-	if (cursor >= size) {
-	    prev = size;
-	    input->active = list;
-	}
+    size = 0;
+    for (list = g_list_first(input->list);list;list=g_list_next(list)) {
+	prev=size;
+	addy = (emailData *)list->data;
+	size += strlen(addy->user) + 1;
+	addy->user = g_strchug(addy->user);
+	if (cursor<size) break;
+    }
+    input->active = list;
+    /* Don't forget to strip out the leading space added because
+       the delimiter to split the addresses was just ',' so each
+       address begins with the space following the coma */
+    for (list = g_list_next(list);list;list=g_list_next(list)) {
 	addy = (emailData *)list->data;
-	size = size + strlen(addy->user) + 1;
 	addy->user = g_strchug(addy->user);
     }
-
     addy = (emailData *)input->active->data;
     addy->cursor = cursor - prev;
     if (input->active != input->list)
-	addy->cursor = addy->cursor - 1; /* Compensate for the ',' */
+	addy->cursor--; /* Compensate for the ',' */
     if (addy->cursor < 0) addy->cursor = 0;
-    if (addy->cursor > (tmp = strlen(addy->user)))
-        addy->cursor = tmp;
+    tmp = strlen(addy->user);
+    if (addy->cursor > tmp)
+	addy->cursor = tmp;
 
     return input;
 }
@@ -911,16 +903,12 @@
     /*
      * Free all the following data.
      */
-    for (list = g_list_next(input->active);
-	 list != NULL;
-	 list = g_list_next(input->active)) {
-	 /*
-	  * Concatenate the two e-mails.
-	  */
-	 libbalsa_emailData_free(list->data);
-	 input->list = g_list_remove_link(input->list, list);
-	 g_list_free_1(list);
-    }
+    g_list_foreach(g_list_next(input->active),(GFunc)libbalsa_emailData_free,NULL);
+    g_list_free(g_list_next(input->active));
+
+    /* input->active must be the last address */
+    input->active->next=NULL;
+
     /* libbalsa_inputData_free(address_entry->input); 
      * look above: the line below is not necessary */
     /* address_entry->input = input; */
@@ -1019,7 +1007,7 @@
 {
     GtkEditable *editable;
     emailData *addy, *extra;
-    gchar *left, *right, *str;
+    gchar *p,*str;
     GList *list;
     unsigned i;
     inputData *input;
@@ -1074,18 +1062,12 @@
      * Normal character needs deleting.
      */
     } else {
-       left = g_strndup(addy->user, (addy->cursor - 1));
-       right = addy->user;
-       for (i = 0; i < addy->cursor; i++) right++;
-       str = g_strconcat(left, right, NULL);
-       g_free(addy->user);
-       g_free(left);
-       addy->user = str;
-       addy->cursor--;
-       if (*str == '\0')
-	   libbalsa_force_no_match(addy);
-       else if (address_entry->find_match)
-	   (*address_entry->find_match) (addy, TRUE);
+	addy->cursor--;
+	for (p=addy->user+addy->cursor;*p;p++) *p=*(p+1);
+	if (!*(addy->user))
+	    libbalsa_force_no_match(addy);
+	else if (address_entry->find_match)
+	    (*address_entry->find_match) (addy, TRUE);
     }
 }
 
@@ -1113,7 +1095,7 @@
 {
     GtkEditable *editable;
     emailData *addy, *extra;
-    gchar *left, *right, *str;
+    gchar *p, *str;
     GList *list;
     inputData *input;
     
@@ -1159,14 +1141,7 @@
      * Normal character needs deleting.
      */
     } else {
-	unsigned i;
-	left = g_strndup(addy->user, addy->cursor);
-	right = addy->user;
-	for (i = 0; i <= addy->cursor; i++) right++;
-	str = g_strconcat(left, right, NULL);
-	g_free(addy->user);
-	g_free(left);
-	addy->user = str;
+	for (p=addy->user+addy->cursor;*p;p++) *p=*(p+1);
     }
 }
 
@@ -1590,7 +1565,7 @@
      */
     input = address_entry->input;
     addy = input->active->data;
-    if (input->active == g_list_last(input->list)) {
+    if (!g_list_next(input->active)) {
 	if (addy->cursor >= strlen(addy->user) && (addy->match == NULL)) {
 	    libbalsa_accept_match(address_entry);
 	    gtk_widget_activate(GTK_WIDGET(address_entry));
@@ -1633,7 +1608,7 @@
     gint address_start;
     gboolean found;
     emailData *addy;
-    gint pos;
+    gint pos,tmp;
 
     g_return_val_if_fail(address_entry != NULL, NULL);
     g_return_val_if_fail(LIBBALSA_IS_ADDRESS_ENTRY(address_entry), NULL);
@@ -1646,17 +1621,20 @@
 	 (list != NULL) && (found == FALSE);
 	 list = g_list_next(list)) {
 	addy = (emailData *)list->data;
-	address_start += libbalsa_length_of_address(addy);
+	tmp=libbalsa_length_of_address(addy);
+	address_start += tmp;
 	if (pos <= address_start) {
 	    found = TRUE;
-	    *cursor = libbalsa_length_of_address(addy) - (address_start - pos);
+	    *cursor = tmp - (address_start - pos);
 	}
 	address_start += 2; /* strlen(", ") */
 	previous = list;
     }
     g_assert(found == TRUE);
     if(*cursor<0) { /* error, correct it and print a warning.
-		       This needs to be fixed in long term. */
+		       This needs to be fixed in long term. 
+		       I found where this is triggered, I'll try
+		       to fix it definitely (MANU)*/
 	*cursor = 0;
 	g_warning("libbalsa_find_list_entry failed to compute the cursor.\n"
 		  "find a way to reproduce it and report it.");
@@ -1728,7 +1706,7 @@
     GtkEditable *editable;
     GList *start, *end, *list;
     gint start_pos, end_pos;
-    gchar *str, *left, *right, *new;
+    gchar *str, *left, *new;
     emailData *addy;
     gint i;
     size_t tmp;
@@ -1760,12 +1738,11 @@
 	addy = start->data;
 	str = libbalsa_make_address_string(addy);
 	libbalsa_force_no_match(addy);
-	left = g_strndup(str, start_pos);
-	right = str;
-	for (i = 0; i < end_pos; i++) right++;
-	new = g_strconcat(left, right, NULL);
-	g_free(str); /* also does g_free(right); */
-	g_free(left);
+	/* First we cut the string at the start_pos */
+	str[start_pos]='\0';
+	/* The we concat the first part with the end part */
+	new = g_strconcat(str, str+end_pos, NULL);
+	g_free(str);
 	g_free(addy->user);
 	addy->user = new;
 	addy->cursor = start_pos;
@@ -1795,10 +1772,8 @@
 	addy = end->data;
 	str = libbalsa_make_address_string(addy);
 	libbalsa_force_no_match(addy);
-	right = str;
-	for (i = 0; i < end_pos; i++) right++;
 	g_free(addy->user);
-	addy->user = g_strdup(right);
+	addy->user = g_strdup(str+end_pos);
 	g_free(str);
 
 	/*
@@ -1811,13 +1786,15 @@
 	/*
 	 * Delete the GList inbetween(!)
 	 */
-	for (list = g_list_next(start);
-	     list != end;
-	     list = g_list_next(start)) {
-	    libbalsa_emailData_free(list->data);
-	    g_list_remove_link(address_entry->input->list, list);
-            g_list_free_1(list);
-	}
+	/* Unlink the part of the list to be deleted */
+	start->next->prev=NULL;
+	end->prev->next=NULL;
+	/* Free the unlinked part */
+	g_list_foreach(start->next,(GFunc)libbalsa_emailData_free,NULL);
+	g_list_free(start->next);
+	/* Re-link the remaining parts */
+	start->next=end;
+	end->prev=start;
     }
 
     editable->selection_start_pos = editable->selection_end_pos = 0;
@@ -2113,11 +2090,7 @@
 	 */
 	addy = (emailData *)list->data;
 	g_assert(addy != NULL);
-	if (addy->match != NULL) {
-	    out = g_strconcat("", addy->user, " (", addy->match, ")", NULL);
-	} else {
-	    out = g_strdup(addy->user);
-	}
+	out = libbalsa_make_address_string(addy);
 	/*
 	 * Copy the string, adding a delimiter if need be.
 	 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]