From 7239e19eaa67ee28c4ac19cb8422e0efa6d63856 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 21 Sep 2000 00:24:15 +0000 Subject: Make this work when a field is spread across multiple lines. 2000-09-21 Christopher James Lahey * backend/ebook/load-pine-addressbook.c: Make this work when a field is spread across multiple lines. svn path=/trunk/; revision=5531 --- addressbook/backend/ebook/load-pine-addressbook.c | 70 ++++++++++++++++------- 1 file changed, 50 insertions(+), 20 deletions(-) (limited to 'addressbook/backend/ebook/load-pine-addressbook.c') diff --git a/addressbook/backend/ebook/load-pine-addressbook.c b/addressbook/backend/ebook/load-pine-addressbook.c index 7d74fe20a4..073c35c915 100644 --- a/addressbook/backend/ebook/load-pine-addressbook.c +++ b/addressbook/backend/ebook/load-pine-addressbook.c @@ -27,27 +27,16 @@ add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) } static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) +parse_line (EBook *book, char *line) { - FILE *fp = fopen (".addressbook", "r"); - char line[1024]; - - if (!fp) { - g_warning ("Can't find .addressbook"); - return; - } - - while(fgets(line, 1024, fp)) { - int length = strlen(line); - char **strings; - ECardName *name; - ECard *card; - EList *list; - if (line[length - 1] == '\n') - line[--length] = 0; - - card = e_card_new(""); - strings = g_strsplit(line, "\t", 3); + char **strings; + ECardName *name; + ECard *card; + EList *list; + + card = e_card_new(""); + strings = g_strsplit(line, "\t", 3); + if (strings[0] && strings[1] && strings[2]) { name = e_card_name_from_string(strings[1]); gtk_object_set(GTK_OBJECT(card), "nickname", strings[0], @@ -63,6 +52,47 @@ book_open_cb (EBook *book, EBookStatus status, gpointer closure) } } +static void +book_open_cb (EBook *book, EBookStatus status, gpointer closure) +{ + FILE *fp = fopen (".addressbook", "r"); + char line[2 * 1024]; + int which = 0; + char *lastline = NULL; + + if (!fp) { + g_warning ("Can't find .addressbook"); + return; + } + + while(fgets(line + which * 1024, 1024, fp)) { + int length; + char *thisline = line + which * 1024; + length = strlen(thisline); + if (thisline[length - 1] == '\n') + line[--length] = 0; + if (lastline && *thisline && isspace(*thisline)) { + char *temp; + while(*thisline && isspace(*thisline)) + thisline ++; + temp = lastline; + lastline = g_strdup_printf("%s%s", lastline, thisline); + g_free(temp); + continue; + } + if (lastline) { + parse_line (book, lastline); + g_free(lastline); + } + lastline = g_strdup(thisline); + } + + if (lastline) { + parse_line (book, lastline); + g_free(lastline); + } +} + static guint ebook_create (void) { -- cgit