示例#1
0
文件: archives.cpp 项目: jackyf/cupt
void ArchivesWorker::deletePartialArchives()
{
	auto partialArchivesDirectory = _get_archives_directory() + partialDirectorySuffix;
	if (!fs::dirExists(partialArchivesDirectory))
	{
		return;
	}

	bool simulating = _config->getBool("cupt::worker::simulate");

	auto paths = fs::glob(partialArchivesDirectory + "/*");
	bool success = true;
	FORIT(pathIt, paths)
	{
		if (simulating)
		{
			auto filename = fs::filename(*pathIt);
			simulate2("deleting a partial archive file '%s'", filename);
		}
		else
		{
			if (unlink(pathIt->c_str()) == -1)
			{
				success = false;
				warn2e(__("unable to remove the file '%s'"), (*pathIt));
			}
		}
	}
	if (!success)
	{
		fatal2(__("unable to remove partial archives"));
	}
}
示例#2
0
文件: base.cpp 项目: jackyf/cupt
void WorkerBase::_run_external_command(Logger::Subsystem subsystem,
		const string& command, const CommandInput& commandInput, const string& errorId)
{
	const Logger::Level level = 3;
	_logger->log(subsystem, level, format2("running: %s", command));

	if (_config->getBool("cupt::worker::simulate"))
	{
		if (commandInput.buffer.empty())
		{
			simulate2("running command '%s'", command);
		}
		else
		{
			simulate2("running command '%s' with the input\n-8<-\n%s\n->8-",
					command, commandInput.buffer);
		}
	}
	else
	{
		const string& id = (errorId.empty() ? command : errorId);

		if (commandInput.buffer.empty())
		{
			p_invokeShellCommand(subsystem, level, command);
		}
		else try
		{
			p_runCommandWithInput(subsystem, level, command, commandInput);
		}
		catch (...)
		{
			_logger->loggedFatal2(subsystem, level, format2, "%s failed", id);
		}
	}
}
示例#3
0
文件: main.c 项目: miryala/lift
main(){
	int no,i,j,k=0;
	int **info;
	info=malloc(MAX_FLOORS*sizeof(int*));
	person p;
	Stack *up,*down;  //up and down lists contain persons going up and down
	up=stack_new();
	down=stack_new();
	for(i=0;i<10;i++){
		scanf("%d",&no);  //number of persons in lift
		info[i]=malloc(2*no*sizeof(int));
		for(j=0;j<2*no;j++){
			scanf("%d",&info[i][j]);
			if(j%2==1&&info[i][j]>i){
				p.time=info[i][j-1];
				p.id=k; //k is the identity of person.
				k++;
				p.from_floor=i;
				p.to_floor=info[i][j];
				up=stack_push(up,p);
			}
			if(j%2==1&&info[i][j]<i){
				p.time=info[i][j-1];
				p.id=k;
				k++;
				p.from_floor=i;
				p.to_floor=info[i][j];
				down=stack_push(down,p);
			}	
		}
	}
	LIFT *lift1,*lift2;
	lift1=malloc(sizeof(LIFT));
	lift2=malloc(sizeof(LIFT));
	//initialising lifts
	lift1->list=stack_new();
	lift2->list=stack_new();
	lift1->size=0;
	lift2->size=0;
	lift2->position=0;
	lift1->position=0;
	lift1->status=0;
	lift2->status=0;
	//initialisations
	simulate2 (up,down,lift1,lift2);
}
示例#4
0
int main() {
	int i;
	while(scanf("%d",&hand.s[0]) && hand.s[0]) {
		for(i=1;i<52;i++)
			scanf("%d",&hand.s[i]);
		
		for(i=0;i<52;i++)
			handd.s[i] = handdd.s[i] = hand.s[i];
		hand.first = handd.first = handdd.first = 0;
		hand.last = handd.last = handdd.last = 51;
		
		for(i=0;i<7;i++) {
			deck[i].state = deck[i].first = deck[i].last = 0;
			deckk[i].state = deckk[i].first = deckk[i].last = 0;
			deckkk[i].state = deckkk[i].first = deckkk[i].last = 0;
			record[i] = deck[i];
		}
		record[7] = hand;
		
		state = -1;
		cstep = 1;
		step = stepp = steppp = 0;
		ptr = ptrr = ptrrr = 0;
		while(1) {
			simulate();
			if(state >= 0)	break;
			ptr++;
			if(ptr == 7)	ptr = 0;
			while(deck[ptr].state < 0) {
				ptr++;
				if(ptr == 7)	ptr = 0;
			}
		}
		
		if(state == 0)
			printf("Loss: %d\n",step+1);
		else if(state == 1)
			printf("Win : %d\n",step);
		else {
			int period = step-cstep/2;
			for(i=0;i<period;i++) {
				simulate3();
				ptrrr++;
				if(ptrrr == 7)	ptrrr = 0;
				while(deckkk[ptrrr].state < 0) {
					ptrrr++;
					if(ptrrr == 7)	ptrrr = 0;
				}
			}
			state = 0;
			while(steppp <= step) {
				simulate2();
				simulate3();
				statee = check2();
				if(statee)	break;
				ptrr++;
				if(ptrr == 7)	ptrr = 0;
				while(deckk[ptrr].state < 0) {
					ptrr++;
					if(ptrr == 7)	ptrr = 0;
				}
				ptrrr++;
				if(ptrrr == 7)	ptrrr = 0;
				while(deckkk[ptrrr].state < 0) {
					ptrrr++;
					if(ptrrr == 7)	ptrrr = 0;
				}
			}
			printf("Draw: %d\n",steppp);
		}
	}
	return 0;
}