Beispiel #1
0
void AsmEnums()
{
	int Value=0;	//Fredrik: correct initializer in case first token is not "=" ?
		
	NeedToken("{");

	do
	{
		GetName();							// Get the new type Name	

		if (Token("="))
		{
			Value = GetExpression();
		}
		else
			Value++;

//		if (Pass == 1)
			RedefENum(Name, Value);

		//printf("- Enum %s' Value %ld\n",Name,Value);

		SkipWhiteSpace();
	}
	while(Token(","));
	
	NeedToken("}");
}
Beispiel #2
0
void 
XMLParser::ParseCDATA()
{
  CString value;

  // Skip past "<![CDATA["
  m_pointer += 9;

  // Read everything until we find "]]>"
  // XML says a ']]' can occur in a CDATA section
  while(*m_pointer && strncmp((const char*)m_pointer,"]]>",3))
  {
    value += *m_pointer++;
  }
  NeedToken(']');
  NeedToken(']');
  NeedToken('>');
  // Add to current element
  if(m_lastElement)
  {
    m_lastElement->SetValue(value);
    m_lastElement->SetType(XDT_CDATA);
  }
  SkipWhiteSpace();
}
Beispiel #3
0
int GetNum()
{
	register unsigned int v = 0;

	if (Token("'"))			// found «
	{		
		if (Token("\\"))		// Test "\"
		{
			v = GetEscCode();
			NeedToken("\'");
			return v;
		}

		v = GetCharNum();
		NeedToken("\'");
		return v;
	}

	if (*FilePtr == '0' && (*(FilePtr+1) =='x' || *(FilePtr+1) == 'X'))
	{
		FilePtr+=2;
		
		return GetHexNum(16);
	}

	return GetDecNum(16);
}
Beispiel #4
0
void
XMLParser::ParseComment()
{
  // We throw comment's away real quick
  while(*m_pointer && strncmp((const char*)m_pointer,"-->",3))
  {
    m_pointer++;
  }
  // Skip end of comment
  NeedToken('-');
  NeedToken('-');
  NeedToken('>');
  SkipWhiteSpace();
}
Beispiel #5
0
// Get quoted string from message
CString
XMLParser::GetQuotedString()
{
  CString result;

  SkipWhiteSpace();
  if(*m_pointer && (*m_pointer == '\"' || *m_pointer == '\''))
  {
    // Save the delimiter
    char delim = *m_pointer;

    m_pointer++;
    while(*m_pointer && *m_pointer != delim)  
    {
      result += ValueChar();
    }
    NeedToken(delim);

    if(m_utf8)
    {
      result = DecodeStringFromTheWire(result);
    }
  }
  return result;
}
Beispiel #6
0
void
XMLParser::ParseDTD()
{
  // Setting the error, but we do not throw from here.
  SetError(XmlError::XE_DTDNotSupported,(uchar*)"DTD's are unsupported",false);

  // Skip past a DTD part
  while(*m_pointer && *m_pointer != '>')
  {
    m_pointer++;
  }
  NeedToken('>');
  SkipWhiteSpace();
}
Beispiel #7
0
// Get a character from message including '& translation'
unsigned char
XMLParser::ValueChar()
{
  if(*m_pointer == '&')
  {
    if(*(m_pointer + 1) == '#')
    {
      // Parse a number
      int number = 0;
      int radix  = 10;

      // Eventually a hexadecimal number
      m_pointer += 2;
      if(*m_pointer == 'x')
      {
        ++m_pointer;
        radix = 16;
      }

      // Read number
      while(*m_pointer && isxdigit(*m_pointer) && *m_pointer != ';')
      {
        number *= radix;
        number += XDigitToValue(*m_pointer++);
      }
      // Skip closing ';'
      NeedToken(';');
      // Result
      return (unsigned char)(number);
    }
    // Search for known entities such as '&amp;' or '&quot;'
    for(unsigned ind = 0;ind < NUM_ENTITY; ++ind)
    {
      if(strncmp((const char*)m_pointer,g_entity[ind].m_entity,g_entity[ind].m_length) == 0)
      {
        m_pointer += g_entity[ind].m_length;
        return g_entity[ind].m_char;
      }
    }
    // Unrecognized. Keep on going
    // Parse according to garbage-in/garbage-out principle
  }
  return *m_pointer++;
}
Beispiel #8
0
short Directives()
{	
	int t;
	
	SkipWhiteSpace();

	if (*FilePtr != '.')
		return 0;

	DataCharPtr = FilePtr;

	if (QToken(".eof"))
	{
		// mark end of label array as end of bss
		
		strcpy(Name, "_________eof_________");
		Section = SECT_bss;
		DefineLabel(label_Local);

		SourceFileCheckEOF(LastTokenPtr() - FileTop);

		EndFile = 1;
		return 1;
	}


	GetToken();	
	t = ScanAsmToken();

	switch(t)
	{

//---------------------------------------------------------

	case 0:
		Error(Error_Skip, "Illegal directive '%s'",Name);


//---------------------------------------------------------

	case dir_sourcefile:
	{		
		int file;
		
		SkipWhiteSpace();
		GetLFileName();	

//		SetCSourceFile(Name);
		file = SetSLD_Name(Name);

		SetCSourceFile(Name, file);
		return 1;
	}

//---------------------------------------------------------


	case dir_model:
	{	
		int model=0;
	
		if (Token("full"))				// Get return type
			model = MODEL_full;
		else if (Token("half"))				// Get return type
			model = MODEL_half;
		else if (Token("compact"))			// Get return type
			model = MODEL_compact;
		else if (Token("mini"))				// Get return type
			model = MODEL_mini;
		else if (Token("tiny"))				// Get return type
			model = MODEL_tiny;
		else 
			Error(Error_Fatal, "invalid model type");

		// if model is not set then set it
			
		if (!CurrentModel)
			CurrentModel = model;
		else
		{
			if (model != CurrentModel)
				Error(Error_Fatal, "multiple architectual models defined");
		}

		return 1;
	}

//---------------------------------------------------------

	case dir_ctor:
	{
		SYMBOL* ref;
		imm = GetExpression();				// Get the number
		ref = GetLastSymbolRef();

		if(pass_count > 1)
		{
			if (!ref)
				Error(Error_Fatal, "Constructor has bad reference");

			ArraySet(&CtorArrayImm, CtorCount, imm);
			ArraySet(&CtorArray, CtorCount++, (int) ref);
		}
		return 1;		
	}

//---------------------------------------------------------

	case dir_dtor:
	{		
		SYMBOL* ref;
		imm = GetExpression();				// Get the number
		ref = GetLastSymbolRef();

		if(pass_count > 1)
		{
			if (!ref)
				Error(Error_Fatal, "Destructor has bad reference");

			ArraySet(&DtorArrayImm, DtorCount, imm);
			ArraySet(&DtorArray, DtorCount++, (int) ref);
		}
		return 1;		
	}


//---------------------------------------------------------

	case dir_sourcedir:
	{		
		SkipWhiteSpace();
		GetLFileName();	
		SetCSourceDir(Name);
		return 1;
	}

//---------------------------------------------------------

	case dir_line:
	{
		int v;
		
		SkipWhiteSpace();
		v = GetNum();	
		SetCSourceLine(v);
		SetSLD_Line(v);

		return 1;
	}

//---------------------------------------------------------

	case dir_dlab:
	{
		if (!ArgUseStabs)
		{
			SkipLine();			// Skip excess debug labels
			return 1;
		}

		// Define a label

		Section = SECT_code;

		GetAsmName();
		DefineLabel(label_Local);
		return 1;
	}

//---------------------------------------------------------

	case dir_library:
	{
		SkipLine();
		return 1;
	}

//---------------------------------------------------------

	case dir_exit:
	{
		if (NextToken("\""))
		{
			GetStringName(1024);

			Error(Error_Fatal, "User: %s", Name);
			return 1;
		}
	
	
		Error(Error_Fatal, "Exiting with user error");
		return 1;
	}

//---------------------------------------------------------

	case dir_asm_on:
	{
		return 1;
	}

//---------------------------------------------------------

	case dir_asm_off:
	{
/*		if (QToken(".asm_off"))
		{
			return 1;
		}
*/
		return 1;
	}

//---------------------------------------------------------

	case dir_AllowFarBranches:
	{
		AllowFarBranches = 1;
		return 1;
	}

//---------------------------------------------------------

	case dir_bp:
	{
		return 1;
	}

//---------------------------------------------------------

	case dir_localscope:
	{
		SkipWhiteSpace();

		if (Token("+"))
		{
			LocalScope++;
			return 1;
		}

		if (Token("reset"))
		{
			LocalScope = 1;
			return 1;
		}

		Error(Error_Fatal, "Bad .localscope type");
		return 1;
	}

//---------------------------------------------------------

	case dir_func:
	{	
		Function_Return_Type = RET_void;

		GetName();

		ReplaceChar(Name, '.', '_');

		Function_Param_Count = -1;

		if (Token(","))
		{
			Function_Param_Count = GetNum();

			if (Token(","))				// Get param count
			{				
				if (Token("int"))				// Get return type
					Function_Return_Type = RET_int;
				else if (Token("float"))
					Function_Return_Type = RET_float;
				else if (Token("double"))
					Function_Return_Type = RET_double;
				else if (Token("void"))
					Function_Return_Type = RET_void;
				else if (Token("?"))
					Function_Return_Type = RET_double;	//patch fix
			}
		}

		DefineLabel(label_Function);		
		return 1;
	}

//---------------------------------------------------------

	case dir_local:
	{
		GetName();
		return 1;
	}

//---------------------------------------------------------

	case dir_vec_elt:
	{
		GetName();
		return 1;
	}

//---------------------------------------------------------

	case dir_syscall:
	{
		char SysCallName[256];
		char istr[4096];
		char *iptr = 0;
		
		int v, p, r;
		
		p = 0;
		r = RET_void;
		
		GetName();
		strcpy(SysCallName,Name);
	
		SkipWhiteSpace();

		v = GetExpression();

		if (Token(","))				// Get param count
		{
			p = GetExpression();

			NeedToken(",");
			
			if (Token("int"))				// Get return type
				r = RET_int;
			else if (Token("float"))
				r = RET_float;
			else if (Token("double"))
				r = RET_double;
			else if (Token("void"))
				r = RET_void;

			if (Token(","))				// Get interface
			{
				GetStringName(2048);
				strcpy(istr,Name);
				iptr = istr;
			}

		}

		if (Pass == 1)
			MapSysCall(SysCallName, v, p, r, iptr);

		return 1;
	}

//---------------------------------------------------------

	case dir_lfile:
	{
		SkipWhiteSpace();
		GetLFileName();
		
		strcpy(CurrentFile, Name);
//		CurrentFileLine = GetLineNumber(FileTop,GetPrevFilePtr());
		
		AddFileSym(Name, LocalScope+1);
		
		GetRelPath(CurrentFile);
		return 1;
	}

//---------------------------------------------------------

	case dir_org:
	{
		int v = GetExpression();

		if (v >= MAX_CODE_MEM)
			Error(Error_Fatal, ".org has illegal address");

		CodeIP = v;
//!		CodePtr = &CodeMem[v];
		printf("*Warning* org %x\n", v);
		return 1;
	}


//---------------------------------------------------------

	case dir_set:
	{
		
		SkipWhiteSpace();

		// Catch Thunks
		
		if (Token("%"))
		{
			SYMBOL *ThunkSym;
			int v;

			v = GetDecNum(5);
			
			if (GetDecNumDigitCount() == 0)
				Error(Error_Fatal, "Missing Thunk Number");

			NeedToken("=");
			SkipWhiteSpace();

			GetName();			// Get the name of the thunk alias
			GetEnumValue(Name);	// Evaluate the symbol


			ThunkSym = GetLastSymbolRef();

			//N_FUN 141 4935 '_Z7XPClosev:F(0,6)'

			StabsEmit("N_THUNK %d %d '%s'\n", v, ThunkSym, Name);

			RegisterThunk(v, ThunkSym);
			return 1;
		}
		
		// Catch normal sets
		
		GetName();							// Get the new type Name	
		NeedToken("=");
		RedefENum(Name, GetExpression());	
		return 1;
	}

//---------------------------------------------------------

	case dir_debug:
	{
		DEBUG = (short)GetExpression();	
		return 1;
	}


//---------------------------------------------------------

	case dir_info:
	{
		INFO = (short)GetExpression();	
		return 1;
	}

//---------------------------------------------------------

	case dir_list:
	{
		LIST = (short)GetExpression();	
		return 1;
	}

//---------------------------------------------------------

	case dir_show:
	{
		int exp = GetExpression();
		
		if (Pass == 1)
			printf("%d",exp);

		if (!Token(";"))
			if (Pass == 1) printf("\n");
	
		return 1;
	}

//---------------------------------------------------------

	case dir_print:
	//if (QToken(".print") || QToken(".?"))
	{
		int exp;
		char v;
	
		if (Token("\""))
		{
			while(1)	
			{
				v = *FilePtr;
				
				if (v == 0 || v == '"')
					break;
				
				printf("%c",v);

				FilePtr++;
			}

			NeedToken("\"");

			if (!Token(";"))
				printf("\n");

			return 1;
		}

		exp = GetExpression();

		printf("%d",exp);

		if (!Token(";"))
			printf("\n");
	
		return 1;
	}

//---------------------------------------------------------

	case dir_ifdef:
	{
		GetName();							// Get the new type Name	
		SkipWhiteSpace();
		
		if (!SymbolExists(Name, section_Script, -1))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//---------------------------------------------------------

	case dir_ifdefglobal:
	{
		GetName();							// Get the new type Name	
		SkipWhiteSpace();
		
		if (!SymbolExists(Name, section_Enum, 0))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//---------------------------------------------------------

	case dir_ifndefglobal:
	{
		GetName();							// Get the new type Name	
		SkipWhiteSpace();
		
		if (SymbolExists(Name, section_Enum, 0))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//---------------------------------------------------------

	case dir_ifndef:
	{
		GetName();							// Get the new type Name	
		SkipWhiteSpace();
		
		if (SymbolExists(Name, section_Script, -1))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//---------------------------------------------------------

	case dir_if:
	{

		if (!GetExpression())
		{
			SkipWhiteSpace();

			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}


//---------------------------------------------------------

	case dir_do:
	{

		// If we have a '{' just ignore it an keep going
		
		if (Token("{"))
			return 1;
	
		// Must be an expression then

		// if false then skip to while

		if (!GetExpression())
		{
			SearchScopeForward();
			NeedToken(".enddo");
		}
			
		return 1;
	}

//---------------------------------------------------------

	case dir_enddo:
	{
		FilePtr = SearchScope(FilePtr);			
		return 1;
	}


//---------------------------------------------------------

	case dir_while:
	{
		if (GetExpression())
		{
			FilePtr = SearchScope(FilePtr);
		}
		return 1;
	}

//---------------------------------------------------------

	case dir_enum:
	{
		AsmEnums();
		return 1;
	}


//---------------------------------------------------------

	case dir_breakpoint:
	{
		SkipWhiteSpace();
		return 1;
	}

//---------------------------------------------------------

	case dir_globals_in_code:
	{
		GlobalsInCode = 1;
		SkipWhiteSpace();
		return 1;
	}

//---------------------------------------------------------

	case dir_globl:
//	if (QToken(".globl") || QToken(".global") || QToken(".weak"))
	{
		unsigned int n;
		
		GetAsmName();

		if (GlobalsInCode && (Section == SECT_code))
		{
//!			*CodePtr++ = '*';

			ArraySet(&CodeMemArray, CodeIP, '*');
			CodeIP++;

			for (n=0;n<strlen(Name);n++)
			{
//!				*CodePtr++ = Name[n];

				ArraySet(&CodeMemArray, CodeIP, Name[n]);
				CodeIP++;
			}
	
//!			*CodePtr++ = '*';

			ArraySet(&CodeMemArray, CodeIP, '*');
			CodeIP++;
		}

		if (LIST)
			printf("Found global '%s'\n",Name);

		DefineLabelGlobal();

//#ifdef INCLUDE_JAVAGEN
//		if (JavaPass)
//			JavaGen_Global(Name);
//#endif
		
		SkipWhiteSpace();
		return 1;
	}

//---------------------------------------------------------

	case dir_extern:
//	if (QToken(".extern") || QToken(".extrn"))
	{
		GetAsmName();

		if (LIST)
			printf("Found external '%s'\n",Name);

		// SHOULD DO NOTHING 
		//ExternDecl(Name);

		SkipWhiteSpace();
		return 1;
	}

//---------------------------------------------------------

	case dir_byte:
	{
		SetAsmDataChar();

		do
		{
			imm = GetExpression();					// Get the number

			WriteDataTypeArray(dir_byte, 1);
			WriteByte(imm);
		}
		while (QToken(","));

		return 1;

	}

//---------------------------------------------------------

	case dir_half:
	{
		SetAsmDataChar();

		do
		{
			imm = GetExpression();					// Get the number

			WriteDataTypeArray(dir_half, 2);
			WriteWord(imm);
		}
		while (QToken(","));

		return 1;
	}

//---------------------------------------------------------

	case dir_word:
	{
		SYMBOL *ref;
		
		if (Section != SECT_data)
			Error(Error_Skip,"data word in not in data section");

		SetAsmDataChar();
		
		do
		{
			imm = GetExpression();				// Get the number

			WriteDataTypeArray(dir_word, 4);

			ref = GetLastSymbolRef();
			WriteLongRef(imm, ref);

		}
		while (QToken(","));
		return 1;
	}

//---------------------------------------------------------

	case dir_space:
	{
		SetAsmDataChar();

		imm = GetExpression();					// Get the number

		if (LIST)
			printf("space %d\n",imm);
	
		if (!imm)
			return 1;

		WriteDataTypeArray(dir_space, imm);
		
		do
		{
			WriteByteSpace(0);
		}
		while(--imm);

		return 1;
	}

//---------------------------------------------------------

	case dir_string:
	{
		SetAsmDataChar();

		WriteDataTypeArray(dir_string, 1);

		GetStrings();
		return 1;
	}

//---------------------------------------------------------

	case dir_comm:
	{
		int LastSect = Section;

		SetAsmDataChar();

		Section = SECT_bss;

		GetAsmName();
		
		//!! make this global too

		DefineLabelGlobal();
		DefineLabel(label_Local);
		
		NeedToken(",");
				
		imm = GetExpression();					// Get the number

		if (LIST)
			printf("comm %d to .bss\n",imm);
	
		if (imm == 0)
			return 1;

		WriteDataTypeArray(dir_comm, imm);
		
		BssIP += imm;

		Section = LastSect;

		return 1;
	}

//---------------------------------------------------------

	case dir_lcomm:
	{
		int LastSect = Section;

		SetAsmDataChar();

		Section = SECT_bss;

		GetAsmName();
		DefineLabel(label_Local);
		
		NeedToken(",");
				
		imm = GetExpression();					// Get the number

		if (LIST)
			printf("lcomm %d to .bss\n",imm);
	
		if (imm == 0)
			return 1;

		WriteDataTypeArray(dir_lcomm, imm);
		
		BssIP += imm;

		Section = LastSect;

		return 1;
	}

//---------------------------------------------------------

	case dir_align:
	{
		imm = GetExpression();					// Get the number

		if (Section == SECT_code)
			return 1;

		AddAlignRef(imm);
		return 1;
	}


//---------------------------------------------------------

	case dir_bss:
	{
		Section = SECT_bss;

		if (LIST)
			printf("** Section .bss IP = %x\n",BssIP);

		return 1;
	}

//---------------------------------------------------------

	case dir_data:
	{
		Section = SECT_data;

		if (LIST)
			printf("** Section .data IP = %x\n",DataIP);

		return 1;
	}

//---------------------------------------------------------

	case dir_code:
//	if (QToken(".code") || QToken(".text"))
	{
		Section = SECT_code;

		if (LIST)
			printf("** Section .code IP = %x\n",CodeIP);

		return 1;
	}

//---------------------------------------------------------

	case dir_ent:
	{
		SkipLine();
		return 1;
	}


//---------------------------------------------------------

	case dir_end:
		return 1;

//---------------------------------------------------------

	case dir_stabs:
	{
		Parse_stabs();
		//SkipLine();
		return 1;
	}

//---------------------------------------------------------

	case dir_stabn:
	{
		Parse_stabn();
		//SkipLine();
		return 1;
	}

//---------------------------------------------------------

	case dir_stabd:
	{
		SkipLine();
		return 1;
	}

//---------------------------------------------------------

	}		// End of switch

	return 0;
}
Beispiel #9
0
short ResourceCommands()
{
	char *filemem;
	int filelen;
	int n,v;

	SkipWhiteSpace();

//---------------------------------------------------------

	if (QToken(".library"))
	{
		SkipLine();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".lfile"))
	{
		SkipWhiteSpace();

		GetLFileName();

		GetRelPath(Name);
		return 1;
	}


	if (QToken(".localscope"))
	{
		SkipWhiteSpace();
		NeedToken("+");

//		LocalScope++;
		return 1;
	}


	if (QToken(".res"))
	{
		// If there is previous data to be written out
		// do it here !!

		if (ResType != 0)
		{
			FinalizeResource();
		}

		SkipWhiteSpace();

		ResName[0] = 0;
		Name[0] = 0;

		if (isalpha(*FilePtr))
		{
			GetName();						// Get the new type Name
			strcpy(ResName, Name);
		}


		// Clear index table

		IndexCount = 0;
		IndexWidth = 0;

		MakeNewResource(Name);				// Make this symbolic
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".index"))
	{
		int IndexOffset = GetDataIndex();

		SkipWhiteSpace();

		Name[0] = 0;

		if (isalpha(*FilePtr))
			GetName();						// Get the index ref name

		// add index to table

		IndexTable[IndexCount] = IndexOffset;

//		MakeIndexedResource(IndexName, IndexCount);

		infoprintf("%d: index = %d ('%s')\n",IndexCount, IndexOffset, Name);

		if (Pass == 2)
			if (Name[0])
				fprintf(HeaderFile,"#define idx_%s %d\n", Name, IndexCount);

		IndexCount++;
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".wideindex"))
	{
		IndexWidth = 1;
		SkipWhiteSpace();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".extension"))
	{
		SkipWhiteSpace();

		v = GetExpression();		// x

		ResType = v;

		infoprintf("%d: Prototype = %d\n",CurrentResource, ResType);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".dispose"))
	{
		SkipWhiteSpace();

		ResDispose = 1;
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".placeholder"))
	{
		ResType = ResType_PlaceHolder;

		infoprintf("%d: Placeholder\n",CurrentResource);
		return 1;
	}


//------------------------------------
//
//------------------------------------

	if (QToken(".skip"))
	{
		ResType = ResType_Skip;

		infoprintf("%d: Skip\n",CurrentResource);
		return 1;
	}


//------------------------------------
//
//------------------------------------

	if (QToken(".bin"))
	{
		ResType = ResType_Binary;

		infoprintf("%d: Binary\n",CurrentResource);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".ubin"))
	{
		ResType = ResType_UBinary;

		infoprintf("%d: UBinary\n",CurrentResource);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".media"))
	{
		int slen;

		SkipWhiteSpace();

		ResType = ResType_Binary;			//ResType_Media;
		GetStringName(128);

		slen = strlen(Name) + 1;

		for (n=0;n<slen;n++)
			WriteByte(Name[n]);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		GetStringName(128);

		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading data file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		for (n=0;n<filelen;n++)
		{
			WriteByte(filemem[n]);
		}

		Free_File(filemem);

		infoprintf("%d: Media Binary\n",CurrentResource);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".umedia"))
	{
		int slen;

		SkipWhiteSpace();

		ResType = ResType_UBinary; //ResType_UMedia;
		GetStringName(128);

		slen = strlen(Name) + 1;

		for (n=0;n<slen;n++)
			WriteByte(Name[n]);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		GetStringName(128);

		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading data file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		for (n=0;n<filelen;n++)
		{
			WriteByte(filemem[n]);
		}

		Free_File(filemem);

		infoprintf("%d: Media Binary\n",CurrentResource);
		return 1;
	}

//------------------------------------
//
//------------------------------------
/*
	if (QToken(".file"))
	{
		SkipWhiteSpace();

		ResType = ResType_File;

		GetStringName(128);

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error("Error reading data file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		for (n=0;n<filelen;n++)
		{
			WriteByte(filemem[n]);
		}

		Free_File(filemem);

		printf("%d: File '%s' size %d\n", CurrentResource, Name, filelen);
		return 1;
	}
*/

//------------------------------------
//
//------------------------------------

	if (QToken(".label"))			// filename
	{
		int slen;

		SkipWhiteSpace();

		ResType = ResType_Label;
		GetStringName(128);

		slen = strlen(Name) + 1;

		for (n=0;n<slen;n++)
			WriteByte(Name[n]);

		return 1;
	}


//------------------------------------
//
//------------------------------------

// ResType_TileSet = 7
// ushort xsize, ysize
// bytes png_image

	if (QToken(".tileset"))			// filename
	{
		int xsize,ysize;

		SkipWhiteSpace();

		ResType = ResType_TileSet;

		GetStringName(128);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		xsize = GetExpression();		// xsize

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		ysize = GetExpression();		// ysize

		WriteWord(xsize);
		WriteWord(ysize);

		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading tileset file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		for (n=0;n<filelen;n++)
			WriteByte(filemem[n]);

		Free_File(filemem);

		infoprintf("%d: Tileset '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen);
		return 1;
	}

//------------------------------------
//
//------------------------------------

// ResType_TileMap = 8
// ushort mapWidth, mapHeight
// ushort map[mapWidth*mapHeight]

	if (QToken(".tilemap"))			// filename
	{
		int xsize,ysize;

		SkipWhiteSpace();

		ResType = ResType_TileMap;

		GetStringName(128);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		xsize = GetExpression();		// xsize

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		ysize = GetExpression();		// ysize

		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading tilemap file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		if (filelen != (xsize * ysize * 2))
		{
			Error(Error_Fatal, "%d: Tilemap '%s' xy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen);
			return 1;
		}

		WriteWord(xsize);
		WriteWord(ysize);

		for (n=0;n<filelen;n++)
			WriteByte(filemem[n]);

		Free_File(filemem);

		infoprintf("%d: Tilemap '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen);
		return 1;


	}

//------------------------------------
//
//------------------------------------

	if (QToken(".image"))			// filename
	{
		SkipWhiteSpace();

		ResType = ResType_Image;

		GetStringName(128);

/*
		spr_cx = spr_cy = 0;

		SkipWhiteSpace();

		if (QToken(","))
		{
			spr_cx = GetExpression();		// cx

			SkipWhiteSpace();
			NeedToken(",");
			SkipWhiteSpace();

			spr_cy = GetExpression();		// cy
		}

		WriteWord(spr_cx);
		WriteWord(spr_cy);
*/
		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading image file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		// write the length
		//WriteEncodedInt(filelen);

		for (n=0;n<filelen;n++)
			WriteByte(filemem[n]);

		Free_File(filemem);

		infoprintf("%d: Image '%s' cxy %d,%d size %d\n", CurrentResource, Name, spr_cx, spr_cy, filelen);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".sprite"))			// index, x,y,w,h,cx,cy
	{
		ResType = ResType_Sprite;

		SkipWhiteSpace();

		spr_ind = v = GetExpression();		// ind
		WriteWord(v);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		spr_x = v = GetExpression();		// x
		WriteWord(v);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		spr_y = v = GetExpression();		// y
		WriteWord(v);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		spr_w = v = GetExpression();		// w
		WriteWord(v);

		SkipWhiteSpace();
		NeedToken(",");
		SkipWhiteSpace();

		spr_h = v = GetExpression();		// h
		WriteWord(v);

		spr_cx = spr_cy = 0;

		SkipWhiteSpace();

		if (QToken(","))
		{
			spr_cx = (short)GetExpression();		// cx

			SkipWhiteSpace();
			NeedToken(",");
			SkipWhiteSpace();

			spr_cy = (short)GetExpression();		// cy
		}

		WriteWord(spr_cx);
		WriteWord(spr_cy);


		infoprintf("%d: Sprite ind %d, xy %d,%d, wh %d,%d cxy %d,%d\n",
			CurrentResource, spr_ind, spr_x, spr_y, spr_w, spr_h, spr_cx, spr_cy);

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".end"))
	{
		SkipLine();
//		EndComp = 1;
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".eof"))
	{
		SkipLine();
		EndComp = 1;
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".parseheader"))
	{
		GetStringName(128);
		ReadAndParseHeaders(Name);
		return 1;
	}

//------------------------------------
// Other directives
//------------------------------------

	if (QToken(".set"))
	{
		if (QToken("$"))
		{
			char VarName[256];

			// Accept a string

			GetName();							// Get the new type Name
			strcpy(VarName, Name);
			NeedToken("=");
			GetStringName(128);

			printf("string set %s = '%s'\n", VarName, Name);

			RedefENumString(VarName, Name);
			return 1;
		}

		GetName();							// Get the new type Name
		NeedToken("=");
		RedefENum(Name, GetExpression());
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".debug"))
	{
		DEBUG = (short)GetExpression();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".info"))
	{
		INFO = (short)GetExpression();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".list"))
	{
		LIST = (short)GetExpression();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".show"))
	{
		int exp = GetExpression();

		printf("%d",exp);

		if (!Token(";"))
			printf("\n");

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".print") || QToken(".?"))
	{
		int exp;
		char c;

		if (Token("\""))
		{
			while(1)
			{
				c = *FilePtr;

				if (c == 0 || c == '"')
					break;

				printf("%c",c);

				FilePtr++;
			}

			NeedToken("\"");

			if (!Token(";"))
				printf("\n");

			return 1;
		}

		exp = GetExpression();

		printf("%d",exp);

		if (!Token(";"))
			printf("\n");

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".if"))
	{
		if (!GetExpression())
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".ifdef"))
	{
		GetName();							// Get the new type Name
		SkipWhiteSpace();

		if (!SymbolExists(Name, section_Script, -1))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}


//------------------------------------
//
//------------------------------------

	if (QToken(".ifndef"))
	{
		GetName();							// Get the new type Name
		SkipWhiteSpace();

		if (SymbolExists(Name, section_Script, -1))
		{
			if (NextToken("{"))
			{
				SkipPair('{','}');
			}
		}
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".while"))
	{

		if (GetExpression())
		{
			FilePtr = SearchScope(FilePtr);
		}
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".enum"))
	{
		AsmEnums();
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".include"))			// filename
	{
		SkipWhiteSpace();

		GetStringName(128);

		if(Do_Export_Dependencies && Pass == 2) {
			ExportFileDependency(Name);
		}

		filemem = Open_FileAlloc(AddRelPrefix(Name));

		if (!filemem)
		{
			Error(Error_Fatal, "Error reading include file '%s'", Name);
			return 1;
		}

		filelen = FileAlloc_Len();

		for (n=0;n<filelen;n++)
			WriteByte(filemem[n]);

		Free_File(filemem);

		infoprintf("bin include '%s' size %d\n", Name, filelen);
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".varint"))
	{
		do
		{
			imm = GetExpression();					// Get the number
			WriteEncodedInt(imm);
		}
		while (QToken(","));

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".varsint"))
	{
		do
		{
			imm = GetExpression();					// Get the number
			WriteEncodedSignedInt(imm);
		}
		while (QToken(","));

		return 1;

	}

//------------------------------------
//
//------------------------------------

	if (QToken(".byte"))
	{
		do
		{
			imm = GetExpression();					// Get the number
			WriteByte(imm);
		}
		while (QToken(","));

		return 1;

	}

//------------------------------------
//
//------------------------------------

	if (QToken(".half"))
	{

		do
		{
			imm = GetExpression();					// Get the number

			WriteWord(imm);
		}
		while (QToken(","));

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".word"))
	{
		do
		{
			imm = GetExpression();				// Get the number

			WriteLong(imm);
		}
		while (QToken(","));
		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".fill"))
	{
		imm = GetExpression();					// Get the number

		if (!imm)
			return 1;

		NeedToken(",");

		v = GetExpression();

		do
		{
			WriteByte(v);
		}
		while(--imm);

		return 1;
	}


//------------------------------------
//
//------------------------------------

	if (QToken(".pstring"))
	{
		int dataStart;
		int len;

		// Write length byte

		WriteByte(0);

		// Get current data location

		dataStart = DataIP;

		// read string to mem

		GetStrings();

		// find the string length

		len = DataIP - dataStart;

		if (len > 255)
		{
			Error(Error_Skip, "pstring is longer that 255 chars\n");
			return 1;
		}

		// Patch the string length

		ArraySet(&DataMemArray, dataStart-1, len);


		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".cstring"))
	{
		GetStrings();
		WriteByte(0);

		return 1;
	}

//------------------------------------
//
//------------------------------------

	if (QToken(".string"))
	{
		GetStrings();
		return 1;
	}

//------------------------------------
//
//------------------------------------

// Error


	GetAsmName();
	Error(Error_Fatal, "Illegal resource directive '%s'",Name);

	return 0;
}
Beispiel #10
0
// Parse element node
// Returns true if parsing level complete
bool
XMLParser::ParseElement()
{
  CString elementName;
  CString attributeName;
  WhiteSpace elemspace = m_whiteSpace;
  // Skip leading '<'
  m_pointer++;

  if(GetIdentifier(elementName))
  {
    // Creating an identifier
    CString namesp = SplitNamespace(elementName);
    MakeElement(namesp,elementName);

    if(isspace(*m_pointer))
    {
      SkipWhiteSpace();
      // See if we must get attributes
      while(GetIdentifier(attributeName))
      {
        SkipWhiteSpace();
        NeedToken('=');
        CString value = GetQuotedString();
        SkipWhiteSpace();

        // Adding an attribute
        m_message->SetAttribute(m_lastElement,attributeName,value);

        // In special case "[xml:]space", we must change whitespace preserving
        if(attributeName.Compare("space") == 0)
        {
          elemspace = value.Compare("preserve") == 0 ? WhiteSpace::PRESERVE_WHITESPACE 
                                                     : WhiteSpace::COLLAPSE_WHITESPACE;
        }
      }
    }
    if(*m_pointer && strncmp((const char*)m_pointer,"/>",2) == 0)
    {
      m_pointer += 2;
      return false;
    }
    if(*m_pointer == '>')
    {
      // Closing of the element
      m_pointer++;

      SkipOuterWhiteSpace();
      if(*m_pointer && *m_pointer == '<')
      {
        // Push element and space-preserving and parse next level
        XMLElement* level = m_element;
        WhiteSpace  space = m_whiteSpace;

        m_whiteSpace = elemspace;
        m_element = m_lastElement;
        ParseLevel();
        m_element = level;
        m_whiteSpace = space;
      }
      else
      {
        ParseText();
      }
    }
    // Need to see ending of the element
    CString closing;
    NeedToken('<');
    NeedToken('/');
    if(GetIdentifier(closing))
    {
      CString closingNS = SplitNamespace(closing);
      if(elementName.Compare(closing) == 0)
      {
        if(namesp.Compare(closingNS))
        {
          CString error;
          error.Format("Element [%s] has closing tag with different namespace.",elementName.GetString());
          SetError(XmlError::XE_MissingEndTag,(uchar*)error.GetString());
        }
        NeedToken('>');
        SkipOuterWhiteSpace();
        // Parsing level complete
        return strncmp((const char*)m_pointer,"</",2) == 0;
      }
      CString error;
      error.Format("Element [%s] has incorrect closing tag [%s]",elementName.GetString(),closing.GetString());
      SetError(XmlError::XE_MissingEndTag,(uchar*)error.GetString());
    }
    else
    {
      CString error;
      error.Format("Missing end tag for element: %s",elementName.GetString());
      SetError(XmlError::XE_MissingEndTag,(uchar*)error.GetString());
    }
  }
  // End of a list of elements
  if(*m_pointer == '/')
  {
    m_pointer--;
    return true;
  }
  CString error;
  error.Format("Missing ending of XML element: %s",elementName.GetString());
  SetError(XmlError::XE_MissingElement,(uchar*)error.GetString());
  return false;
}
Beispiel #11
0
// Parse the declaration of form:
// <?xml version="1.0" encoding="utf-8" space="preserve" standalone="yes"?>
void
XMLParser::ParseDeclaration()
{
  CString attributeName;

  // Initially set to empty.
  // The 'encoding' could have been set by the 
  // HTTP content type 'charset' attribute, so we leave it for now.
  m_message->m_version.Empty();
  m_message->m_standalone.Empty();

  // Skip over "<?xml"
  m_pointer += 5;

  SkipWhiteSpace();
  while(GetIdentifier(attributeName))
  {
    SkipWhiteSpace();
    NeedToken('=');
    CString value = GetQuotedString();
    SkipWhiteSpace();

    // Remove possibly "xml" namespace
    CString namesp = SplitNamespace(attributeName);

    if(attributeName.Compare("version") == 0)
    {
      if(value.Compare("1.0") == 0)
      {
        m_message->m_version = value;
      }
    }
    else if(attributeName.Compare("encoding") == 0)
    {
      m_message->m_encoding = XMLEncoding::ENC_Plain;
      if(value.CompareNoCase("utf-8") == 0)
      {
        m_utf8 = true; 
        m_message->m_encoding = XMLEncoding::ENC_UTF8;
      }
      else if(value.Left(6).CompareNoCase("utf-16") == 0)
      {
        // Works for "UTF-16", "UTF-16LE" and "UTF-16BE" as of RFC 2781
        // Although one should only specify "utf-16" without the endianess
        m_message->m_encoding = XMLEncoding::ENC_UTF16;
      }
      else if(value.CompareNoCase("iso-8859-1") == 0)
      {
        m_message->m_encoding = XMLEncoding::ENC_ISO88591;
      }
      else
      {
        // If it was send in the current codepage, use that
        if(GetACP() == (UINT) CharsetToCodepage(value))
        {
          m_message->m_encoding = XMLEncoding::ENC_Plain;
        }
        else
        {
          CString message;
          message.Format("Unknown XML character encoding: %s",value.GetString());
          SetError(XmlError::XE_UnknownEncoding,(uchar*)message.GetString());
        }
      }
    }
    else if(attributeName.Compare("standalone") == 0)
    {
      if(value.CompareNoCase("yes") == 0 || value.CompareNoCase("no") == 0)
      {
        m_message->m_standalone = value;
      }
    }
    else
    {
      CString message;
      message.Format("Unknown header attributes [%s=%s]",attributeName.GetString(),value.GetString());
      SetError(XmlError::XE_HeaderAttribs,(uchar*)message.GetString());
    }
    if(!namesp.IsEmpty() && namesp.Compare("xml"))
    {
      CString message;
      message.Format("Unknown root namespace [%s] for attribute [%s]",namesp.GetString(),attributeName.GetString());
      SetError(XmlError::XE_HeaderAttribs,(uchar*)message.GetString());
    }
  }
  // Skip over end of declaration
  NeedToken('?');
  NeedToken('>');
  SkipWhiteSpace();
}