an iCal processing library

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Mon Feb 27 02:17:06 2017 +0000
Parent:
10:deeaec151283
Commit message:
Some incomplete work on making it less memory intensive. Far from complete.

Changed in this revision

iCal.cpp Show annotated file Show diff for this revision Revisions of this file
iCal.h Show annotated file Show diff for this revision Revisions of this file
--- a/iCal.cpp	Tue Jan 26 11:58:10 2016 +0000
+++ b/iCal.cpp	Mon Feb 27 02:17:06 2017 +0000
@@ -10,7 +10,7 @@
 #include <algorithm>
 
 //#ifdef _DEBUG
-//#define DEBUG "iCal"
+#define DEBUG "iCal"
 //#endif
 #ifdef WIN32
 #define LF "\n"
@@ -34,6 +34,16 @@
 int EventCount = 0;
 int32_t tzoTZIDSec = 0;
 
+bool tzAdjusted = false;    // used during parsing of an iCal resource
+typedef enum { 
+    idle, 
+    inTimeZone, 
+    inEvent 
+} seekstate_t;
+seekstate_t seeking = idle;
+Event_T Event;
+
+
 const char * RPT_DAYS[] = { "SU", "MO", "TU", "WE", "TH", "FR", "SA", "" };
 
 int GetNumEvents(void)
@@ -520,15 +530,23 @@
     return tzo;
 }
 
+void ParseICalStart(void) {
+    tzAdjusted = false;
+    seeking = idle;
+    EventCount = 0;
+
+}
+
+int ParseICalClose(void) {
+    if (EventCount > 0)
+        SortEvents();
+    return GetNumEvents();
+}
+
 int ParseICalStream(char * pStart, time_t gridStartTime, time_t gridEndTime, tz_min_t tzoMin, bool showEvents)
 {
-    Event_T Event;
-    bool tzAdjusted = false;
     char * pEnd;
-    typedef enum { idle, inTimeZone, inEvent } seekstate_t;
-    seekstate_t seeking = idle;
 
-    EventCount = 0;
     if (gridEndTime == gridStartTime)
         gridEndTime++;  // advance so they are not equal
     while (pStart && EventCount < EVENT_COUNT) {
@@ -541,8 +559,6 @@
                 pEnd++;
             }
             // pStart now has a single null terminated line of text.
-            if (showEvents)
-                INFO("*** %s", pStart);
             switch (seeking) {
                 case idle:
                     if (strcmp(pStart, "BEGIN:VTIMEZONE") == 0)
@@ -614,7 +630,4 @@
             pStart = NULL;
         }
     } // while
-    if (EventCount > 0)
-        SortEvents();
-    return GetNumEvents();
 }
--- a/iCal.h	Tue Jan 26 11:58:10 2016 +0000
+++ b/iCal.h	Mon Feb 27 02:17:06 2017 +0000
@@ -65,6 +65,27 @@
 
 extern Event_T EventList[EVENT_COUNT];
 
+/// Prepare to start processing an iCal stream
+///
+/// This initializes the data structures for parsing.
+///
+/// @code
+/// ParseICalStart();
+/// while (receive(buf, ... ))
+///     ParseICalStream(buf, ...);
+/// count = ParseICalClose();
+/// @endcode
+///
+void ParseICalStart(void);
+
+
+/// End processing an iCal stream and return the number of events
+///
+/// @returns number of events in range
+///
+int ParseICalClose(void);
+
+
 /// Parse an iCal stream, and extract everything useful.
 ///
 /// This accepts a pointer to a [large] buffer, which is the contents