ErrVal
MVCScalableModifyCode::WritePayloadHeader( enum h264::SEI::MessageType eType, UInt uiSize )
{
	//type
	{
		UInt uiTemp = eType;
		UInt uiByte = 0xFF;	
		while( 0xFF == uiByte )
		{
			uiByte  = (0xFF > uiTemp) ? uiTemp : 0xff;
			uiTemp -= 0xFF;
			RNOK( WriteCode( uiByte, 8 ) );
		}
	}

	// size
	{
		UInt uiTemp = uiSize;
		UInt uiByte = 0xFF;

		while( 0xFF == uiByte )
		{
			uiByte  = (0xFF > uiTemp) ? uiTemp : 0xff;
			uiTemp -= 0xFF;
			RNOK( WriteCode( uiByte, 8 ) );
		}
	}
	return Err::m_nOK;
}
Example #2
0
void ProcComment(char *cmt)
{
	if (PendingText) {
		WriteText(PendingText);
		PendingText = NULL;
	}

	if (EmptyTag) {
		WriteChar('>');
		EmptyTag = false;
	}

	WriteCode("<!-- ");
	WriteText(cmt);
	WriteCode(" -->");
}
ErrVal
MVCScalableTestCode::WriteUVLC( UInt uiValue )
{
	UInt uiLength = 1;
	UInt uiTemp = ++uiValue;
	while( uiTemp != 1 )
	{
		uiTemp >>= 1;
		uiLength += 2;
	}
	RNOK( WriteCode( uiValue, uiLength ) );
	return Err::m_nOK;
}
Example #4
0
void WriteEndFullTag(void)
{
	char *etag = NULL;

	if ((etag = CurrFull->find(CurrDepth)) == NULL)
		return;

	long etype = GetCurrEtype(etag);

	// if pending text, strip trailing space until after end tag
	if (PendingText)
		PendingText = WriteTextWithoutTrailingSpace(PendingText);

	if (DoFull && DoPara) {
		// if ending block, and in wrapped text, close the p
		if ((etype == 1)
		 && WrappedText) {
			WriteCode("</p>");
			WrappedText = false;
		}
	}

	bool skiptag = false;

	if (DoMin && DoPara) {
		if (SkippedPTag
		 && !stricmp(etag, "p")) {
			skiptag = true;
			SkippedPTag = false;
		}
	}

	if (!skiptag) {
		WriteChar('<');
		WriteChar('/');
		WriteText(etag);
		WriteChar('>');
	}

	if (((etag = CurrShort->find(CurrDepth)) != NULL)
	 && !stricmp(etag, CurrElems->find(CurrDepth))) {
		CurrElems->remove(CurrDepth);
		CurrEtypes->remove(CurrDepth);
	}
	CurrFull->remove(CurrDepth);
	CurrShortEnd->remove(CurrDepth);
	CurrShort->remove(CurrDepth);
	LastFullEndDepth = --CurrDepth;
}
Example #5
0
TInt CodeModifier::SafeWriteCode(DProcess* aProcess, TLinAddr aAddress, TInt aSize, TUint aValue, void* aOldValue)
	{
	//Set exception handler. Make sure the boundaries cover the worst case (aSize = 4)
	TIpcExcTrap xt;
	xt.iLocalBase=0;
	xt.iRemoteBase=(TLinAddr)aAddress&~3; //word aligned.
	xt.iSize=sizeof(TInt);
	xt.iDir=1;
	NKern::LockSystem();
	TInt r=xt.Trap(NULL);
	if (r==0)
		{
		r = WriteCode(aAddress, aSize, aValue, aOldValue);
		xt.UnTrap();
		}
	NKern::UnlockSystem();
	return r;	
	}
Example #6
0
bool DefFile::Write()
{
    stream = new std::fstream(fileName.c_str(), std::ios::out);
    //if (stream != NULL)
    {
        WriteName();
        WriteLibrary();
        WriteExports();
        WriteImports();
        WriteDescription();
        WriteStacksize();
        WriteHeapsize();
        WriteCode();
        WriteData();
        WriteSections();
        delete stream;
    }
    return true;
}
static void RunPatch() {
    int vers = 0;

	ULONG gIntVal = GetInt(0x00BE15D4);
    if (gIntVal == 0xa77f40)
		vers = 23;
    else if (GetInt(0x00BE38BC) == 0xa76044)
		vers = 24;
    else
		Bailout("Sorry, your cityofheroes.exe file is not a supported version.");

    InitCoh(vers);

    WriteStrings();
    WriteData();
    RelocateCode();
    FixupCode(vers);
    WriteCode();

    if (vers == 23)
		PatchI23();
    else if (vers == 24)
		PatchI24();
}
Example #8
0
void ProcChar(unl *str, long len)
{
	if (DoMin
	 && DoBlank
	 && EndingPTag) {
		if (str
		 && (*str == '\n')
		 && (*(str + 1) == '\n')) {
			unl *cp = str;
			while (*cp == '\n')
				cp++;
			if (!*cp) { // only returns
				PendingText = (char *) Parser->U32to8Str(str, len);
				return;  // wait for start tag
			}
		}
		WriteCode("</p>");
		EndingPTag = false;
	}

	if (PendingText) {
		WriteText(PendingText);
		PendingText = NULL;
	}

	char *txt = (char *) Parser->U32to8Str(str, len);
	if (!CurrElem) {  // after end of root elem
		WriteText(txt);
		return;
	}

	if (EmptyTag) {
		WriteChar('>');
		EmptyTag = false;
	}

	if (DoFull && DoPara) {
		if (!WrappedText
		 && (CurrEtype == 1)) {  //block
			char *cp = txt;
			while (*cp && isspace(*cp))
				cp++;
			if (*cp) {
				for (char *fcp = txt; fcp < cp; fcp++)
					WriteChar(*fcp);
				txt = cp;
				WriteCode("<p>");
				WrappedText = true;
			}
		}
	}

	// check for wiki chars, double returns, and missing p tags

	if (DoFull) {  // this is all done here
		// for \n\n in a p, insert </p> before and <p> after, keep \n's
		bool blanks = DoBlank && !stricmp(CurrElem, "p");
		char *cp = txt;

		// replace wiki chars with tags
		if (DoWiki) {
			char *wval = NULL;
			char *wtag = NULL;
			char *sch = NULL;
			char *ech = NULL;

			char buf[2];
			buf[1] = '\0';
			char sym = 0;

			while (*cp) {
				if (blanks
				 && (*cp == '\n')
				 && (*(cp + 1) == '\n')
				 && (cp > txt)) {
					char *fret = cp;
					while (*cp == '\n')
						cp++;
					if (!*cp) // trailing returns
						break;
					*fret = '\0';
					WriteText(txt);
					*fret = '\n';
					WriteCode("</p>");
					while (fret < cp) {
						WriteChar('\n');
						fret++;
					}
					WriteCode("<p>");
					txt = cp;
					continue;
				}
				if ((*cp < 0x21) // UTF-8, space, or control
				 || isalnum(*cp)
				 || ((cp != txt)
				  && (*(cp - 1) == '\\'))
				 || (*cp == '\\')) {
					cp++;
					continue;
				}
				// must be symbol, check list
				buf[0] = *cp;  // single char
				if ((wval = CurrW2T->getitem(buf)) != NULL) {
					wtag = NULL;
					sch = NULL;
					ech = NULL;
					ParseWikiTag(wval, &wtag, &sch, &ech);

					sym = *cp;
					if (IsCodeTag(wtag)) { // code tag
						// if already in pre or code don't use tag
						if (InCode > 1) {
							wtag = NULL;
							if (!sch && !ech) {
								cp++;;
								continue;
							}
						}
						else
							InCode++;
					}
					else { //  inline format, not used in code
						// need to know if enclosing tag is pre or what
						// if in pre or code, it is literal ****
						if (InCode) {
							cp++;
							continue;
						}
						// see if preceded or followed by space or punct
						if ((cp != txt)
						 && (*(cp - 1) != '\\')
						 && !isspace(*(cp - 1))
						 && !ispunct(*(cp - 1))
						 && (*(cp + 1) != '\0')
						 && !isspace(*(cp + 1))
						 && !ispunct(*(cp + 1))) {
							cp++;
							continue;
						}
					}
					// is this first or second instance of sym at this level?
					bool start = true;
					UDilist *ip = WikiSymsUsed;
					UDilist *last = ip;
					while ((ip = ip->next) != NULL) {
						if ((ip->id == CurrDepth)
						 && (ip->val == (long) sym)) {
							start = false;
							if (IsCodeTag(wtag))
								InCode -= 2;
							last->next = ip->next;
							delete ip;
							break;
						}
						last = ip;	
					}
					if (start)
						WikiSymsUsed->add((long) sym, CurrDepth);

					// put out preceding text, then start or end tsg and string
					*cp = '\0';
					WriteText(txt);
					if (start) {
						if (wtag) {  // put out tag if needed
							WriteChar('<');
							WriteText(wtag);
							WriteChar('>');
						}
						if (sch && *sch)
							WriteCode(sch);
					}
					else {
						if (ech && *ech)
							WriteCode(ech);
						if (wtag) {  // put out tag if needed
							WriteChar('<');
							WriteChar('/');
							WriteText(wtag);
							WriteChar('>');
						}
					}
					txt = cp + 1;
				}
				cp++;
			}
			// process last text
			PendingText = txt;

		}
		else if (blanks) {
			while (*cp) {
				if ((*cp == '\n')
				 && (*(cp + 1) == '\n')
				 && (cp > txt)) {
					char *fret = cp;
					while (*cp == '\n')
						cp++;
					if (!*cp) // trailing returns
						break;
					*fret = '\0';
					WriteText(txt);
					*fret = '\n';
					WriteCode("</p>");
					while (fret < cp) {
						WriteChar('\n');
						fret++;
					}
					WriteCode("<p>");
					txt = cp;
					continue;
				}
				cp++;
			}
			PendingText = txt;
		}
	}
	else if (DoMin) {  // this is mainly done in StartTag and EndTag, not here
		// replace </p>...<p> with \n...\n.  
		//  If EndingP and then starting p w/o attrs,
		//  replace both tags but don't change line count.
		// replace inline tags with wiki chars in start/end procs
		if (StartTextPend) {  // from start tag
			char *gt = NULL;
			if ((*txt == '<')
			 && ((gt = strchr(txt, '>')) != NULL)
			 && (gt == (txt + strlen(txt) - 1))) {
				WriteCode(WikiLT);
				txt++;
				EndTextPend = ">";
				*gt = '\0';
			}
			else
				WriteCode(StartTextPend);
			StartTextPend = NULL;
		}
	}

	PendingText = txt;
}
Example #9
0
void EndTag(unl *tag, long len)
{
	char *name = (char *) Parser->U32to8Str(tag, len);
	long etype = CurrEtype;

	if (!stricmp(name, "udx")) {
		if (PendingText) {
			WriteText(PendingText);
			PendingText = NULL;
		}
		WriteCode("</udx>");
		CheckUdxEnd();
		return;
	}

	if (DoMin
	 && DoBlank
	 && EndingPTag) {
		if (!SkippedPTag)
			WriteCode("</p>");
		else
			SkippedPTag = false;
		EndingPTag = false;
	}

	if (PendingText) {
		EmptyTag = false;
		PendingText = WriteTextWithoutTrailingSpace(PendingText);
	}

	char *etag = NULL;
	char *shend = NULL;
	bool removed = false;

	if (DoFull) {
		if (((etag = CurrShort->find(CurrDepth)) != NULL)
		 && !stricmp(etag, name)) { // close of replaced short tag
			//removed = true;
			return;
		}
	}
	else if (DoMin) {
		if (((etag = CurrFull->find(CurrDepth)) != NULL)
		 && !stricmp(etag, name)) { // close of replaced full tag
			removed = true;
			CurrFull->remove(CurrDepth);
		}
	}

	bool skiptag = false;

	if (EmptyTag) {
		WriteChar('/');
		WriteChar('>');
		EmptyTag = false;
	}
	else if (!removed) {
		if (DoFull) {
			// see if end tag at same level as pending full end tag
			if (NestingLevel) {
				while (((((shend = CurrShortEnd->find(CurrDepth)) != NULL)
				  && CheckList(shend, name))  // end of CurrFull goes here
				 || (((etag = CurrStype->find(NestingLevel)) != NULL)
				  && !stricmp(name, etag)))
				 && (CurrDepth > NestingLevel))
					WriteEndFullTag();  // close curr open tag if any
				if (((etag = CurrStype->find(CurrDepth)) != NULL)
				 && !stricmp(name, etag)) { // see if closing CurrStype
					long depth = CurrDepth;
					while (LastFullEndDepth > depth) {
						CurrDepth = LastFullEndDepth;
						WriteEndFullTag();  // close last open tag in container if any
					}
					CurrDepth = depth;
					CurrStype->remove(CurrDepth);
					NestingLevel = Nesting->find(CurrDepth);
					Nesting->remove(CurrDepth);
				}
			}
		}
		else if (DoMin) {
			if (ShortTag) {
				skiptag = true;
				ShortTag = false;
			}

			if (NestingLevel) {
				if (((etag = CurrFull->find(CurrDepth)) != NULL)
				 && !stricmp(name, etag)) {  // see if end for removed full tag
					skiptag = true;
					CurrFull->remove(CurrDepth);
					CurrShort->remove(CurrDepth);
				}
				else if (((etag = CurrStype->find(CurrDepth)) != NULL)
				 && !stricmp(name, etag)) { // see if closing CurrStype
					CurrStype->remove(CurrDepth);
					NestingLevel = Nesting->find(CurrDepth);
					Nesting->remove(CurrDepth);
				}
			}
		}

		if (PendingText) {
			WriteText(PendingText);
			PendingText = NULL;
		}

		if (DoMin) {
			if (DoWiki) {  // check for wiki symbol tags
				if (WriteWikiSym(name, false))
					skiptag = true;;
			}

			if (DoBlank) {
				if (!stricmp(CurrElem, "p")
				 && !stricmp(name, "p")) {
					EndingPTag = true;
					skiptag = true;;
				}
			}

			if (DoPara) {
				if (SkippedPTag
				 && !stricmp(name, "p"))
					skiptag = true;;
			}
		}

		if (DoFull && DoPara) {
			// if ending block, and in wrapped text, close the p
			if ((etype == 1)
			 && WrappedText) {
				WriteCode("</p>");
				WrappedText = false;
			}
		}

		if (!skiptag) {
			WriteChar('<');
			WriteChar('/');
			WriteText(name);
			if (IsCodeTag(name))
				InCode--;
			WriteChar('>');
		}
	}

	CurrElems->remove(CurrDepth);
	CurrEtypes->remove(CurrDepth);
	CurrElem = CurrElems->find(CurrDepth - 1);
	CurrEtype = CurrEtypes->find(CurrDepth - 1);

	CurrDepth--;
}
Example #10
0
void StartTag(unl *tag, long len, pair **attrs, long attrcnt)
{
	if (EmptyTag) { // end of previous start tag
		WriteChar('>');
		EmptyTag = false;
	}

	char *name = (char *) Parser->U32to8Str(tag, len);
	if (!stricmp(name, "udx")) {
		if (PendingText) {
			WriteText(PendingText);
			PendingText = NULL;
		}
		WriteStartTag(name, attrs, attrcnt);
		WriteChar('>');
		CheckUdxTag(attrs, attrcnt);
		return;
	}

	IsPTag = !stricmp(name, "p");
	long lastetype = CurrEtype;

	CurrElem = name;
	CurrEtype = GetCurrEtype(name);

	bool skiptag = false;

	if (DoMin) {
		if (DoBlank
		 && EndingPTag
		 && PendingText) {
			if (!IsPTag
			 || attrs) {  // mismatch
				WriteCode("</p>");
				WriteText(PendingText);  // double return
			}
			else { // suppress this one
				WriteText(PendingText);  // double return
				skiptag = true;
			}
			PendingText = NULL;
			EndingPTag = false;
		}
		else if (IsPTag
		 && !EndingPTag
		 && !PendingText) {
			SkippedPTag = true;
			skiptag = true;
		}
	}

	char *shtag = NULL;
	char *futag = NULL;
	char *shend = NULL;
	char *tmptxt = NULL;

	if (PendingText) {
		tmptxt = PendingText + strlen(PendingText);
		while ((*(tmptxt - 1) == '\n')
		 || (*(tmptxt - 1) == '\t')) {
			if (--tmptxt <= PendingText)
				break;
		}
		if (tmptxt > PendingText) {
			char ch = *tmptxt;
			*tmptxt = '\0';
			WriteText(PendingText);
			PendingText = tmptxt;
			*tmptxt = ch;
		}
		// else write it later, after added end tags
	}

	if (DoFull && DoPara) {
		if (!WrappedText
		 && (lastetype == 1)
		 && (CurrEtype == 3)) {  //block to inline
			WriteCode("<p>");
			WrappedText = true;
		}
		else if (WrappedText
		 && (CurrEtype == 1)) {
			WriteCode("</p>");
			WrappedText = false;
		}
	}

	if (PendingText) // if writing end tag for short, keep \ns till after
		PendingText = WriteTextWithoutTrailingSpace(PendingText);

	while (DoFull
	 && NestingLevel
	 && ((shend = CurrShortEnd->find(CurrDepth)) != NULL)
	 && CheckList(shend, name))  // end of CurrFull goes here
		WriteEndFullTag();  // close curr open tag if any

	if (PendingText) {  // write \ns now
		WriteText(PendingText);
		PendingText = NULL;
	}

	CurrElems->add(name, CurrDepth + 1);
	CurrEtypes->add(CurrEtype, CurrDepth + 1);

	CurrDepth++;

// NestingLevel of containers to check = depth of start tag
// for each container type, list of sections to use
	char *stype = IniFile->GetVal("ShortTagContainers", name);
	if (stype) { // end tag at which to end last open short tag
		if (DoFull) {
			CurrStype->add(name, CurrDepth);
			if (IniFile->GetBool("udxFullTaggingOptions",
													 "sConvert", stype)) {
				CurrSTR = IniFile->GetSect("ShortTagReplacement", stype);
				CurrSTE = IniFile->GetSect("ShortTagEnds", stype);
				Nesting->add(NestingLevel, CurrDepth);
				NestingLevel = CurrDepth;  // use list as stack ***
			}
		}
		else if (DoMin) {
			CurrStype->add(name, CurrDepth);
			if (IniFile->GetBool("udxTagMinimizingOptions",
													 "sToShortTagsConvert", stype)) {
				CurrLTR = IniFile->GetSect("LongTagReplacement", stype);
				Nesting->add(NestingLevel, CurrDepth);
				NestingLevel = CurrDepth;  // use list as stack ***
			}
		}
	}


	if (NestingLevel) {
		if (DoFull) {
			shtag = (char *) CurrSTR->getitem(name);
			shend = (char *) CurrSTE->getitem(name);
			if (shtag) {  // replace with full tag
				CurrShort->add(name, CurrDepth);
				// start tag before which to add end tag
				CurrShortEnd->add(shend, CurrDepth);
				CurrFull->add(shtag, CurrDepth);
				LastFullEndDepth = CurrDepth;
				name = shtag;
			}
		}
		else if (DoMin) {
			futag = (char *) CurrLTR->getitem(name);
			if (futag) {  // replace with short tag
				CurrFull->add(name, CurrDepth);
				CurrShort->add(futag, CurrDepth);
				name = futag;
				ShortTag = true;
			}
		}
	}

	// check for wiki symbol tags
	if (DoMin && DoWiki
	 && !attrs) {
		if (WriteWikiSym(name, true))
			return;
	}

	if (skiptag)
		return;

	WriteStartTag(name, attrs, attrcnt);
	if (IsCodeTag(name))
		InCode++;
	if (ShortTag) {  // write end now
		WriteChar('/');
		WriteChar('>');
		ShortTag = false;
	}
	else
		EmptyTag = true;

}
int
main(int argc, char** argv)
{
  // Get the URL from which to load the model...
  if (argc < 2)
  {
    printf("Usage: CellML2C modelURL\n");
    return -1;
  }

  uint32_t usenames = 0, useida = 0;

  for (int32_t i = 2; i < argc; i++)
  {
    if (!strcmp(argv[i], "usenames"))
      usenames = 1;
    else if (!strcmp(argv[i], "useida"))
      useida = 1;
  }

  wchar_t* URL;
  size_t l = strlen(argv[1]);
  URL = new wchar_t[l + 1];
  memset(URL, 0, (l + 1) * sizeof(wchar_t));
  const char* mbrurl = argv[1];
  mbsrtowcs(URL, &mbrurl, l, NULL);

  iface::cellml_api::CellMLBootstrap* cb =
    CreateCellMLBootstrap();

  iface::cellml_api::ModelLoader* ml =
    cb->modelLoader();
  cb->release_ref();

  iface::cellml_api::Model* mod;
  try
  {
    mod = ml->loadFromURL(URL);
  }
  catch (...)
  {
    printf("Error loading model URL.\n");
    // Well, a leak on exit wouldn't be so bad, but someone might reuse this
    // code, so...
    delete [] URL;
    ml->release_ref();
    return -1;
  }

  ml->release_ref();
  delete [] URL;

  mod->fullyInstantiateImports();

  iface::cellml_services::CodeGeneratorBootstrap* cgb =
    CreateCodeGeneratorBootstrap();
  iface::cellml_services::CodeGenerator* cg;
  iface::cellml_services::IDACodeGenerator* icg;

  if (useida)
    cg = icg = cgb->createIDACodeGenerator();
  else
    cg = cgb->createCodeGenerator();
  cgb->release_ref();

  if (usenames)
    doNameAnnotations(mod, cg);

  iface::cellml_services::CodeInformation* cci = NULL;
  try
  {
    cci = cg->generateCode(mod);
  }
  catch (iface::cellml_api::CellMLException&)
  {
    printf("Caught a CellMLException while generating code.\n");
    cg->release_ref();
    mod->release_ref();
    return -1;
  }
  catch (...)
  {
    printf("Unexpected exception calling generateCode!\n");
    // this is a leak, but it should also never happen :)
    return -1;
  }
  mod->release_ref();
  cg->release_ref();

  std::wstring m = cci->errorMessage();
  if (m != L"")
  {
    printf("Error generating code: %S\n", m.c_str());
    cci->release_ref();
    return -1;
  }

  // We now have the code information...
  WriteCode(cci, useida);
  cci->release_ref();

  return 0;
}