Created
December 9, 2016 22:07
-
-
Save benbek/cb368a63a7def199ce74bfdf3ef51d16 to your computer and use it in GitHub Desktop.
Appointments calendar Passover project, April 2004
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A P P O I N T M E N T | |
A Schedule program written in C | |
Passover 2004 */ | |
#include <stdio.h> //Basic header file | |
#include <conio.h> //Basic header file | |
#include <dos.h> //Mouse, sound, etc. header file | |
#include <stdlib.h> //Supplemental services (exit(), etc.) | |
#include <alloc.h> //Memory allocation services | |
#include <time.h> //Timing and dates header file | |
#include <string.h> //Dealing with strings | |
#include <ctype.h> //Dealing with keyboard strokes | |
/* Defines (constants) */ | |
//Date and time constants | |
#define Month "April" //The month we're working on | |
#define Year 2004 //The year we're working on | |
#define MaxDays 31 //Maximum number of days in [Month] | |
#define MinGap 30 //The minimum gap required between meetings | |
#define DaysInWeek 7 //Fixed value of the amount of days in a week | |
#define HolyDay 7 //The frequency in which comes a holy day (every X days) | |
#define MaxFreeText 100 //Maximum limitation of the Details string | |
#define StartWork 9 //The hour in which the workday starts | |
#define EndWork 17 //The hour in which the workday ends | |
//Colors | |
#define HotKeyColor YELLOW //The color used for bolding a hotkey | |
//ASCII characters | |
#define BackChar 176 //The '°' character | |
//Calendar Drawing | |
#define CalendarX 15 //The horzional coordinate at which the drawing begins | |
#define CalendarY 5 //The vertical coordinate at which the drawing begins | |
#define DayWidth 7 //How wide is a day cell | |
#define DayHeight 3 //How tall is a day cell | |
/* Global/Scope-wide variables */ | |
int xMouse, yMouse; //X and Y coordinates of the mouse | |
//The area in where each day is, in the visual calendar, to compare with input | |
int XCoorCalendar[MaxDays]={0}; | |
int YCoorCalendar[MaxDays]={0}; | |
typedef struct Meida //Global record, contains two wide strings to hold each | |
{ //meeting's details, such as place or person to meet | |
char Person[MaxFreeText]; //The person who is going to be met | |
char Details[MaxFreeText]; //Some more info the user want to supply | |
} Meida; | |
typedef struct Pgisha //Global record, contains the exact details of each meet | |
{ | |
short int Hour; //The hour of the meeting (0-23) | |
short int Min; //The minutes (0-59) | |
struct Meida *MoreInfo; //Points to the MoreInfo record | |
struct Pgisha *Next; //Points to the next record (the next meeting) | |
struct Pgisha *Prev; //Points to the previous record (the prev. meeting) | |
} Pgisha; | |
typedef struct Date //Global record, contains each and every day's meetings | |
{ | |
short int Day; //The day in the month [0-MaxDays] | |
struct Pgisha *Meeting; //Points to the first meeting in that day | |
struct Date *Next; //Points to the next record (the next day) | |
struct Date *Prev; //Points to the previous record (the previous day) | |
} Date; | |
/* Functions */ | |
//User-Interface Functions | |
void WelcomeScreen(); | |
void FillScreen(char, short int, short int); | |
void InitScreen(); | |
void DrawBorder(short int, short int, short int, short int, short int); | |
void CastShadow(short int, short int, short int, short int, char); | |
void DrawCalendar(); | |
void Center(char[80], short int); | |
void HotPrint(char[80], char); | |
void Schedule(); | |
void AddMeeting(); | |
Pgisha *GetAttributes(int); | |
int ConfirmDetails(int, int, Pgisha *, char); | |
void UpdateMeeting(); | |
void EraseMeeting(); | |
void PrintMeeting(); | |
void PrintMeetingInDay(short int); | |
void PrintByRange(int, int, int, int); | |
int ExtractDayFromCalendar(); | |
void QuitScreen(); | |
//Date, Time and Meetings Handling Functions | |
int NumMeetings(short int); | |
Date *FindDay(int); | |
Date *FindLast(Date *, Date *); | |
Pgisha *LastMeeting(int); | |
void AddTimeGap(int *, int *); | |
void SubstractTimeGap(int *, int *); | |
int ValidTime(int, int, int); | |
int CompareTime(int, int, int, int); | |
void DateSort(Date *); | |
void MeetingSort(Date *, Pgisha *); | |
Pgisha *FindMeetingByName(char[]); | |
void EraseByRange(int, int, int, int); | |
void EraseByDay(short int); | |
void Erase (Pgisha *); | |
//Dynamic-Memory Managment Functions | |
Date *AllocateDate(); | |
Pgisha *AllocatePgisha(); | |
Meida *AllocateMeida(); | |
void Free(); | |
//Mouse Functions | |
void InitMouse(); | |
int MouseButton(); | |
void ShowMouse(); | |
void HideMouse(); | |
int whereMouseX(); | |
int whereMouseY(); | |
Date *Head=NULL; //The head pointer | |
/* Main Subroutine */ | |
void main() | |
{ | |
InitMouse(); | |
InitScreen(); | |
WelcomeScreen(); | |
Schedule(); | |
Free(); | |
QuitScreen(); | |
} | |
void WelcomeScreen() | |
{ | |
HideMouse(); | |
FillScreen(BackChar,BLUE,CYAN); | |
_setcursortype(_NOCURSOR); | |
textcolor(CYAN); | |
textbackground(BLUE); | |
DrawBorder(2,1,8,80,18); | |
window(2,8,80,18); | |
cprintf("¹ Welcome to Ben Bekerman's ּ\r\n"); | |
textcolor(MAGENTA); | |
cprintf(" .,. .' ' ' \r\n\ | |
.J53. ,( ,# *A \r\n\ | |
!@*@! %!$3(. J(3$=' .7$$7* *J ¦3C$$!.%M$,*J=$J¦C$C. ,7$$7' (3C$$*'AW$' \r\n\ | |
.5= =5. ©=..J$ #3'.(#.#%..¦@,¦5 7@*.*M *׀. (׀!.$#,.57'#(..=#.J#,.¦׀ ¦#. \r\n\ | |
(׀JJJ@= © ,׀ #¦ M.©. 5(¦5 7% .M ,׀ (5 C3 $7*M$$$$A.J3 ,׀ !# \r\n\ | |
'׀¦,,,¦@' ©(..C\% #J'.¦#.#C..!@*¦5 7\% .M ,׀. (5 C3 $7'@('.*=.J3 ,׀ !#. \r\n\ | |
(( (( ©(3J7. #CJ3C, 'C33C! *C ¦7 .% .33,*C ¦= 7¦ *J333, (= '$ '$3' \r\n\ | |
\ \ \ \ \ \ \ \ \ \ \ W .. A!.. .. . . .. . ... . .. \r\n\ | |
\ \ \ \ \ \ \ \ \ \ \ ! *. \r\n"); | |
window(1,1,80,25); | |
textcolor(CYAN); | |
Center("¹ A P P O I N T M E N T ּ",18); | |
textcolor(WHITE); | |
Center(" Schedule Program for the Month of ",21); | |
Center(Month,22); | |
textcolor(BLUE); | |
textbackground(CYAN); | |
Center("Press any key or click a mouse button to continue...",25); | |
ShowMouse(); | |
//OpeningSound(); | |
while(!kbhit() && !MouseButton()) //Waits until the user pressed a key | |
; //or clicked a mouse button | |
if(kbhit()) | |
getch(); | |
} | |
void InitScreen() | |
{ | |
textmode(C80); //Forces color, 80x25 screen | |
window(1,1,80,25); | |
textcolor(LIGHTGRAY); | |
textbackground(BLACK); | |
clrscr(); | |
} | |
void FillScreen(char Chr, short int ForeColor, short int BackColor) | |
{ | |
int i; | |
clrscr(); | |
textcolor(ForeColor); | |
textbackground(BackColor); | |
for(i=1;i<=80*25;i++) | |
cprintf("%c",Chr); | |
insline(); | |
Center("APPOINTMENT by Ben Bekerman, ",25); | |
gotoxy(wherex()-10,wherey()); | |
cprintf("%s %d",Month,Year); | |
} | |
void QuitScreen() | |
{ | |
HideMouse(); | |
InitScreen(); | |
_setcursortype(_NORMALCURSOR); | |
window(1,1,80,25); | |
cprintf("Thank you for using \"Appointment\".\r\n\n"); | |
} | |
void DrawCalendar() | |
{ | |
struct text_info ti; | |
short int temp,temp2; | |
short int WeeksInMonth; //Fixed value of the amount of weeks in [Month] | |
short int TheDay=1; | |
int Pgishot; | |
#if((MaxDays%DaysInWeek)!=0) | |
WeeksInMonth=(MaxDays/DaysInWeek)+ | |
(MaxDays/DaysInWeek)%(MaxDays%DaysInWeek); | |
#else | |
WeeksInMonth=MaxDays/DaysInWeek; | |
#endif | |
HideMouse(); | |
gettextinfo(&ti); //Store the current screen attributes in a structure, | |
//so we can extract from there the previous colors | |
textbackground(BLUE); | |
//Writing the names of the days | |
#if(DaysInWeek==7 && DayWidth==7) | |
textcolor(LIGHTMAGENTA); | |
gotoxy(CalendarX+2,CalendarY+1); | |
cprintf("Sun Mon Tue Wed Thu Fri Sat"); | |
#endif | |
//Drawing the skeleton of the calendar | |
textcolor(CYAN); | |
gotoxy(CalendarX,CalendarY); | |
cprintf(""); | |
for(temp=CalendarX+1;temp<CalendarX+DayWidth*DaysInWeek;temp++) | |
cprintf("ִ"); | |
cprintf("¿"); | |
for(temp=CalendarX+DayWidth;temp<CalendarX+DayWidth*DaysInWeek;temp+=DaysInWeek) | |
{ | |
gotoxy(temp,CalendarY); | |
cprintf("ֲ"); | |
} | |
for(temp=CalendarY+1;temp<=CalendarY+WeeksInMonth*DayHeight+1;temp++) | |
for(temp2=CalendarX;temp2<=CalendarX+DayWidth*DaysInWeek;temp2+=DaysInWeek) | |
{ | |
gotoxy(temp2,temp); | |
cprintf("³"); | |
} | |
for(temp=CalendarY+2;temp<=CalendarY+2+WeeksInMonth*DayHeight;temp+=DayHeight) | |
for(temp2=CalendarX+1;temp2<CalendarX+DayWidth*DaysInWeek;temp2++) | |
{ | |
gotoxy(temp2,temp); | |
cprintf("ִ"); | |
} | |
for(temp=CalendarY+2;temp<=CalendarY+1+WeeksInMonth*DayHeight;temp+=DayHeight) | |
{ | |
gotoxy(CalendarX,temp); | |
cprintf("ֳ"); | |
for(temp2=CalendarX+DayWidth;temp2<CalendarX+DayWidth*DaysInWeek;temp2+=DayWidth) | |
{ | |
gotoxy(temp2,temp); | |
cprintf("ֵ"); | |
} | |
gotoxy(CalendarX+DayWidth*DaysInWeek,temp); | |
cprintf("´"); | |
} | |
gotoxy(CalendarX,CalendarY+WeeksInMonth*DayHeight+2); | |
cprintf("ְ"); | |
for(temp2=CalendarX+DayWidth;temp2<CalendarX+DayWidth*DaysInWeek;temp2+=DayWidth) | |
{ | |
gotoxy(temp2,CalendarY+WeeksInMonth*DayHeight+2); | |
cprintf("ֱ"); | |
} | |
gotoxy(CalendarX+DayWidth*DaysInWeek,CalendarY+WeeksInMonth*DayHeight+2); | |
cprintf(""); | |
//Writing the days (1, 2, 3...) | |
textcolor(LIGHTCYAN); | |
for(temp=CalendarY+DayHeight;temp<CalendarY+1+WeeksInMonth*DayHeight;temp+=DayHeight) | |
for(temp2=CalendarX+(DayWidth/2);temp2<CalendarX+DayWidth*DaysInWeek && TheDay<=MaxDays;temp2+=DayWidth) | |
{ | |
gotoxy(temp2,temp); | |
cprintf("%d",TheDay); | |
TheDay++; | |
} | |
//Writing the vacancy | |
TheDay=1; | |
for(temp=CalendarY+1+DayHeight;temp<=CalendarY+1+WeeksInMonth*DayHeight;temp+=DayHeight) | |
for(temp2=CalendarX+1;temp2<CalendarX+DayWidth*DaysInWeek && TheDay<=MaxDays;temp2+=DayWidth) | |
{ | |
gotoxy(temp2,temp); | |
XCoorCalendar[TheDay-1]=temp2; | |
YCoorCalendar[TheDay-1]=temp-1; | |
if(TheDay % HolyDay ==0) | |
{ | |
textcolor(LIGHTRED); | |
cprintf("------"); | |
} | |
else | |
{ | |
Pgishot=NumMeetings(TheDay); | |
if(Pgishot==0) | |
{ | |
textcolor(LIGHTGREEN); | |
cprintf("Vacant"); | |
} | |
else | |
if(Pgishot!=(EndWork-StartWork)*(60/MinGap)) | |
{ | |
textcolor(YELLOW); | |
cprintf("(%d)",NumMeetings(TheDay)); | |
} | |
else | |
{ | |
textcolor(LIGHTRED); | |
cprintf(" Full "); | |
} | |
} | |
TheDay++; | |
} | |
CastShadow(CalendarY,CalendarX,CalendarX+DayWidth*DaysInWeek,CalendarY+2+WeeksInMonth*DayHeight,' '); | |
textattr(ti.attribute); //Restore the previous colors | |
ShowMouse(); | |
} | |
void DrawBorder | |
(short int BorderType, | |
short int xTop, short int yTop, short int xBot, short int yBot) | |
/* Sub: DrawBorder | |
Purpose: Drawing a border, creating a frame | |
In: BorderType - Line's type (whatever ³ (1-Single) or ÷ (2-Double) | |
xTop & yTop - Coordinates of the left-topmost spot of the border | |
xBot & yBot - Coordinates of the right-bottommost spot of the border | |
Out: Nothing */ | |
{ | |
int count; | |
if (BorderType==1) | |
{ | |
gotoxy(xTop, yTop); | |
cprintf(""); | |
for (count=1; count<(xBot-xTop); count++) | |
{ | |
gotoxy(xTop+count,yTop); | |
cprintf("ִ"); | |
} | |
gotoxy(xBot,yTop); | |
cprintf("¿"); | |
for (count=1; count<(yBot-yTop); count++) | |
{ | |
gotoxy(xTop,yTop+count); | |
cprintf("³"); | |
} | |
gotoxy(xTop,yBot); | |
cprintf("ְ"); | |
for (count=1; count<(xBot-xTop); count++) | |
{ | |
gotoxy(xTop+count,yBot); | |
cprintf("ִ"); | |
} | |
for (count=1; count<(yBot-yTop); count++) | |
{ | |
gotoxy(xBot,yTop+count); | |
cprintf("³"); | |
} | |
gotoxy(xBot,yBot); | |
cprintf(""); | |
} else //Other board type | |
{ | |
gotoxy(xTop, yTop); | |
cprintf("ֹ"); | |
for(count=1; count<(xBot-xTop); count++) | |
{ | |
gotoxy(xTop+count,yTop); | |
cprintf("ֽ"); | |
} | |
gotoxy(xBot,yTop); | |
cprintf("»"); | |
for (count=1; count<(yBot-yTop); count++) | |
{ | |
gotoxy(xTop,yTop+count); | |
cprintf("÷"); | |
} | |
gotoxy(xTop,yBot); | |
cprintf("ָ"); | |
for (count=1; count<(xBot-xTop); count++) | |
{ | |
gotoxy(xTop+count,yBot); | |
cprintf("ֽ"); | |
} | |
for (count=1; count<(yBot-yTop); count++) | |
{ | |
gotoxy(xBot,yTop+count); | |
cprintf("÷"); | |
} | |
gotoxy(xBot,yBot); | |
cprintf("¼"); | |
} | |
} | |
void CastShadow | |
(short int top, | |
short int left, short int right, short int bottom, char Background) | |
{ | |
struct text_info ti; | |
gettextinfo(&ti); //Store the current screen attributes in a structure, | |
//so we can extract from there the previous textcolor | |
textcolor(LIGHTGRAY); | |
textbackground(BLACK); | |
while(top++<bottom) | |
{ | |
gotoxy(right+1,top); | |
cprintf("%c",Background); | |
} | |
gotoxy(left+1,bottom+1); | |
while(left<right+1) | |
{ | |
cprintf("%c",Background); | |
left++; | |
} | |
textattr(ti.attribute); | |
} | |
void Center(char Text[80], short int Coloum) | |
/* Centers the given text on the screen */ | |
{ | |
struct text_info ti; | |
gettextinfo(&ti); //Get the left and the right coordinates of the current | |
//text window | |
gotoxy(((ti.winright-ti.winleft+1)-strlen(Text))/2, Coloum); | |
cprintf(Text); | |
} | |
void HotPrint(char Text[80], char HotKey) | |
{ | |
char *Pntr; | |
struct text_info ti; | |
gettextinfo(&ti); //Store the current screen attributes in a structure, | |
//so we can extract from there the previous textcolor | |
cprintf("%s",Text); | |
Pntr=strchr(Text,HotKey); | |
if(Pntr!=NULL) | |
{ | |
gotoxy(wherex()-strlen(Text)+(Pntr-Text),wherey()); | |
textcolor(HotKeyColor); | |
cprintf("%c",HotKey); | |
textattr(ti.attribute); | |
} | |
} | |
void DateSort(Date *p) | |
{ | |
Date *Temp=Head; | |
while(Temp!=NULL && Temp->Day <= p->Day) | |
Temp=Temp->Next; | |
if(Temp!=NULL) //"Temp" points to a day "bigger" than p; Temp->Day >p->Day | |
{ | |
if((Temp->Prev)!=NULL) | |
(Temp->Prev)->Next=p; //Update the prev. entry as well | |
else | |
Head=p; | |
p->Prev=Temp->Prev; | |
Temp->Prev=p; | |
p->Next=Temp; | |
} | |
else | |
{ | |
Temp=FindLast(Head,Temp); //Find the one before "NULL" | |
if(Temp==NULL) //"*p" should be the first | |
{ | |
Temp=Head; | |
p->Next=Temp; | |
Head=p; | |
Temp->Prev=p; | |
} | |
else //"*p" should be the last structure | |
{ | |
Temp->Next=p; | |
p->Prev=Temp; | |
} | |
} | |
} | |
void MeetingSort(Date *Yom, Pgisha *p) | |
{ | |
Pgisha *Temp; | |
int a=-1; | |
Temp=Yom->Meeting; //The first meeting in that day | |
while((Temp!=NULL) && (a <= 0)) | |
{ | |
a=CompareTime(Temp->Hour, Temp->Min, | |
p->Hour, p->Min); | |
Temp=Temp->Next; | |
} | |
Temp=Temp->Prev; //Remove the advancing made by the last iteration of "while" | |
if(Temp!=NULL) //"*Temp" is a meeting being later than "*p"; (*Temp) > (*p) | |
{ //"*p" should be before this meeting | |
if((Temp->Prev)!=NULL) | |
(Temp->Prev)->Next=p; //Update the prev. entry as well | |
else | |
Yom->Meeting=p; | |
p->Prev=Temp->Prev; | |
Temp->Prev=p; | |
p->Next=Temp; | |
} | |
else | |
{ | |
Temp=LastMeeting(Yom->Day); | |
if(CompareTime(Temp->Hour, Temp->Min, p->Hour, p->Min)>=0) | |
{ //"*p" should be the first structure | |
Temp=Yom->Meeting; | |
p->Next=Temp; | |
Yom->Meeting=p; | |
Temp->Prev=p; | |
} | |
else | |
{ | |
Temp->Next=p; | |
p->Prev=Temp; | |
} | |
} | |
} | |
Date *FindLast(Date *Pnt, Date *EndSearch) | |
{ | |
while(Pnt->Next!=EndSearch && Pnt!=NULL) | |
Pnt=Pnt->Next; | |
return (Pnt); | |
} | |
Date *FindDay(int TheDay) | |
{ | |
Date *p=Head; | |
while(p!=NULL && p->Day < TheDay) | |
p=p->Next; | |
if(p!=NULL && p->Day==TheDay) | |
return (p); | |
return (NULL); | |
} | |
Pgisha *FindMeeting(int yom, int meetH, int meetM) | |
{ | |
Date *pDate; | |
Pgisha *Pntr; | |
pDate=FindDay(yom); | |
if(pDate==NULL) | |
return (NULL); //NULL | |
Pntr=pDate->Meeting; //not NULL | |
while(Pntr!=NULL && Pntr->Hour!=meetH) | |
Pntr=Pntr->Next; | |
while(Pntr!=NULL && Pntr->Hour==meetH && Pntr->Min!=meetM) | |
Pntr=Pntr->Next; | |
if(Pntr==NULL || Pntr->Hour!=meetH || Pntr->Min!=meetM) | |
return (NULL); | |
return (Pntr); | |
} | |
Date *AllocateDate() | |
{ | |
Date *P=NULL; | |
P=malloc(1*sizeof(Date)); | |
if (P!=NULL) | |
{ | |
P->Meeting=AllocatePgisha(); | |
if(P->Meeting!=NULL) | |
{ | |
P->Next=NULL; | |
P->Prev=NULL; | |
P->Day=0; | |
return(P); | |
} | |
} | |
return(NULL); | |
} | |
Pgisha *AllocatePgisha() | |
{ | |
Pgisha *p=NULL; | |
p=malloc(1*sizeof(Pgisha)); | |
if (p!=NULL) | |
{ | |
p->MoreInfo=AllocateMeida(); | |
if(p->MoreInfo!=NULL) | |
{ | |
p->Next=NULL; | |
p->Prev=NULL; | |
p->Hour=0; | |
p->Min=0; | |
return(p); | |
} | |
} | |
return(NULL); | |
} | |
Meida *AllocateMeida() | |
{ | |
Meida *pn=NULL; | |
pn=malloc(1*sizeof(Meida)); | |
if (pn==NULL) | |
return(NULL); | |
return(pn); | |
} | |
void Schedule() | |
{ | |
unsigned char UserInput; | |
char Done; | |
_setcursortype(_NORMALCURSOR); | |
do | |
{ | |
UserInput='q'; | |
HideMouse(); | |
FillScreen(BackChar,BLUE,CYAN); | |
textbackground(BLUE); | |
textcolor(WHITE); | |
DrawBorder(1,5,3,75,15); | |
CastShadow(3,5,75,15,BackChar); | |
Center("´ M a i n M e n u ֳ",3); | |
window(6,4,74,14); | |
clrscr(); | |
gotoxy(5,2); | |
HotPrint("1. Add a meeting",'A'); | |
gotoxy(5,4); | |
HotPrint("2. Update a meeting",'U'); | |
gotoxy(5,6); | |
HotPrint("3. Erase one or more meeting(s)",'E'); | |
gotoxy(5,8); | |
HotPrint("4. View one or more meeting(s)",'V'); | |
gotoxy(5,10); | |
HotPrint("5. Exit APPOINTMENT",'x'); | |
window(1,1,80,25); | |
textcolor(LIGHTGREEN); | |
textbackground(LIGHTBLUE); | |
Center(" Please choose one of the above, ",18); | |
Center(" click on it or type its number ",19); | |
Center(" or its hotkey. ",20); | |
textcolor(LIGHTRED); | |
Center(" ִ ִ ",22); | |
gotoxy(wherex()-5,wherey()); | |
ShowMouse(); | |
Done='0'; | |
do | |
{ | |
UserInput=0; | |
while(!kbhit() && !MouseButton()); | |
if(kbhit()) | |
UserInput=getch(); | |
else | |
{ | |
xMouse=whereMouseX(); | |
yMouse=whereMouseY(); | |
switch(yMouse) | |
{ | |
case 5: | |
if(xMouse >= 10 && xMouse <= 25) | |
UserInput='1'; | |
break; | |
case 7: | |
if(xMouse >= 10 && xMouse <= 29) | |
UserInput='2'; | |
break; | |
case 9: | |
if(xMouse >= 10 && xMouse <= 40) | |
UserInput='3'; | |
break; | |
case 11: | |
if(xMouse >= 10 && xMouse <= 39) | |
UserInput='4'; | |
break; | |
case 13: | |
if(xMouse >= 10 && xMouse <= 28) | |
UserInput='5'; | |
break; | |
} | |
} | |
switch(UserInput) | |
{ | |
case '1': | |
case 'A': | |
case 'a': | |
AddMeeting(); | |
Done='1'; | |
break; | |
case '2': | |
case 'U': | |
case 'u': | |
UpdateMeeting(); | |
Done='1'; | |
break; | |
case '3': | |
case 'E': | |
case 'e': | |
EraseMeeting(); | |
Done='1'; | |
break; | |
case '4': | |
case 'V': | |
case 'v': | |
PrintMeeting(); | |
Done='1'; | |
break; | |
case '5': | |
case 'X': | |
case 'x': | |
Done='1'; | |
break; | |
} | |
} | |
while(Done=='0'); | |
} | |
while(UserInput!='X' && UserInput!='x' && UserInput!='5'); | |
} | |
void AddMeeting() | |
{ | |
char GetOut; | |
int Yom=1; | |
Date *Pnt=NULL; | |
Pgisha *Point=NULL; | |
do | |
{ | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
FillScreen(' ',WHITE,BLUE); | |
textbackground(BLUE); | |
textcolor(YELLOW); | |
DrawBorder(2,1,1,80,24); | |
Center("¹ Adding a meeting ּ",1); | |
textcolor(WHITE); | |
Center("Please select a date (via mouse or the TAB key. when you're done,",CalendarY-3); | |
Center("press ENTER) or press Escape to return to the main menu:",CalendarY-2); | |
Center("ִ¯??®ִ",CalendarY-1); | |
gotoxy(wherex()-4,wherey()); | |
cprintf("%02d",Yom); | |
DrawCalendar(); | |
if(kbhit()) | |
getch(); | |
ShowMouse(); | |
do | |
{ | |
GetOut=0; | |
while ((!kbhit()) && ((GetOut=MouseButton()) == 0)); | |
if(GetOut==0) //The user pressed a key rather than clicked the mouse | |
{ | |
GetOut = getch(); | |
if(GetOut==9) //TAB key | |
{ | |
Yom++; | |
Yom = Yom & MaxDays; //Masking | |
if(Yom==0) | |
Yom=1; | |
gotoxy(39,CalendarY-1); | |
cprintf("%02d",Yom); | |
} | |
} | |
else | |
{ | |
xMouse=whereMouseX()-CalendarX; | |
yMouse=whereMouseY()-CalendarY; | |
if(xMouse>=0 && yMouse>=0) | |
{ | |
xMouse+=CalendarX; | |
yMouse+=CalendarY; | |
GetOut=Yom; //Retain the old Yom, it might be useful | |
Yom=ExtractDayFromCalendar(); | |
if(Yom==0) //Not checking for HolyDay because it's a valid input | |
Yom=GetOut; | |
gotoxy(39,CalendarY-1); | |
cprintf("%02d",Yom); | |
GetOut=13; | |
} | |
} | |
if((Yom!=0 && Yom % HolyDay !=0) && GetOut==13 || GetOut==10) | |
{ | |
Pnt=FindDay(Yom); | |
if(Pnt!=NULL) //The day exists | |
{ | |
Point=GetAttributes(Yom); | |
if(Point!=NULL) | |
{ | |
MeetingSort(Pnt,Point); | |
GetOut=27; | |
} | |
else | |
GetOut=26; | |
} | |
else | |
{ | |
Pnt=AllocateDate(); | |
if(Pnt==NULL) | |
{ | |
clrscr(); | |
textcolor(RED+BLINK); | |
cprintf("Fatal error: Cannot allocate enough" | |
" memory for a day.\r\n\n"); | |
textcolor(LIGHTGRAY); | |
Free(); | |
exit(1); | |
} | |
Pnt->Day=Yom; | |
free(Pnt->Meeting); | |
Point=GetAttributes(Yom); | |
if(Point==NULL) | |
{ | |
free(Pnt); | |
GetOut=26; | |
} | |
else | |
{ | |
Pnt->Meeting=Point; | |
if(Head==NULL) //First time ever | |
Head=Pnt; | |
else | |
DateSort(Pnt); | |
GetOut=27; | |
} | |
} | |
} | |
} | |
while(GetOut < 26 || GetOut > 27); | |
_setcursortype(_NORMALCURSOR); | |
} | |
while(GetOut!=27 && Point==NULL); | |
} | |
Pgisha *GetAttributes(int TheDay) | |
{ | |
int meetH, meetM; | |
char FreeText[MaxFreeText]; | |
char Input='Y'; | |
Pgisha *Temp, *Point; | |
HideMouse(); | |
textcolor(WHITE); | |
DrawBorder(1,5,3,75,22); | |
CastShadow(3,5,75,22,' '); | |
gotoxy(8,3); | |
cprintf("´ New meeting attributes at %d-%s-%d ֳ",TheDay,Month,Year); | |
Center(" ",CalendarY-1); //Clear the line of the userinput | |
window(7,5,73,21); | |
clrscr(); | |
_setcursortype(_NORMALCURSOR); | |
ShowMouse(); | |
Point=AllocatePgisha(); | |
if(Point==NULL) | |
{ | |
_setcursortype(_NOCURSOR); | |
textcolor(RED+BLINK); | |
Center("ERROR:",8); | |
textcolor(RED); | |
Center("Couldn't allocate enough memory for a new meeting.",9); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
_setcursortype(_NORMALCURSOR); | |
} | |
else | |
{ | |
do | |
{ | |
meetH=0; | |
meetM=0; | |
textcolor(LIGHTBLUE); | |
Temp=LastMeeting(TheDay); | |
if(Temp!=NULL) | |
{ | |
meetH=Temp->Hour; | |
meetM=Temp->Min; | |
} | |
if(meetH!=0) | |
{ | |
AddTimeGap(&meetH,&meetM); | |
if(meetH < EndWork) | |
{ | |
_setcursortype(_NOCURSOR); | |
cprintf("The next most appropriate time for a meeting is " | |
"%02d:%02d.",meetH,meetM); | |
gotoxy(1,wherey()+1); | |
cprintf("Do you want to set a different time for your meeting" | |
" (Y/N)? "); | |
if(kbhit()) | |
getch(); | |
do | |
Input=toupper(getch()); | |
while(Input != 'Y' && Input != 'N'); | |
_setcursortype(_NORMALCURSOR); | |
cprintf("\r\n"); | |
} | |
else | |
meetH=0; | |
} | |
if(meetH==0 || Input=='Y') //Not using 'else' because we are also | |
{ //checking for the input | |
do | |
{ | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
textcolor(MAGENTA); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
fflush(stdin); | |
scanf("%2s",&FreeText); | |
if(stricmp(FreeText,"ex")==0) | |
{ | |
free(Point); | |
Point=NULL; | |
Input='f'; | |
} | |
while((atoi(FreeText) < StartWork || atoi(FreeText) >= EndWork) && (Input!='f')) | |
{ | |
_setcursortype(_NOCURSOR); | |
textcolor(RED+BLINK); | |
Center("Invalid hour!",wherey()+1); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+2); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
_setcursortype(_NORMALCURSOR); | |
fflush(stdin); | |
scanf("%2s",&FreeText); | |
if(stricmp(FreeText,"ex")==0) | |
{ | |
free(Point); | |
Point=NULL; | |
Input='f'; | |
} | |
} | |
if(Input!='f') | |
{ | |
meetH=atoi(FreeText); | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
textcolor(MAGENTA); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
fflush(stdin); | |
scanf("%2s",&FreeText); | |
if(stricmp(FreeText,"ex")==0) | |
{ | |
free(Point); | |
Point=NULL; | |
Input='f'; | |
} | |
while((atoi(FreeText) < 0 || atoi(FreeText) > 59) && (Input!='f')) | |
{ | |
_setcursortype(_NOCURSOR); | |
textcolor(RED+BLINK); | |
Center("Invalid Minute!",wherey()+1); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+2); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
_setcursortype(_NORMALCURSOR); | |
fflush(stdin); | |
scanf("%2s",&FreeText); | |
if(stricmp(FreeText,"ex")==0) | |
{ | |
free(Point); | |
Point=NULL; | |
Input='f'; | |
} | |
} | |
if(Input!='f') | |
{ | |
meetM=atoi(FreeText); | |
if(FindMeeting(TheDay,meetH,meetM)) | |
{ | |
_setcursortype(_NOCURSOR); | |
textcolor(RED+BLINK); | |
Center("Invalid meeting time!",wherey()+1); | |
textcolor(RED); | |
gotoxy(1,wherey()+2); | |
cprintf("Another meeting already exists at the entered time.\r\n"); | |
cprintf("Do you want to erase the existing one (Y/N)? "); | |
cprintf("(Choosing No will allow you to pick a better date/time.)"); | |
if(kbhit()) | |
getch(); | |
do | |
Input=toupper(getch()); | |
while(/*Input != 'Y' &&*/ Input != 'N'); | |
cprintf("\r\n"); | |
_setcursortype(_NORMALCURSOR); | |
if(Input=='N') | |
{ | |
free(Point); | |
Point=NULL; | |
Input='f'; | |
} | |
//else | |
// Erase(FindMeeting(TheDay,meetH,meetM)); | |
} | |
else | |
if(!ValidTime(TheDay,meetH,meetM)) | |
{ | |
_setcursortype(_NOCURSOR); | |
textcolor(RED+BLINK); | |
Center("Invalid meeting time!",wherey()+1); | |
textcolor(RED); | |
gotoxy(1,wherey()+2); | |
cprintf("Please allow a %d-minutes gap between the meetings.",MinGap); | |
textcolor(LIGHTBLUE); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while(!kbhit() && !MouseButton()); | |
if(kbhit()) | |
getch(); | |
gotoxy(1,1); | |
_setcursortype(_NORMALCURSOR); | |
} | |
} | |
} | |
} | |
while((Point->Hour!=meetH && !ValidTime(TheDay,meetH,meetM)) && Input!='f'); | |
} | |
} | |
while(!ConfirmDetails(meetH, meetM, Point, Input)); | |
} //end of "else" statement | |
window(1,1,80,25); | |
return (Point); | |
} | |
int ConfirmDetails(int meetH, int meetM, Pgisha *Informatzia, char ChipSelect) | |
{//The time for the meeting is set; get from the user the rest of the attributes | |
char Name_[MaxFreeText], Extra_[MaxFreeText], Input; | |
if(ChipSelect=='f') | |
return 1; //Can't do anything, the user chose to abort | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
Center("Meeting time: ",1); | |
gotoxy(wherex()-5,wherey()); | |
cprintf("%02d:%02d\r\n",meetH,meetM); | |
cprintf("Enter the name of the person you are to meet: \r\n"); | |
fflush(stdin); | |
gets(Name_); | |
gotoxy(1,wherey()); | |
cprintf("Enter any more information you want to store about the " | |
"meeting (%d characters maximum, please): \r\n",MaxFreeText); | |
fflush(stdin); | |
gets(Extra_); | |
_setcursortype(_NOCURSOR); | |
gotoxy(1,wherey()); | |
cprintf("Is the information that appears above correct (Y/N)?"); | |
if(kbhit()) | |
getch(); | |
do | |
Input=toupper(getch()); | |
while(Input != 'Y' && Input != 'N'); | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
_setcursortype(_NORMALCURSOR); | |
if(Input == 'N') | |
return 0; | |
Informatzia->Hour=meetH; | |
Informatzia->Min=meetM; | |
strcpy(Informatzia->MoreInfo->Person,Name_); | |
strcpy(Informatzia->MoreInfo->Details,Extra_); | |
return 1; | |
} | |
void UpdateMeeting() | |
{ /* | |
char GetOut; | |
int Yom=1; | |
Date *Pnt=NULL; | |
Pgisha *Point=NULL; | |
do | |
{ | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
FillScreen(' ',WHITE,BLUE); | |
textbackground(BLUE); | |
textcolor(YELLOW); | |
DrawBorder(2,1,1,80,24); | |
Center("¹ Updating a meeting ּ",1); | |
textcolor(WHITE); | |
Center("Please select a date (via mouse or the TAB key. when you're done,",CalendarY-3); | |
Center("press ENTER) or press Escape to return to the main menu:",CalendarY-2); | |
Center("ִ¯??®ִ",CalendarY-1); | |
gotoxy(wherex()-4,wherey()); | |
cprintf("%02d",Yom); | |
DrawCalendar(); | |
if(kbhit()) | |
getch(); | |
ShowMouse(); | |
do | |
{ | |
GetOut=0; | |
while ((!kbhit()) && ((GetOut=MouseButton()) == 0)); | |
if(GetOut==0) //The user pressed a key rather than clicked the mouse | |
{ | |
GetOut = getch(); | |
if(GetOut==9) //TAB key | |
{ | |
Yom++; | |
Yom = Yom & MaxDays; //Masking | |
if(Yom==0) | |
Yom=1; | |
gotoxy(39,CalendarY-1); | |
cprintf("%02d",Yom); | |
} | |
} | |
else | |
{ | |
xMouse=whereMouseX()-CalendarX; | |
yMouse=whereMouseY()-CalendarY; | |
if(xMouse>=0 && yMouse>=0) | |
{ | |
xMouse+=CalendarX; | |
yMouse+=CalendarY; | |
GetOut=Yom; //Retain the old Yom, it might be useful | |
Yom=ExtractDayFromCalendar(); | |
if(Yom==0 || Yom % HolyDay ==0) | |
Yom=GetOut; | |
GetOut=13; | |
} | |
} | |
if((Yom!=0 && Yom % HolyDay !=0) && GetOut==13 || GetOut==10) | |
{ | |
Pnt=FindDay(Yom); | |
if(Pnt!=NULL) //The day exists | |
{ | |
Point=GetAttributes(Yom); | |
if(Point!=NULL) | |
{ | |
MeetingSort(Pnt,Point); //Sorts again, the hours may have changed | |
GetOut=27; | |
} | |
else | |
GetOut=26; | |
} | |
else | |
{ | |
Pnt=AllocateDate(); | |
if(Pnt==NULL) | |
{ | |
clrscr(); | |
textcolor(RED+BLINK); | |
cprintf("The meeting does not exist." | |
" Cannot continue.\r\n\n"); | |
textcolor(LIGHTGRAY); | |
Free(); | |
exit(1); | |
} | |
Pnt->Day=Yom; | |
free(Pnt->Meeting); | |
Point=GetAttributes(Yom); | |
if(Point==NULL) | |
{ | |
free(Pnt); | |
GetOut=26; | |
} | |
else | |
{ | |
Pnt->Meeting=Point; | |
GetAttributes(); | |
GetOut=27; | |
} | |
} | |
} | |
} | |
while(GetOut < 26 || GetOut > 27); | |
_setcursortype(_NORMALCURSOR); | |
} | |
while(GetOut!=27 && Point==NULL); */ | |
} | |
void EraseMeeting() | |
{ /* | |
char UserInput,GetOut, FreeText[MaxFreeText]; | |
int Yom=1,Done,meetH[2],meetM[2]; | |
Date *YomPnt=NULL; | |
Pgisha *MeetingPnt=NULL; | |
_setcursortype(_NORMALCURSOR); | |
do | |
{ | |
HideMouse(); | |
FillScreen(' ',WHITE,BLUE); | |
textbackground(BLUE); | |
textcolor(YELLOW); | |
DrawBorder(2,1,1,80,24); | |
Center("¹ Erase meetings ּ",1); | |
textcolor(WHITE); | |
DrawBorder(1,CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+5,CalendarY+13); | |
CastShadow(CalendarY+2,CalendarX-5,CalendarX+DaysInWeek*DayWidth+5,CalendarY+13,32); | |
Center("´ What would you like to do? ֳ",CalendarY+2); | |
textcolor(LIGHTGREEN); | |
gotoxy(CalendarX-2,CalendarY+4); | |
HotPrint("1. Erase all meetings in a specific date",'d'); | |
gotoxy(CalendarX-2,CalendarY+6); | |
HotPrint("2. Erase all meetings in a specific time range",'r'); | |
gotoxy(CalendarX-2,CalendarY+8); | |
HotPrint("3. Erase all meetings with a specific person",'p'); | |
gotoxy(CalendarX-2,CalendarY+10); | |
HotPrint("4. Return to the main menu",'m'); | |
textcolor(LIGHTRED); | |
Center("ִִ ִִ",CalendarY+13); | |
gotoxy(wherex()-5,wherey()); | |
ShowMouse(); | |
Done='0'; | |
do | |
{ | |
UserInput=0; | |
while(!kbhit() && !MouseButton()); | |
if(kbhit()) | |
UserInput=getch(); | |
else | |
{ | |
xMouse=whereMouseX(); | |
yMouse=whereMouseY(); | |
switch(yMouse) | |
{ | |
case CalendarY+4: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+43) | |
UserInput='1'; | |
break; | |
case CalendarY+6: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+49) | |
UserInput='2'; | |
break; | |
case CalendarY+8: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+50) | |
UserInput='3'; | |
break; | |
case CalendarY+10: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+26) | |
UserInput='4'; | |
break; | |
} | |
} | |
switch(UserInput) | |
{ | |
case '1': | |
case 'D': | |
case 'd': | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
window(CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+6,CalendarY+14); | |
clrscr(); //Clears the menu | |
window(1,1,80,25); | |
Center("Please select a date (via mouse or the TAB key. when you're done,",CalendarY-3); | |
Center("press ENTER) or press Escape to return to the options menu:",CalendarY-2); | |
Center("ִ¯??®ִ",CalendarY-1); | |
gotoxy(wherex()-4,wherey()); | |
cprintf("%02d",Yom); | |
DrawCalendar(); | |
if(kbhit()) | |
getch(); | |
ShowMouse(); | |
do | |
{ | |
GetOut=0; | |
while ((!kbhit()) && ((GetOut=MouseButton()) == 0)); | |
if(GetOut==0) //The user pressed a key rather than clicked the mouse | |
{ | |
GetOut = getch(); | |
if(GetOut==9) //TAB key | |
{ | |
Yom++; | |
Yom = Yom & MaxDays; //Masking | |
if(Yom==0) | |
Yom=1; | |
gotoxy(39,CalendarY-1); | |
cprintf("%02d",Yom); | |
} | |
} | |
else | |
{ | |
xMouse=whereMouseX()-CalendarX; | |
yMouse=whereMouseY()-CalendarY; | |
if(xMouse>=0 && yMouse>=0) | |
{ | |
xMouse+=CalendarX; | |
yMouse+=CalendarY; | |
GetOut=Yom; //Retain the old Yom, it might be useful | |
Yom=ExtractDayFromCalendar(); | |
if(Yom==0 || Yom % HolyDay ==0) | |
Yom=GetOut; | |
GetOut=13; | |
} | |
} | |
if((Yom!=0 && Yom % HolyDay !=0) && GetOut==13 || GetOut==10) | |
EraseByDay(Yom); | |
} | |
while((GetOut!=27) && (GetOut!=10 && GetOut!=13)); | |
_setcursortype(_NORMALCURSOR); | |
Done='1'; | |
break; | |
case '2': | |
case 'R': | |
case 'r': | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
window(CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+6,CalendarY+14); | |
clrscr(); //Clears the menu | |
for(Done=0; Done < 2; Done++) { | |
window(1,1,80,25); | |
ShowMouse(); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
while(atoi(FreeText) < StartWork || atoi(FreeText) >= EndWork) | |
{ | |
textcolor(RED+BLINK); | |
Center("Invalid hour!",wherey()); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+1); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
} | |
meetH[Done]=atoi(FreeText); | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
textcolor(MAGENTA); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
while(atoi(FreeText) < 0 || atoi(FreeText) > 59) | |
{ | |
textcolor(RED+BLINK); | |
Center("Invalid Minute!",wherey()); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+1); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
} | |
meetH[Done]=atoi(FreeText); | |
} //End of for | |
EraseByRange(meetH[0],meetM[0],meetH[1],meetM[1]); | |
Done='1'; | |
break; | |
case '3': | |
case 'P': | |
case 'p': | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
cprintf("Enter the name: "); | |
fflush(stdin); | |
gets(FreeText); | |
MeetingPnt=FindMeetingByName(FreeText); | |
while(MeetingPnt!=NULL) | |
{ | |
Erase(MeetingPnt); | |
MeetingPnt=FindMeetingByName(FreeText); | |
} | |
Done='1'; | |
break; | |
case '4': | |
case 'M': | |
case 'm': | |
Done='1'; | |
break; | |
} | |
} | |
while(Done=='0'); | |
} | |
while(UserInput!='M' && UserInput!='m' && UserInput!='4'); | |
*/ | |
} | |
void PrintMeeting() | |
{ | |
char UserInput,GetOut, FreeText[6]; | |
int Yom=1,Done,meetH[2],meetM[2]; | |
Date *YomPnt=NULL; | |
Pgisha *MeetingPnt=NULL; | |
_setcursortype(_NOCURSOR); | |
do | |
{ | |
HideMouse(); | |
FillScreen(' ',WHITE,BLUE); | |
textbackground(BLUE); | |
textcolor(YELLOW); | |
DrawBorder(2,1,1,80,24); | |
Center("¹ View meetings ּ",1); | |
textcolor(WHITE); | |
DrawBorder(1,CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+5,CalendarY+13); | |
CastShadow(CalendarY+2,CalendarX-5,CalendarX+DaysInWeek*DayWidth+5,CalendarY+13,32); | |
Center("´ What would you like to do? ֳ",CalendarY+2); | |
textcolor(LIGHTGREEN); | |
gotoxy(CalendarX-2,CalendarY+4); | |
HotPrint("1. View all of the meetings in a specific date",'d'); | |
gotoxy(CalendarX-2,CalendarY+6); | |
HotPrint("2. View all of the meetings in a specific time range",'r'); | |
gotoxy(CalendarX-2,CalendarY+8); | |
HotPrint("3. View all of the meetings, start with the first one",'a'); | |
gotoxy(CalendarX-2,CalendarY+10); | |
HotPrint("4. Return to the main menu",'m'); | |
textcolor(LIGHTRED); | |
Center("ִִ ִִ",CalendarY+13); | |
gotoxy(wherex()-5,wherey()); | |
ShowMouse(); | |
_setcursortype(_NORMALCURSOR); | |
Done='0'; | |
do | |
{ | |
UserInput=0; | |
while(!kbhit() && !MouseButton()); | |
if(kbhit()) | |
UserInput=getch(); | |
else | |
{ | |
xMouse=whereMouseX(); | |
yMouse=whereMouseY(); | |
switch(yMouse) | |
{ | |
case CalendarY+4: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+43) | |
UserInput='1'; | |
break; | |
case CalendarY+6: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+49) | |
UserInput='2'; | |
break; | |
case CalendarY+8: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+50) | |
UserInput='3'; | |
break; | |
case CalendarY+10: | |
if(xMouse >= CalendarX-2 && xMouse <= CalendarX+26) | |
UserInput='4'; | |
break; | |
} | |
} | |
switch(UserInput) | |
{ | |
case '1': | |
case 'D': | |
case 'd': | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
window(CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+6,CalendarY+14); | |
clrscr(); //Clears the menu | |
window(1,1,80,25); | |
Center("Please select a date (via mouse or the TAB key. when you're done,",CalendarY-3); | |
Center("press ENTER) or press Escape to return to the options menu:",CalendarY-2); | |
Center("ִ¯??®ִ",CalendarY-1); | |
gotoxy(wherex()-4,wherey()); | |
cprintf("%02d",Yom); | |
DrawCalendar(); | |
if(kbhit()) | |
getch(); | |
ShowMouse(); | |
do | |
{ | |
GetOut=0; | |
while ((!kbhit()) && ((GetOut=MouseButton()) == 0)); | |
if(GetOut==0) //The user pressed a key rather than clicked the mouse | |
{ | |
GetOut = getch(); | |
if(GetOut==9) //TAB key | |
{ | |
Yom++; | |
Yom = Yom & MaxDays; //Masking | |
if(Yom==0) | |
Yom=1; | |
gotoxy(39,CalendarY-1); | |
cprintf("%02d",Yom); | |
} | |
} | |
else | |
{ | |
xMouse=whereMouseX()-CalendarX; | |
yMouse=whereMouseY()-CalendarY; | |
if(xMouse>=0 && yMouse>=0) | |
{ | |
xMouse+=CalendarX; | |
yMouse+=CalendarY; | |
GetOut=Yom; //Retain the old Yom, it might be useful | |
Yom=ExtractDayFromCalendar(); | |
if(Yom==0 || Yom % HolyDay ==0) | |
Yom=GetOut; | |
GetOut=13; | |
} | |
} | |
if((Yom!=0 && Yom % HolyDay !=0) && GetOut==13 || GetOut==10) | |
PrintMeetingInDay(Yom); | |
} | |
while((GetOut!=27) && (GetOut!=10 && GetOut!=13)); | |
Done='1'; | |
break; | |
case '2': | |
case 'R': | |
case 'r': | |
HideMouse(); | |
_setcursortype(_NOCURSOR); | |
window(CalendarX-5,CalendarY+2,CalendarX+DaysInWeek*DayWidth+6,CalendarY+14); | |
clrscr(); //Clears the menu | |
for(Done=0; Done < 2; Done++) { | |
window(1,1,80,25); | |
ShowMouse(); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
while(atoi(FreeText) < StartWork || atoi(FreeText) >= EndWork) | |
{ | |
textcolor(RED+BLINK); | |
Center("Invalid hour!",wherey()); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+1); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the hour of the meeting (%d-%d): ",StartWork,EndWork); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
} | |
meetH[Done]=atoi(FreeText); | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
textcolor(MAGENTA); | |
Center("Type \"ex\" to return to the day selection screen",17); | |
textcolor(LIGHTBLUE); | |
gotoxy(1,1); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
while(atoi(FreeText) < 0 || atoi(FreeText) > 59) | |
{ | |
textcolor(RED+BLINK); | |
Center("Invalid Minute!",wherey()); | |
textcolor(RED); | |
Center("Please make sure that the input is within its limits.",wherey()+1); | |
textcolor(MAGENTA); | |
Center("Press any key or click a mouse button to continue...",17); | |
if(kbhit()) | |
getch(); | |
while((!kbhit()) && (!MouseButton())); | |
if(kbhit()) | |
getch(); //Not returning the key the user pressed to anything | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
gotoxy(1,1); | |
textcolor(LIGHTBLUE); | |
cprintf("Enter the minute part of the meeting's time (0-59): "); | |
fflush(stdin); | |
cscanf("%2s",&FreeText); | |
} | |
meetH[Done]=atoi(FreeText); | |
} //End of for | |
PrintByRange(meetH[0],meetM[0],meetH[1],meetM[1]); | |
Done='1'; | |
break; | |
case '3': | |
case 'A': | |
case 'a': | |
HideMouse(); | |
clrscr(); | |
ShowMouse(); | |
_setcursortype(_NORMALCURSOR); | |
YomPnt=Head; | |
while(YomPnt!=NULL) | |
{ | |
printf("Meetings for %d-%s-%d:\n", YomPnt->Day, Month, Year); | |
MeetingPnt=YomPnt->Meeting; | |
while(MeetingPnt!=NULL) | |
{ | |
printf("\t%02d:%02d (%s), %s\n",MeetingPnt->Hour,MeetingPnt->Min, | |
MeetingPnt->MoreInfo->Person,MeetingPnt->MoreInfo->Details); | |
MeetingPnt=MeetingPnt->Next; | |
} | |
YomPnt=YomPnt->Next; | |
} | |
getch(); | |
_setcursortype(_NOCURSOR); | |
Done='1'; | |
break; | |
case '4': | |
case 'M': | |
case 'm': | |
Done='1'; | |
break; | |
} | |
} | |
while(Done=='0'); | |
} | |
while(UserInput!='M' && UserInput!='m' && UserInput!='4'); | |
} | |
void PrintMeetingInDay(short int Yom) | |
{ | |
Date *YomPnt; | |
Pgisha *MeetPnt; | |
char UserInput; | |
do | |
{ | |
HideMouse(); | |
textcolor(DARKGRAY); | |
textbackground(LIGHTGRAY); | |
DrawBorder(1,20,8,60,19); | |
CastShadow(8,20,60,19,32); | |
window(21,9,59,18); | |
clrscr(); | |
window(1,1,80,25); | |
gotoxy(23,8); | |
cprintf("´ Meetings at %d-%s-%d ֳ", Yom, Month, Year); | |
gotoxy(40,19); | |
cprintf("´ (ESC to abort) ֳ"); | |
YomPnt=FindDay(Yom); | |
if(YomPnt==NULL) //The day does not exist | |
{ | |
textcolor(LIGHTMAGENTA+BLINK); | |
Center("There are no meetings in this day",13); | |
} | |
else | |
{ | |
MeetPnt=YomPnt->Meeting; | |
while(MeetPnt!=NULL) | |
{ | |
printf("\t%02d:%02d (%s), %s\n",MeetPnt->Hour,MeetPnt->Min, | |
MeetPnt->MoreInfo->Person,MeetPnt->MoreInfo->Details); | |
MeetPnt=MeetPnt->Next; | |
} | |
} | |
UserInput=getch(); | |
} | |
while(UserInput!=27); | |
} | |
void PrintByRange(int LShour, int LSmin, int MShour, int MSmin) | |
{ | |
} | |
int NumMeetings(short int Yom) | |
{ | |
Date *Pntr=Head; | |
Pgisha *SubPoint; | |
int HowMuch=0; | |
while(Pntr!=NULL && Pntr->Day < Yom) | |
Pntr=Pntr->Next; | |
if(Pntr!=NULL && Pntr->Day==Yom) | |
{ | |
SubPoint=Pntr->Meeting; | |
while(SubPoint!=NULL) | |
{ | |
HowMuch++; | |
SubPoint=SubPoint->Next; | |
} | |
} | |
return (HowMuch); | |
} | |
Pgisha *LastMeeting(int TheDay) | |
{ | |
Date *Temp=Head; | |
Pgisha *Pntr; | |
while(Temp!=NULL && Temp->Day!=TheDay) | |
Temp=Temp->Next; | |
if(Temp!=NULL) //Found the day | |
{ | |
Pntr=Temp->Meeting; | |
while(Pntr->Next!=NULL) | |
Pntr=Pntr->Next; | |
} | |
else | |
return (NULL); | |
return (Pntr); | |
} | |
void AddTimeGap(int *Hour, int *Min) | |
{ | |
if(*Min < MinGap) | |
*Min+=MinGap; | |
else | |
{ | |
(*Hour)++; | |
*Min = 0 + (*Min-MinGap); | |
} | |
} | |
void SubstractTimeGap(int *Hour, int *Min) | |
{ | |
if(*Min >= MinGap) | |
*Min-=MinGap; | |
else | |
{ | |
(*Hour)--; | |
*Min = 60 + (*Min-MinGap); | |
} | |
} | |
int ValidTime(int Yom, int Hour, int Min) | |
{ | |
Date *Temp=Head; | |
Pgisha *Pntr1, *Pntr2; | |
int tempH=Hour, tempM=Min; | |
int isValid=0; | |
while(Temp!=NULL && Temp->Day!=Yom) | |
Temp=Temp->Next; | |
if(Temp!=NULL) //Found the day | |
{ | |
//Making Pntr1 to contain the next time of meetings after [Hour]:[Min] | |
Pntr1=Temp->Meeting; | |
while(Pntr1!=NULL && CompareTime(Pntr1->Hour,Pntr1->Min,Hour,Min) <= 0) | |
Pntr1=Pntr1->Next; | |
if(Pntr1!=NULL) | |
{ | |
//Making Pntr2 to contain the meeting time just before the time in Pntr1 | |
Pntr2=Pntr1->Prev; | |
if(Pntr2!=NULL) | |
{ | |
AddTimeGap(&tempH, &tempM); | |
if(CompareTime(tempH,tempM, Pntr1->Hour, Pntr1->Min) <= 0) | |
{ | |
tempH=Hour; | |
tempM=Min; | |
SubstractTimeGap(&tempH, &tempM); | |
if(CompareTime(tempH, tempM, Pntr2->Hour, Pntr2->Min) >=0) | |
isValid=1; //The time is okay | |
} | |
} | |
else | |
{ | |
AddTimeGap(&tempH, &tempM); | |
if(CompareTime(tempH, tempM, Pntr1->Hour, Pntr1->Min) <= 0) | |
isValid=1; | |
} | |
} | |
else | |
Pntr1=LastMeeting(Yom); | |
if(Pntr1==NULL) | |
isValid=1; //There are no other meeting in that day | |
else | |
{ | |
tempH=Hour; | |
tempM=Min; | |
SubstractTimeGap(&tempH, &tempM); | |
if(CompareTime(tempH, tempM, Pntr1->Hour, Pntr1->Min) >= 0) | |
isValid=1; | |
} | |
} | |
else | |
isValid=1; //The day does not exists (yet...) | |
return(isValid); | |
} | |
int ExtractDayFromCalendar() | |
{ | |
int i=0; | |
do | |
i++; | |
while(i<=MaxDays && | |
!(XCoorCalendar[i-1]<=xMouse && (XCoorCalendar[i-1]+DayWidth-2)>=xMouse && | |
YCoorCalendar[i-1]<=yMouse && (YCoorCalendar[i-1]+DayHeight-2)>=yMouse)); | |
if(i>MaxDays) | |
return 0; | |
return i; | |
} | |
int CompareTime(int Hour1, int Min1, int Hour2, int Min2) | |
/* Compares two times, divided to hours and minutes | |
Returns... If... | |
-1 Time1 < Time2 | |
0 Time1 = Time2 | |
+1 Time1 > Time2 */ | |
{ | |
if(Hour1 < Hour2) | |
return (-1); | |
else | |
if(Hour1 > Hour2) | |
return (1); | |
else //Hour1 equals to Hour2 | |
if(Min1 < Min2) | |
return (-1); | |
else | |
if(Min1 > Min2) | |
return (1); | |
else //The times are equal | |
return (0); | |
} | |
void Free() | |
{ | |
Date *Temp,*p=Head; | |
while (p!=NULL) | |
{ | |
Temp=p->Next; | |
free((p->Meeting)->MoreInfo); | |
free(p->Meeting); | |
free(p); | |
p=Temp; | |
} | |
} | |
void InitMouse() | |
{ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=0; | |
int86(0x33,&i,&o); | |
if(o.x.ax!=0) | |
ShowMouse(); | |
} | |
int MouseButton() | |
{ | |
/* MouseButton() | |
Returns the number of the mouse-button that has been just clicked: | |
0 No button was pressed | |
1 Left button was pressed | |
2 Right button was pressed | |
3 Left and Right buttons were pressed | |
4 Middle button was pressed | |
5 Left and Middle buttons were pressed | |
6 Right and Middle buttons were pressed | |
7 Left, Middle and Right buttons were pressed altogheter. */ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=3; | |
int86(0x33,&i,&o); | |
return(o.x.bx&7); | |
} | |
void ShowMouse() | |
{ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=1; | |
int86(0x33,&i,&o); | |
} | |
void HideMouse() | |
{ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=2; | |
int86(0x33,&i,&o); | |
} | |
int whereMouseX() | |
{ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=3; | |
int86(0x33,&i,&o); | |
return((o.x.cx/8)+1); | |
} | |
int whereMouseY() | |
{ | |
union REGS i,o; //Declare the REGS used by the mouse portions of the program | |
i.x.ax=3; | |
int86(0x33,&i,&o); | |
return((o.x.dx/8)+1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment