|
|
|
@ -4,15 +4,27 @@
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <uuid/uuid.h>
|
|
|
|
|
|
|
|
|
|
void insert_event(char *file_name) {
|
|
|
|
|
int myfd = open(file_name, O_RDWR);
|
|
|
|
|
|
|
|
|
|
int all_day_event = 0;
|
|
|
|
|
char summary_buf[256] = "SUMMARY:";
|
|
|
|
|
|
|
|
|
|
char *input_buffer = &summary_buf[8];
|
|
|
|
|
uuid_t uuid;
|
|
|
|
|
char uuid_str[37] = "";
|
|
|
|
|
|
|
|
|
|
printf("Insert a new event\n");
|
|
|
|
|
|
|
|
|
|
printf("Is this an all day event? [y/n] ");
|
|
|
|
|
all_day_event = binary_user_choice();
|
|
|
|
|
|
|
|
|
|
if (all_day_event) {
|
|
|
|
|
printf("this will be an all day event\n");
|
|
|
|
|
} else {
|
|
|
|
|
printf("this will not be an all day event\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("SUMMARY: ");
|
|
|
|
|
fgets (input_buffer, (sizeof(summary_buf)-strlen(summary_buf)), stdin);
|
|
|
|
|
|
|
|
|
@ -24,8 +36,15 @@ void insert_event(char *file_name) {
|
|
|
|
|
summary_buf[strlen(summary_buf)-1] = '\r';
|
|
|
|
|
summary_buf[strlen(summary_buf)] = '\n';
|
|
|
|
|
|
|
|
|
|
uuid_generate(uuid);
|
|
|
|
|
// parse uuid to a string
|
|
|
|
|
uuid_unparse(uuid, uuid_str);
|
|
|
|
|
|
|
|
|
|
seek_cal_end(myfd);
|
|
|
|
|
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
|
|
|
|
|
write(myfd, "UID:", strlen("UID:"));
|
|
|
|
|
write(myfd, uuid_str, strlen(uuid_str));
|
|
|
|
|
write(myfd, "\r\n", strlen("\r\n"));
|
|
|
|
|
write(myfd, summary_buf, strlen(summary_buf));
|
|
|
|
|
write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n"));
|
|
|
|
|
|
|
|
|
@ -55,3 +74,23 @@ void seek_cal_end(int fd) {
|
|
|
|
|
lseek(fd, -2, SEEK_CUR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int binary_user_choice() {
|
|
|
|
|
char input_buffer[64] = "";
|
|
|
|
|
if (fgets (input_buffer, sizeof(input_buffer), stdin) == NULL) {
|
|
|
|
|
printf ("an fgets error occured\n");
|
|
|
|
|
}
|
|
|
|
|
if (! strchr(input_buffer, '\n')) {
|
|
|
|
|
printf ("Input buffer overflow!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (input_buffer[0] == 'n' || input_buffer[0] == 'N') {
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (input_buffer[0] == 'y' || input_buffer[0] == 'Y') {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
printf ("Please enter a N/n or Y/y character!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|