aboutsummaryrefslogtreecommitdiffstats
path: root/libical/examples/parse_text.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@src.gnome.org>2000-08-25 03:31:03 +0800
committerJP Rosevear <jpr@src.gnome.org>2000-08-25 03:31:03 +0800
commit8357d7b199e26e4d071b267a314447b22f2ddb3c (patch)
treef6ed518cd2056dacdc9833750137db05bb7fb7cb /libical/examples/parse_text.c
parent695baf618d363f760ec81d109c6e6185e510b1e7 (diff)
downloadgsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.gz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.bz2
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.lz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.xz
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.tar.zst
gsoc2013-evolution-8357d7b199e26e4d071b267a314447b22f2ddb3c.zip
Initial revision
svn path=/trunk/; revision=5011
Diffstat (limited to 'libical/examples/parse_text.c')
-rw-r--r--libical/examples/parse_text.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/libical/examples/parse_text.c b/libical/examples/parse_text.c
new file mode 100644
index 0000000000..2761e6f951
--- /dev/null
+++ b/libical/examples/parse_text.c
@@ -0,0 +1,73 @@
+/* parse_text.c
+
+ */
+#include <stdio.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include "ical.h"
+
+#include <stdlib.h>
+
+/* The icalparser_get_line routine will create a single *content* line
+out of one or more input lines. The content line is all of the
+properties and values for a single property, and it can span several
+input lines. So, icalparser_get_line will need to be able to get more
+data on its own. Read_string is a routine that does this. You can
+write your own version of read stream to get data from other types of
+files, sockets, etc. */
+
+char* read_stream(char *s, size_t size, void *d)
+{
+ char *c = fgets(s,size, (FILE*)d);
+
+ return c;
+
+}
+
+int parse_text(int argc, char* argv[])
+{
+
+ int lineno = 0;
+ char* line;
+ FILE* stream;
+ icalcomponent *c;
+
+ /* Create a new parser object */
+ icalparser *parser = icalparser_new();
+
+ stream = fopen(argv[1],"r");
+
+ assert(stream != 0);
+
+ /* Tell the parser what input routie it should use. */
+ icalparser_set_gen_data(parser,stream);
+
+ do{
+
+ /* Get a single content line by making one or more calls to
+ read_stream()*/
+ line = icalparser_get_line(parser,read_stream);
+
+ /* Now, add that line into the parser object. If that line
+ completes a component, c will be non-zero */
+ c = icalparser_add_line(parser,line);
+
+
+ if (c != 0){
+ printf("%s",icalcomponent_as_ical_string(c));
+
+ /* Tell the parser that the caller will take ownership of
+ this component */
+ icalparser_claim(parser);
+
+ printf("\n---------------\n");
+
+ icalcomponent_free(c);
+ }
+
+ } while ( line != 0);
+
+
+ icalparser_free(parser);
+}