home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
dirs
/
curses_391.lzh
/
Curses
/
examples
/
bio
/
bio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-27
|
4KB
|
222 lines
/*Program to calculate your bioryhms*/
/*written by S.J.R.*/
#include <curses.h>
#include <signal.h>
#include "defs.h"
#include "globs.h"
main ()
{
int finished = FALSE, catch();
signal(SIGINT, catch);
initscr ();
cbreak ();
todays_date ();
while (!finished) {
erase ();
printw ("Biorhythms by S.J.Raybould\n\n");
printw ("Do you require instructions ? ");
printw ("(Y/N or E to end) ");
refresh ();
switch (getch()) {
case 'e':
case 'E':
finished = TRUE;
break;
case 'y':
case 'Y':
instructions ();
default :
play ();
break;
}
}
endwin ();
}
play ()
{
int Bday, Bmonth, Byear;/* Birth day,month and year */
int Sday, Smonth, Syear;/* Start day,month and year */
int start;
int ok;
erase ();
printw ("First of all the dates must be entered.\n\n");
ok = NO;
while (!ok)
{
move (10, 0);
printw ("please enter your birthdate (DD,MM,YYYY)\n");
printw ("Birthdate : ");
clrtoeol ();
refresh ();
if (rd_dte (&Bday, &Bmonth, &Byear)) { /* read date of birth */
move (11, 0);
printw ("Birthdate : %2d,%2d,%4d\n", Bday, Bmonth, Byear);
printw (" \n");
ok = YES;
} else {
printw ("Please re-enter birth date.\n");
refresh ();
beep ();
sleep (1);
}
}
ok = NO;
while (!ok)
{
move (13, 0);
printw ("please enter the starting date");
printw (" (or press ");
attrset (A_UNDERLINE);
printw ("RETURN");
attrset (0);
printw (" for today.)\nStartdate : ");
clrtoeol ();
refresh ();
if (rd_dte (&Sday, &Smonth, &Syear))/* read starting date */
{
move (14, 0);
printw ("Startdate : %2d,%2d,%4d\n", Sday, Smonth, Syear);
printw (" \n");
ok = YES;
}
else if (Sday == 0 && Smonth == 0 && Syear == 0)
{
move (14, 0);
Sday = today;
Smonth = this_month;
Syear = this_year;
ok = YES;
printw ("Startdate : %2d,%2d,%4d\n", Sday, Smonth, Syear);
printw (" \n");
} else {
printw ("Please re-enter starting date.\n");
refresh ();
beep ();
sleep (1);
}
}
start = days_passed (Sday, Bday, Smonth, Bmonth, Syear, Byear);
move (17, 25);
noecho ();
attrset (A_REVERSE);
printw ("PRESS ANY KEY TO DRAW CHART");
attrset (0);
refresh ();
getch ();
echo ();
disp_chart (start, day_of_the_year (Sday, Smonth, Syear), Syear);
}
days_passed (sd, bd, sm, bm, sy, by)
int bd, bm, by, sd, sm, sy;
{
int days;
int sdy, bdy; /* starting & birth day of the year */
if (sd == bd && sm == bm && sy == by)
return (0);
sdy = day_of_the_year (sd, sm, sy);
bdy = day_of_the_year (bd, bm, by);
days = (sdy - bdy);
while (sy > by)
{
days += 365;
days += (by % 4 == 0 && by % 100 != 0 || by % 400 == 0);
++by;
}
return (days);
}
day_of_the_year (day, month, year)
int day, month, year;
{
int leap, i = 1;
leap = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
while (i < month)
day += monlen[leap][i++];
return (day);
}
rd_dte (ddptr, mmptr, yyptr)
int *ddptr, *mmptr, *yyptr;
{
getstr(date_string);
if(date_string[0] == '\0') {
*ddptr = *mmptr = *yyptr = 0;
return(NO);
}
sscanf(date_string, "%d,%d,%d\n", ddptr, mmptr, yyptr);
if (*yyptr < 100) *yyptr += 1900;
if (*ddptr<1||*ddptr>31||*mmptr<1||*mmptr>12||*yyptr<1800||*yyptr>3000)
return(NO);
return (YES);
}
date (dayno, styr, monptr)
int dayno, styr;
int *monptr;
{
int leap, month = 1;
leap = styr % 4 == 0 && styr % 100 != 0 || styr % 400 == 0;
while (dayno > monlen[leap][month])
dayno -= monlen[leap][month++];
*monptr = month;
return (dayno);
}
pr_dte (date, col, month)
int date, col, month;
{
if (month > 12)
month = 1;
attrset (A_REVERSE);
move (20, col);
addch ((date / 10) + '0');
move (21, col);
addch ((date % 10) + '0');
attrset (0);
if (date == 1)
{
move (22, col);
addstr (mon_name[month]);
}
}
catch()
{
endwin();
exit(1);
}
#ifdef AMIGA
sleep(n)
{
Delay(n * 50);
}
#endif