File: ical_apply_patch.c

package info (click to toggle)
cyrus-imapd 3.6.1-4%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,688 kB
  • sloc: ansic: 255,928; perl: 97,730; javascript: 9,266; sh: 5,537; yacc: 2,651; cpp: 2,128; makefile: 2,099; lex: 660; xml: 621; python: 388; awk: 303; asm: 262
file content (53 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Program for testing VPATCH application
 */

#include <stdio.h>
#include <libical/ical.h>

#include "ical_support.h"

extern int optind, opterr;
extern char *optarg;

static char *read_stream(char *s, size_t size, void *d)
{
    return fgets(s, (int) size, (FILE*) d);
}

static icalcomponent *parse_file(const char *fname)
{
     icalcomponent *component = NULL;
     FILE *stream = fopen(fname, "r");

     if (!stream) return NULL;

     icalparser *parser = icalparser_new();
     icalparser_set_gen_data(parser, stream);

     component = icalparser_parse(parser, read_stream);

     icalparser_free(parser);
     fclose(stream);

     return component;
 }

int main(int argc, char *argv[])
{
    if (argc < 3) {
        fprintf(stderr, "usage: %s <VCALENDAR_file> <VPATCH_file>\n", argv[0]);
        exit(0);
    }

    icalcomponent *resource = parse_file(argv[1]);
    icalcomponent *patch = parse_file(argv[2]);

    icalcomponent_apply_vpatch(resource, patch, NULL, NULL);

    printf("%s", icalcomponent_as_ical_string(resource));
    icalcomponent_free(resource);
    icalcomponent_free(patch);

    exit(0);
}