Beispiel #1
0
void HtmlToken::SetTag(TokenType new_type, const char *new_s, const char *end)
{
    type = new_type;
    s = new_s;
    sLen = end - s;
    SkipName(new_s, s + sLen);
    nLen = new_s - s;
    tag = FindHtmlTag(s, nLen);
    nextAttr = NULL;
}
Beispiel #2
0
// We expect:
// whitespace | attribute name | = | attribute value
// where attribute value can be quoted
AttrInfo *HtmlToken::NextAttr()
{
    // start after the last attribute found (or the beginning)
    const char *curr = nextAttr;
    if (!curr)
        curr = s + nLen;
    const char *end = s + sLen;

    // parse attribute name
    SkipWs(curr, end);
    if (curr == end) {
NoNextAttr:
        nextAttr = NULL;
        return NULL;
    }
    attrInfo.name = curr;
    SkipName(curr, end);
    attrInfo.nameLen = curr - attrInfo.name;
    if (0 == attrInfo.nameLen)
        goto NoNextAttr;
    SkipWs(curr, end);
    if ((curr == end) || ('=' != *curr)) {
        // attributes without values get their names as value in HTML
        attrInfo.val = attrInfo.name;
        attrInfo.valLen = attrInfo.nameLen;
        nextAttr = curr;
        return &attrInfo;
    }

    // parse attribute value
    ++curr; // skip '='
    SkipWs(curr, end);
    if (curr == end) {
        // attribute with implicit empty value
        attrInfo.val = curr;
        attrInfo.valLen = 0;
    } else if (('\'' == *curr) || ('\"' == *curr)) {
        // attribute with quoted value
        ++curr;
        attrInfo.val = curr;
        if (!SkipUntil(curr, end, *(curr - 1)))
            goto NoNextAttr;
        attrInfo.valLen = curr - attrInfo.val;
        ++curr;
    } else {
        attrInfo.val = curr;
        SkipNonWs(curr, end);
        attrInfo.valLen = curr - attrInfo.val;
    }
    nextAttr = curr;
    return &attrInfo;
}
Beispiel #3
0
/*		printf("Face %i:\n  v0: %f, %f, %f\n  v1: %f, %f, %f\n"
			"  v2: %f, %f, %f\n", i,
			tList[i].verts[0][0],
			tList[i].verts[0][1],
			tList[i].verts[0][2],
			tList[i].verts[1][0],
			tList[i].verts[1][1],
			tList[i].verts[1][2],
			tList[i].verts[2][0],
			tList[i].verts[2][1],
			tList[i].verts[2][2]);
*/
	}
}

//==========================================================================
//
// Load3DS
//
//==========================================================================
#if 0	/* 3DS stuff is unused. don't even know whether it's working */
static void Load3DS(FILE *input, triangle_t **triList, int *triangleCount)
{
	unsigned int i, j;
	qboolean stop;
	qboolean foundVertexList;
	unsigned int chunkType, chunkPos, chunkSize;
	unsigned int editChunkSize, editChunkPos;
	unsigned int objectChunkSize, objectChunkPos;
	unsigned int meshChunkSize, meshChunkPos;
	unsigned int vertex;
	unsigned int vertexCount;
	struct vList_s
	{
		float v[3];
	} *vList;
	unsigned int triCount;
	triangle_t	*tList;

	InputFile = input;
	if (ReadShort() != _3DS_MAIN3DS)
	{
		_3DSError("Missing 3DS main chunk header.\n");
	}
	SeekTo(16);
	if (ReadShort() != _3DS_EDIT3DS)
	{
		_3DSError("Missing 3DS edit chunk header.\n");
	}

	editChunkSize = ReadLong();
	editChunkPos = FilePosition()-6;
	stop = false;
	while (stop == false)
	{
		chunkPos = FilePosition();
		chunkType = ReadShort();
		switch (chunkType)
		{
			case _3DS_EDIT_UNKNW01:
			case _3DS_EDIT_UNKNW02:
			case _3DS_EDIT_UNKNW03:
			case _3DS_EDIT_UNKNW04:
			case _3DS_EDIT_UNKNW05:
			case _3DS_EDIT_UNKNW06:
			case _3DS_EDIT_UNKNW07:
			case _3DS_EDIT_UNKNW08:
			case _3DS_EDIT_UNKNW09:
			case _3DS_EDIT_UNKNW10:
			case _3DS_EDIT_UNKNW11:
			case _3DS_EDIT_UNKNW12:
			case _3DS_EDIT_UNKNW13:
			case _3DS_EDIT_MATERIAL:
			case _3DS_EDIT_VIEW1:
			case _3DS_EDIT_BACKGR:
			case _3DS_EDIT_AMBIENT:
				SeekTo(chunkPos+ReadLong());
				break;
			case _3DS_EDIT_OBJECT:
				stop = true;
			default:
				break;
		}
		if (FilePosition()-editChunkPos >= editChunkSize)
		{
			_3DSError("Couldn't find OBJECT chunk.\n");
		}
	}

	objectChunkSize = ReadLong();
	objectChunkPos = FilePosition()-6;
	SkipName();
	stop = false;
	while (stop == false)
	{
		chunkPos = FilePosition();
		chunkType = ReadShort();
		switch (chunkType)
		{
			case _3DS_OBJ_UNKNWN01:
			case _3DS_OBJ_UNKNWN02:
			case _3DS_OBJ_LIGHT:
			case _3DS_OBJ_CAMERA:
				SeekTo(chunkPos+ReadLong());
				break;
			case _3DS_OBJ_TRIMESH:
				stop = true;
			default:
				break;
		}
		if (FilePosition()-objectChunkPos >= objectChunkSize)
		{
			_3DSError("Couldn't find TRIMESH chunk.\n");
		}
	}

	meshChunkSize = ReadLong();
	meshChunkPos = FilePosition()-6;
	stop = false;
	foundVertexList = false;
	while (stop == false)
	{
		chunkPos = FilePosition();
		chunkType = ReadShort();
		switch (chunkType)
		{
			case _3DS_TRI_FACEL2:
			case _3DS_TRI_VISIBLE:
				SeekTo(chunkPos+ReadLong());
				break;
			case _3DS_TRI_VERTEXL:
				chunkSize = ReadLong();
				vertexCount = ReadShort();
				vList = (struct vList_s *) SafeMalloc(vertexCount * sizeof(vList[0]));
				for (i = 0; i < vertexCount; i++)
				{
					vList[i].v[0] = ReadFloat();
					vList[i].v[1] = -ReadFloat();
					vList[i].v[2] = ReadFloat();
				}
				SeekTo(chunkPos+chunkSize);
				foundVertexList = true;
				break;
			case _3DS_TRI_FACEL1:
				chunkSize = ReadLong();
				triCount = ReadShort();
				if (triCount >= MAXTRIANGLES)
				{
					COM_Error("Too many triangles in file %s\n",
								InputFileName);
				}
				*triangleCount = triCount;
				tList = (triangle_t *) SafeMalloc(MAXTRIANGLES * sizeof(triangle_t));
				*triList = tList;
				for (i = 0; i < triCount; i++)
				{
					for (j = 0; j < 3; j++)
					{
						vertex = ReadShort();
						tList[i].verts[j][0] = vList[vertex].v[0];
						tList[i].verts[j][1] = vList[vertex].v[1];
						tList[i].verts[j][2] = vList[vertex].v[2];
					}
					ReadShort(); // Skip face flags
				}
				stop = true;
				break;
			default:
				break;
		}
		if (FilePosition()-meshChunkPos >= meshChunkSize)
		{
			if (foundVertexList == false)
			{
				_3DSError("Couldn't find TRI_VERTEXL chunk.\n");
			}
			else
			{
				_3DSError("Couldn't find TRI_FACEL1 chunk.\n");
			}
		}
	}
}