aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2003-03-25 21:57:25 +0800
committerDan Winship <danw@src.gnome.org>2003-03-25 21:57:25 +0800
commit5d40c589ac1f330e06d6384ebd150f24f15c04a9 (patch)
treec92a8d01fdd15526c650b1d67fa74b4c8ba6f224 /calendar/cal-util
parentbe58e1949e5df9f14d07f1019a273a74aa4982f8 (diff)
downloadgsoc2013-evolution-5d40c589ac1f330e06d6384ebd150f24f15c04a9.tar.gz
gsoc2013-evolution-5d40c589ac1f330e06d6384ebd150f24f15c04a9.tar.zst
gsoc2013-evolution-5d40c589ac1f330e06d6384ebd150f24f15c04a9.zip
Utility wrapper around icalparser.
* cal-util/cal-util.c (cal_util_parse_ics_file): Utility wrapper around icalparser. * cal-util/test-recur.c (main): Use it * pcs/cal-backend-file.c (open_cal): Likewise * gui/comp-editor-factory.c (open_client): Add the OpenClient to the hash before calling cal_client_open_calendar, since in some failure cases, that will call cal_opened_cb (which will free the oc) with a failure immediately, causing a crash if we then try to deref it. svn path=/trunk/; revision=20492
Diffstat (limited to 'calendar/cal-util')
-rw-r--r--calendar/cal-util/cal-util.c27
-rw-r--r--calendar/cal-util/cal-util.h2
-rw-r--r--calendar/cal-util/test-recur.c42
3 files changed, 31 insertions, 40 deletions
diff --git a/calendar/cal-util/cal-util.c b/calendar/cal-util/cal-util.c
index 040e322cce..ad495bca77 100644
--- a/calendar/cal-util/cal-util.c
+++ b/calendar/cal-util/cal-util.c
@@ -102,6 +102,33 @@ cal_util_new_top_level (void)
return icalcomp;
}
+static char *
+get_line_fn (char *buf, size_t size, void *file)
+{
+ return fgets (buf, size, file);
+}
+
+icalcomponent *
+cal_util_parse_ics_file (const char *filename)
+{
+ icalparser *parser;
+ icalcomponent *icalcomp;
+ FILE *file;
+
+ file = fopen (filename, "r");
+ if (!file)
+ return NULL;
+
+ parser = icalparser_new ();
+ icalparser_set_gen_data (parser, file);
+
+ icalcomp = icalparser_parse (parser, get_line_fn);
+ icalparser_free (parser);
+ fclose (file);
+
+ return icalcomp;
+}
+
/* Computes the range of time in which recurrences should be generated for a
* component in order to compute alarm trigger times.
*/
diff --git a/calendar/cal-util/cal-util.h b/calendar/cal-util/cal-util.h
index bf43493f82..7b4f6c051e 100644
--- a/calendar/cal-util/cal-util.h
+++ b/calendar/cal-util/cal-util.h
@@ -71,6 +71,8 @@ void cal_obj_uid_list_free (GList *list);
icalcomponent *cal_util_new_top_level (void);
+icalcomponent *cal_util_parse_ics_file (const char *filename);
+
CalComponentAlarms *cal_util_generate_alarms_for_comp (CalComponent *comp,
time_t start,
time_t end,
diff --git a/calendar/cal-util/test-recur.c b/calendar/cal-util/test-recur.c
index 5078a1db94..03f19b52bd 100644
--- a/calendar/cal-util/test-recur.c
+++ b/calendar/cal-util/test-recur.c
@@ -37,6 +37,7 @@
#include <string.h>
#include <gtk/gtkmain.h>
#include <cal-util/cal-recur.h>
+#include <cal-util/cal-util.h>
/* Since events can recur infinitely, we set a limit to the number of
@@ -44,10 +45,6 @@
#define MAX_OCCURRENCES 1000
static void usage (void);
-static icalcomponent* scan_ics_file (char *filename);
-static char* get_line (char *s,
- size_t size,
- void *data);
static void generate_occurrences (icalcomponent *comp);
static gboolean occurrence_cb (CalComponent *comp,
time_t instance_start,
@@ -69,7 +66,7 @@ main (int argc,
filename = argv[1];
- icalcomp = scan_ics_file (filename);
+ icalcomp = cal_util_parse_ics_file (filename);
if (icalcomp)
generate_occurrences (icalcomp);
@@ -85,41 +82,6 @@ usage (void)
}
-static icalcomponent*
-scan_ics_file (char *filename)
-{
- FILE *fp;
- icalcomponent *icalcomp;
- icalparser *parser;
-
- g_print ("Opening file: %s\n", filename);
- fp = fopen (filename, "r");
-
- if (!fp) {
- g_print ("Can't open file: %s\n", filename);
- return NULL;
- }
-
- parser = icalparser_new ();
- icalparser_set_gen_data (parser, fp);
-
- icalcomp = icalparser_parse (parser, get_line);
- icalparser_free (parser);
-
- return icalcomp;
-}
-
-
-/* Callback used from icalparser_parse() */
-static char *
-get_line (char *s,
- size_t size,
- void *data)
-{
- return fgets (s, size, (FILE*) data);
-}
-
-
/* This resolves any TZIDs in the components. The VTIMEZONEs must be in the
file we are reading. */
static icaltimezone*