Exemplo n.º 1
0
long ftimediff (FTIME *t1,FTIME *t2)
/***********
* Describe : вычисляет pазницу между вpеменем t1 и t2 в минутах
* Params   : FTIME *t1 - пеpвое вpемя
*          : FTIME *t2 - втоpое вpемя
* Return   : long      - pазница в минутах
* Call     : diffdate,min_of_day
***********/
{
 long days_diff,min_diff;

 days_diff = diffdate (&(t1->date),&(t2->date));
 min_diff = days_diff * HOUR_IN_DAY * MIN_IN_HOUR;
 min_diff += min_of_day (&(t2->time)) - min_of_day (&(t1->time));
 return min_diff;
}
Exemplo n.º 2
0
time_t CCalendarCtrl::DateToSeconds(COleDateTime& date)
{
	// FIX : We need to find the gmt bias for the zone	
	time_t t = (time_t)(date - COleDateTime(1970, 1, 1, 0, 0, 0)).GetTotalSeconds();
	COleDateTime diffdate(t);
	int gmtbias = 0;
	if(diffdate > date) 
		 gmtbias = -((int)(diffdate-date).GetTotalSeconds());
	else gmtbias =  ((int)(date-diffdate).GetTotalSeconds());

	// The next check is to handle the case when system is adjusting the clock 
	// and we meet a time change
	// Note: for the missing hour case, bias is left untouched so the date may have a time > 0
	COleDateTime v((time_t)(t/86400*86400 + gmtbias));
	if(v < date) gmtbias += 3600;

	return (time_t)(t/86400*86400 + gmtbias);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	struct hist_record rec;
	char *line;
	game initgame;
	bool localdat = false;
	char cwd_buf[1024];
	unsigned int (*bcounts)[3];
	int ca[2];
	date current = {0, 0, 0};
	int arg;
	int rc;
	for (arg = 1; arg < argc; arg++)
	{
		if (!strcmp(argv[arg], "--localdat"))
		{
			localdat=true;
		}
		else
		{
			fprintf(stderr, "Unrecognised argument '%s'\n", argv[arg]);
			return 5;
		}
	}

	if(!(cwd=getcwd(cwd_buf, 1024)))
	{
		perror("getcwd");
		return 5;
	}

	fprintf(stderr, "Loading data files...\n");
	
#ifndef WINDOWS
	if(chdir(localdat?cwd:DATIDIR))
	{
		perror("Failed to enter data dir: chdir");
		if(!localdat)
			fprintf(stderr, "(Maybe try with --localdat, or make install)\n");
		return 5;
	}
#endif

	rc = load_data();
	if (rc)
		return rc;
	bcounts = calloc(ntypes, sizeof(*bcounts));
	if (!bcounts)
	{
		perror("calloc");
		return 5;
	}
	rc = set_init_state(&initgame);
	if (rc)
		return rc;

	fprintf(stderr, "Data files loaded\n");

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line)
		{
			fprintf(stderr, "Unexpected EOF\n");
			return 3;
		}
		if (!strncmp(line, "History:", 8))
		{
			free(line);
			break;
		}
	}

	while(!feof(stdin))
	{
		line = fgetl(stdin);
		if (!line) break;
		rc = parse_event(&rec, line);
		if (rc)
		{
			fprintf(stderr, "Error %d in line: %s\n", rc, line);
			free(line);
			return rc;
		}
		free(line);
		if (rec.type == HT_INIT)
		{
			char savbuf[80];

			snprintf(savbuf, 80, "save/%s", rec.init);
			rc = loadgame(savbuf, &initgame);
			if (rc)
			{
				fprintf(stderr, "Error %d loading INITgame '%s'\n", rc, savbuf);
				return 6;
			}
			for (unsigned int i = 0; i < initgame.nbombers; i++)
				bcounts[initgame.bombers[i].type][0]++;
			ca[0] = initgame.cshr;
			ca[1] = initgame.cash;
		}
		else if (rec.type == HT_AC)
		{
			if (rec.ac.type == AE_CT)
			{
				if (!rec.ac.fighter)
				{
					bcounts[rec.ac.ac_type][0]++;
					bcounts[rec.ac.ac_type][1]++;
				}
			}
			else if (rec.ac.type == AE_CROB)
			{
				if (!rec.ac.fighter)
				{
					bcounts[rec.ac.ac_type][0]--;
					bcounts[rec.ac.ac_type][2]++;
				}
			}
		}
		else if (rec.type == HT_MISC)
		{
			if (rec.misc.type == ME_CASH)
			{
				ca[0] = rec.misc.cash.delta;
				ca[1] = rec.misc.cash.current;
			}
		}
		if (diffdate(rec.date, current))
			write_counts(current = rec.date, bcounts, ca);
	}
	return 0;
}