Пример #1
0
void ParseTemplateFile(FILE *nodes, GF_List *BNodes, GF_List *NDTs)
{
	char sLine[2000];
	char token[100];
	char *p;
	X3DNode *n;
	X3DField *f;
	u32 j, i, k;

	//get lines one by one
	n = NULL;
	while (!feof(nodes)) {
		fgets(sLine, 2000, nodes);
		//skip comment and empty lines
		if (sLine[0] == '#') continue;
		if (sLine[0] == '\n') continue;

		CurrentLine = sLine;

		//parse the line till end of line
		while (GetNextToken(token, " \t")) {

			//this is a new node
			if (!strcmp(token, "PROTO") ) {
				n = BlankNode();
				gf_list_add(BNodes, n);

				//get its name
				GetNextToken(n->name, " \t[");

				//extract the NDTs
				GetNextToken(token, "\t[ %#=");
				if (strcmp(token, "NDT")) {
					printf("Corrupted template file\n");
					return;
				}
				while (1) {
					GetNextToken(token, "=, \t");
					//done with NDTs
					if (!token[0]) break;

					//update the NDT list
					CheckInTable(token, NDTs);
					p = gf_malloc(strlen(token)+1);
					strcpy(p, token);
					gf_list_add(n->NDT, p);
				}
			}
			//this is NOT a field
			else if (token[0] == ']' || token[0] == '{' || token[0] == '}' ) {
				break;
			}
			//parse a field
			else {
				if (!n) {
					printf("Corrupted template file\n");
					return;
				}
				f = BlankField();
				gf_list_add(n->Fields, f);

				//get the field type
				strcpy(f->type, token);
				GetNextToken(f->familly, " \t");
				GetNextToken(f->name, " \t");
				//fix for our own code :(
				if (!strcmp(f->name, "tag")) strcpy(f->name, "_tag");

				//has default
				skip_sep(" \t");
				if (GetNextToken(token, "#\t")) {
					j=0;
					while (token[j] == ' ') j+=1;
					if (token[j] == '[') j+=1;
					if (token[j] == '"') j+=1;

					if (token[j] != '"' && token[j] != ']') {
						strcpy(f->def, token+j);
						j=1;
						while (j) {
							switch (f->def[strlen(f->def)-1]) {
							case ' ':
							case '"':
							case ']':
								f->def[strlen(f->def)-1] = 0;
								break;
							default:
								j=0;
								break;
							}
						}
					} else {
						strcpy(f->def, "");
					}
					if (!strcmp(f->familly, "SFFloat")) {
						if (!strcmp(f->def, "+I") || !strcmp(f->def, "I")) {
							strcpy(f->def, "GF_MAX_FLOAT");
						} else if (!strcmp(f->def, "-I")) {
							strcpy(f->def, "GF_MIN_FLOAT");
						}
					} else if (!strcmp(f->familly, "SFTime")) {
						if (!strcmp(f->def, "+I") || !strcmp(f->def, "I")) {
							strcpy(f->def, "GF_MAX_FLOAT");
						} else if (!strcmp(f->def, "-I")) {
							strcpy(f->def, "GF_MIN_FLOAT");
						}
					} else if (!strcmp(f->familly, "SFInt32")) {
						if (!strcmp(f->def, "+I") || !strcmp(f->def, "I")) {
							strcpy(f->def, "2 << 31");
						} else if (!strcmp(f->def, "-I")) {
							strcpy(f->def, "- (2 << 31)");
						}
					}
				}
				//has other
				while (GetNextToken(token, " \t#%=")) {
					switch (token[0]) {
					//bounds
					case 'b':
					case 'q':
					case 'a':
						printf("Corrupted X3D template file (quantization/animation not allowed)\n");
						gf_list_del_item(n->Fields, f);
						gf_free(f);
						return;
					default:
						break;
					}
				}
				/*we ignore these*/
				if (!stricmp(f->name, "bboxCenter") || !stricmp(f->name, "bboxSize")) {
					gf_list_del_item(n->Fields, f);
					gf_free(f);
				}
			}
		}
	}


	for (k=0; k<gf_list_count(BNodes); k++) {
		n = gf_list_get(BNodes, k);

		for (i=0; i<gf_list_count(n->Fields); i++) {
			f = gf_list_get(n->Fields, i);
			//nothing on events
			if (!strcmp(f->type, "eventIn")) continue;
			if (!strcmp(f->type, "eventOut")) continue;
			if (!strcmp(f->def, "")) continue;
			if (strstr(f->familly, "Node")) continue;
			n->hasDefault = 1;
		}
	}
}
Пример #2
0
int main()
{
	int row = 4;
	int col = 4;
	int max_len;
	int dirct;
	int size;
	int x, y;
	HashTable H;
	int i, num;

	/* Construct dictionary */
	freopen("dictionary.txt", "r", stdin);
	scanf("%d", &num);

	H = InitializeTable( TableSize );
	
	for(i = 0; i < num; i++) {
		scanf("%s", s);
		Insert(s, H);
	}


	/* Read data */
	max_len = row > col ? row : col;
	//for(y = 0; y < row; y++) {
	//	printf("%s\n", m[y]);
	//}	

	/* */
	for(y = 0; y < row; y++) {
		for(x = 0; x < col; x++) {
			for(dirct = 0; dirct < 8; dirct++) {
				for(size = 0; size < max_len; size++) {
					switch(dirct) {
					case 0:
						if(x+size < col)
							a[size] = m[y][x+size];
						else
							goto finish;
						break;
					case 1:
						if(x+size < col && y+size < row)
							a[size] = m[y+size][x+size];
						else
							goto finish;
						break;
					case 2:
						if(y+size < row)
							a[size] = m[y+size][x];
						else
							goto finish;
						break;	
					case 3:
						if(x-size >= 0 && y+size < row)
							a[size] = m[y+size][x-size];
						else
							goto finish;
						break;	
					case 4:
						if(x-size >= 0)
							a[size] = m[y][x-size];
						else
							goto finish;
						break;	
					case 5:
						if(x-size >= 0 && y-size >= 0)
							a[size] = m[y-size][x-size];
						else
							goto finish;
						break;	
					case 6:
						if(y-size >= 0)
							a[size] = m[y-size][x];
						else
							goto finish;
						break;	
					case 7:
						if(x+size < col && y-size >= 0)
							a[size] = m[y-size][x+size];
						else
							goto finish;
						break;	
					default:
						break;		
					}

					if(size + 1 >= max_len) {
						size++;
						goto finish;
					}
					continue;
finish:
					a[size] = '\0';
					if(CheckInTable(a, H)) {
						printf("(%d, %d) dirct = %d, size = %d: ",
							 y, x, dirct, size);
						printf("%s\n", a);
					}
					break; // break from for
				}
			}
		}
	}	
	
}