Esempio n. 1
0
void SystemDraw::DrawRectOp(int x, int y, int cx, int cy, Color color)
{
	if(IsNull(color))
		return;
	FlushText();
	cairo_rectangle(cr, x, y, cx, cy);
	if(color == InvertColor()) {
#if GTK_CHECK_VERSION(2,24,0) && (CAIRO_VERSION_MAJOR > 1 || CAIRO_VERSION_MINOR > 9)
		SetColor(White());
		cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);
		cairo_fill(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
#else
		if(drawable) {
			GdkGC *gc = gdk_gc_new(drawable);
	        gdk_gc_set_function(gc, GDK_INVERT);
	        Point o = GetOffset();
	        gdk_draw_drawable(drawable, gc, drawable, x + o.x, y + o.y, x + o.x, y + o.y, cx, cy);
	        gdk_gc_set_function(gc, GDK_COPY);
	        gdk_gc_destroy(gc);
		}
#endif
	}
	else {
		SetColor(color);
		cairo_fill(cr);
	}
}
Esempio n. 2
0
void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
	if(IsNull(width) || IsNull(color))
		return;
	if(width == 0)
		width = 1;
	FlushText();
	SetColor(color);
	if(width == PEN_SOLID)
		width = 1;
	if(y1 == y2 && width >= 0)
		DrawRect(x1, y1 - width / 2, x2 - x1, width, color);
	else
	if(x1 == x2 && width >= 0)
		DrawRect(x1 - width / 2, y1, width, y2 - y1, color);
	else {
		int w = width < 0 ? 1 : width;
		double d = w / 2.0;
		if(y1 == y2) {
			cairo_move_to(cr, min(x1, x2) + 0.5, y1 + d);
			cairo_line_to(cr, max(x1, x2) - 0.5, y1 + d);
		}
		else
		if(x1 == x2) {
			cairo_move_to(cr, x1 + d, min(y1, y2) + 0.5);
			cairo_line_to(cr, x1 + d, max(y1, y2) - 0.5);
		}
		else {
			cairo_move_to(cr, x1, y1);
			cairo_line_to(cr, x2, y2);
		}
		sDrawLineStroke(cr, width);
	}
}
Esempio n. 3
0
void ContinuityEditor::OnCloseWindow(wxCommandEvent& event)
{
	// if the current field is modified, then do something
	if (mUserInput->IsModified())
	{
		// give the user a chance to save, discard, or cancle the action
		int userchoice = wxMessageBox(wxT("Continuity modified.  Save changes or cancel?"), wxT("Save changes?"), wxYES_NO|wxCANCEL);
		if (userchoice == wxYES)
		{
			Save();
		}
		if (userchoice == wxNO)
		{
			Discard();
		}
		if (userchoice == wxCANCEL)
		{
			wxString message = wxT("Close cancelled.");
			wxMessageBox(message, message);
			return;
		}
	}

	FlushText();
	Close();
}
Esempio n. 4
0
bool SystemDraw::IntersectClipOp(const Rect& r)
{
	FlushText();
	RectPath(r);
	cairo_clip(cr);
	return true;
}
Esempio n. 5
0
void SystemDraw::OffsetOp(Point p)
{
	FlushText();
	Push();
	offset.Top() += p;
	cairo_translate(cr, p.x, p.y);
}
Esempio n. 6
0
NS_IMETHODIMP 
XULContentSinkImpl::HandleProcessingInstruction(const PRUnichar *aTarget, 
                                                const PRUnichar *aData)
{
    FlushText();

    const nsDependentString target(aTarget);
    const nsDependentString data(aData);

    // Note: the created nsXULPrototypePI has mRefCnt == 1
    nsRefPtr<nsXULPrototypePI> pi = new nsXULPrototypePI();
    if (!pi)
        return NS_ERROR_OUT_OF_MEMORY;

    pi->mTarget = target;
    pi->mData = data;

    if (mState == eInProlog) {
        // Note: passing in already addrefed pi
        return mPrototype->AddProcessingInstruction(pi);
    }

    nsresult rv;
    nsPrototypeArray* children = nsnull;
    rv = mContextStack.GetTopChildren(&children);
    if (NS_FAILED(rv)) {
        return rv;
    }

    if (!children->AppendElement(pi)) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    return NS_OK;
}
Esempio n. 7
0
NAMESPACE_UPP

#define LLOG(x)

SystemDraw::~SystemDraw()
{
	FlushText();
}
Esempio n. 8
0
bool SystemDraw::ClipOp(const Rect& r)
{
	FlushText();
	Push();
	clip.Top() &= r.Offseted(GetOffset());
	RectPath(r);
	cairo_clip(cr);
	return true;
}
Esempio n. 9
0
void
MIFrd::ProcATbl()
{
	FlushText();
  GroupStack[MIFlevel]->add(*TblList.find(MIFval));

	// process anchored frames in table
	TblAFIndex.execu(MIFval, (void (__cdecl *)(void *)) ProcAFLinks);
}
Esempio n. 10
0
bool SystemDraw::ExcludeClipOp(const Rect& r)
{
	FlushText();
	RectPath(Rect(-99999, -99999, 99999, r.top));
	RectPath(Rect(-99999, r.top, r.left, 99999));
	RectPath(Rect(r.right, r.top, 99999, 99999));
	RectPath(Rect(r.left, r.bottom, r.right, 99999));
	cairo_clip(cr);
	return true;
}
Esempio n. 11
0
bool SystemDraw::ClipoffOp(const Rect& r)
{
	FlushText();
	Push();
	clip.Top() &= r.Offseted(GetOffset());
	offset.Top() += r.TopLeft();
	RectPath(r);
	cairo_clip(cr);
	cairo_translate(cr, r.left, r.top);
	return true;
}
Esempio n. 12
0
void SystemDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
                                  const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts,
                                  int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor)
{
	FlushText();
	Image fill_img;
	if(pattern && !IsNull(color)) {
		ImageBuffer ibuf(8, 8);
		RGBA r[2] = { color, RGBAZero() };
		for(RGBA *out = ibuf, *end = out + 64; out < end; pattern >>= 1)
			*out++ = r[(byte)pattern & 1];
		fill_img = ibuf;
	}
Esempio n. 13
0
	void SpriteBatch::Flush()
	{
		//Game drawn in negative
		//Game hUD drawn in positive
		Begin();
		//Sprites
		FlushSprites(m_SpriteQueue);
		//First background text
		for(auto& textDesc : m_TextBackQueue)
		{
			FlushText(textDesc);
		}
		
		//Clean all variables again
		m_WorldMatBuffer.clear();
		m_VertexBuffer.clear();
		m_UvCoordBuffer.clear();
		m_CurrentSprite = 0;
		m_CurrentHudSprite = 0;
		
		//HUD
		FlushSprites(m_HudSpriteQueue);

		//Front text
		for(auto& textDesc : m_TextFrontQueue)
		{
			FlushText(textDesc);
		}

		//Clean all variables again
		m_WorldMatBuffer.clear();
		m_VertexBuffer.clear();
		m_UvCoordBuffer.clear();
		m_CurrentSprite = 0;
		m_CurrentHudSprite = 0;

		End();
	}
Esempio n. 14
0
NS_IMETHODIMP 
RDFContentSinkImpl::HandleEndElement(const PRUnichar *aName)
{
  FlushText();

  nsIRDFResource* resource;
  if (NS_FAILED(PopContext(resource, mState, mParseMode))) {
      // XXX parser didn't catch unmatched tags?
#ifdef PR_LOGGING
      if (PR_LOG_TEST(gLog, PR_LOG_WARNING)) {
          nsAutoString tagStr(aName);
          char* tagCStr = ToNewCString(tagStr);

          PR_LogPrint
                 ("rdfxml: extra close tag '%s' at line %d",
                  tagCStr, 0/*XXX fix me */);

          NS_Free(tagCStr);
      }
#endif

      return NS_ERROR_UNEXPECTED; // XXX
  }

  // If we've just popped a member or property element, _now_ is the
  // time to add that element to the graph.
  switch (mState) {
    case eRDFContentSinkState_InMemberElement: 
      {
        nsCOMPtr<nsIRDFContainer> container;
        NS_NewRDFContainer(getter_AddRefs(container));
        container->Init(mDataSource, GetContextElement(1));
        container->AppendElement(resource);
      } 
      break;

    case eRDFContentSinkState_InPropertyElement: 
      {
        mDataSource->Assert(GetContextElement(1), GetContextElement(0), resource, PR_TRUE);                                          
      } break;
    default:
      break;
  }
  
  if (mContextStack->IsEmpty())
      mState = eRDFContentSinkState_InEpilog;

  NS_IF_RELEASE(resource);
  return NS_OK;
}
Esempio n. 15
0
void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts,
                                    int count_count, int width, Color color, Color doxor)
{
	if(vertex_count < 2 || IsNull(color))
		return;
	FlushText();
	while(--count_count >= 0) {
		const Point *pp = vertices;
		vertices += *counts++;
		cairo_move_to(cr, pp->x, pp->y);
		while(++pp < vertices)
			cairo_line_to(cr, pp->x, pp->y);
		SetColor(color);
		sDrawLineStroke(cr, width);
	}
}
Esempio n. 16
0
NS_IMETHODIMP 
RDFContentSinkImpl::HandleStartElement(const PRUnichar *aName, 
                                       const PRUnichar **aAtts, 
                                       PRUint32 aAttsCount, 
                                       PRInt32 aIndex, 
                                       PRUint32 aLineNumber)
{
  FlushText();

  nsresult rv = NS_ERROR_UNEXPECTED; // XXX

  RegisterNamespaces(aAtts);

  switch (mState) {
  case eRDFContentSinkState_InProlog:
      rv = OpenRDF(aName);
      break;

  case eRDFContentSinkState_InDocumentElement:
      rv = OpenObject(aName,aAtts);
      break;

  case eRDFContentSinkState_InDescriptionElement:
      rv = OpenProperty(aName,aAtts);
      break;

  case eRDFContentSinkState_InContainerElement:
      rv = OpenMember(aName,aAtts);
      break;

  case eRDFContentSinkState_InPropertyElement:
  case eRDFContentSinkState_InMemberElement:
      rv = OpenValue(aName,aAtts);
      break;

  case eRDFContentSinkState_InEpilog:
      PR_LOG(gLog, PR_LOG_WARNING,
             ("rdfxml: unexpected content in epilog at line %d",
              aLineNumber));
      break;
  }

  return rv;
}
Esempio n. 17
0
nsresult
XULContentSinkImpl::AddText(const PRUnichar* aText, 
                            PRInt32 aLength)
{
  // Create buffer when we first need it
  if (0 == mTextSize) {
      mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
      if (nsnull == mText) {
          return NS_ERROR_OUT_OF_MEMORY;
      }
      mTextSize = 4096;
  }

  // Copy data from string into our buffer; flush buffer when it fills up
  PRInt32 offset = 0;
  while (0 != aLength) {
    PRInt32 amount = mTextSize - mTextLength;
    if (amount > aLength) {
        amount = aLength;
    }
    if (0 == amount) {
      if (mConstrainSize) {
        nsresult rv = FlushText();
        if (NS_OK != rv) {
            return rv;
        }
      }
      else {
        mTextSize += aLength;
        mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
        if (nsnull == mText) {
            return NS_ERROR_OUT_OF_MEMORY;
        }
      }
    }
    memcpy(&mText[mTextLength],aText + offset, sizeof(PRUnichar) * amount);
    
    mTextLength += amount;
    offset += amount;
    aLength -= amount;
  }

  return NS_OK;
}
Esempio n. 18
0
void SystemDraw::BeginOp()
{
	FlushText();
	Push();
}
Esempio n. 19
0
NS_IMETHODIMP 
XULContentSinkImpl::HandleCDataSection(const PRUnichar *aData, PRUint32 aLength)
{
    FlushText();
    return AddText(aData, aLength);
}
Esempio n. 20
0
NS_IMETHODIMP 
XULContentSinkImpl::HandleComment(const PRUnichar *aName)
{
   FlushText();
   return NS_OK;
}
Esempio n. 21
0
NS_IMETHODIMP 
XULContentSinkImpl::HandleEndElement(const PRUnichar *aName)
{
    // Never EVER return anything but NS_OK or
    // NS_ERROR_HTMLPARSER_BLOCK from this method. Doing so will blow
    // the parser's little mind all over the planet.
    nsresult rv;

    nsRefPtr<nsXULPrototypeNode> node;
    rv = mContextStack.GetTopNode(node);

    if (NS_FAILED(rv)) {
      return NS_OK;
    }

    switch (node->mType) {
    case nsXULPrototypeNode::eType_Element: {
        // Flush any text _now_, so that we'll get text nodes created
        // before popping the stack.
        FlushText();

        // Pop the context stack and do prototype hookup.
        nsPrototypeArray* children = nsnull;
        rv = mContextStack.GetTopChildren(&children);
        if (NS_FAILED(rv)) return rv;

        nsXULPrototypeElement* element =
          static_cast<nsXULPrototypeElement*>(node.get());

        PRInt32 count = children->Length();
        if (count) {
            if (!element->mChildren.SetCapacity(count))
                return NS_ERROR_OUT_OF_MEMORY;

            for (PRInt32 i = 0; i < count; ++i)
                element->mChildren.AppendElement(children->ElementAt(i));

        }
    }
    break;

    case nsXULPrototypeNode::eType_Script: {
        nsXULPrototypeScript* script =
            static_cast<nsXULPrototypeScript*>(node.get());

        // If given a src= attribute, we must ignore script tag content.
        if (! script->mSrcURI && ! script->mScriptObject.mObject) {
            nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);

            script->mOutOfLine = false;
            if (doc)
                script->Compile(mText, mTextLength, mDocumentURL,
                                script->mLineNo, doc, mPrototype);
        }

        FlushText(false);
    }
    break;

    default:
        NS_ERROR("didn't expect that");
        break;
    }

    rv = mContextStack.Pop(&mState);
    NS_ASSERTION(NS_SUCCEEDED(rv), "context stack corrupted");
    if (NS_FAILED(rv)) return rv;

    if (mContextStack.Depth() == 0) {
        // The root element should -always- be an element, because
        // it'll have been created via XULContentSinkImpl::OpenRoot().
        NS_ASSERTION(node->mType == nsXULPrototypeNode::eType_Element, "root is not an element");
        if (node->mType != nsXULPrototypeNode::eType_Element)
            return NS_ERROR_UNEXPECTED;

        // Now that we're done parsing, set the prototype document's
        // root element. This transfers ownership of the prototype
        // element tree to the prototype document.
        nsXULPrototypeElement* element =
            static_cast<nsXULPrototypeElement*>(node.get());

        mPrototype->SetRootElement(element);
        mState = eInEpilog;
    }

    return NS_OK;
}
Esempio n. 22
0
NS_IMETHODIMP 
XULContentSinkImpl::HandleStartElement(const PRUnichar *aName, 
                                       const PRUnichar **aAtts,
                                       PRUint32 aAttsCount, 
                                       PRInt32 aIndex, 
                                       PRUint32 aLineNumber)
{ 
  // XXX Hopefully the parser will flag this before we get here. If
  // we're in the epilog, there should be no new elements
  NS_PRECONDITION(mState != eInEpilog, "tag in XUL doc epilog");
  NS_PRECONDITION(aIndex >= -1, "Bogus aIndex");
  NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
  // Adjust aAttsCount so it's the actual number of attributes
  aAttsCount /= 2;
  
  if (mState == eInEpilog)
      return NS_ERROR_UNEXPECTED;

  if (mState != eInScript) {
      FlushText();
  }

  PRInt32 nameSpaceID;
  nsCOMPtr<nsIAtom> prefix, localName;
  nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
                                 getter_AddRefs(localName), &nameSpaceID);

  nsCOMPtr<nsINodeInfo> nodeInfo;
  nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
                                           nsIDOMNode::ELEMENT_NODE);
  NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
  
  nsresult rv = NS_OK;
  switch (mState) {
  case eInProlog:
      // We're the root document element
      rv = OpenRoot(aAtts, aAttsCount, nodeInfo);
      break;

  case eInDocumentElement:
      rv = OpenTag(aAtts, aAttsCount, aLineNumber, nodeInfo);
      break;

  case eInEpilog:
  case eInScript:
      PR_LOG(gLog, PR_LOG_WARNING,
             ("xul: warning: unexpected tags in epilog at line %d",
             aLineNumber));
      rv = NS_ERROR_UNEXPECTED; // XXX
      break;
  }

  // Set the ID attribute atom on the node info object for this node
  if (aIndex != -1 && NS_SUCCEEDED(rv)) {
    nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);

    if (IDAttr) {
      nodeInfo->SetIDAttributeAtom(IDAttr);
    }
  }

  return rv;
}
Esempio n. 23
0
void ContinuityEditor::Save()
{
	FlushText();
}
Esempio n. 24
0
	void SpriteBatch::FlushText(const TextDesc& textDesc)
	{
		FlushText(textDesc.Text, textDesc.Fontname, textDesc.TransformComp, textDesc.TextColor);
	}
NS_IMETHODIMP 
nsXBLContentSink::HandleEndElement(const PRUnichar *aName)
{
  FlushText();

  if (mState != eXBL_InDocument) {
    PRInt32 nameSpaceID;
    nsCOMPtr<nsIAtom> prefix, localName;
    nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
                                   getter_AddRefs(localName), &nameSpaceID);

    if (nameSpaceID == kNameSpaceID_XBL) {
      if (mState == eXBL_Error) {
        // Check whether we've opened this tag before; we may not have if
        // it was a real XBL tag before the error occured.
        if (!GetCurrentContent()->NodeInfo()->Equals(localName,
                                                     nameSpaceID)) {
          // OK, this tag was never opened as far as the XML sink is
          // concerned.  Just drop the HandleEndElement
          return NS_OK;
        }
      }
      else if (mState == eXBL_InHandlers) {
        if (localName == nsGkAtoms::handlers) {
          mState = eXBL_InBinding;
          mHandler = nsnull;
        }
        else if (localName == nsGkAtoms::handler)
          mSecondaryState = eXBL_None;
        return NS_OK;
      }
      else if (mState == eXBL_InResources) {
        if (localName == nsGkAtoms::resources)
          mState = eXBL_InBinding;
        return NS_OK;
      }
      else if (mState == eXBL_InImplementation) {
        if (localName == nsGkAtoms::implementation)
          mState = eXBL_InBinding;
        else if (localName == nsGkAtoms::property) {
          mSecondaryState = eXBL_None;
          mProperty = nsnull;
        }
        else if (localName == nsGkAtoms::method) {
          mSecondaryState = eXBL_None;
          mMethod = nsnull;
        }
        else if (localName == nsGkAtoms::field) {
          mSecondaryState = eXBL_None;
          mField = nsnull;
        }
        else if (localName == nsGkAtoms::constructor ||
                 localName == nsGkAtoms::destructor)
          mSecondaryState = eXBL_None;
        else if (localName == nsGkAtoms::getter ||
                 localName == nsGkAtoms::setter)
          mSecondaryState = eXBL_InProperty;
        else if (localName == nsGkAtoms::parameter ||
                 localName == nsGkAtoms::body)
          mSecondaryState = eXBL_InMethod;
        return NS_OK;
      }
      else if (mState == eXBL_InBindings &&
               localName == nsGkAtoms::bindings) {
        mState = eXBL_InDocument;
      }
      
      nsresult rv = nsXMLContentSink::HandleEndElement(aName);
      if (NS_FAILED(rv))
        return rv;

      if (mState == eXBL_InBinding && localName == nsGkAtoms::binding) {
        mState = eXBL_InBindings;
        if (mBinding) {  // See comment in HandleStartElement()
          mBinding->Initialize();
          mBinding = nsnull; // Clear our current binding ref.
        }
      }

      return NS_OK;
    }
  }

  return nsXMLContentSink::HandleEndElement(aName);
}
Esempio n. 26
0
bool Template::ParseHelper()
{
	// Build our master string.
	m_helper->m_buffer.SetCount(0, 1024);
	m_helper->m_outBolPos = 0;

	// Start copying the string in.
	m_helper->m_codePtr = (LPCTSTR)m_code;
	m_helper->m_codeBolPtr = m_helper->m_codePtr;
	LPCTSTR& codePtr = m_helper->m_codePtr;
	CharArray& buffer = m_helper->m_buffer;

	// Conditional stack.
	CList<CondInfo, CondInfo&> conditionalStack;
	int nestedFalseConditionals = 0;

	// Go 'til the end.
	while (*codePtr != 0)
	{
		LPCTSTR outBolPtr = buffer.GetData() + m_helper->m_outBolPos;

		TokenHelper helper;
		helper.m_tabSize = m_helper->m_tabSize;
		helper.m_outBolPtr = outBolPtr;
		helper.m_file = this;
		helper.m_helper = m_helper;

		// See if it is a command.  Commands can only occur at the beginning
		// of a line.
		if (*codePtr == '!'  &&  *(codePtr + 1) == '!'  &&  codePtr == m_helper->m_codeBolPtr)
		{
			// Move past the exclamation points.
			codePtr += 2;

			// Is it a command comment?
			// !!// This is a comment.
			if (*codePtr == '/'  &&  *(codePtr + 1) == '/')
			{
				// Move past the double slash.
				codePtr += 2;
				
				SkipToEol(codePtr);
				
				continue;
			}

			///////////////////////////////////////////////////////////////////
			// Lex the command token.
			char command[256];
			char *comPtr = command;
			while (*codePtr != 0)
			{
				// Is it a space?
				if (*codePtr == ' ')
				{
					// Break at a space.
					codePtr++;
					break;
				}
				else if (*codePtr == '\n'  ||  *codePtr == '\r')
				{
					break;
				}
				else
				{
					// Copy the command or flag.
					*comPtr++ = *codePtr++;
				}
			}
			*comPtr = 0;

			///////////////////////////////////////////////////////////////////
			// "Conditional" commands
			///////////////////////////////////////////////////////////////////
			// If the last conditional was false, then we ignore until the next
			// endif.
			if (conditionalStack.GetCount() > 0  &&
				conditionalStack.GetTail().m_curState == false)
			{
				CondInfo condInfo = conditionalStack.GetTail();
				if (stricmp(command, "if") == 0)
				{
					SkipToEol(codePtr);
					nestedFalseConditionals++;
					continue;
				}
				else if (stricmp(command, "elif") == 0  ||  stricmp(command, "else") == 0)
				{
					// If we're in nested false conditionals, then ignore.
					if (nestedFalseConditionals > 0)
					{
						SkipToEol(codePtr);
						continue;
					}
				}
				else if (stricmp(command, "endif") == 0)
				{
					// If we're in nested false conditionals, then ignore.
					if (nestedFalseConditionals > 0)
					{
						SkipToEol(codePtr);
						nestedFalseConditionals--;
						continue;
					}
				}
			}

			if (stricmp(command, "if") == 0  ||
				stricmp(command, "elif") == 0)
			{
				// Our CondInfo structure.
				CondInfo condInfo;
				
				// If the command is an elif, then pop the old state.
				if (tolower(command[0]) == 'e')
				{
					// The conditional stack can't be empty on an elif.
					if (conditionalStack.IsEmpty())
					{
						CString err;
						err.Format("!!elif used with no preceding !!if.");
						throw TException(TException::CONDSTACK_EMPTY, err);
					}

					// Get the current conditionalStack state.  We are most 
					// interested in retaining the m_thisLevelTrue variable.
					condInfo = conditionalStack.GetTail();
					
					// Remove the old state, because it was false.
					conditionalStack.RemoveTail();
				}
				
				// if and elif are setup in this format:
				// !!if var [cond] [condCheck]
				// condCheck is only optional if cond doesn't exist.
				// var is required.
				// Get the requested dictionary entry name.
				CString var = ParseToken(codePtr, &helper);
/*				if (var.IsEmpty())
				{
					CString err;
					err.Format("The variable is missing.");
					throw TException(TException::IF_VAR_MISSING, err);
				}
*/
				CString cond = ParseToken(codePtr, &helper);
				CString condCheck = ParseToken(codePtr, &helper);
/*				if (!cond.IsEmpty()  &&  condCheck.IsEmpty())
				{
					CString err;
					err.Format("The conditional is missing.");
					throw TException(TException::IF_COND_CHECKVAR_MISSING, err);
				}
*/
				// Check for a ! symbol.
				bool isNot = false;
				if (!var.IsEmpty()  &&  var[0] == '!')
				{
					isNot = true;
					var = var.Mid(1);
				}
				
				// Lookup the value.
				CString value = var;
				SkipToEol(codePtr);

				bool result;
				if (cond.IsEmpty())
				{
					if (value != "0")
						result = true;
					else
						result = false;
				}
				else
				{
					// There is a conditional expression.  Do it.
					result = CheckCondition(value, cond, condCheck);
				}
				if (isNot)
					result ^= 1;
				if (tolower(command[0]) == 'e'  &&  result)
					result ^= condInfo.m_thisLevelTrue;
				condInfo.m_curState = result;
				condInfo.m_thisLevelTrue |= result;		// Retain the old state.
				conditionalStack.AddTail(condInfo);
				continue;
			}

			///////////////////////////////////////////////////////////////////
			else if (stricmp(command, "else") == 0)
			{
				SkipToEol(codePtr);

				if (conditionalStack.IsEmpty())
				{
					CString err;
					err.Format("!!else used with no preceding !!if.");
					throw TException(TException::CONDSTACK_EMPTY, err);
				}

				// Get the current conditionalStack state.  We are most 
				// interested in retaining the m_thisLevelTrue variable.
				CondInfo condInfo = conditionalStack.GetTail();
				
				conditionalStack.RemoveTail();
				condInfo.m_curState = condInfo.m_thisLevelTrue ^ 1;
				conditionalStack.AddTail(condInfo);
				continue;
			}
			else if (stricmp(command, "endif") == 0)
			{
				SkipToEol(codePtr);

				if (conditionalStack.IsEmpty())
				{
					CString err;
					err.Format("!!endif used with no preceding !!if.");
					throw TException(TException::CONDSTACK_EMPTY, err);
				}

				conditionalStack.RemoveTail();

				continue;
			}
			
			if (conditionalStack.GetCount() > 0  &&
				conditionalStack.GetTail().m_curState == false)
			{
				continue;
			}

			///////////////////////////////////////////////////////////////////
			// Look up the command in the map.
			///////////////////////////////////////////////////////////////////
			WWhizTemplateCommand* commandObject = m_helper->GetCommand(command);
			if (commandObject)
			{
				TemplateCommandArgs args;

				// Found a command.  Build the arg list.
				while (true)
				{
					CString arg = ParseToken(codePtr, &helper);
					if (arg.IsEmpty())
						break;
					args.m_argList.Add(arg);
				}

				// Skip anything else.
				SkipToEol(codePtr);

				// Run the command.
				commandObject->Run(this, args);
				RefreshFileInfo();

				// Parse the next part.
				continue;
			}
			else
			{
				CString err;
				err.Format("Unable to find the command [%s].", command);
				if (AfxMessageBox(err + "\n\nKeep executing?", MB_YESNO) == IDNO)
				{
					throw TException(TException::MISSING_COMMAND, err);
				}
			}
		}

		///////////////////////////////////////////////////////////////////////
		else if (*codePtr == '@'  &&  *(codePtr + 1) == '@')
		{
			// If we're ignoring text, then skip.
			if (conditionalStack.GetCount() > 0  &&  conditionalStack.GetTail().m_curState == false)
			{
				codePtr += 2;
				continue;
			}
			
			// Is it a line continuation?
			// @@backslash
			if (*(codePtr + 2) == '\\')
			{
				SkipToEol(codePtr);
				continue;
			}

			CString out;

			// Ugly, but we need that \0 in there.
			buffer.Add(0);
			buffer.RemoveAt(buffer.GetCount() - 1);

			if (ParseTag(codePtr, out, &helper))
			{
				// Move the output string into the buffer.
				for (int i = 0; i < out.GetLength(); i++)
					buffer.Add(out[i]);
			}
		}
		else
		{
			// See if it is an EOL.
			if (*codePtr == '\n')
			{
				m_helper->m_outBolPos = buffer.GetCount() + 1;
				m_helper->m_codeBolPtr = codePtr + 1;
			}

			// If we're ignoring text, then skip.
			if (conditionalStack.GetCount() > 0  &&  conditionalStack.GetTail().m_curState == false)
			{
				codePtr++;
				continue;
			}
			
			// Copy it straight.
			buffer.Add(*codePtr++);
		}
	}

	// Flush what's left.
	FlushText();

	buffer.RemoveAll();

	return true;
}
Esempio n. 27
0
File: mcp.c Progetto: hyena/fuzzball
int
mcp_frame_output_mesg(McpFrame * mfr, McpMesg * msg)
{
	char outbuf[BUFFER_LEN * 2];
	int bufrem = sizeof(outbuf);
	char mesgname[128];
	char datatag[32];
	McpArg *anarg = NULL;
	int mlineflag = 0;
	char *p;
	char *out;
	int flushcount = 8;

	if (!mfr->enabled && strcmp_nocase(msg->package, MCP_INIT_PKG)) {
		return EMCP_NOMCP;
	}

	/* Create the message name from the package and message subnames */
	if (msg->mesgname && *msg->mesgname) {
		snprintf(mesgname, sizeof(mesgname), "%s-%s", msg->package, msg->mesgname);
	} else {
		snprintf(mesgname, sizeof(mesgname), "%s", msg->package);
	}

	strcpyn(outbuf, sizeof(outbuf), MCP_MESG_PREFIX);
	strcatn(outbuf, sizeof(outbuf), mesgname);
	if (strcmp_nocase(mesgname, MCP_INIT_PKG)) {
		McpVer nullver = { 0, 0 };

		strcatn(outbuf, sizeof(outbuf), " ");
		strcatn(outbuf, sizeof(outbuf), mfr->authkey);
		if (strcmp_nocase(msg->package, MCP_NEGOTIATE_PKG)) {
			McpVer ver = mcp_frame_package_supported(mfr, msg->package);

			if (!mcp_version_compare(ver, nullver)) {
				return EMCP_NOPACKAGE;
			}
		}
	}

	/* If the argument lines contain newlines, split them into separate lines. */
	for (anarg = msg->args; anarg; anarg = anarg->next) {
		if (anarg->value) {
			McpArgPart *ap = anarg->value;

			while (ap) {
				p = ap->value;
				while (*p) {
					if (*p == '\n' || *p == '\r') {
						McpArgPart *nu = (McpArgPart *) malloc(sizeof(McpArgPart));

						nu->next = ap->next;
						ap->next = nu;
						*p++ = '\0';
						nu->value = string_dup(p);
						ap->value = (char *) realloc(ap->value, strlen(ap->value) + 1);
						ap = nu;
						p = nu->value;
					} else {
						p++;
					}
				}
				ap = ap->next;
			}
		}
	}

	/* Build the initial message string */
	out = outbuf;
	bufrem = outbuf + sizeof(outbuf) - out;
	for (anarg = msg->args; anarg; anarg = anarg->next) {
		out += strlen(out);
		bufrem = outbuf + sizeof(outbuf) - out;
		if (!anarg->value) {
			anarg->was_shown = 1;
			snprintf(out, bufrem, " %s: %s", anarg->name, MCP_ARG_EMPTY);
			out += strlen(out);
			bufrem = outbuf + sizeof(outbuf) - out;
		} else {
			int totlen = strlen(anarg->value->value) + strlen(anarg->name) + 5;

			if (anarg->value->next || totlen > ((BUFFER_LEN - (out - outbuf)) / 2)) {
				/* Value is multi-line or too long.  Send on separate line(s). */
				mlineflag = 1;
				anarg->was_shown = 0;
				snprintf(out, bufrem, " %s*: %s", anarg->name, MCP_ARG_EMPTY);
			} else {
				anarg->was_shown = 1;
				snprintf(out, bufrem, " %s: ", anarg->name);
				out += strlen(out);
				bufrem = outbuf + sizeof(outbuf) - out;

				msgarg_escape(out, bufrem, anarg->value->value);
				out += strlen(out);
				bufrem = outbuf + sizeof(outbuf) - out;
			}
			out += strlen(out);
			bufrem = outbuf + sizeof(outbuf) - out;
		}
	}

	/* If the message is multi-line, make sure it has a _data-tag field. */
	if (mlineflag) {
		snprintf(datatag, sizeof(datatag), "%.8lX", (unsigned long)(RANDOM() ^ RANDOM()));
		snprintf(out, bufrem, " %s: %s", MCP_DATATAG, datatag);
		out += strlen(out);
		bufrem = outbuf + sizeof(outbuf) - out;
	}

	/* Send the initial line. */
	SendText(mfr, outbuf);
	SendText(mfr, "\r\n");

	if (mlineflag) {
		/* Start sending arguments whose values weren't already sent. */
		/* This is usually just multi-line argument values. */
		for (anarg = msg->args; anarg; anarg = anarg->next) {
			if (!anarg->was_shown) {
				McpArgPart *ap = anarg->value;

				while (ap) {
					*outbuf = '\0';
					snprintf(outbuf, sizeof(outbuf), "%s* %s %s: %s", MCP_MESG_PREFIX, datatag, anarg->name, ap->value);
					SendText(mfr, outbuf);
					SendText(mfr, "\r\n");
					if (!--flushcount) {
						FlushText(mfr);
						flushcount = 8;
					}
					ap = ap->next;
				}
			}
		}

		/* Let the other side know we're done sending multi-line arg vals. */
		snprintf(outbuf, sizeof(outbuf), "%s: %s", MCP_MESG_PREFIX, datatag);
		SendText(mfr, outbuf);
		SendText(mfr, "\r\n");
	}

	return EMCP_SUCCESS;
}
Esempio n. 28
0
void SystemDraw::EndOp()
{
	FlushText();
	Pop();
}