Compare commits

...

5 Commits

Author SHA1 Message Date
ketrptr 7f487016dc modified: .gitignore 2024-12-17 10:45:33 +01:00
ketrptr cd7094263a Merge branch 'carla'
modified:   src/iCal.c
	modified:   src/iCal.h
	modified:   src/planner.c
	modified:   src/planner.h
	modified:   src/ui.c
2024-12-17 10:45:05 +01:00
ketrptr 809efb512a modified: src/iCal.c
modified:   src/iCal.h
	modified:   src/planner.c
	modified:   src/planner.h
	modified:   src/ui.c
2024-12-17 10:37:31 +01:00
ketrptr cb6571a0d6 modified: Makefile 2024-12-17 10:33:49 +01:00
carlaTechnulgy 0943d4f321 carlas commit 2024-12-17 09:57:50 +01:00
8 changed files with 260 additions and 84 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ testing
debugOut
.idea
.run
.vscode
# ---> C
# Prerequisites
*.d

28
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

View File

@ -14,14 +14,14 @@ CONFIG=src/config.h #config file
ALLF=$(UIF) $(PLF) $(DBF) $(LLST)
all: debug release
all: debug
#targets
debug: test ui planner db iCal llist
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
gcc -DDEBUG test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
release: $(ALLF)
gcc -DRELEASE -fPIC -shared -o libStudyPlanner.so $(ALLF)
# release: $(ALLF)
# gcc -DRELEASE -fPIC -shared -o $(ALLF)
# config: $(CONFIG)

View File

@ -1,7 +1,143 @@
/* INPUT: linked list of events
*
* OUTPUT: Ical File, OK to caller
*
*/
#include "planner.h" // for task and event structs
#include "llist.h"
#include "planner.h"
#include <stdio.h>
#include <string.h>
const char *iCalHeader =
"BEGIN:VCALENDAR\r\n" // definition of commands for final iCal file
"VERSION:2.0\r\n"
"PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n";
const char *iCalEvent = "BEGIN:VEVENT\r\n"
"UID:%s%d\r\n"
"DTSTAMP:%s\r\n"
"DTSTART:%s\r\n"
"DTEND:%s\r\n"
"SUMMARY:%s\r\n"
"END:VEVENT\r\n";
const char *iCalFileExtension = "ics"; // doctype
/*
* Wikipedia
*
*The body of the iCalendar object (the icalbody) contains single-line Calendar
* Properties that apply to the entire calendar, as well as one or more blocks
* of multiple lines that each define a Calendar Component such as an event,
* journal entry, alarm, or one of several other types. Here is a simple example
* of an iCalendar object with a single calendar containing a single Calendar
* Component, a "Bastille Day Party" event starting at 5pm on July 14, 1997, and
* ending at 4am the following morning:[10]
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:uid1@example.com
ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
DTSTART:19970714T170000Z
DTEND:19970715T040000Z
SUMMARY:Bastille Day Party
GEO:48.85299;2.36885
END:VEVENT
END:VCALENDAR
The UID field distributes updates when a scheduled event changes. When the event
is first generated a globally unique identifier is created. If a later event is
distributed with the same UID, it replaces the original one. An example UID
might be Y2007S2C131M5@example.edu, for the 5th meeting of class 131 in semester
2 at a hypothetical college. Email-style UIDs are now considered bad practice,
with a UUID recommended instead.[11]
The most common representation of date and time is a tz timestamp such as
20010911T124640Z with the format <year (4 digits)><month (2)><day (2)>T<hour
(2)><minute (2)><second (2)>Z for a total fixed length of 16 characters. Z
indicates the use of UTC (referring to its Zulu time zone).[12] When used in
DTSTART and DTEND properties, start times are inclusive while end times are not.
This allows an event's end time to be the same as a consecutive event's start
without those events overlapping and potentially creating (false) scheduling
conflicts.[13]
*/
// exportical function: generates ical file from llist
int exportiCal(llist *events_ll) {
llist *ev_ll = events_ll; // input from llist
llistPrintE(ev_ll);
printf("%s", iCalHeader);
time_t now = time(NULL); // current time is captured an formatted
struct tm lc;
localtime_r(&now, &lc);
// gen filename & open for write
char nameBuf[32];
strftime(nameBuf, 32 - 12, "%F", &lc);
strcat(nameBuf, "dayplan.ics");
FILE *fp = fopen(nameBuf, "w");
if (fp == NULL) {
printf("fopen failed!!");
return 1;
}
// write iCal header to file
fprintf(fp, "%s", iCalHeader);
// for every event in events_ll create VEVENT str and write to fp
int count = 0;
while (ev_ll != NULL) {
// gen iCal compatible time str
Event *current = ev_ll->data;
struct tm startlc;
struct tm endlc;
localtime_r(&current->plannedStartTime, &startlc);
localtime_r(&current->plannedEndTime, &endlc);
char timeStartBuf[17];
char timeEndBuf[17];
char timeStamp[17];
strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ",
&lc); // strftime to match ical format
printf("%s\n", timeStamp);
strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc);
printf("%s\n", timeStartBuf);
strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", &endlc);
printf("%s\n", timeEndBuf);
fprintf(fp, iCalEvent, current->task->name, count, timeStamp, timeStartBuf,
timeEndBuf, current->task->name);
ev_ll = ev_ll->next;
count += 1;
}
// after all events are written end cal with
// END:VCALENDAR
fprintf(fp, "END:VCALENDAR\r\n");
fclose(fp);
return 0;
}
// export data from llist to csv file
const char *taskFileFormat = "%s,%lu,%lu,%d,%lu\n";
int taskLlToFile(llist *tll) {
// open file
FILE *fp = fopen("db.csv", "w");
if (fp == NULL)
return -1; // if file cannot be opend, return -1
llist *c = tll;
while (c != NULL) {
Task *ct = (Task *)c->data; // loop to go through tasks(name, created time,
// deadline, priority, etc.)
fprintf(fp, taskFileFormat, ct->name, ct->created, ct->deadline,
ct->priority, ct->spare);
c = c->next;
}
fclose(fp);
return 0;
}

View File

@ -0,0 +1,7 @@
#ifndef iCAL
#define iCAL
#include "llist.h"
int exportiCal(llist *events_ll);
#endif

View File

@ -16,8 +16,8 @@
#include <time.h>
#ifdef _WIN32
#define ctime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
#define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
#define ctime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
#define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
#endif /* ifdef _WIN32 */
const unsigned int intervalLen = 45; // min
@ -205,7 +205,8 @@ llist *genPlan(llist *head, time_t timeAvail) {
planLog("creating eventList", false);
// genertate plan basen on priorities and available time
// genertate plan based on priorities and available time
now = time(NULL);
struct tm *lc = localtime(&now);
llist *events_ll = llistNew(NULL, cmpEvent);
if (events_ll == NULL) {
@ -261,71 +262,72 @@ llist *genPlan(llist *head, time_t timeAvail) {
return events_ll;
}
const char *iCalHeader = "BEGIN:VCALENDAR\r\n"
"VERSION:2.0\r\n"
"PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n";
const char *iCalEvent = "BEGIN:VEVENT\r\n"
"UID:%s%d\r\n"
"DTSTAMP:%s\r\n"
"DTSTART:%s\r\n"
"DTEND:%s\r\n"
"SUMMARY:%s\r\n"
"END:VEVENT\r\n";
int exportiCal(llist *events_ll) {
llist *ev_ll = events_ll;
llistPrintE(ev_ll);
printf("%s", iCalHeader);
time_t now = time(NULL);
struct tm lc;
localtime_r(&now, &lc);
// gen filename & open for write
char nameBuf[32];
strftime(nameBuf, 32 - 12, "%F", &lc);
strcat(nameBuf, "dayplan.ics");
FILE *fp = fopen(nameBuf, "w");
if (fp == NULL) {
planLog("fopen failed!!", 1);
return 1;
}
// write iCal header to file
fprintf(fp, "%s", iCalHeader);
// for every event in events_ll create VEVENT str and write to fp
int count = 0;
while (ev_ll != NULL) {
// gen iCal compatible time str
Event *current = ev_ll->data;
struct tm startlc;
struct tm endlc;
localtime_r(&current->plannedStartTime, &startlc);
localtime_r(&current->plannedEndTime, &endlc);
char timeStartBuf[17];
char timeEndBuf[17];
char timeStamp[17];
strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", &lc);
printf("%s\n", timeStamp);
strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc);
printf("%s\n", timeStartBuf);
strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", &endlc);
printf("%s\n", timeEndBuf);
fprintf(fp, iCalEvent, current->task->name, count, timeStamp, timeStartBuf,
timeEndBuf, current->task->name);
ev_ll = ev_ll->next;
count += 1;
}
// after all events are written end cal with
// END:VCALENDAR
fprintf(fp, "END:VCALENDAR\r\n");
fclose(fp);
return 0;
}
//
// const char *iCalHeader = "BEGIN:VCALENDAR\r\n"
// "VERSION:2.0\r\n"
// "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n";
// const char *iCalEvent = "BEGIN:VEVENT\r\n"
// "UID:%s%d\r\n"
// "DTSTAMP:%s\r\n"
// "DTSTART:%s\r\n"
// "DTEND:%s\r\n"
// "SUMMARY:%s\r\n"
// "END:VEVENT\r\n";
//
// int exportiCal(llist *events_ll) {
//
// llist *ev_ll = events_ll;
//
// llistPrintE(ev_ll);
//
// printf("%s", iCalHeader);
//
// time_t now = time(NULL);
// struct tm lc;
// localtime_r(&now, &lc);
//
// // gen filename & open for write
// char nameBuf[32];
// strftime(nameBuf, 32 - 12, "%F", &lc);
// strcat(nameBuf, "dayplan.ics");
// FILE *fp = fopen(nameBuf, "w");
// if (fp == NULL) {
// planLog("fopen failed!!", 1);
// return 1;
// }
// // write iCal header to file
// fprintf(fp, "%s", iCalHeader);
//
// // for every event in events_ll create VEVENT str and write to fp
// int count = 0;
// while (ev_ll != NULL) {
// // gen iCal compatible time str
// Event *current = ev_ll->data;
// struct tm startlc;
// struct tm endlc;
// localtime_r(&current->plannedStartTime, &startlc);
// localtime_r(&current->plannedEndTime, &endlc);
// char timeStartBuf[17];
// char timeEndBuf[17];
// char timeStamp[17];
// strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", &lc);
// printf("%s\n", timeStamp);
// strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc);
// printf("%s\n", timeStartBuf);
// strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", &endlc);
// printf("%s\n", timeEndBuf);
//
// fprintf(fp, iCalEvent, current->task->name, count, timeStamp,
// timeStartBuf,
// timeEndBuf, current->task->name);
// ev_ll = ev_ll->next;
// count += 1;
// }
//
// // after all events are written end cal with
// // END:VCALENDAR
// fprintf(fp, "END:VCALENDAR\r\n");
// fclose(fp);
//
// return 0;
// }

View File

@ -84,6 +84,6 @@ int cmpEvent(const void *a, const void *b);
*/
llist *genPlan(llist *head, time_t timeAvail);
int exportiCal(llist *head);
// int exportiCal(llist *head);
#endif // !PLANNER

View File

@ -8,6 +8,7 @@
#include "ui.h"
#include "StudyPlanner.h"
#include "db.h"
#include "iCal.h"
#include "llist.h"
#include "planner.h" // for subject and event structs
#include <assert.h>
@ -17,14 +18,15 @@
#include <time.h>
#ifdef _WIN32
#define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
#define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
#endif
#define minutes(n) (60 * n)
#define hours(n) (60 * minutes(n))
#define days(n) (24 * hours(n))
const char *dbName = "db.csv";
// #define DEBUG
#define DEBUG
#ifdef DEBUG
int main(void) {
#endif