Exemple #1
0
//get pin map from the xml nodes
static int get_pin_map(node_t *node,u8 *pins,int maxpins)
{
	node_t *pin;
	char *num,*func;
	u8 pinnum,pinfunc;

	//clear pins array
	memset(pins,P_ERROR,maxpins);

	//get first pin node
	pin = get_child("pin",node);
	while(pin) {

		//get pin number and function attributes
		num = find_attrib(pin,"number");
		func = find_attrib(pin,"function");

		//get and verify the pin number
		pinnum = (u8)atoi(num);
		if(pinnum >= maxpins) {
			log_printf("get_pin_map:  pinnum exceeds maxpins\n");
			continue;
		}

		//get and verify the pin function
		pinfunc = get_pin_func(func);
		if(pinfunc != P_ERROR)
			pins[pinnum] = pinfunc;

		//get node sibling for continued processing
		pin = get_sibling("pin",pin);
	}
	return(0);
}
Exemple #2
0
/* get the 'uncle' - the sibling of the parent - of the given node */
static DLRBT_Node *get_uncle (DLRBT_Node *node)
{
	if (node)
		/* return the child of the grandparent which isn't the node's parent */
		return get_sibling(node->parent);
	
	/* uncle not found */
	return NULL;
}
Exemple #3
0
// Sets the 'counter' on all the descendants of 'cat' to 'COUNTER_SENTINEL'.
void clear_descendants(CatID cat, int max_depth, int curr_depth) {
  if (cat == NIL) return;
  else if (curr_depth > max_depth) return;
  else {
    // clear self
    cats[cat].counter = COUNTER_SENTINEL;

    // recur on children by looping though the eldest's siblings
    for (CatID child = cats[cat].eldest_child;
         child != NIL; child = get_sibling(child, is_male(cat))) {
      clear_descendants(child, max_depth, curr_depth + 1);
    }
  }
}
Exemple #4
0
// Sets the 'counter' on the descendants of 'cat'.
void mark_descendants(CatID cat, int max_depth, int curr_depth) {
  if (cat == NIL) return;
  else if (curr_depth > max_depth) return;
  else {
    // mark self
    cats[cat].counter = min_counter(curr_depth, cats[cat].counter);

    // recur on children by looping though the eldest's siblings
    for (CatID child = cats[cat].eldest_child;
         child != NIL; child = get_sibling(child, is_male(cat))) {
      mark_descendants(child, max_depth, curr_depth + 1);
    }
  }
}
Exemple #5
0
//finds the correct mapper id using the information given
static int determine_mapperid(cart_t *cart,char *type,char *mapper,node_t *boardnode)
{
	int n,ret = B_UNSUPPORTED;
	node_t *node;

	//turn mapper string into mapper integer
	n = mapper ? atoi(mapper) : -1;

	//see if this board is supported by the unif mappers
	if((ret = mapper_get_mapperid_unif(type ? type : "")) == B_UNSUPPORTED) {

		//check if this ines mapper is supported
		if((ret = mapper_get_mapperid_ines(n)) == B_UNSUPPORTED) {

			//not supported, use mapperid from the rom loader maybe it is different
			ret = cart->mapperid;
		}
		else {
			log_printf("determine_mapperid:  ines mapper %d supported.  (board '%s')\n",n,type ? type : "");

			//save ines -> unif conversions to add to the unif section
		{{{{{{{
			FILE *fp = fopen("c:\\mingw\\home\\ines2unf.txt","at");

			if(fp) {
				fprintf(fp,"%d = %s\n",n,type ? type : "<UNKNOWN>");
				fclose(fp);
			}
		}}}}}}}

		}
	}
	else
		log_printf("determine_mapperid:  unif board '%s' supported.\n",type);

	//find the chips used and process them
	node = get_child("chip",boardnode);
	while(node) {
		ret = process_chip(ret,type,n,node);
		node = get_sibling("chip",node);
	}

	return(ret);
}
Exemple #6
0
// Prints the descendants of 'curr'.
void print_descendants(CatID root, CatID curr, int max_depth, int curr_depth) {
  if (curr == NIL) return;
  else if (curr_depth > max_depth) return;
  else {
    // print self
    if (curr_depth == cats[curr].counter) {
      printf("At generation %d, ", curr_depth);
      print_relationship(curr, curr_depth, root, 0);

      // ensure we don't print this cat again
      cats[curr].counter = COUNTER_SENTINEL;
    }

    // recur on children by looping though the eldest's siblings
    for (CatID child = cats[curr].eldest_child;
         child != NIL; child = get_sibling(child, is_male(curr))) {
      print_descendants(root, child, max_depth, curr_depth + 1);
    }
  }
}
Exemple #7
0
int cartdb_find(cart_t *cart)
{
	node_t *cartnode,*boardnode,*node;
	u32 crc32,wramsize,vramsize,battery;
	char *str,*str2,*tmp;

	if(cartxml == 0)
		return(1);

	//calculate crc32 of entire image
	crc32 = crc32_block(cart->prg.data,cart->prg.size,0);
	crc32 = crc32_block(cart->chr.data,cart->chr.size,crc32);

	//initialize the size and battery vars
	wramsize = vramsize = 0;
	battery = 0;

	//try to find cart node with same crc32
	cartnode = find_cart(crc32);
	if(cartnode) {

		//copy game title
		if((str = find_attrib(cartnode->parent,"name")))
			strcpy(cart->title,str);

		//see if board node exists
		if((boardnode = get_child("board",cartnode))) {

			//get unif board name and ines mapper number
			str = find_attrib(boardnode,"type");
			str2 = find_attrib(boardnode,"mapper");

			//set mapperid with information discovered
			cart->mapperid = determine_mapperid(cart,str,str2,boardnode);

			//find the vram size
			node = get_child("vram",boardnode);
			while(node) {
				tmp = find_attrib(node,"size");
				if(tmp) {
					battery |= hasbattery(node) << 1;
					vramsize += sizestr2int(tmp);
				}
				node = get_sibling("vram",node);
			}

			//find the wram size and battery status
			node = get_child("wram",boardnode);
			while(node) {
				tmp = find_attrib(node,"size");
				if(tmp) {
					battery |= hasbattery(node);
					wramsize += sizestr2int(tmp);
				}
				node = get_sibling("wram",node);
			}

			//debug messages
			if(wramsize) {
				cart_setwramsize(cart,wramsize / 1024);
				if(battery & 1)
					cart->battery |= 1;
			}
			if(vramsize) {
				cart_setvramsize(cart,vramsize / 1024);
				if(battery & 2)
					cart->battery |= 2;
			}
			return(0);
		}
	}

	log_printf("cartdb_find:  cart not found in database.\n");
	return(1);
}
int main(){
	Ty_Node *root= NULL;
	Ty_Node *p = NULL;
	char fpath[100];
	char order[100];
	element data;
	char a[100];
	char *token = NULL;
	char *token1 = NULL;
	char *separator = " ,\n";
	int level = 0;
	printf("파일 이름이 뭐인가요?\n");								
	scanf("%s", &fpath);													// 파일이름 입력


	fp = fopen(fpath, "r");	
	if(fp){																	// 파일이름이 존재할 때

		insert_from_file(&root);											// 파일로부터 노드 삽입
		while(1){
			printf("명령어를 입력하세요\n");
			fflush(stdin);													// scanf 버퍼 비우기
			scanf("%[^\n]s", &order);										// scanf 를 마치 gets 처럼 공백 무시하고 \n 까지 읽어들이는 방법
			token = strtok(order, separator);								// token 을 이용해 단어 분할
			switch(token[0]){												// 첫번째 명령어 부분을 switch 에 넣어 사용 case는 아스키코드값으로 

			case 105 :	// i
				token = strtok(NULL, separator);
				strcpy(data.name, token); 
				token = strtok(NULL, separator);
				data.key = atoi(token);
				insert_anode(&root, data);									// 추가정보를 data에 넣어서 노드에 삽입
				break;
			case 112 : 
				// p
				inorder(root);												// 중위순회방식으로 출력
				break;
			case 100 :  // d
				token = strtok(NULL, separator);
				delete_anode(root, token);									// 삭제
				break;
			case 115 :  // s
				token = strtok(NULL, separator);
				p = search_anode(root, token);								// 해당 키값의 노드정보 출력
				if(p !=NULL)
					printf("%s %d\n", p->data.name, p->data.key); 
				else
					printf("%s을 찾을 수 없습니다\n", token);
				break;
			case 118 :  // v
				token = strtok(NULL, separator);
				level = get_level(root, token);								// 해당 키값의 노드 높이 출력
				if(level !=0)
					printf("%s의 높이 : %d\n", token, level);
				else
					printf("%s을 찾을 수 없습니다\n", token);

				break;
			case 98 :  // b
				token = strtok(NULL, separator);
				get_sibling(root, token);									// 해당 키값의 노드 형제 출력
				break;
			case 104 : // h
				level = get_height(root);									// 높이 출력
				if(level !=NULL)
					printf("높이 : %d\n", level);
				break;
			case 101 : exit(0);												// 종료


			}
		}
	}
	else
	{
		printf("file 이름을 찾을 수 없습니다\n");
	}
}