Compare commits
No commits in common. "master" and "bugfix" have entirely different histories.
|
@ -1,8 +1,6 @@
|
||||||
testing
|
testing
|
||||||
debugOut
|
debugOut
|
||||||
.idea
|
.idea
|
||||||
.run
|
|
||||||
.vscode
|
|
||||||
# ---> C
|
# ---> C
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="StudyPlanner" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" RUN_PATH="$PROJECT_DIR$/Makefile" EXPLICIT_BUILD_TARGET_NAME="all">
|
||||||
|
<method v="2">
|
||||||
|
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
19
Makefile
19
Makefile
|
@ -12,19 +12,12 @@ CALF=src/iCal.c src/iCal.h
|
||||||
LLST=src/llist.c src/llist.h
|
LLST=src/llist.c src/llist.h
|
||||||
CONFIG=src/config.h #config file
|
CONFIG=src/config.h #config file
|
||||||
|
|
||||||
ALLF=$(UIF) $(PLF) $(DBF) $(LLST)
|
|
||||||
|
|
||||||
all: debug
|
|
||||||
#targets
|
#targets
|
||||||
debug: test ui planner db iCal llist
|
debug: test ui planner db iCal config llist
|
||||||
gcc -DDEBUG test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
|
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
|
||||||
|
|
||||||
|
config: $(CONFIG)
|
||||||
# release: $(ALLF)
|
|
||||||
# gcc -DRELEASE -fPIC -shared -o $(ALLF)
|
|
||||||
|
|
||||||
|
|
||||||
# config: $(CONFIG)
|
|
||||||
llist: $(LLST)
|
llist: $(LLST)
|
||||||
gcc -c $(CFLAGS) $(LLST)
|
gcc -c $(CFLAGS) $(LLST)
|
||||||
test: src/test.c
|
test: src/test.c
|
||||||
|
@ -32,7 +25,7 @@ test: src/test.c
|
||||||
iCal: $(CALF)
|
iCal: $(CALF)
|
||||||
gcc -c $(CFLAGS) $(CALF)
|
gcc -c $(CFLAGS) $(CALF)
|
||||||
ui: $(UIF)
|
ui: $(UIF)
|
||||||
gcc -DDEBUG -c $(CFLAGS) $(UIF)
|
gcc -c $(CFLAGS) $(UIF)
|
||||||
planner: $(PLF)
|
planner: $(PLF)
|
||||||
gcc -c $(CFLAGS) $(PLF)
|
gcc -c $(CFLAGS) $(PLF)
|
||||||
db: $(DBF)
|
db: $(DBF)
|
||||||
|
@ -40,10 +33,10 @@ db: $(DBF)
|
||||||
|
|
||||||
|
|
||||||
edit:
|
edit:
|
||||||
nvim $(PLF) Makefile $(ALLF)
|
nvim $(PLF) Makefile $(LLST) src/test.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.o debugOut src/*.gch *.csv *.ics *.so
|
rm -rf *.o debugOut src/*.gch *.csv *.ics
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
10
README.md
10
README.md
|
@ -13,16 +13,6 @@
|
||||||
|
|
||||||
Time management optimisation tool.
|
Time management optimisation tool.
|
||||||
|
|
||||||
# How to use
|
|
||||||
|
|
||||||
- to use program directly compile with
|
|
||||||
make debug
|
|
||||||
. this creates executable binary.
|
|
||||||
|
|
||||||
- to integrate in other software use:
|
|
||||||
make release
|
|
||||||
. This creates shared library. use StudyPlanner.h (untested)
|
|
||||||
|
|
||||||
# Procedure
|
# Procedure
|
||||||
|
|
||||||
## User input
|
## User input
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#ifndef SPLANNER
|
|
||||||
#define SPLANNER
|
|
||||||
|
|
||||||
int StudyPlanner();
|
|
||||||
|
|
||||||
#endif // StudyPlanner
|
|
3
src/db.c
3
src/db.c
|
@ -60,8 +60,7 @@ llist *write_csv_to_llist(const char *filename) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char *line = NULL; // Line Buffer
|
char *line = NULL; // Line Buffer
|
||||||
ssize_t nnread;
|
size_t nnread, len;
|
||||||
size_t len;
|
|
||||||
int count = 0; // task counter
|
int count = 0; // task counter
|
||||||
getline(&line, &len, file);
|
getline(&line, &len, file);
|
||||||
free(line);
|
free(line);
|
||||||
|
|
3
src/db.h
3
src/db.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void write_linkedlist_to_csv(llist *head, const char *filename);
|
void write_linkedlist_to_csv(llist *head, const char *filename);
|
||||||
llist *write_csv_to_llist(const char *filename);
|
llist *write_csv_to_llist(const char *filename);
|
||||||
#endif
|
|
||||||
|
|
144
src/iCal.c
144
src/iCal.c
|
@ -1,143 +1,7 @@
|
||||||
|
/* INPUT: linked list of events
|
||||||
#include "llist.h"
|
*
|
||||||
#include "planner.h"
|
* OUTPUT: Ical File, OK to caller
|
||||||
#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
|
#include "planner.h" // for task and event structs
|
||||||
|
|
||||||
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(¤t->plannedStartTime, &startlc);
|
|
||||||
localtime_r(¤t->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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#ifndef iCAL
|
|
||||||
#define iCAL
|
|
||||||
|
|
||||||
#include "llist.h"
|
|
||||||
int exportiCal(llist *events_ll);
|
|
||||||
|
|
||||||
#endif
|
|
129
src/planner.c
129
src/planner.c
|
@ -16,8 +16,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define ctime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
|
#define ctime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
|
||||||
#define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
|
#define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
|
||||||
#endif /* ifdef _WIN32 */
|
#endif /* ifdef _WIN32 */
|
||||||
|
|
||||||
const unsigned int intervalLen = 45; // min
|
const unsigned int intervalLen = 45; // min
|
||||||
|
@ -161,14 +161,6 @@ int cmpEvent(const void *a, const void *b) {
|
||||||
return cmpTaskN(aa->task, bb->task);
|
return cmpTaskN(aa->task, bb->task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetPrio(Task **sortedPrio, int len) {
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
if ((*sortedPrio)[i].priority < 0) // ignore past deadline
|
|
||||||
continue;
|
|
||||||
printf("incrementing prio!\n");
|
|
||||||
(*sortedPrio)[i].priority += 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
llist *genPlan(llist *head, time_t timeAvail) {
|
llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
|
|
||||||
// map llist to pointer arr & sort by priority
|
// map llist to pointer arr & sort by priority
|
||||||
|
@ -178,7 +170,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
printf("len: %d\n", lLen);
|
printf("len: %d\n", lLen);
|
||||||
llistPrintT(head);
|
llistPrintT(head);
|
||||||
|
|
||||||
time_t now = time(NULL);
|
// Task *sortedNames = calloc(lLen, sizeof(Task));
|
||||||
Task *sortedPrio = calloc(lLen, sizeof(Task));
|
Task *sortedPrio = calloc(lLen, sizeof(Task));
|
||||||
if (/*sortedNames == NULL ||*/ sortedPrio == NULL) {
|
if (/*sortedNames == NULL ||*/ sortedPrio == NULL) {
|
||||||
planLog("gen plan : calloc failed!!\n", true);
|
planLog("gen plan : calloc failed!!\n", true);
|
||||||
|
@ -188,16 +180,23 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
// add Tasks from llist to arr
|
// add Tasks from llist to arr
|
||||||
llist *c = head;
|
llist *c = head;
|
||||||
for (int i = 0; c != NULL; i++) {
|
for (int i = 0; c != NULL; i++) {
|
||||||
|
// sortedNames[i] = *copyTask(c->data);
|
||||||
|
// sortedPrio[i] = *copyTask(c->data);
|
||||||
|
// sortedNames[i] = *(Task *)c->data;
|
||||||
sortedPrio[i] = *(Task *)c->data;
|
sortedPrio[i] = *(Task *)c->data;
|
||||||
if (sortedPrio[i].deadline + 1 < now) {
|
|
||||||
sortedPrio[i].priority = -1; // ignore past deadlines
|
|
||||||
}
|
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort
|
// sort
|
||||||
|
// qsort(sortedNames, lLen, sizeof(Task), cmpTaskN);
|
||||||
qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP);
|
qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP);
|
||||||
|
|
||||||
|
// // test print
|
||||||
|
// planLog("sortendName", 0);
|
||||||
|
// for (int i = 0; i < lLen; i++) {
|
||||||
|
// printTask(sortedNames + i);
|
||||||
|
// }
|
||||||
|
|
||||||
planLog("sortendPrio", 0);
|
planLog("sortendPrio", 0);
|
||||||
for (int i = 0; i < lLen; i++) {
|
for (int i = 0; i < lLen; i++) {
|
||||||
printTask(sortedPrio + i);
|
printTask(sortedPrio + i);
|
||||||
|
@ -205,21 +204,17 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
|
|
||||||
planLog("creating eventList", false);
|
planLog("creating eventList", false);
|
||||||
|
|
||||||
// genertate plan based on priorities and available time
|
// genertate plan basen on priorities and available time
|
||||||
now = time(NULL);
|
time_t now = time(NULL);
|
||||||
struct tm *lc = localtime(&now);
|
struct tm *lc = localtime(&now);
|
||||||
llist *events_ll = llistNew(NULL, cmpEvent);
|
llist *events_ll = llistNew(NULL, cmpEvent);
|
||||||
if (events_ll == NULL) {
|
if (events_ll == NULL) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
// time_t avail = mktime(timeAvail);
|
||||||
time_t start, end;
|
time_t start, end;
|
||||||
|
// (mktime(lc) < mktime(timeAvail))
|
||||||
do {
|
do {
|
||||||
if ((*sortedPrio).priority < 0) {
|
|
||||||
continue;
|
|
||||||
} else if ((*sortedPrio).priority == 0) {
|
|
||||||
printf("All tasks have priority <0!!");
|
|
||||||
resetPrio(&sortedPrio, lLen);
|
|
||||||
}
|
|
||||||
start = mktime(lc); // start now
|
start = mktime(lc); // start now
|
||||||
lc->tm_min += intervalLen;
|
lc->tm_min += intervalLen;
|
||||||
end = mktime(lc); //
|
end = mktime(lc); //
|
||||||
|
@ -230,9 +225,9 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
c = newEvent(tmp->data, start, end,
|
c = newEvent(tmp->data, start, end,
|
||||||
0); // use elem with wighest priority
|
0); // use elem with wighest priority
|
||||||
}
|
}
|
||||||
|
|
||||||
llistAppend(events_ll, c);
|
llistAppend(events_ll, c);
|
||||||
printEvent(c);
|
printEvent(c);
|
||||||
|
// printEvent((Event *)((events_ll)->next)->data);
|
||||||
|
|
||||||
// decrement priority of first elem and resort list
|
// decrement priority of first elem and resort list
|
||||||
(*sortedPrio).priority -= 1;
|
(*sortedPrio).priority -= 1;
|
||||||
|
@ -242,12 +237,29 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
|
|
||||||
} while (mktime(lc) < timeAvail);
|
} while (mktime(lc) < timeAvail);
|
||||||
|
|
||||||
|
// for (int i = 0; i < lLen; i++) {
|
||||||
|
// time_t start = mktime(lc);
|
||||||
|
//
|
||||||
|
// printf("start:: %s\n", ctime(&start));
|
||||||
|
// lc->tm_min += 45;
|
||||||
|
// time_t end = mktime(lc);
|
||||||
|
// printf("end:: %s\n", ctime(&end));
|
||||||
|
//
|
||||||
|
// Event *c = newEvent(sortedPrio + i, start, end, 0);
|
||||||
|
// printEvent(c);
|
||||||
|
// lc->tm_min += 15;
|
||||||
|
// llistAppend(events_ll, c);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
// free empty head
|
// free empty head
|
||||||
llist *tmp = events_ll;
|
llist *tmp = events_ll;
|
||||||
events_ll = events_ll->next;
|
events_ll = events_ll->next;
|
||||||
tmp->next = NULL;
|
tmp->next = NULL;
|
||||||
llistFreeE(tmp);
|
llistFreeE(tmp);
|
||||||
// llistPrintE(events_ll);
|
printf("====EVENTSLL:\n");
|
||||||
|
llistPrintE(events_ll);
|
||||||
|
printf("====EVENTSLL:\n");
|
||||||
// update prioriteis in original llist
|
// update prioriteis in original llist
|
||||||
for (int i = 0; i < lLen; i++) {
|
for (int i = 0; i < lLen; i++) {
|
||||||
llist *tmp = llistGet(head, sortedPrio + i);
|
llist *tmp = llistGet(head, sortedPrio + i);
|
||||||
|
@ -258,7 +270,76 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
free(sortedPrio);
|
free(sortedPrio);
|
||||||
|
|
||||||
planLog("END GEN PLAN", 0);
|
planLog("END GEN PLAN", 0);
|
||||||
|
// llistFreeT(head);
|
||||||
// send updated tasks to db for storage
|
// send updated tasks to db for storage
|
||||||
|
|
||||||
return events_ll;
|
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(¤t->plannedStartTime, &startlc);
|
||||||
|
localtime_r(¤t->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;
|
||||||
|
}
|
||||||
|
|
|
@ -84,6 +84,6 @@ int cmpEvent(const void *a, const void *b);
|
||||||
*/
|
*/
|
||||||
llist *genPlan(llist *head, time_t timeAvail);
|
llist *genPlan(llist *head, time_t timeAvail);
|
||||||
|
|
||||||
// int exportiCal(llist *head);
|
int exportiCal(llist *head);
|
||||||
|
|
||||||
#endif // !PLANNER
|
#endif // !PLANNER
|
||||||
|
|
29
src/ui.c
29
src/ui.c
|
@ -4,11 +4,8 @@
|
||||||
*/
|
*/
|
||||||
/* Created by Juergen Buechel, 13.12.2024/
|
/* Created by Juergen Buechel, 13.12.2024/
|
||||||
*/
|
*/
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "StudyPlanner.h"
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "iCal.h"
|
|
||||||
#include "llist.h"
|
#include "llist.h"
|
||||||
#include "planner.h" // for subject and event structs
|
#include "planner.h" // for subject and event structs
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -18,21 +15,12 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
|
#define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define minutes(n) (60 * n)
|
|
||||||
#define hours(n) (60 * minutes(n))
|
|
||||||
#define days(n) (24 * hours(n))
|
|
||||||
|
|
||||||
const char *dbName = "db.csv";
|
const char *dbName = "db.csv";
|
||||||
#define DEBUG
|
|
||||||
#ifdef DEBUG
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
#endif
|
|
||||||
#ifdef RELEASE
|
|
||||||
int StudyPlanner() {
|
|
||||||
#endif
|
|
||||||
int taskcreation_date = 0;
|
int taskcreation_date = 0;
|
||||||
int taskdeadline_date = 0;
|
int taskdeadline_date = 0;
|
||||||
int taskpriority = 0;
|
int taskpriority = 0;
|
||||||
|
@ -60,10 +48,10 @@ int main(void) {
|
||||||
|
|
||||||
taskname = NULL;
|
taskname = NULL;
|
||||||
size_t nameLen;
|
size_t nameLen;
|
||||||
ssize_t nnread;
|
size_t nnread;
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
printf(" Geben sie das gewünschte Fach ein (Name): \n");
|
printf(" Geben sie das gewünschte Fach ein: \n");
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
struct tm lc;
|
struct tm lc;
|
||||||
localtime_r(&now, &lc);
|
localtime_r(&now, &lc);
|
||||||
|
@ -81,7 +69,7 @@ int main(void) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" Gib die Prioritaet des Faches an(1-10): \n");
|
printf(" Gib die Prioritaet des Faches an: \n");
|
||||||
if (scanf("%d", &taskpriority) != 1) {
|
if (scanf("%d", &taskpriority) != 1) {
|
||||||
printf("Ungueltige Eingabe.\n");
|
printf("Ungueltige Eingabe.\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -94,7 +82,8 @@ int main(void) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// create deadline timestamp
|
// create deadline timestamp
|
||||||
time_t deadline = now + days(taskdeadline_date);
|
lc.tm_yday += taskdeadline_date;
|
||||||
|
time_t deadline = mktime(&lc);
|
||||||
Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
|
Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
|
||||||
if (listT == NULL) {
|
if (listT == NULL) {
|
||||||
listT = llistNew(newT, cmpTaskN);
|
listT = llistNew(newT, cmpTaskN);
|
||||||
|
@ -104,8 +93,8 @@ int main(void) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("Geben Sie die zur verfuegung stehende Zeit für die Faecher an "
|
printf(
|
||||||
"(geplante arbeitsstunden huete): \n");
|
"Geben Sie die zur verfuegung stehende Zeit für die Faecher an: \n");
|
||||||
scanf("%d", &taskspare);
|
scanf("%d", &taskspare);
|
||||||
// if list exists use it to generate plan
|
// if list exists use it to generate plan
|
||||||
if (listT != NULL) {
|
if (listT != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue