Re: [misc] adding LOCATION to import

Hi–

The patch below adds LOCATION and URL to the note when importing an
iCalendar file.  It does not preserve the data upon repeated imports
and exports, and possibly the code is a bit stupid because I'm not
coding enough C.  Any suggestions are welcome, but I'm not sure it
should go into the main branch as long as the caveats are not
addressed.  It works for me, for now.


diff --git src/ical.c src/ical.c
index 95fef51..43f7717 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -909,11 +909,14 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
 		int has_alarm;
 	} vevent;
 	int skip_alarm;
+	char *buf_for_note;
 
 	vevent_type = UNDEFINED;
 	memset(&vevent, 0, sizeof vevent);
 	LLIST_INIT(&vevent.exc);
 	skip_alarm = 0;
+	buf_for_note = malloc(1);
+	buf_for_note[0] = '\0';
 	while (ical_readline(fdi, buf, lstore, lineno)) {
 		if (skip_alarm) {
 			/*
@@ -926,6 +929,10 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
 		}
 
 		if (starts_with_ci(buf, "END:VEVENT")) {
+			if (strlen(buf_for_note) != 0) {
+				vevent.note = ical_read_note(buf_for_note, noskipped,
+						ICAL_VEVENT, ITEMLINE, log);
+			}
 			if (!vevent.mesg) {
 				ical_log(log, ICAL_VEVENT, ITEMLINE,
 					 _("could not retrieve item summary."));
@@ -1027,8 +1034,20 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
 		} else if (starts_with_ci(buf, "BEGIN:VALARM")) {
 			skip_alarm = vevent.has_alarm = 1;
 		} else if (starts_with_ci(buf, "DESCRIPTION")) {
-			vevent.note = ical_read_note(buf, noskipped,
-					ICAL_VEVENT, ITEMLINE, log);
+			buf_for_note = realloc(buf_for_note, strlen(buf_for_note) +
+			                       strlen(buf) + 3);
+			strcat(buf_for_note, buf);
+			strcat(buf_for_note, "\n\n");
+		} else if (starts_with_ci(buf, "LOCATION")) {
+			buf_for_note = realloc(buf_for_note, strlen(buf_for_note) +
+			                       strlen(buf) + 3);
+			strcat(buf_for_note, buf);
+			strcat(buf_for_note, "\n\n");
+		} else if (starts_with_ci(buf, "URL")) {
+			buf_for_note = realloc(buf_for_note, strlen(buf_for_note) +
+			                       strlen(buf) + 3);
+			strcat(buf_for_note, buf);
+			strcat(buf_for_note, "\n\n");
 		}
 	}



I first tried to add the ical_read_note(buf_for_note... call below the
*while* loop (but before the *cleanup* label), but anything I add there
is not executed; I don't understand why.  But at "END:VEVENT" is the
best place anyway.

—Marco

Links