예제 #1
0
파일: NBT.cpp 프로젝트: zzh8829/PythonCraft
	TagBase* ReadNamedTag(istream& input)
	{
		uint8_t typ = Read<uint8_t>(input);
		if(typ == 0) return NewTag(0,"");
		TagBase* tag = NewTag(typ,ReadString(input));
		tag->read(input);
		return tag;
	}
예제 #2
0
static long
ParseTagData( char * buffer, TagPtr * tag )
{
    long   length;
    TagPtr tmpTag;

    length = FixDataMatchingTag(buffer, kXMLTagData);
    if (length == -1) return -1;
    
    tmpTag = NewTag();
    if (tmpTag == 0) return -1;
    
	//printf("ParseTagData unimplimented\n");
	//printf("Data: %s\n", buffer);
	//	getchar();
	
	// TODO: base64 decode
	
	char* string = NewSymbol(buffer);
    tmpTag->type = kTagTypeData;
    tmpTag->string = string;
    tmpTag->tag = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
    tmpTag->tagNext = 0;
    
    *tag = tmpTag;
    
    return length;
}
예제 #3
0
static long ParseTagInteger(char *buffer, TagPtr * tag)
{
    long length = FixDataMatchingTag(buffer, kXMLTagInteger);

    if (length == -1) {
        return -1;
    }

    TagPtr tmpTag = NewTag();

    if (tmpTag == 0) {
        return -1;
    }

    long integer = 0;

    tmpTag->type = kTagTypeInteger;
    tmpTag->string = (char *)integer;
    tmpTag->tag = 0;
    tmpTag->tagNext = 0;

    *tag = tmpTag;

    return length;
}
예제 #4
0
static long
ParseTagString( char * buffer, TagPtr * tag )
{
    long   length;
    char * string;
  
    length = FixDataMatchingTag(buffer, kXMLTagString);
    if (length == -1) return -1;
  
	TagPtr tmpTag = NewTag();
    if (tmpTag == 0) return -1;
  
    string = NewSymbol(buffer);
    if (string == 0)
    {
        XMLFreeTag(tmpTag);
        return -1;
    }
  
    tmpTag->type = kTagTypeString;
    tmpTag->string = string;
    tmpTag->tag = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
    tmpTag->tagNext = 0;
  
    *tag = tmpTag;
    return length;
}
예제 #5
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagData(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length;
	TagPtr		tmpTag;

	Status = FixDataMatchingTag(buffer, kXMLTagData,&length);
	if (EFI_ERROR(Status))
		return Status;

	tmpTag = NewTag();
	if (tmpTag == 0) 
		return EFI_UNSUPPORTED;
//Slice - correction as Apple 2003
	CHAR8* string = NewSymbol(buffer);
	tmpTag->type = kTagTypeData;
	tmpTag->string = string;
	tmpTag->tag = NULL;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
	tmpTag->tagNext = NULL;

	*tag = tmpTag;
	*lenPtr=length;

	return EFI_SUCCESS;
}
예제 #6
0
static long
ParseTagData( char * buffer, TagPtr * tag )
{
    int actuallen = 0;
    long   length;
    TagPtr tmpTag;

    length = FixDataMatchingTag(buffer, kXMLTagData);
    if (length == -1) return -1;
    
    tmpTag = NewTag();
    if (tmpTag == 0) return -1;
    
	//printf("ParseTagData unimplimented\n");
	//printf("Data: %s\n", buffer);
	//	getchar();

	char* string = BASE64Decode(buffer, strlen(buffer), &actuallen);
    tmpTag->type = kTagTypeData;
    tmpTag->string = string;
    tmpTag->tag = 0;
	tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0;
    tmpTag->tagNext = 0;
    
    *tag = tmpTag;
    
    return length;
}
예제 #7
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagString(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length;
	CHAR8*		string;
	TagPtr		tmpTag;

	Status = FixDataMatchingTag(buffer, kXMLTagString,&length);
	if (EFI_ERROR(Status))
		return Status;

	tmpTag = NewTag();
	if (tmpTag == NULL) 
		return EFI_UNSUPPORTED;

	string = NewSymbol(buffer);
	if (string == NULL)
	{
		FreeTag(tmpTag);
		return EFI_UNSUPPORTED;
	}

	tmpTag->type = kTagTypeString;
	tmpTag->string = string;
	tmpTag->tag = NULL;
	tmpTag->tagNext = NULL;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
	*tag = tmpTag;
	*lenPtr=length;

	return EFI_SUCCESS;
}
예제 #8
0
static long
ParseTagDate( char * buffer, TagPtr * tag )
{
    long   length;
    TagPtr tmpTag;
    
    length = FixDataMatchingTag(buffer, kXMLTagDate);
    if (length == -1) return -1;
    
    tmpTag = NewTag();
    if (tmpTag == 0) return -1;
    
	printf("ParseTagDate unimplimented\n");
	getchar();
	
    tmpTag->type = kTagTypeDate;
    tmpTag->string = 0;
    tmpTag->tag = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
    tmpTag->tagNext = 0;
    
    *tag = tmpTag;
    
    return length;
}
예제 #9
0
static long ParseTagInteger(char *buffer, TagPtr *tag)
{
  long   length;
  char   *intString;
  TagPtr tmpTag;
  
  length = FixDataMatchingTag(buffer, kXMLTagInteger);
  if (length == -1) return -1;
  
  tmpTag = NewTag();
  if (tmpTag == 0) return -1;
  
  intString = NewSymbol(buffer);
  if (intString == 0) {
    FreeTag(tmpTag);
    return -1;
  }
  
  tmpTag->type = kTagTypeInteger;
  tmpTag->string = intString;
  tmpTag->tag = 0;
  tmpTag->tagNext = 0;
  
  *tag = tmpTag;
  
  return length;
}
Ttk_Tag Ttk_GetTag(Ttk_TagTable tagTable, const char *tagName)
{
    int isNew = 0;
    Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
	&tagTable->tags, tagName, &isNew);

    if (isNew) {
	tagName = Tcl_GetHashKey(&tagTable->tags, entryPtr);
	Tcl_SetHashValue(entryPtr, NewTag(tagTable,tagName));
    }
    return Tcl_GetHashValue(entryPtr);
}
예제 #11
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagList( CHAR8* buffer, TagPtr * tag, UINT32 type, UINT32 empty, UINT32* lenPtr)
{
	EFI_STATUS	Status=EFI_SUCCESS;
	UINT32		pos;
	TagPtr		tagList;
	TagPtr		tmpTag;
	UINT32		length=0;

	tagList = NULL;
	pos = 0;

	if (!empty)
	{
		while (TRUE)
		{
			Status = XMLParseNextTag(buffer + pos, &tmpTag,&length);
			if (EFI_ERROR(Status)) 
				break;

			pos += length;

			if (tmpTag == NULL) 
				break;

			tmpTag->tagNext = tagList;
			tagList = tmpTag;
		}

		if (EFI_ERROR(Status))
		{
			FreeTag(tagList);
			return Status;
		}
	}

	tmpTag = NewTag();
	if (tmpTag == NULL)
	{
		FreeTag(tagList);
		return EFI_UNSUPPORTED;
	}

	tmpTag->type = type;
	tmpTag->string = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start : 0;
	tmpTag->tag = tagList;
	tmpTag->tagNext = 0;

	*tag = tmpTag;
	*lenPtr=pos;
	return Status;
}
예제 #12
0
파일: fb2xml.cpp 프로젝트: UncleRus/fb2edit
bool FbXmlHandler::NodeHandler::doStart(const QString &name, const QXmlAttributes &attributes)
{
    if (m_handler) return m_handler->doStart(name, attributes);
    m_handler = NewTag(name, attributes);
    if (m_handler) {
        if (m_handler->m_closed) {
            delete m_handler;
            m_handler = NULL;
        }
        return true;
    }
    m_handler = new NodeHandler(name);
    return true;
}
예제 #13
0
static long ParseTagList(char *buffer, TagPtr * tag, long type, long empty)
{
    long length, pos = 0;

    TagPtr tmpTag, tagList = 0;

    if (!empty) {
        while (1) {
            length = XMLParseNextTag(buffer + pos, &tmpTag);

            if (length == -1) {
                break;
            }

            pos += length;

            if (tmpTag == 0) {
                break;
            }

            tmpTag->tagNext = tagList;
            tagList = tmpTag;
        }

        if (length == -1) {
            XMLFreeTag(tagList);

            return -1;
        }
    }

    tmpTag = NewTag();

    if (tmpTag == 0) {
        XMLFreeTag(tagList);

        return -1;
    }

    tmpTag->type = type;
    tmpTag->string = 0;
    tmpTag->tag = tagList;
    tmpTag->tagNext = 0;

    *tag = tmpTag;

    return pos;
}
예제 #14
0
static long ParseTagBoolean(char *buffer, TagPtr *tag, long type)
{
  TagPtr tmpTag;
  
  tmpTag = NewTag();
  if (tmpTag == 0) return -1;
  
  tmpTag->type = type;
  tmpTag->string = 0;
  tmpTag->tag = 0;
  tmpTag->tagNext = 0;
  
  *tag = tmpTag;
  
  return 0;
}
예제 #15
0
static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty)
{
  long   length, pos;
  TagPtr tagList, tmpTag = (TagPtr)-1;
  
  tagList = 0;
  pos = 0;
  
  if (!empty) {
    while (1) {
      tmpTag = (TagPtr)-1;
      length = ParseNextTag(buffer + pos, &tmpTag);
      if (length == -1) break;
      pos += length;

      // detect end of list
      if (tmpTag == 0) break;

      // if we made a new tag, insert into list
      if (tmpTag != (TagPtr)-1) {
        tmpTag->tagNext = tagList;
        tagList = tmpTag;
      }
    }
    
    if (length == -1) {
      FreeTag(tagList);
      return -1;
    }
  }
  
  tmpTag = NewTag();
  if (tmpTag == 0) {
    FreeTag(tagList);
    return -1;
  }
  
  tmpTag->type = type;
  tmpTag->string = 0;
  tmpTag->tag = tagList;
  tmpTag->tagNext = 0;
  
  *tag = tmpTag;
  
  return pos;
}
예제 #16
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagBoolean(CHAR8* buffer, TagPtr * tag, UINT32 type,UINT32* lenPtr)
{
	TagPtr tmpTag;

	tmpTag = NewTag();
	if (tmpTag == NULL) 
		return EFI_UNSUPPORTED;

	tmpTag->type = type;
	tmpTag->string = NULL;
	tmpTag->tag = NULL;
	tmpTag->tagNext = NULL;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;

	*tag = tmpTag;
	*lenPtr=0;
	return EFI_SUCCESS;
}
예제 #17
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagKey( char * buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length;
	UINT32		length2;
	CHAR8*		string;
	TagPtr		tmpTag;
	TagPtr		subTag;

	Status = FixDataMatchingTag(buffer, kXMLTagKey,&length);
	if (EFI_ERROR(Status)) 
		return Status;

	Status = XMLParseNextTag(buffer + length, &subTag,&length2);
	if (EFI_ERROR(Status)) 
		return Status;

	tmpTag = NewTag();
	if (tmpTag == NULL)
	{
		FreeTag(subTag);
		return EFI_UNSUPPORTED;
	}

	string = NewSymbol(buffer);
	if (string == NULL)
	{
		FreeTag(subTag);
		FreeTag(tmpTag);
		return EFI_UNSUPPORTED;
	}

	tmpTag->type = kTagTypeKey;
	tmpTag->string = string;
	tmpTag->tag = subTag;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
	tmpTag->tagNext = 0;

	*tag = tmpTag;
	*lenPtr=length + length2;

	return EFI_SUCCESS;
}
예제 #18
0
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value)
{
    if (!dict || dict->type != kTagTypeDict) return false;

    TagPtr tmpTag;
    char* string;

    tmpTag = NewTag();
    if (tmpTag == 0)
    {
        return false;
    }
    
    string = NewSymbol(key);
    if (string == 0)
    {
        XMLFreeTag(tmpTag);
        return false;
    }
    
    tmpTag->type = kTagTypeKey;
    tmpTag->string = string;
    tmpTag->tag = value;
	tmpTag->offset = 0;
    tmpTag->tagNext = 0;
    
    TagPtr tagList = dict->tag;
    if(!tagList)
    {
        // First tag
        dict->tag = tmpTag;
        return true;
    }
    while(tagList && tagList->tagNext) tagList = tagList->tagNext;
    if(tagList)
    {
        tagList->tagNext = tmpTag;
        return true;
    }

    XMLFreeTag(tmpTag);
    return false;
}
예제 #19
0
static long ParseTagKey(char *buffer, TagPtr * tag)
{
    long length = FixDataMatchingTag(buffer, kXMLTagKey);

    if (length == -1) {
        return -1;
    }

    TagPtr subTag;

    long length2 = XMLParseNextTag(buffer + length, &subTag);

    if (length2 == -1) {
        return -1;
    }

    TagPtr tmpTag = NewTag();

    if (tmpTag == 0) {
        XMLFreeTag(subTag);

        return -1;
    }

    char *string = NewSymbol(buffer);

    if (string == 0) {
        XMLFreeTag(subTag);
        XMLFreeTag(tmpTag);

        return -1;
    }

    tmpTag->type = kTagTypeKey;
    tmpTag->string = string;
    tmpTag->tag = subTag;
    tmpTag->tagNext = 0;

    *tag = tmpTag;

    return length + length2;
}
예제 #20
0
static long ParseTagDate(char *buffer, TagPtr *tag)
{
  long   length;
  TagPtr tmpTag;
  
  length = FixDataMatchingTag(buffer, kXMLTagDate);
  if (length == -1) return -1;
  
  tmpTag = NewTag();
  if (tmpTag == 0) return -1;
  
  tmpTag->type = kTagTypeDate;
  tmpTag->string = 0;
  tmpTag->tag = 0;
  tmpTag->tagNext = 0;
  
  *tag = tmpTag;
  
  return length;
}
예제 #21
0
static long ParseTagKey(char *buffer, TagPtr *tag)
{
  long   length, length2;
  char   *string;
  TagPtr tmpTag, subTag = (TagPtr)-1;  // eliminate possible stale tag
  
  length = FixDataMatchingTag(buffer, kXMLTagKey);
  if (length == -1) return -1;
  
  length2 = ParseNextTag(buffer + length, &subTag);
  if (length2 == -1) return -1;

  // XXXX revisit 4063982 if FreeTag becomes real
  if(subTag == (TagPtr)-1)
    subTag = NULL;
  
  tmpTag = NewTag();
  if (tmpTag == 0) {
    FreeTag(subTag);
    return -1;
  }
  
  string = NewSymbol(buffer);
  if (string == 0) {
    FreeTag(subTag);
    FreeTag(tmpTag);
    return -1;
  }
  
  tmpTag->type = kTagTypeKey;
  tmpTag->string = string;
  tmpTag->tag = subTag;
  tmpTag->tagNext = 0;
  
  *tag = tmpTag;
  
  return length + length2;
}
예제 #22
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagDate(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length;
	TagPtr		tmpTag;
	
	Status = FixDataMatchingTag(buffer, kXMLTagDate,&length);
	if (EFI_ERROR(Status))
		return Status;


	tmpTag = NewTag();
	if (tmpTag == 0) return EFI_UNSUPPORTED;

	tmpTag->type = kTagTypeDate;
	tmpTag->string = NULL;
	tmpTag->tag = NULL;
	tmpTag->tagNext = NULL;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;

	*tag = tmpTag;

	return length;
}
예제 #23
0
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
{
	long   length, pos;
	char * tagName;
	
	length = GetNextTag(buffer, &tagName, 0);
	if (length == -1) return -1;
	
	pos = length;
	if (!strncmp(tagName, kXMLTagPList, 6))
	{
		length = 0;
	}
	/***** dict ****/
	else if (!strcmp(tagName, kXMLTagDict))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
	}
	else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
	}
	else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
	}
	/***** key ****/
	else if (!strcmp(tagName, kXMLTagKey))
	{
		length = ParseTagKey(buffer + pos, tag);
	}
	
	/***** string ****/
	else if (!strcmp(tagName, kXMLTagString))
	{
		length = ParseTagString(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
	{
		// TODO: save tag if if found
		if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
		{
			// ID=
			int id = 0;
			int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringID error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			length = ParseTagString(buffer + pos, tag);
			
			SaveRefString(buffer + pos, id);
		}
		else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
		{
			// IDREF=
			int id = 0;
			int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringIDREF error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			char* str = GetRefString(id);

			TagPtr tmpTag = NewTag();
			tmpTag->type = kTagTypeString;
			tmpTag->string = str;
			tmpTag->tag = 0;
			tmpTag->tagNext = 0;
			tmpTag->offset = buffer_start ? buffer - buffer_start  + pos : 0;
			*tag = tmpTag;
			
			length = 0;
			//printf("Located IDREF, id = %d, string = %s\n", id, str);
		}
	}
	
	/***** integer ****/
	else if (!strcmp(tagName, kXMLTagInteger))
	{
		length = ParseTagInteger(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
	{
		if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
		{
			// ID=
			int id = 0;
			int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseIntegerID error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			length = ParseTagInteger(buffer + pos, tag);
			
			SaveRefString((*tag)->string, id);
		}
		else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
		{
			// IDREF=
			int id = 0;
			int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
			while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
			tagName[cnt] = 0;
			char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
			while(*val)
			{
				if ((*val >= '0' && *val <= '9'))	// 0 - 9
				{
					id = (id * 10) + (*val++ - '0');
				}
				else
				{
					printf("ParseStringIDREF error (0x%x)\n", *val);
					getchar();
					return -1;
				}
			}
			int integer = (int)GetRefString(id);
			
			TagPtr tmpTag = NewTag();
			tmpTag->type = kTagTypeInteger;
			tmpTag->string = (char*) integer;
			tmpTag->tag = 0;
			tmpTag->tagNext = 0;
			tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
			
			*tag = tmpTag;
			
			length = 0;
			//printf("Located IDREF, id = %d, string = %s\n", id, str);
		}
		else
		{
			length = ParseTagInteger(buffer + pos, tag);
		}
	}
	
	/***** data ****/
	else if (!strcmp(tagName, kXMLTagData))
	{
		length = ParseTagData(buffer + pos, tag);
	}
	else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
	{
		length = ParseTagData(buffer + pos, tag);
	}
	else if (!strcmp(tagName, kXMLTagDate))
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** date ****/
	else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** false ****/
	else if (!strcmp(tagName, kXMLTagFalse))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
	}
	/***** true ****/
	else if (!strcmp(tagName, kXMLTagTrue))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
	}
	
	/***** array ****/
	else if (!strcmp(tagName, kXMLTagArray))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
	}
	else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
	}
	else if (!strcmp(tagName, kXMLTagArray "/"))
	{
		length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
	}
	
	/***** unknown ****/
	else
	{
		*tag = 0;
		length = 0;
	}
	
	if (length == -1) return -1;
	
	return pos + length;
}
예제 #24
0
void CChangeTag::OnOK() 
  {
  if (m_ReadOnly)
    CDialog::OnOK();

  //gs_pAccWnd->CloseAccessData(False, False, True);
  //gs_pAccWnd->CloseWnd();
  UpdateData(TRUE);
  Strng OldTag(m_OldTag.GetBuffer(0));
  OldTag.Trim(" \t\n\r\v\f");
  Strng NewTag(m_NewTag.GetBuffer(0));
  if (OldTag.XStrICmp(NewTag)!=0)
    {
    CWaitCursor Wait;
    BOOL ok = TRUE;
    if (TaggedObject::ValidateTagChanged(NewTag))
      {
      Strng s;
      s.Set("New tag '%s' is illegal and has been altered to '%s'\nContinue?", (const char*)m_NewTag, NewTag());
      ok = (AfxMessageBox(s(), MB_YESNO|MB_ICONQUESTION)==IDYES);
      if (ok)
        LogNote("ChangeTag", 0, "New tag '%s' altered to '%s'", (const char*)m_NewTag, NewTag());
      }
    if (ok && !gs_pPrj->AllGrfLoaded())
      {
      Strng s;
      s.Set("All the graphics pages have not been loaded!\nTag '%s' may not be changed in the graphics window.\nContinue?", OldTag());
      ok = (AfxMessageBox(s(), MB_YESNO|MB_ICONEXCLAMATION|MB_DEFBUTTON2)==IDYES);
      }
    if (ok)
      {
      pStatusBar->SetMsg("Attempting to change tag %s to %s", OldTag(), NewTag());
      int Err = gs_Exec.ChangeTag(OldTag(), NewTag());
      Strng Txt;
      switch (Err)
        {
        case EOCT_NOTFOUND:
          Txt.Set("Tag %s not found", OldTag());
          break;
        case EOCT_DUPLICATE:
          Txt.Set("Duplicate Tag %s", NewTag());
          break;
        case EOCT_FAILED:
          Txt.Set("FAILURE %s", OldTag());
          break;
        case EOCT_NULLTAG:
          Txt.Set("Valid (not blank) tags must be specified");
          break;
        case EOCT_INVALIDTAG:
          Txt.Set("Valid (all characters must be legal) tags must be specified");
          break;
        case EOCT_BADTAGLEN:
          Txt.Set("New tag length is too long");
          break;
        case EOCT_NOTDIFFER:
          Txt.Set("Tags should differ");
          break;
        case EOCT_NOTALLOWED:
          Txt.Set("Tag %s not allowed to be changed", OldTag());
          break;
        case EOCT_DRVNOTALLOWED:
          Txt.Set("Tag %s is referenced by a driver and cannot be changed while solving", OldTag());
          break;
        case EOCT_ARCNOTALLOWED:
          Txt.Set("Tag %s is referenced by the acrhiver and cannot be changed while solving", OldTag());
          break;
        case EOCT_DONE:
          CExploreScd::RefreshIt(true); 
          gs_AccessWnds.CloseAccessData(-1, False, False, True);
          gs_AccessWnds.CloseWnd(-1);
          for (int a=0; a<NAccessWnds; a++)
            {
            if (!fCallAccess && gs_AccessWnds.CurTag(a) && strlen(gs_AccessWnds.CurTag(a))>0 && _stricmp(gs_AccessWnds.CurTag(a), OldTag())==0)
              {
              fCallAccess = 1;
              break;
              }
            }
          if (fCallAccess)
            {
            char* pTxt = new char[NewTag.Len()+1];
            strcpy(pTxt, NewTag());
            ScdMainWnd()->PostMessage(WMU_TAGACTION, SUB_TAG_ACCESS, (LPARAM)pTxt);
            }

          CDialog::OnOK();
          break;
        }
      if (Txt.Len()>0)
        {
        m_OldTag = OldTag();
        m_NewTag = NewTag();
        MessageBox(Txt(), "Change Tag", MB_OK);
        UpdateData(FALSE);
        }
      else
        pStatusBar->SetMsg("Changed tag %s to %s", OldTag(), NewTag());
      }
    }
  else
    CDialog::OnOK();
  }
예제 #25
0
파일: plist.c 프로젝트: weixu8/Duet
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
{
	EFI_STATUS	Status;
	UINT32		length; 
	UINT32		integer;
	UINT32		size;
	BOOLEAN		negative = FALSE;
	CHAR8*		val = buffer;
	TagPtr tmpTag;
	
	Status = FixDataMatchingTag(buffer, kXMLTagInteger,&length);
	if (EFI_ERROR(Status))
		return Status;

	tmpTag = NewTag();
	if (tmpTag == NULL) 
		return EFI_UNSUPPORTED;
	size = length;
	
	integer = 0;
	if(buffer[0] == '<')
	{
		tmpTag->type = kTagTypeInteger;
		tmpTag->string = 0;
		tmpTag->tag = 0;
		tmpTag->offset =  0;
		tmpTag->tagNext = 0;
		
		*tag = tmpTag;
		length = 0;
		return EFI_SUCCESS;
	}
	if(size > 1 && (val[1] == 'x' || val[1] == 'X'))	// Hex value
	{
		val += 2;
		while(*val)
		{
			if ((*val >= '0' && *val <= '9'))	// 0 - 9
			{
				integer = (integer * 16) + (*val++ - '0');
			}
			else if ((*val >= 'a' && *val <= 'f'))	// a - f
			{
				integer = (integer * 16) + (*val++ - 'a' + 10);
			}
			else if ((*val >= 'A' && *val <= 'F'))	// A - F
			{
				integer = (integer * 16) + (*val++ - 'a' + 10);
			}
			else
			{
//				getchar();
				return EFI_UNSUPPORTED;
			}
		}
	}
	else if ( size )	// Decimal value
	{
		if (*val == '-')
		{
			negative = TRUE;
			val++;
			size--;
		}
		
		for (integer = 0; size > 0; size--)
		{
			if(*val) // UGLY HACK, fix me.
			{
				if (*val < '0' || *val > '9')
				{
//					getchar();
					return EFI_UNSUPPORTED;
				}				
				integer = (integer * 10) + (*val++ - '0');
			}
		}
		
		if (negative)
			integer = -integer;
	}

	
	tmpTag->type = kTagTypeInteger;
	tmpTag->string = (CHAR8*)(UINTN)integer;
	tmpTag->tag = NULL;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
	tmpTag->tagNext = NULL;

	*tag = tmpTag;
	*lenPtr=length;
	return EFI_SUCCESS;
}
예제 #26
0
static long
ParseTagInteger( char * buffer, TagPtr * tag )
{
    long   length, integer;
	bool negative = false;
    TagPtr tmpTag;
	char* val = buffer;
    int size;
	
	if(buffer[0] == '<')
	{
		printf("Warning integer is non existant\n");
		getchar();
		tmpTag = NewTag();
		tmpTag->type = kTagTypeInteger;
		tmpTag->string = 0;
		tmpTag->tag = 0;
		tmpTag->offset =  0;
		tmpTag->tagNext = 0;
		
		*tag = tmpTag;
		
		return 0;
	}
	
    size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
    if (length == -1) return -1;
    
    tmpTag = NewTag();
    if (tmpTag == 0) return -1;
    
    integer = 0;

	if(size > 1 && (val[1] == 'x' || val[1] == 'X'))	// Hex value
	{
		val += 2;
		while(*val)
		{
			if ((*val >= '0' && *val <= '9'))	// 0 - 9
			{
				integer = (integer * 16) + (*val++ - '0');
			}
			else if ((*val >= 'a' && *val <= 'f'))	// a - f
			{
				integer = (integer * 16) + (*val++ - 'a' + 10);
			}
			else if ((*val >= 'A' && *val <= 'F'))	// A - F
			{
				integer = (integer * 16) + (*val++ - 'A' + 10);
			}
			else
			{
				printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
				getchar();
                XMLFreeTag(tmpTag);
				return -1;
			}
		}
	}
	else if ( size )	// Decimal value
	{
		if (*val == '-')
		{
			negative = true;
			val++;
			size--;
		}
		
		for (integer = 0; size > 0; size--)
		{
			if(*val) // UGLY HACK, fix me.
			{
				if (*val < '0' || *val > '9')
				{
					printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
					getchar();
					return -1;
				}
				
				integer = (integer * 10) + (*val++ - '0');
			}
		}
		
		if (negative)
			integer = -integer;
	}
		
    tmpTag->type = kTagTypeInteger;
	tmpTag->string = (char *)integer;
	tmpTag->tag = 0;
	tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
    tmpTag->tagNext = 0;
    
    *tag = tmpTag;
    
    return length;
}
예제 #27
0
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
{
	long   length, pos;
	char * tagName;
	
	length = GetNextTag(buffer, &tagName, 0);
	if (length == -1) return -1;
	
	pos = length;

    /* Check most common cases first, make them fast */

	/***** key ****/
	if (!strcmp(tagName, kXMLTagKey))
	{
		length = ParseTagKey(buffer + pos, tag);
	}

	/***** string ****/
    else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) {
      if (!tagName[kXMLTagStringLen]) /* <string> */
        {
          length = ParseTagString(buffer + pos, tag);
        }
      else if (' ' == tagName[kXMLTagStringLen]) /* <string ...> */
        {
          // TODO: save tag if if found
          if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) /* <string ID="...> */
            {
              // ID=
              int id = 0;
              /* find end of ID string */
              int cnt = kXMLTagStringLen + 1 + kXMLStringIDLen + 2;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + kXMLTagStringLen + 1 + kXMLStringIDLen + 1;
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringID error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              length = ParseTagString(buffer + pos, tag);
			
              SaveRefString(buffer + pos, id);
            }
          else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <string IDREF= ...> */
            {
              // IDREF=
              int id = 0;
              int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringIDREF error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              char* str = GetRefString(id);

              TagPtr tmpTag = NewTag();
              tmpTag->type = kTagTypeString;
              tmpTag->string = str;
              tmpTag->tag = 0;
              tmpTag->tagNext = 0;
              tmpTag->offset = buffer_start ? buffer - buffer_start  + pos : 0;
              *tag = tmpTag;
			
              length = 0;
              //printf("Located IDREF, id = %d, string = %s\n", id, str);
            }
        }
      else /* unrecognized <string...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** integer ****/
    else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) {
      if (!tagName[kXMLTagIntegerLen]) /* <integer> */
        {
          length = ParseTagInteger(buffer + pos, tag);
        }
      else if (' ' == tagName[kXMLTagIntegerLen]) /* <integer ...> */
        {
          if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) /* <integer ID=...> */
            {
              // ID=
              int id = 0;
              int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseIntegerID error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              length = ParseTagInteger(buffer + pos, tag);
			
              SaveRefString((*tag)->string, id);
            }
          else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <integer IDREF=...> */
            {
              // IDREF=
              int id = 0;
              int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
              while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
              tagName[cnt] = 0;
              char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
              while(*val)
                {
                  if ((*val >= '0' && *val <= '9'))	// 0 - 9
                    {
                      id = (id * 10) + (*val++ - '0');
                    }
                  else
                    {
                      printf("ParseStringIDREF error (0x%x)\n", *val);
                      getchar();
                      return -1;
                    }
                }
              int integer = (int)GetRefString(id);
			
              TagPtr tmpTag = NewTag();
              tmpTag->type = kTagTypeInteger;
              tmpTag->string = (char*) integer;
              tmpTag->tag = 0;
              tmpTag->tagNext = 0;
              tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
			
              *tag = tmpTag;
			
              length = 0;
              //printf("Located IDREF, id = %d, string = %s\n", id, str);
            }
          else /* presume <integer ...>...</integer> */
            {
              length = ParseTagInteger(buffer + pos, tag);
            }
        }
      else /* unrecognized <integer...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** false ****/
	else if (!strcmp(tagName, kXMLTagFalse))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
	}

	/***** true ****/
	else if (!strcmp(tagName, kXMLTagTrue))
	{
		length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
	}

	/***** plist ****/
	else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen))
	{
		length = 0;
	}

	/***** dict ****/
    else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) {
      if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') /* <dict.../> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
        }
      else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) /* <dict> or<dict ...> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
        }
      else /* unrecognized <dict...> */
        {
          *tag = 0;
          length = 0;
        }
    }
	
	/***** data ****/
	else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen))
             && (!tagName[kXMLTagDataLen]             /* <data> */
                 || ' ' == tagName[kXMLTagDataLen]))  /* <data ...> */
	{
		length = ParseTagData(buffer + pos, tag);
	}
	
	/***** date ****/
	else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen))
             && (!tagName[kXMLTagDateLen]             /* <date> */
                 || ' ' == tagName[kXMLTagDateLen]))  /* <date ...> */
	{
		length = ParseTagDate(buffer + pos, tag);
	}
	
	/***** array ****/
	else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* <array...> */
      char c = tagName[kXMLTagArrayLen];
      if ('/' == c) /* <array/> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
        }
      else if ('\0' == c || ' ' == c) /* <array> or <array ...> */
        {
          length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
        }
      else /* unrecognized <array...> */
        {
          *tag = 0;
          length = 0;
        }
	}
	/***** unknown ****/
	else
	{
		*tag = 0;
		length = 0;
	}
	
	if (length == -1) return -1;
	
	return pos + length;
}