Download write_toHTML.h
//toHTML(LOG_INDEX* index_start) WRITES OUT ALL LOG DATA AS AN HTML DOCUMENT
//index_start points to start of list.
//
//Brian Smith 2022-04-10
/*Copyright (C) 2022 Brian R. Smith
* Contact: briansmith2865@gmail.com
**The source code in this file is free software: you can
**redistribute it and/or modify it under the terms of the GNU
**General Public License (GNU GPL) as published by the Free Software
**foundation, either version 3 of the License, or (at your option)
**any later version. The code is distributed WITHOUT ANY WARRANTY;
**without even the implied warranty of MERCHANTABILITY or FITNESS
**FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
**
**As additional permission under GNU GPL version 3 section 7, you
**may distribute non-source (e.g., minimized or compacted) forms of
**that code without the copy of the GNU GPL normally required by
**section 4, provided you include this license notice and a URL
**through which recipients can access the Corresponding Source.
**
** @licend The above is the entire license notice
**for the source code in this file.
*/
#ifndef WRITE_TOHTML_H
#define WRITE_TOHTML_H
#include"log_entry_ll.h"
#include"tot_time.h"
static const char* myheader = "<!DOCTYPE html>\n"\
"<html xmlns=\"http://w3.org/1999/xhtml\">\n"\
"<head>"\
"<meta http-equiv=\"content-type\" content=\"text/html; charset=\"utf-8\"\">\n"\
"<title>DAGBOK -- VFU4</title>\n"\
"<style>\n"\
"\ttable {\n"\
"\tborder: 1px solid #dddddd;\n"\
"\twidth: 100%;\n"\
"\tfont-size: 30px;\n"\
"\ttext-align: center;\n"\
"\ttable-layout: fixed;\n"\
"}\n"\
"tr, td {\n"\
"\tborder: 1px solid black;\n"\
"}\n"\
"</style>\n"\
"</head>\n"\
"<body>\n"\
"<center><h1 style=\"font-size: 40px\">Dagbok — VFU4</h1></center><br/><br/>\n"\
"<table>\n"\
"<colgroup\n>"\
"<col span=\"1\" style=\"width: 12%;\">\n"\
"\t\t<col span=\"1\" style=\"width: 6%;\">\n"\
"\t\t<col span=\"1\" style=\"width: 27%;\">\n"\
"\t\t<col span=\"1\" style=\"width: 55%;\">\n"\
"\t</colgroup>\n"\
"<tbody>\n";
static const char* closetable = "</tbody>\n</table>\n";
static const char* myfooter = "</body>\n</html>\n";
void toHTML(const LOG_INDEX* index_start) {
if(index_start == NULL) {
printf("\033[0;31mIndex list appears to be empty.\033[0m\n\n");
return;
}
FILE * fp = NULL;
fp = fopen("dagbok.html", "w");
if(fp == NULL) {
printf("\033[0;31mCan't open or create dagbok.html\033[0m\n\n");
return;
}
fprintf(fp, "%s", myheader);
char wday[8];
//Obs: in the loop below, there could be a problem with buffer lengths. Check if they are long enough
//for current practices: sessiontype[] was too short before. Caused stack smashing on function return.
fprintf(fp, "\t<tr>\n\t\t<th>DATUM</th>\n"\
"\t\t<th>MIN\n</th>\n\t\t<th>AKTIVITET</th>\n\t\t<th>KOMMENTARER</th>\n\t</tr>\n\n");
for(LOG_INDEX* index = (LOG_INDEX*) index_start; index != NULL; index = index -> next) {
char sessiontype[16]; typeToString(sessiontype, (index -> entryPtr) -> sessiontype);
LOG_ENTRY* entry = index -> entryPtr;
fprintf(fp, "\t<tr>\n");
weekDayToStr(wday, entry -> date.wday);
fprintf(fp, "\t\t<td style='text-align: left'><b>%s %02d-%02d</b><br/>\n%02d:%02d – %02d:%02d</td>\n",
wday, (entry -> date).month, (entry->date).day,
(entry->startTime).hour,(entry->startTime).minute,
(entry->endTime).hour,(entry->endTime).minute ); //datetime
fprintf(fp, "\t\t<td>%d</td>\n", numMinutes(&(entry->startTime), &(entry->endTime)) ); //num min
fprintf(fp, "\t\t<td>%s: %s</td>\n", sessiontype, entry->with); //Session with ____.
fprintf(fp, "\t\t<td style='text-align: left'>%s</td>\n", index->comments); //comments
fprintf(fp, "\t</tr>\n");
}
fprintf(fp, "%s", closetable);
int ausk_minutes = totalminutes(index_start, AUSK);
struct mytime2 ausk_hrs = minToHrs(ausk_minutes);
int lekt_minutes = totalminutes(index_start, LEKT);
struct mytime2 lekt_hrs = minToHrs(lekt_minutes);
fprintf(fp, "<p style=\"font-size: 30px\">\n");
fprintf(fp, "<b> Total auskultation</b>: %d minuter – %d timmar, %d minuter.<br/>",
ausk_minutes, ausk_hrs.hours, ausk_hrs.minutes);
fprintf(fp, "<b> Total lektion</b>: %d minuter – %d timmar, %d minuter.<br/><br/>",
lekt_minutes, lekt_hrs.hours, lekt_hrs.minutes);
fprintf(fp, "</p>\n");
fprintf(fp,"%s", myfooter);
fclose(fp);
}
#endif