diff options
author | nobody <nobody@localhost> | 2001-04-16 17:30:54 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2001-04-16 17:30:54 +0800 |
commit | a7063754437e9ce90775718f69dd0e770a3b8f6e (patch) | |
tree | aaa46c1cf6c9a87e8f291ef7673bd9463803e8c9 /libical/examples | |
parent | 75a16468d369f58587f27ab4655fbe1c1091fc95 (diff) | |
download | gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar.gz gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar.bz2 gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar.lz gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar.xz gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.tar.zst gsoc2013-evolution-GNOME-VFS_1_0_1_ANCHOR.zip |
This commit was manufactured by cvs2svn to create tagGNOME-VFS_1_0_1_ANCHOR
'GNOME-VFS_1_0_1_ANCHOR'.
svn path=/tags/GNOME-VFS_1_0_1_ANCHOR/; revision=9348
Diffstat (limited to 'libical/examples')
-rw-r--r-- | libical/examples/.cvsignore | 5 | ||||
-rw-r--r-- | libical/examples/Makefile.am | 15 | ||||
-rw-r--r-- | libical/examples/access_components.c | 319 | ||||
-rw-r--r-- | libical/examples/access_properties_and_parameters.c | 144 | ||||
-rw-r--r-- | libical/examples/errors.c | 70 | ||||
-rw-r--r-- | libical/examples/main.c | 12 | ||||
-rw-r--r-- | libical/examples/parse_text.c | 68 |
7 files changed, 0 insertions, 633 deletions
diff --git a/libical/examples/.cvsignore b/libical/examples/.cvsignore deleted file mode 100644 index 29ef3ef4c8..0000000000 --- a/libical/examples/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -.libs -.deps -Makefile -Makefile.in -doesnothing diff --git a/libical/examples/Makefile.am b/libical/examples/Makefile.am deleted file mode 100644 index 99e33d3400..0000000000 --- a/libical/examples/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ - -noinst_PROGRAMS = doesnothing - -LDADD = ../src/libical/libical.a ../src/libicalss/libicalss.la ../src/libicalvcal/libicalvcal.la -INCLUDES = -I . -I../src/libical -I$(srcdir)/../src/libical -I../src/libicalss -I../src/libicalvcal - -INCLUDES = -I. -I../src/libical -I$(srcdir)/../src/libical -I../src/libicalss -I../src/libicalvcal - -doesnothing_SOURCES = \ - access_components.c \ - access_properties_and_parameters.c \ - errors.c \ - main.c \ - parse_text.c - diff --git a/libical/examples/access_components.c b/libical/examples/access_components.c deleted file mode 100644 index cc5a33d6d2..0000000000 --- a/libical/examples/access_components.c +++ /dev/null @@ -1,319 +0,0 @@ -/* Access_component.c */ - -#include "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() */ -#include "icalmemory.h" - -void do_something(icalcomponent *c); - -/* 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 - from a string. - - There are two variations of the API for building the component from - primitive parts. In the first variation, you add each parameter and - value to a property, and then add each property to a - component. This results in a long series of function calls. This - style is show in create_new_component() - - The second variation uses vargs lists to nest many primitive part - 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() -{ - - /* variable definitions */ - icalcomponent* calendar; - icalcomponent* event; - struct icaltimetype atime = icaltime_from_timet( time(0),0); - struct icalperiodtype rtime; - icalproperty* property; - - /* Define a time type that will use as data later. */ - rtime.start = icaltime_from_timet( time(0),0); - rtime.end = icaltime_from_timet( time(0),0); - rtime.end.hour++; - - /* 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. */ - - icalcomponent_add_property( - 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. - - If the routine name has "add" in it: - 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. - - There are more rules, so refer to the documentation for more - details. - - */ - - icalcomponent_add_property( - 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) - ); - - /* 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") - ); - - /* add a property that has parameters */ - property = icalproperty_new_organizer("mailto:mrbig@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_CHAIR) - ); - - icalcomponent_add_property(event,property); - - /* In this style of component creation, you need to use an extra - call to add parameters to properties, but the form of this - operation is the same as adding a property to a 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) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_rsvp(1) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_cutype(ICAL_CUTYPE_GROUP) - ); - - icalcomponent_add_property(event,property); - - - /* more properties */ - - icalcomponent_add_property( - event, - icalproperty_new_description("Project XYZ Review Meeting") - ); - - icalcomponent_add_property( - event, - icalproperty_new_categories("MEETING") - ); - - icalcomponent_add_property( - event, - icalproperty_new_class("PUBLIC") - ); - - icalcomponent_add_property( - event, - icalproperty_new_created(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_summary("XYZ Project Review") - ); - - property = icalproperty_new_dtstart(atime); - - icalproperty_add_parameter( - 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") - ); - - icalcomponent_add_property(event,property); - - icalcomponent_add_property( - event, - icalproperty_new_location("1CP Conference Room 4350") - ); - - icalcomponent_add_component(calendar,event); - - return calendar; -} - - -/* Now, create the same component as in the previous routine, but use -the constructor style. */ - -icalcomponent* create_new_component_with_va_args() -{ - - /* This is a similar set up to the last routine */ - 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++; - - /* Some of these routines are the same as those in the previous - routine, but we've also added several 'vanew' routines. These - 'vanew' routines take a list of properties, parameters or - 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("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' - call is a zero. Without, your program will probably crash. */ - - return calendar; -} - - -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)){ - - 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)){ - - do_something(c); - } - -} - -/* Ical components only have one internal iterator, so removing the - object that the iterator points to can cause problems. Here is the - 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) - { - next = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT); - - icalcomponent_remove_component(comp,c); - - do_something(c); - } - -} - diff --git a/libical/examples/access_properties_and_parameters.c b/libical/examples/access_properties_and_parameters.c deleted file mode 100644 index ba3d7fcc0b..0000000000 --- a/libical/examples/access_properties_and_parameters.c +++ /dev/null @@ -1,144 +0,0 @@ -/* access_properties_and_parameters.c */ - -#include "ical.h" -#include <string.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 - 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); - - /* 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 - should strdup it if you want to change it. */ - const char *attendee = icalproperty_get_attendee(p); - } - } - -} - -/* 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; - icalparameter* parameter; - - 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 - 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) - ); - } - - } -} - -/* Here are some examples of manipulating properties */ - -void test_properties() -{ - icalproperty *prop; - icalparameter *param; - icalvalue *value; - - icalproperty *clone; - - /* 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); - - /* 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)); - } - - /* Get a string representation of the property's value */ - printf("Prop value: %s\n",icalproperty_get_comment(prop)); - - /* Spit out the property in its RFC 2445 representation */ - printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); - - /* Make a copy of the property. Caller owns the memory */ - clone = icalproperty_new_clone(prop); - - /* Get a reference to the value within the clone property */ - value = icalproperty_get_value(clone); - - printf("Value: %s",icalvalue_as_ical_string(value)); - - /* Free the original and the clone */ - icalproperty_free(clone); - icalproperty_free(prop); - -} diff --git a/libical/examples/errors.c b/libical/examples/errors.c deleted file mode 100644 index 86d963bd75..0000000000 --- a/libical/examples/errors.c +++ /dev/null @@ -1,70 +0,0 @@ -/* errors.c */ - -#include "ical.h" -#include <stdio.h> - -void program_errors() -{ - /*Most routines will set icalerrno on errors. This is an - enumeration defined in icalerror.h */ - - icalcomponent *c; - - icalerror_clear_errno(); - - c = icalcomponent_new(ICAL_VEVENT_COMPONENT); - - if (icalerrno != ICAL_NO_ERROR){ - - fprintf(stderr,"Horrible libical error: %s\n", - icalerror_strerror(icalerrno)); - - } - -} - -void component_errors(icalcomponent *comp) -{ - int errors; - icalproperty *p; - - /* presume that we just got this component from the parser */ - - errors = icalcomponent_count_errors(comp); - - printf("This component has %d parsing errors\n", errors); - - /* Print out all of the parsing errors. This is not strictly - correct, because it does not descend into any sub-components, - 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)) - { - - printf("-- The error is %s:\n",icalproperty_get_xlicerror(p)); - } - - - - /* 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"); - } - - /* Since there are iTIP restriction errors, it may be impossible - to process this component as an iTIP request. In this case, the - X-LIC-ERROR proeprties should be expressed as REQUEST-STATUS - properties in the reply. This following routine makes this - conversion */ - - - icalcomponent_convert_errors(comp); - -} diff --git a/libical/examples/main.c b/libical/examples/main.c deleted file mode 100644 index 1be2de5c9e..0000000000 --- a/libical/examples/main.c +++ /dev/null @@ -1,12 +0,0 @@ -/* This is just to make the code in the example directory link properly. */ -#include "ical.h" - -int main() -{ - - return 1; -} - - -void do_something(icalcomponent* comp){ -} diff --git a/libical/examples/parse_text.c b/libical/examples/parse_text.c deleted file mode 100644 index b7eba43b8a..0000000000 --- a/libical/examples/parse_text.c +++ /dev/null @@ -1,68 +0,0 @@ -/* 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; - -} - -void parse_text(int argc, char* argv[]) -{ - - 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)); - - printf("\n---------------\n"); - - icalcomponent_free(c); - } - - } while ( line != 0); - - - icalparser_free(parser); -} |