Download loggbok.c
//MAIN FUNCTION FOR PROGRAM LOGGBOK.
//MAKE, EDIT, AND DELETE LOG ENTRIES WITH FOLLOWING FIELDS:
// DATE, START-TIME, END-TIME, WITH, SESSIONTYPE, COMMENTS.
//
//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.
*/
//The first 5 fields are stored in structure LOG_ENTRY, defined in
//log_entry_def.h. Comments are stored separately and linked to a
//LOG_ENTRY via a structure LOG_INDEX. The LOG_INDEXes form a linked
//list in chronological order.
//The main function is primarily a loop that awaits user input and based on user's
//request calls functions from the following files:
#include"parse_log_entry.h" //getNewEntry() type LOG_INDEX, macro NUM_ELEMS
#include"log_entry_ll.h" //printLogList()
#include"get_new_entry.h" //getNewEntry(), EMPTY_STRING
#include"log_entry_files.h" //read_log(), write_log()
#include"write_toHTML.h" //toHTML()
#include"edit_entry.h" //dateStart()
#include"tot_time.h" //totalminutes() minToHrs() <-- automatic: part of print request.
#include"schedule.h" //getSchedule()
//USER COMMANDS:
//print (Print entire list of entries to screen).
//clear, save, exit, exit!! (Last means exit and don't save.)
//new, edit (Edit gives also option to delete.)
//sch (See schedule on file).
int main () {
FILE* sch_p = fopen("myschedule.txt", "r");
LOG_INDEX* schedule_start = NULL;
schedule_start = getSchedule(sch_p); //Get schedule on file.
if(sch_p != NULL)
fclose(sch_p);
printf("Schedule:\n");
printLogList(schedule_start);
LOG_INDEX* index_start = NULL; //Pointer to head of list.
NUM_ELEMS = read_log(&index_start); //Read log entries and comments, create linked list.
//index_start points now to the head of list.
//NUM_ELEMS is no. elements in list.
char buff[50]; //For receiving user command.
//char comments_buff[2048]; //Comments temporarily saved here.
char* empty = ""; //An empty string. If no comments log entries comments pointer
//....points to this string.
//MAIN LOOP ** MAIN LOOP ** MAIN LOOP ** MAIN LOOP.
while(1) {
printf(">> ");
getmaline(buff); strip(buff); //Get user command in buff.
if(strcmp(buff,"exit") == 0) { //Exit and save data.
if(NUM_ELEMS == 0) {
printf("\033[0;32mEXITING. ENTRY LIST IS EMPTY.\033[0m\n");
break;
}
write_log(index_start, NUM_ELEMS); //Write log entries and comments to files.
break;
}
else if(strcmp(buff, "sch") == 0)
printLogList(schedule_start);
else if(strcmp(buff, "save") == 0) {
if(NUM_ELEMS == 0)
printf("\033[0;32mEXITING. ENTRY LIST IS EMPTY.\033[0m\n");
else
write_log(index_start, NUM_ELEMS); //Write as above.
}
else if(strcmp(buff, "exit!!") == 0) { //Exit. Do not save.
printf("\033[0;31mLOG ENTRIES NOT SAVED\033[0m\n");
break;
}
else if(strcmp(buff,"print") == 0) { //Print log entries with comments to screen.
printf("\n\033[0;35mLOG ENTRIES ** LOG ENTIRES ** LOG ENTRIES \033[0m\n\n");
printLogList(index_start);
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);
printf("\033[0;93mAuskultation total: \033[1;92m%d min. -- %d hrs, %d min.\n",
ausk_minutes, ausk_hrs.hours, ausk_hrs.minutes);
printf("\033[0;93mLektion total: \033[1;92m%d min. -- %d hrs, %d min.\n\n",
lekt_minutes, lekt_hrs.hours, lekt_hrs.minutes);
printf("\033[0;35mEND: LOG ENTRIES ************************* \033[0m\n\n");
}
else if(strcmp(buff,"html") == 0) //Write log entries as html table.
toHTML(index_start);
else if (strcmp(buff, "edit") == 0) //Edit existing log entry.
dateStart(&index_start);
else if (strcmp(buff,"new") == 0) { //Make a new log entry.
system("clear");
printf("\033[0;35mMAKE NEW ENTRY ** MAKE NEW ENTRY ** MAKE NEW ENTRY\033[0m\n\n");
getNewEntry(&index_start, &NUM_ELEMS, schedule_start);
//NOTE: HAVE TO PASS POINTER TO INDEX START IN CASE LIST IS EMPTY:
//then index_start needs to be modified. Unfortunately this leaves index
//start vulnerable to change.
}
else if (strcmp(buff, "clear") == 0)
system("clear");
else printf("\033[0;31mINVALID COMMAND.\033[0m\n");
}
return 0;
}