4 #include "gsm-common.h"
5 #include "gsm-filetypes.h"
7 #define YY_DECL int yylex(char *type, char *text, char* time, char *alarm, int lexnumber)
23 BEGIN:VCALENDAR BEGIN(vcalendar);
25 <vcalendar>BEGIN:VEVENT ++veventcounter; BEGIN(vevent);
27 <vevent>CATEGORIES: BEGIN(category);
29 <category>[[:alnum:] ]+ {
30 if(veventcounter==lexnumber)
31 strncpy(type, yytext, 21);
35 <vevent>SUMMARY: BEGIN(summary);
37 <summary>[[:alnum:] ]+ {
38 if(veventcounter==lexnumber)
39 strncpy(text, yytext, 21);
43 <vevent>DTSTART: BEGIN(ttime);
45 <ttime>[0-9]{8}T[0-9]{6} {
46 if(veventcounter==lexnumber)
47 strncpy(time, yytext, 16);
51 <vevent>AALARM: BEGIN(aalarm);
53 <aalarm>[0-9]{8}T[0-9]{6} {
54 if(veventcounter==lexnumber)
55 strncpy(alarm, yytext, 16);
60 <vevent>END:VEVENT BEGIN(vcalendar);
62 <vcalendar>END:VCALENDAR BEGIN(0);
65 if((lexnumber<1) | (lexnumber>veventcounter))
67 fprintf(stderr, "Error: Invalid calendar note number!\n");
78 * Fills vCalendar time string into GSM_DateTime structure
81 * dt: datetime structure
82 * time: string in format yyyymmddThhmmss
86 int GetvCalTime(GSM_DateTime *dt, char *time)
88 char year[5]="", month[3]="", day[3]="", hour[3]="", minute[3]="", second[3]="";
89 dt->Year=dt->Month=dt->Day=dt->Hour=dt->Minute=dt->Second=dt->Timezone=0;
91 strncpy(year, time, 4);
92 strncpy(month, time+4, 2);
93 strncpy(day, time+6, 2);
94 strncpy(hour, time+9, 2);
95 strncpy(minute, time+11, 2);
96 strncpy(second, time+13, 2);
98 /* FIXME: Should check ranges... */
100 dt->Month=atoi(month);
103 dt->Minute=atoi(minute);
104 dt->Second=atoi(second);
114 * Fills calendar data from strings into calendar note
117 * note: calendar note structure
118 * type: type of calendar note
119 * text: text or phonenumber
120 * time: string in format yyyymmddThhmmss
125 int FillCalendarNote(GSM_CalendarNote *note, char *type,
126 char *text, char *time, char *alarm)
129 GetvCalTime(¬e->Time, time);
130 GetvCalTime(¬e->Alarm, alarm);
134 strncpy(note->Text, text, 20);
135 strcpy(note->Phone, ""); /* correct in most cases */
137 /* FIXME: Handle additional strings, maybee from configuration file */
139 if(!strcmp(type, "PHONE CALL"))
141 strncpy(note->Phone, text, 20);
144 else if(!strcmp(type, "MEETING"))
145 note->Type=GCN_MEETING;
146 else if(!strcmp(type, "SPECIAL OCASSION"))
147 note->Type=GCN_BIRTHDAY;
149 note->Type=GCN_REMINDER;
155 * GSM_ReadVCalendarFile
157 * Reads vCalendar file
160 * FileName: name of vCalendar file
161 * cnote: pointer to calendar note
162 * number: number in file of calendar note to read
166 int GSM_ReadVCalendarFile(char *FileName, GSM_CalendarNote *cnote, int number)
169 char type[21]="", text[21]="", time[16]="", alarm[16]="";
171 file=fopen(FileName, "r");
173 fprintf(stderr, _("File cannot be opened!\n"));
179 if(yylex(type, text, time, alarm, number))
181 fprintf(stderr, _("Error parsing vCalendar file!\n"));
184 FillCalendarNote(cnote, type, text, time, alarm);