Ejemplo n.º 1
0
Stroka RealLocation(const Stroka& path) {
    if (isexist(~path))
        return RealPath(path);
    Stroka dirpath = GetDirName(path);
    if (isexist(~dirpath))
        return  RealPath(dirpath) + GetDirectorySeparatorS() + GetFileNameComponent(~path);
    ythrow TFileError() << "RealLocation failed \"" << path << "\"";
}
Ejemplo n.º 2
0
//10.<赋值语句>—> id  =  <表达式> ;
void assignment(){
	char varname[MAXIDLEN];
	strcpy(varname, token);
	Val v2 = Val(1, GetIdByName(varname));

	match(id);
	if (!isexist(varname)){
		strcpy(token, varname);
		error(46);
	}
	
	match(equl);
	Val v = expression();

	match(semicolon);

	quadruples.push_back(Quadruple(sno++, equl, v, v2));
	//生成四元式
	/*printf("%3d (=,", sno++);
	if (v.type == 1) printf("%s", GetNameByID(v.value1));
	else if (v.type == 0) printf("%d", v.value1);
	else if (v.type == 2) printf("%lf", v.value2);
	else printf("t%d", v.value1);
	printf(",%s)\n", varname);*/
}
bool CAgencyInfoRetriver::Init(const Stroka& strDoc2AgFile)
{
    if (!strDoc2AgFile.empty() && isexist(strDoc2AgFile.c_str()))
        m_DocId2AgNameFile = TFile(strDoc2AgFile.c_str(), OpenExisting | RdOnly);

    return true;
}
Ejemplo n.º 4
0
int fifo(int* arr, int size) {
	int pages_size=MEM_SIZE/PAGE_SIZE;
	PAGE* pages=(PAGE*)malloc(sizeof(PAGE)*pages_size);
	int fault_count=0;
	int victim_frame=0;

	memset(pages,-1,sizeof(PAGE)*pages_size);
	int i;
	for(i=0; i<size; i++) {
		int frame_num=arr[i]/1024;
#ifdef ADDR_DEBUG
		fprintf(stdout,"Logical Address: %i\n",arr[i]);
		fprintf(stdout,"Frame number: %d\n",getPageNumber(arr[i]));
		fprintf(stdout,"Before frame number: %d\n",frame_num);
#endif
		if(!isexist(pages, pages_size, frame_num)) {
			fault_count++;

			pages[victim_frame].page_num=frame_num;
			pages[victim_frame].recently_used=0;
			victim_frame++;

			if(victim_frame>pages_size) {
				victim_frame=0;
			}
		}
	}

	free(pages);

	return fault_count;
}
Ejemplo n.º 5
0
int lru(int* arr, int size) {
	int pages_size=MEM_SIZE/PAGE_SIZE;
	PAGE* pages=(PAGE*)malloc(sizeof(PAGE)*pages_size);
	int fault_count=0;
	int victim_frame=0;

	memset(pages,-1,sizeof(PAGE)*pages_size);
	int i;
	for(i=0; i<size; i++) {
		int frame_num=arr[i]/1024;

#ifdef LRU_DEBUG
	fprintf(stdout,"[LRU] Page %d required\n",frame_num);
#endif

		if(!isexist(pages, pages_size, frame_num)) {
#ifdef LRU_DEBUG
	fprintf(stdout,"[LRU] Page %d does not exists\n",frame_num);
#endif
			fault_count++;
			
			int j;
			int high_value=0;
			for(j=0; j<pages_size; j++) {
				int temp=i-pages[j].recently_used;
#ifdef LRU_DEBUG
	fprintf(stdout,"[LRU] Page %d unused time %d\n",pages[j].page_num,temp);
#endif
				if(temp>high_value) {
					victim_frame=j;
					high_value=temp;
				}
			}
#ifdef LRU_DEBUG
	fprintf(stdout,"[LRU] Victim page %d will be changed with page %d\n",pages[victim_frame].page_num, frame_num);
#endif

			pages[victim_frame].page_num=frame_num;
			pages[victim_frame].recently_used=i;
		}else {
#ifdef LRU_DEBUG
	fprintf(stdout,"[LRU] Page %d exists\n",frame_num);
#endif
			int j;
			for(j=0; j<size; j++) {
				if(pages[j].page_num==frame_num) {
					pages[j].recently_used=i;
					break;
				}
			}
		}
	}

	free(pages);

	return fault_count;
}
Ejemplo n.º 6
0
//12.<传递参数>—> id [ ,  id ]| ε
void passparameter(char funname[]){
	vector<int> tmptypes;//实参类型序列
	char varname[MAXIDLEN];
	strcpy(varname, token);

	if (lookahead==id){
		match(id);
		if (!isexist(varname)){
			strcpy(token, varname);
			error(46);
		}

		int tmptype = FindTypeByName(varname);

		tmptypes.push_back(tmptype);

		while (lookahead == comma){
			match(comma);

			strcpy(varname, token);
			
			match(id);

			if (!isexist(varname)){
				strcpy(token, varname);
				error(46);
			}

			tmptype = FindTypeByName(varname);
			tmptypes.push_back(tmptype);
		}
		int callfuncId = FindIdByName(funname);
		if (tmptypes.size() != funtabs[callfuncId].para.size()){
			error(51);
		}
		else{
			for (int i = 0; i < tmptypes.size(); i++){
				if (tmptypes[i] != funtabs[callfuncId].para[i]){
					error(52);
				}
			}
		}
	}
}
Ejemplo n.º 7
0
static inline bool FreeBSDGuessExecPath(const Stroka& guessPath, Stroka& execPath) {
    if (isexist(~guessPath)) {
        // now it should work for real
        execPath = FreeBSDGetExecPath();
        if (RealPath(execPath) == RealPath(guessPath)) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 8
0
//初始化函数,检查是否有root,是否用户,没有则默认添加一个用户 :xiaosa,密码:123456
int runfirst()
{
	//检查root的i-node和Memory Manager的inode是否存在
	int path = 0;
	bool memory = isexist(path);
	if(memory)
	{
		return 1;
	}
	else
		return -1;
}
Ejemplo n.º 9
0
//8.<输入语句>—> input  id  [ , id ] ;
void inputStatement(){
	match(input);

	char varname[MAXIDLEN];
	strcpy(varname, token);
	match(id);
	if (!isexist(varname)){
		strcpy(token, varname);
		error(46);
	}

	while (lookahead == comma){
		match(comma);
		strcpy(varname, token);
		match(id);
		if (!isexist(varname)){
			strcpy(token, varname);
			error(46);
		}
	}
	match(semicolon);
}
Ejemplo n.º 10
0
//17.<因子>—> id | con | deci | (<表达式>)
Val Factor(){
	Val val;
	if (lookahead == id){
		
		val.type = 1;//变量
		
		char varname[MAXIDLEN];
		strcpy(varname, token);
		match(id);
		if (!isexist(varname)){
			strcpy(token, varname);
			error(46);
		}
		val.value1 = GetIdByName(varname);
	}
	else if (lookahead == con){
		
		val.type = 0;//整数
		val.value1 = atoi(token);

		match(con);
	}
	else if (lookahead == deci){

		val.type = 2;//小数
		val.value2 = atof(token);

		match(deci);
	}
	else if (lookahead == LP){
		match(LP);

		val = expression();
		
		match(RP);

		
	}
	else {
		error(24);
	}
	return val;
}
Ejemplo n.º 11
0
void CheckIsExist(const char *path) {
    if (!isexist(path)) {
        ythrow yexception() << "File or dir " <<  path << " does not exist";
    }
}
Ejemplo n.º 12
0
bool PathExists(const Stroka& path) {
    VERIFY(path.find('\0') == Stroka::npos);
    return isexist(~path);
}