summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2015-04-28 17:12:59 -0400
committerAllen Winter <allen.winter@kdab.com>2015-04-28 17:12:59 -0400
commitf7d6f275cb3880d519f8fe8016bfaa787c293a2b (patch)
treef16cbe6bd90e59dbab1d36110569cfbd3f933f0d /examples
parent7263e5201247f2cabee805dca6eddf9f9e97704f (diff)
downloadlibical-git-f7d6f275cb3880d519f8fe8016bfaa787c293a2b.tar.gz
finish header cleaning on linux anway. need to test other platforms now
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt6
-rw-r--r--examples/access_components.c267
-rw-r--r--examples/access_properties_and_parameters.c125
-rw-r--r--examples/errors.c21
-rw-r--r--examples/main.c4
-rw-r--r--examples/parse_text.c35
6 files changed, 224 insertions, 234 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d5d3d0e1..d3379593 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,5 +1,10 @@
include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
+ ${CMAKE_SOURCE_DIR}/src/libical
+ ${CMAKE_BINARY_DIR}/src/libical
+ ${CMAKE_SOURCE_DIR}/src/libicalss
)
########### doesnothing target ###############
@@ -41,4 +46,3 @@ else()
target_link_libraries(doesnothing ${BDB_LIBRARY})
endif()
endif()
-
diff --git a/examples/access_components.c b/examples/access_components.c
index 796ce475..be73ba6f 100644
--- a/examples/access_components.c
+++ b/examples/access_components.c
@@ -2,15 +2,9 @@
#include <libical/ical.h>
-#include <assert.h>
-#include <string.h> /* for strdup */
-#include <stdlib.h> /* for malloc */
-#include <stdio.h> /* for printf */
-#include <time.h> /* for time() */
-
void do_something(icalcomponent *c);
-/* Creating iCal Components
+/* Creating iCal Components
There are two ways to create new component in libical. You can
build the component from primitive parts, or you can create it
@@ -26,10 +20,10 @@ void do_something(icalcomponent *c);
constructors, resulting in a compact, neatly formated way to create
components. This style is shown in create_new_component_with_va_args()
-
-
+
+
*/
-
+
icalcomponent* create_new_component()
{
@@ -48,69 +42,69 @@ icalcomponent* create_new_component()
/* Create calendar and add properties */
calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
-
+
/* Nearly every libical function call has the same general
form. The first part of the name defines the 'class' for the
function, and the first argument will be a pointer to a struct
of that class. So, icalcomponent_ functions will all take
icalcomponent* as their first argument. */
- /* The next call creates a new proeprty and immediately adds it to the
- 'calendar' component. */
+ /* The next call creates a new proeprty and immediately adds it to the
+ 'calendar' component. */
icalcomponent_add_property(
- calendar,
- icalproperty_new_version("2.0")
- );
+ calendar,
+ icalproperty_new_version("2.0")
+ );
-
- /* Here is the short version of the memory rules:
- If the routine name has "new" in it:
- Caller owns the returned memory.
- If you pass in a string, the routine takes the memory.
+ /* Here is the short version of the memory rules:
+
+ If the routine name has "new" in it:
+ Caller owns the returned memory.
+ If you pass in a string, the routine takes the memory.
If the routine name has "add" in it:
- The routine takes control of the component, property,
- parameter or value memory.
+ The routine takes control of the component, property,
+ parameter or value memory.
If the routine returns a string ( "get" and "as_ical_string" )
- The library owns the returned memory.
+ The library owns the returned memory.
- There are more rules, so refer to the documentation for more
- details.
+ There are more rules, so refer to the documentation for more
+ details.
*/
icalcomponent_add_property(
- calendar,
- icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN")
- );
-
+ calendar,
+ icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN")
+ );
+
/* Add an event */
event = icalcomponent_new(ICAL_VEVENT_COMPONENT);
icalcomponent_add_property(
- event,
- icalproperty_new_dtstamp(atime)
- );
+ event,
+ icalproperty_new_dtstamp(atime)
+ );
- /* In the previous call, atime is a struct, and it is passed in by value.
+ /* In the previous call, atime is a struct, and it is passed in by value.
This is how all compound types of values are handled. */
icalcomponent_add_property(
- event,
- icalproperty_new_uid("guid-1.host1.com")
- );
+ event,
+ icalproperty_new_uid("guid-1.host1.com")
+ );
/* add a property that has parameters */
property = icalproperty_new_organizer("mailto:mrbig@host.com");
-
+
icalproperty_add_parameter(
- property,
- icalparameter_new_role(ICAL_ROLE_CHAIR)
- );
+ property,
+ icalparameter_new_role(ICAL_ROLE_CHAIR)
+ );
icalcomponent_add_property(event,property);
@@ -120,21 +114,21 @@ icalcomponent* create_new_component()
/* add another property that has parameters */
property = icalproperty_new_attendee("mailto:employee-A@host.com");
-
+
icalproperty_add_parameter(
- property,
- icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT)
- );
+ property,
+ icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT)
+ );
icalproperty_add_parameter(
- property,
- icalparameter_new_rsvp(1)
- );
+ property,
+ icalparameter_new_rsvp(1)
+ );
icalproperty_add_parameter(
- property,
- icalparameter_new_cutype(ICAL_CUTYPE_GROUP)
- );
+ property,
+ icalparameter_new_cutype(ICAL_CUTYPE_GROUP)
+ );
icalcomponent_add_property(event,property);
@@ -142,53 +136,53 @@ icalcomponent* create_new_component()
/* more properties */
icalcomponent_add_property(
- event,
- icalproperty_new_description("Project XYZ Review Meeting")
- );
+ event,
+ icalproperty_new_description("Project XYZ Review Meeting")
+ );
icalcomponent_add_property(
- event,
- icalproperty_new_categories("MEETING")
- );
+ event,
+ icalproperty_new_categories("MEETING")
+ );
icalcomponent_add_property(
- event,
- icalproperty_new_class(ICAL_CLASS_PUBLIC)
- );
-
+ event,
+ icalproperty_new_class(ICAL_CLASS_PUBLIC)
+ );
+
icalcomponent_add_property(
- event,
- icalproperty_new_created(atime)
- );
+ event,
+ icalproperty_new_created(atime)
+ );
icalcomponent_add_property(
- event,
- icalproperty_new_summary("XYZ Project Review")
- );
+ event,
+ icalproperty_new_summary("XYZ Project Review")
+ );
property = icalproperty_new_dtstart(atime);
-
+
icalproperty_add_parameter(
- property,
- icalparameter_new_tzid("US-Eastern")
- );
+ property,
+ icalparameter_new_tzid("US-Eastern")
+ );
icalcomponent_add_property(event,property);
property = icalproperty_new_dtend(atime);
-
+
icalproperty_add_parameter(
- property,
- icalparameter_new_tzid("US-Eastern")
- );
+ property,
+ icalparameter_new_tzid("US-Eastern")
+ );
icalcomponent_add_property(event,property);
icalcomponent_add_property(
- event,
- icalproperty_new_location("1CP Conference Room 4350")
- );
+ event,
+ icalproperty_new_location("1CP Conference Room 4350")
+ );
icalcomponent_add_component(calendar,event);
@@ -206,7 +200,7 @@ icalcomponent* create_new_component_with_va_args()
icalcomponent* calendar;
struct icaltimetype atime = icaltime_from_timet( time(0),0);
struct icalperiodtype rtime;
-
+
rtime.start = icaltime_from_timet( time(0),0);
rtime.end = icaltime_from_timet( time(0),0);
rtime.end.hour++;
@@ -217,50 +211,50 @@ icalcomponent* create_new_component_with_va_args()
values and add each of them to the parent property or
component. */
- calendar =
- icalcomponent_vanew(
- ICAL_VCALENDAR_COMPONENT,
- icalproperty_new_version("2.0"),
- icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"),
- icalcomponent_vanew(
- ICAL_VEVENT_COMPONENT,
- icalproperty_new_dtstamp(atime),
- icalproperty_new_uid("guid-1.host1.com"),
- icalproperty_vanew_organizer(
- "mailto:mrbig@host.com",
- icalparameter_new_role(ICAL_ROLE_CHAIR),
- 0
- ),
- icalproperty_vanew_attendee(
- "mailto:employee-A@host.com",
- icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT),
- icalparameter_new_rsvp(1),
- icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
- 0
- ),
- icalproperty_new_description("Project XYZ Review Meeting"),
-
- icalproperty_new_categories("MEETING"),
- icalproperty_new_class(ICAL_CLASS_PUBLIC),
- icalproperty_new_created(atime),
- icalproperty_new_summary("XYZ Project Review"),
- icalproperty_vanew_dtstart(
- atime,
- icalparameter_new_tzid("US-Eastern"),
- 0
- ),
- icalproperty_vanew_dtend(
- atime,
- icalparameter_new_tzid("US-Eastern"),
- 0
- ),
- icalproperty_new_location("1CP Conference Room 4350"),
- 0
- ),
- 0
- );
-
-
+ calendar =
+ icalcomponent_vanew(
+ ICAL_VCALENDAR_COMPONENT,
+ icalproperty_new_version("2.0"),
+ icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"),
+ icalcomponent_vanew(
+ ICAL_VEVENT_COMPONENT,
+ icalproperty_new_dtstamp(atime),
+ icalproperty_new_uid("guid-1.host1.com"),
+ icalproperty_vanew_organizer(
+ "mailto:mrbig@host.com",
+ icalparameter_new_role(ICAL_ROLE_CHAIR),
+ 0
+ ),
+ icalproperty_vanew_attendee(
+ "mailto:employee-A@host.com",
+ icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT),
+ icalparameter_new_rsvp(1),
+ icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
+ 0
+ ),
+ icalproperty_new_description("Project XYZ Review Meeting"),
+
+ icalproperty_new_categories("MEETING"),
+ icalproperty_new_class(ICAL_CLASS_PUBLIC),
+ icalproperty_new_created(atime),
+ icalproperty_new_summary("XYZ Project Review"),
+ icalproperty_vanew_dtstart(
+ atime,
+ icalparameter_new_tzid("US-Eastern"),
+ 0
+ ),
+ icalproperty_vanew_dtend(
+ atime,
+ icalparameter_new_tzid("US-Eastern"),
+ 0
+ ),
+ icalproperty_new_location("1CP Conference Room 4350"),
+ 0
+ ),
+ 0
+ );
+
+
/* Note that properties with no parameters can use the regular
'new' constructor, while those with parameters use the 'vanew'
constructor. And, be sure that the last argument in the 'vanew'
@@ -273,24 +267,24 @@ icalcomponent* create_new_component_with_va_args()
void find_sub_components(icalcomponent* comp)
{
icalcomponent *c;
-
+
/* The second parameter to icalcomponent_get_first_component
indicates the type of component to search for. This will
iterate through all sub-components */
for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
- c != 0;
- c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
+ c != 0;
+ c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
- do_something(c);
+ do_something(c);
}
/* This will iterate only though VEVENT sub-components */
for(c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT);
- c != 0;
- c = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT)){
+ c != 0;
+ c = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT)){
- do_something(c);
+ do_something(c);
}
}
@@ -300,19 +294,18 @@ void find_sub_components(icalcomponent* comp)
right way to remove components */
void remove_vevent_sub_components(icalcomponent* comp){
-
+
icalcomponent *c, *next;
for( c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT);
- c != 0;
- c = next)
+ c != 0;
+ c = next)
{
- next = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT);
+ next = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT);
- icalcomponent_remove_component(comp,c);
+ icalcomponent_remove_component(comp,c);
- do_something(c);
+ do_something(c);
}
}
-
diff --git a/examples/access_properties_and_parameters.c b/examples/access_properties_and_parameters.c
index 0c0f2ae0..44181366 100644
--- a/examples/access_properties_and_parameters.c
+++ b/examples/access_properties_and_parameters.c
@@ -1,52 +1,51 @@
/* access_properties_and_parameters.c */
#include <libical/ical.h>
-#include <string.h>
#include <stdlib.h>
/* Get a particular parameter out of a component. This routine will
return a list of strings of all attendees who are required. Note
that this routine assumes that the component that we pass in is a
VEVENT. */
-
+
void get_required_attendees(icalcomponent* event)
{
icalproperty* p;
icalparameter* parameter;
-
+
assert(event != 0);
assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);
-
+
/* This loop iterates over all of the ATTENDEE properties in the
event */
-
+
/* The iteration routines save their state in the event
struct, so the are not thread safe unless you lock the whole
component. */
-
+
for(
- p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
- p != 0;
- p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
- ) {
-
- /* Get the first ROLE parameter in the property. There should
+ p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
+ p != 0;
+ p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
+ ) {
+
+ /* Get the first ROLE parameter in the property. There should
only be one, so we won't bother to iterate over them. But,
you can iterate over parameters just like with properties */
- parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER);
+ parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER);
- /* If the parameter indicates the participant is required, get
+ /* If the parameter indicates the participant is required, get
the attendees name and stick a copy of it into the output
array */
- if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT)
- {
- /* Remember, the caller does not own this string, so you
+ if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT)
+ {
+ /* Remember, the caller does not own this string, so you
should strdup it if you want to change it. */
- const char *attendee = icalproperty_get_attendee(p);
- printf("%s",attendee);
- }
+ const char *attendee = icalproperty_get_attendee(p);
+ printf("%s",attendee);
+ }
}
}
@@ -54,7 +53,7 @@ void get_required_attendees(icalcomponent* event)
/* Here is a similar example. If an attendee has a PARTSTAT of
NEEDSACTION or has no PARTSTAT parameter, change it to
TENTATIVE. */
-
+
void update_attendees(icalcomponent* event)
{
icalproperty* p;
@@ -62,38 +61,38 @@ void update_attendees(icalcomponent* event)
assert(event != 0);
assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);
-
+
for(
- p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
- p != 0;
- p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
- ) {
-
- parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);
-
- if (parameter == 0) {
-
- /* There was no PARTSTAT parameter, so add one. */
- icalproperty_add_parameter(
- p,
- icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
- );
-
- } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) {
- /* Remove the NEEDSACTION parameter and replace it with
+ p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
+ p != 0;
+ p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
+ ) {
+
+ parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);
+
+ if (parameter == 0) {
+
+ /* There was no PARTSTAT parameter, so add one. */
+ icalproperty_add_parameter(
+ p,
+ icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
+ );
+
+ } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) {
+ /* Remove the NEEDSACTION parameter and replace it with
TENTATIVE */
-
- icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER);
-
- /* Don't forget to free it */
- icalparameter_free(parameter);
-
- /* Add a new one */
- icalproperty_add_parameter(
- p,
- icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
- );
- }
+
+ icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER);
+
+ /* Don't forget to free it */
+ icalparameter_free(parameter);
+
+ /* Add a new one */
+ icalproperty_add_parameter(
+ p,
+ icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
+ );
+ }
}
}
@@ -111,20 +110,20 @@ void test_properties()
/* Create a new property */
prop = icalproperty_vanew_comment(
- "Another Comment",
- icalparameter_new_cn("A Common Name 1"),
- icalparameter_new_cn("A Common Name 2"),
- icalparameter_new_cn("A Common Name 3"),
- icalparameter_new_cn("A Common Name 4"),
- 0);
+ "Another Comment",
+ icalparameter_new_cn("A Common Name 1"),
+ icalparameter_new_cn("A Common Name 2"),
+ icalparameter_new_cn("A Common Name 3"),
+ icalparameter_new_cn("A Common Name 4"),
+ 0);
/* Iterate through all of the parameters in the property */
for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER);
- param != 0;
- param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) {
-
- printf("Prop parameter: %s\n",icalparameter_get_cn(param));
- }
+ param != 0;
+ param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) {
+
+ printf("Prop parameter: %s\n",icalparameter_get_cn(param));
+ }
/* Get a string representation of the property's value */
printf("Prop value: %s\n",icalproperty_get_comment(prop));
@@ -133,7 +132,7 @@ void test_properties()
str = icalproperty_as_ical_string_r(prop);
printf("As iCAL string:\n %s\n", str);
free(str);
-
+
/* Make a copy of the property. Caller owns the memory */
clone = icalproperty_new_clone(prop);
diff --git a/examples/errors.c b/examples/errors.c
index 0072f144..8ffdc1d3 100644
--- a/examples/errors.c
+++ b/examples/errors.c
@@ -1,22 +1,21 @@
/* errors.c */
#include <libical/ical.h>
-#include <stdio.h>
void program_errors()
{
/*Most routines will set icalerrno on errors. This is an
enumeration defined in icalerror.h */
-
+
icalerror_clear_errno();
(void)icalcomponent_new(ICAL_VEVENT_COMPONENT);
if (icalerrno != ICAL_NO_ERROR){
- fprintf(stderr,"Horrible libical error: %s\n",
- icalerror_strerror(icalerrno));
-
+ fprintf(stderr,"Horrible libical error: %s\n",
+ icalerror_strerror(icalerrno));
+
}
}
@@ -37,11 +36,11 @@ void component_errors(icalcomponent *comp)
as icalcomponent_count_errors() does. */
for(p = icalcomponent_get_first_property(comp,ICAL_XLICERROR_PROPERTY);
- p != 0;
- p = icalcomponent_get_next_property(comp,ICAL_XLICERROR_PROPERTY))
+ p != 0;
+ p = icalcomponent_get_next_property(comp,ICAL_XLICERROR_PROPERTY))
{
-
- printf("-- The error is %s:\n",icalproperty_get_xlicerror(p));
+
+ printf("-- The error is %s:\n",icalproperty_get_xlicerror(p));
}
@@ -49,11 +48,11 @@ void component_errors(icalcomponent *comp)
/* Check the component for iTIP compilance, and add more
X-LIC-ERROR properties if it is non-compilant. */
icalrestriction_check(comp);
-
+
/* Count the new errors. */
if(errors != icalcomponent_count_errors(comp)){
- printf(" -- The component also has iTIP restriction errors \n");
+ printf(" -- The component also has iTIP restriction errors \n");
}
/* Since there are iTIP restriction errors, it may be impossible
diff --git a/examples/main.c b/examples/main.c
index 26725eaf..587dbd21 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -3,11 +3,11 @@
int main()
{
-
return 1;
}
-void do_something(icalcomponent* comp){
+void do_something(icalcomponent* comp)
+{
(void)comp;/*unused*/
}
diff --git a/examples/parse_text.c b/examples/parse_text.c
index 3b6d37b1..67a2345f 100644
--- a/examples/parse_text.c
+++ b/examples/parse_text.c
@@ -1,12 +1,7 @@
/* parse_text.c
-
+
*/
-#include <stdio.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
#include <libical/ical.h>
-
#include <stdlib.h>
/* The icalparser_get_line routine will create a single *content* line
@@ -24,9 +19,9 @@ char* read_stream(char *s, size_t size, void *d)
void parse_text(char* argv[])
{
- char* line;
+ char* line;
FILE* stream;
- icalcomponent *c;
+ icalcomponent *c;
/* Create a new parser object */
icalparser *parser = icalparser_new();
@@ -39,25 +34,25 @@ void parse_text(char* argv[])
icalparser_set_gen_data(parser,stream);
do{
-
- /* Get a single content line by making one or more calls to
+
+ /* Get a single content line by making one or more calls to
read_stream()*/
- line = icalparser_get_line(parser,read_stream);
+ line = icalparser_get_line(parser,read_stream);
- /* Now, add that line into the parser object. If that line
+ /* 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);
+ c = icalparser_add_line(parser,line);
- if (c != 0){
- char *temp = icalcomponent_as_ical_string_r(c);
- printf("%s", temp);
- free(temp);
+ if (c != 0){
+ char *temp = icalcomponent_as_ical_string_r(c);
+ printf("%s", temp);
+ free(temp);
- printf("\n---------------\n");
+ printf("\n---------------\n");
- icalcomponent_free(c);
- }
+ icalcomponent_free(c);
+ }
} while ( line != 0);