insert_event #1

Merged
bjoernf merged 16 commits from insert_event into master 2023-09-09 08:26:50 +02:00
2 changed files with 14 additions and 2 deletions
Showing only changes of commit 27a69bee93 - Show all commits

View File

@ -4,12 +4,18 @@
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
// buffer needs to contain this string: "xxxxxxxxTxxxxxx"
// or "YYYYmmddTHHMMSSZ"
void get_date(char buffer[]) { void get_date(char buffer[]) {
// add 1 because strlen does not include the null character // add 1 because strlen does not include the null character
size_t buffer_size = strlen(buffer) + 1; size_t buffer_size = strlen(buffer) + 1;
time_t my_unix_ts = time(NULL); time_t my_unix_ts = time(NULL);
struct tm* my_tm_local = localtime(&my_unix_ts); struct tm* my_tm_local = localtime(&my_unix_ts);
if (strlen(buffer) == 15) {
strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local); strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local);
} else if (strlen(buffer) == 16) {
strftime(buffer, buffer_size, "%Y%m%dT%H%M%SZ", my_tm_local);
}
} }
// 20230823T194138 -> 2023-08-23 19:41:38 // 20230823T194138 -> 2023-08-23 19:41:38

View File

@ -1,4 +1,5 @@
#include "insert_event.h" #include "insert_event.h"
#include "date_time_handling.h"
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -13,6 +14,7 @@ void insert_event(char *file_name) {
char *input_buffer = &summary_buf[8]; char *input_buffer = &summary_buf[8];
uuid_t uuid; uuid_t uuid;
char uuid_str[37] = ""; char uuid_str[37] = "";
char dtstamp[] = "YYYYmmddTHHMMSSZ";
printf("Insert a new event\n"); printf("Insert a new event\n");
@ -40,11 +42,16 @@ void insert_event(char *file_name) {
// parse uuid to a string // parse uuid to a string
uuid_unparse(uuid, uuid_str); uuid_unparse(uuid, uuid_str);
get_date(dtstamp);
seek_cal_end(myfd); seek_cal_end(myfd);
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n")); write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
write(myfd, "UID:", strlen("UID:")); write(myfd, "UID:", strlen("UID:"));
write(myfd, uuid_str, strlen(uuid_str)); write(myfd, uuid_str, strlen(uuid_str));
write(myfd, "\r\n", strlen("\r\n")); write(myfd, "\r\n", strlen("\r\n"));
write(myfd, "DTSTAMP:", strlen("DTSTAMP:"));
write(myfd, dtstamp, strlen(dtstamp));
write(myfd, "\r\n", strlen("\r\n"));
write(myfd, summary_buf, strlen(summary_buf)); write(myfd, summary_buf, strlen(summary_buf));
write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n")); write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n"));
@ -75,7 +82,6 @@ void seek_cal_end(int fd) {
} }
} }
int binary_user_choice() { int binary_user_choice() {
char input_buffer[64] = ""; char input_buffer[64] = "";
if (fgets (input_buffer, sizeof(input_buffer), stdin) == NULL) { if (fgets (input_buffer, sizeof(input_buffer), stdin) == NULL) {