// Actions implemented public override void TestVariable(int nOp, MHUnion parm, MHEngine engine) { parm.CheckType(MHUnion.U_String); int nRes = m_Value.Compare(parm.String); bool fRes = false; switch (nOp) { case TC_Equal: fRes = (nRes == 0); break; case TC_NotEqual: fRes = (nRes != 0); break; /* case TC_Less: fRes = (m_nValue < parm.Int); break; * case TC_LessOrEqual: fRes = (m_nValue <= parm.Int); break; * case TC_Greater: fRes = (m_nValue > parm.Int); break; * case TC_GreaterOrEqual: fRes = (m_nValue >= parm.Int); break;*/ default: throw new MHEGException("Invalid comparison for string"); // Shouldn't ever happen } MHOctetString sample1 = new MHOctetString(m_Value, 0, 10); MHOctetString sample2 = new MHOctetString(parm.String, 0, 10); Logging.Log(Logging.MHLogDetail, "Comparison " + TestToString(nOp) + " between " + sample1.Printable() + " and " + sample2.Printable() + " => " + (fRes ? "true" : "false")); engine.EventTriggered(this, EventTestEvent, new MHUnion(fRes)); }
public override void Perform(MHEngine engine) { MHObjectRef target = new MHObjectRef(); m_Target.GetValue(target, engine); // Get the item to set. MHColour newColour = new MHColour(); switch (m_ColourType) { case CT_None: { // If the colour is not specified use "transparent". newColour.SetFromString("\u0000\u0000\u0000\u00FF"); break; } case CT_Absolute: { MHOctetString colour = new MHOctetString(); m_Absolute.GetValue(colour, engine); newColour.ColStr.Copy(colour); break; } case CT_Indexed: newColour.SetFromIndex(m_Indexed.GetValue(engine)); break; } SetColour(newColour, engine); // Set the colour of the appropriate portion of the visible }
public override void Perform(MHEngine engine) { MHObjectRef target = new MHObjectRef(); m_Target.GetValue(target, engine); // Get the target if (m_fIsIncluded) { // Included content MHOctetString included = new MHOctetString(); m_Included.GetValue(included, engine); engine.FindObject(target).SetData(included, engine); } else { MHContentRef referenced = new MHContentRef(); int size, cc; m_Referenced.GetValue(referenced, engine); if (m_fSizePresent) { size = m_ContentSize.GetValue(engine); } else { size = 0; } if (m_fCCPriorityPresent) { cc = m_CCPriority.GetValue(engine); } else { cc = 0; } engine.FindObject(target).SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine); } }
public void GetStringValue(MHOctetString str) { if (m_nNodeType != PNString) { Failure("Expected string"); } str.Copy(((MHPString)this).Value); }
public override void Perform(MHEngine engine) { // Get the new font attributes. MHOctetString newAttrs = new MHOctetString(); m_FontAttrs.GetValue(newAttrs, engine); Target(engine).SetFontAttributes(newAttrs, engine); }
protected void GetString(MHParameter parm, MHOctetString str, MHEngine engine) { MHUnion un = new MHUnion(); un.GetValueFrom(parm, engine); un.CheckType(MHUnion.U_String); str.Copy(un.String); }
public override void Perform(MHEngine engine) { // Ignore the target which isn't used. MHOctetString feature = new MHOctetString(); m_Feature.GetValue(feature, engine); engine.FindObject(m_Answer).SetVariableValue(new MHUnion(engine.GetEngineSupport(feature))); }
public virtual void SearchAndExtractSubString(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { if (args.Size == 5) { // Find a substring within a string and return an index to the position // and the prefix to the substring. MHOctetString str = new MHOctetString(); MHOctetString searchString = new MHOctetString(); GetString(args.GetAt(0), str, engine); int nStart = GetInt(args.GetAt(1), engine); if (nStart < 1) { nStart = 1; } GetString(args.GetAt(2), searchString, engine); // Strings are indexed from one. int nPos; for (nPos = nStart - 1; nPos <= str.Size - searchString.Size; nPos++) { int i; for (i = 0; i < searchString.Size; i++) { if (searchString.GetAt(i) != str.GetAt(i + nPos)) { break; // Doesn't match } } if (i == searchString.Size) { break; // Found a match. } } // Set the results. MHParameter pResString = args.GetAt(3); MHParameter pResInt = args.GetAt(4); SetSuccessFlag(success, true, engine); // Set this first. if (nPos <= str.Size - searchString.Size) { // Found // Set the index to the position AFTER the string, counting from 1. engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(nPos + 1 + searchString.Size)); // Return the sequence from nStart - 1 of length nPos - nStart + 1 MHOctetString resultString = new MHOctetString(str, nStart - 1, nPos - nStart + 1); engine.FindObject(pResString.GetReference()).SetVariableValue(new MHUnion(resultString)); } else { // Not found. Set the result string to empty and the result index to -1 engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(-1)); engine.FindObject(pResString.GetReference()).SetVariableValue(new MHUnion(new MHOctetString(""))); } } else { SetSuccessFlag(success, false, engine); } }
private int m_nTabCount; // Number of tabs immediately before this (usually zero) public MHTextItem() { m_nUnicode = 0; m_Width = 0; // Size of this block m_Colour = new MHRgba(0, 0, 0, 255); m_nTabCount = 0; m_Text = new MHOctetString(); m_Colour = new MHRgba(); }
public override void Perform(MHEngine engine) { MHObjectRef target = new MHObjectRef(); m_Target.GetValue(target, engine); // Get the target - this should always be the application MHOctetString fileName = new MHOctetString(); m_FileName.GetValue(fileName, engine); bool fResult = engine.LoadStorePersistent(m_bIsLoad, fileName, m_Variables); engine.FindObject(m_Succeeded).SetVariableValue(new MHUnion(fResult)); }
public MHIngredient() { m_fInitiallyActive = true; // Default is true m_nContentHook = 0; // Need to choose a value that isn't otherwise used m_fShared = false; m_nOrigContentSize = 0; m_nOrigCCPrio = 127; // Default. m_ContentType = IN_NoContent; m_OrigIncludedContent = new MHOctetString(); m_OrigContentRef = new MHContentRef(); m_IncludedContent = new MHOctetString(); m_ContentRef = new MHContentRef(); }
public override void BeginPlaying(MHEngine engine) { m_fStreamPlaying = true; if (m_fRunning && m_streamContentRef.IsSet()) { string stream = ""; MHOctetString str = m_streamContentRef.ContentRef; if (str.Size != 0) { stream = str.ToString(); } engine.GetContext().BeginVideo(stream, m_nComponentTag); } }
public virtual void SearchSubString(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { if (args.Size == 4) { // Find a substring within a string and return an index to the position. MHOctetString str = new MHOctetString(); MHOctetString searchString = new MHOctetString(); GetString(args.GetAt(0), str, engine); int nStart = GetInt(args.GetAt(1), engine); if (nStart < 1) { nStart = 1; } GetString(args.GetAt(2), searchString, engine); // Strings are indexed from one. int nPos; for (nPos = nStart - 1; nPos <= str.Size - searchString.Size; nPos++) { int i; for (i = 0; i < searchString.Size; i++) { if (searchString.GetAt(i) != str.GetAt(i + nPos)) { break; } } if (i == searchString.Size) { break; // Found a match. } } // Set the result. MHParameter pResInt = args.GetAt(3); SetSuccessFlag(success, true, engine); // Set this first. if (nPos <= str.Size - searchString.Size) { // Found // Set the index to the position of the string, counting from 1. engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(nPos + 1)); } else { // Not found. Set the result index to -1 engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(-1)); } } else { SetSuccessFlag(success, false, engine); } }
public virtual void GetStringLength(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { if (args.Size == 2) { // Find a substring within a string and return an index to the position. MHOctetString str = new MHOctetString(); GetString(args.GetAt(0), str, engine); MHParameter pResInt = args.GetAt(1); SetSuccessFlag(success, true, engine); engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(str.Size)); } else { SetSuccessFlag(success, false, engine); } }
// Parse a string argument. ASN1 strings can include nulls as valid characters. private void ParseString(int endStr, MHOctetString str) { // TODO: Don't deal with indefinite length at the moment. Logging.Assert(endStr != INDEFINITE_LENGTH); int nLength = endStr - m_p; char[] stringValue = new char[nLength]; int p = 0; while (m_p < endStr) { stringValue[p++] = (char)GetNextChar(); } str.Copy(new MHOctetString(new string(stringValue, 0, p))); }
public override void SetVariableValue(MHUnion value) { if (value.Type == MHUnion.U_Int) { // Implicit conversion of int to string. m_Value.Copy(Convert.ToString(value.Int)); } else { value.CheckType(MHUnion.U_String); m_Value.Copy(value.String); } MHOctetString sample = new MHOctetString(m_Value, 0, 10); Logging.Log(Logging.MHLogDetail, "Update " + m_ObjectIdentifier.Printable() + " := " + sample.Printable()); }
public MHText() { m_nCharSet = -1; m_HorizJ = m_VertJ = Start; m_LineOrientation = Horizontal; m_StartCorner = UpperLeft; m_fTextWrap = false; m_pDisplay = null; m_OrigFont = new MHFontBody(); m_OriginalFontAttrs = new MHOctetString(); m_OriginalTextColour = new MHColour(); m_OriginalBgColour = new MHColour(); m_textColour = new MHColour(); m_bgColour = new MHColour(); m_fontAttrs = new MHOctetString(); m_Content = new MHOctetString(); }
// Actions. public override void SetData(MHOctetString included, MHEngine engine) { // If the content is currently Included then the data should be Included // and similarly for Referenced content. I've seen cases where SetData // with included content has been used erroneously with the intention that // this should be the file name for referenced content. if (m_ContentType == IN_ReferencedContent) { m_ContentRef.ContentRef.Copy(included); } else { Logging.Assert(m_ContentType == IN_IncludedContent); m_IncludedContent.Copy(included); } ContentPreparation(engine); }
public virtual void CastToContentRef(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { // Converts a string to a ContentRef. if (args.Size == 2) { MHOctetString str = new MHOctetString(); GetString(args.GetAt(0), str, engine); MHContentRef result = new MHContentRef(); result.ContentRef.Copy(str); engine.FindObject(args.GetAt(1).GetReference()).SetVariableValue(new MHUnion(result)); SetSuccessFlag(success, true, engine); } else { SetSuccessFlag(success, false, engine); } }
public override void Activation(MHEngine engine) { if (m_fRunning) { return; } base.Activation(engine); if (m_fStreamPlaying && m_streamContentRef.IsSet()) { string stream = ""; MHOctetString str = m_streamContentRef.ContentRef; if (str.Size != 0) { stream = str.ToString(); } engine.GetContext().BeginVideo(stream, m_nComponentTag); } }
public override void Perform(MHEngine engine) { MHUnion targetVal = new MHUnion(); // Find the target and get its current value. The target can be an indirect reference. MHObjectRef parm = new MHObjectRef(); m_Target.GetValue(parm, engine); MHRoot pTarget = engine.FindObject(parm); pTarget.GetVariableValue(targetVal, engine); targetVal.CheckType(MHUnion.U_String); // Get the string to append. MHOctetString toAppend = new MHOctetString(); m_Operand.GetValue(toAppend, engine); targetVal.String.Append(toAppend); // Add it on the end pTarget.SetVariableValue(targetVal); // Set the target to the result. }
public virtual void SI_GetServiceIndex(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { // Returns an index indicating the service if (args.Size == 2) { MHOctetString str = new MHOctetString(); GetString(args.GetAt(0), str, engine); MHParameter pResInt = args.GetAt(1); // The format of the service is dvb://netID.[transPortID].serviceID // where the IDs are in hex. // or rec://svc/lcn/N where N is the "logical channel number" i.e. the Freeview channel. int nResult = engine.GetContext().GetChannelIndex(str.ToString()); engine.FindObject(pResInt.GetReference()).SetVariableValue(new MHUnion(nResult)); Logging.Log(Logging.MHLogDetail, "Get service index for " + str.Printable() + " - result " + nResult); SetSuccessFlag(success, true, engine); } else { SetSuccessFlag(success, false, engine); } }
public virtual void WhoAmI(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { // Return a concatenation of the strings we respond to in // GetEngineSupport(UKEngineProfile(X)) if (args.Size == 1) { MHOctetString result = new MHOctetString(); result.Copy(MHEngine.MHEGEngineProviderIdString); result.Append(" "); result.Append(engine.GetContext().GetReceiverId()); result.Append(" "); result.Append(engine.GetContext().GetDSMCCId()); engine.FindObject((args.GetAt(0).GetReference())).SetVariableValue(new MHUnion(result)); SetSuccessFlag(success, true, engine); } else { SetSuccessFlag(success, false, engine); } }
// Activation for Audio is defined in the corrigendum public override void Activation(MHEngine engine) { if (m_fRunning) { return; } base.Activation(engine); // Beginning presentation is started by the Stream object. m_fRunning = true; engine.EventTriggered(this, EventIsRunning); if (m_fStreamPlaying && m_streamContentRef.IsSet()) { string stream = ""; MHOctetString str = m_streamContentRef.ContentRef; if (str.Size != 0) { stream = str.ToString(); } engine.GetContext().BeginAudio(stream, m_nComponentTag); } }
public virtual void GetSubString(MHObjectRef success, MHSequence <MHParameter> args, MHEngine engine) { if (args.Size == 4) { // Extract a sub-string from a string. MHOctetString str = new MHOctetString(); GetString(args.GetAt(0), str, engine); int nBeginExtract = GetInt(args.GetAt(1), engine); int nEndExtract = GetInt(args.GetAt(2), engine); if (nBeginExtract < 1) { nBeginExtract = 1; } if (nBeginExtract > str.Size) { nBeginExtract = str.Size; } if (nEndExtract < 1) { nEndExtract = 1; } if (nEndExtract > str.Size) { nEndExtract = str.Size; } MHParameter pResString = args.GetAt(3); // Returns beginExtract to endExtract inclusive. engine.FindObject(pResString.GetReference()).SetVariableValue( new MHUnion(new MHOctetString(str, nBeginExtract - 1, nEndExtract - nBeginExtract + 1))); SetSuccessFlag(success, true, engine); } else { SetSuccessFlag(success, false, engine); } }
protected string m_Path; // Path from the root directory to this application. Either the null string or // a string of the form /a/b/c . public MHApplication() { m_fIsApp = true; m_nCharSet = 0; m_nTextCHook = 0; m_nIPCHook = 0; m_nStrCHook = 0; m_nBitmapCHook = 0; m_nLineArtCHook = 0; m_pCurrentScene = null; m_nLockCount = 0; m_fRestarting = false; m_OnSpawnCloseDown = new MHActionSequence(); m_OnRestart = new MHActionSequence(); m_BGColour = new MHColour(); m_TextColour = new MHColour(); m_ButtonRefColour = new MHColour(); m_HighlightRefColour = new MHColour(); m_SliderRefColour = new MHColour(); m_Font = new MHFontBody(); m_FontAttrs = new MHOctetString(); m_DisplayStack = new MHSequence <MHVisible>(); }
// Simple recursive parser for ASN1 BER. private MHParseNode DoParse() { byte ch; // Tag class int tagClass = Universal; // Byte count of end of this item. Set to INDEFINITE_LENGTH if the length is Indefinite. int endOfItem; int tagNumber = 0; // Read the first character. ch = GetNextChar(); // ASN1 Coding rules: Top two bits (0 and 1) indicate the tag class. // 0x00 - Universal, 0x40 - Application, 0x80 - Context-specific, 0xC0 - Private // We only use Universal and Context. switch (ch & 0xC0) { case 0x00: // Universal tagClass = Universal; break; case 0x80: tagClass = Context; break; default: throw new MHEGException("Invalid tag class = " + ch); } // Bit 2 indicates whether it is a simple or compound type. Not used. // Lower bits are the tag number. tagNumber = ch & 0x1f; if (tagNumber == 0x1f) // Except that if it is 0x1F then the tag is encoded in the following bytes. { tagNumber = 0; do { ch = GetNextChar(); tagNumber = (tagNumber << 7) | (ch & 0x7f); } while ((ch & 0x80) != 0); // Top bit set means there's more to come. } // Next byte is the length. If it is less than 128 it is the actual length, otherwise it // gives the number of bytes containing the length, except that if this is zero the item // has an "indefinite" length and is terminated by two zero bytes. ch = GetNextChar(); if ((ch & 0x80) != 0) { int lengthOfLength = ch & 0x7f; if (lengthOfLength == 0) { endOfItem = INDEFINITE_LENGTH; } else { endOfItem = 0; while ((lengthOfLength--) != 0) { ch = GetNextChar(); endOfItem = (endOfItem << 8) | ch; } endOfItem += m_p; } } else { endOfItem = ch + m_p; } if (tagClass == Context) { MHPTagged pNode = new MHPTagged(tagNumber); // The argument here depends on the particular tag we're processing. switch (tagNumber) { case ASN1Codes.C_MULTIPLE_SELECTION: case ASN1Codes.C_OBSCURED_INPUT: case ASN1Codes.C_INITIALLY_AVAILABLE: case ASN1Codes.C_WRAP_AROUND: case ASN1Codes.C_TEXT_WRAPPING: case ASN1Codes.C_INITIALLY_ACTIVE: case ASN1Codes.C_MOVING_CURSOR: case ASN1Codes.C_SHARED: case ASN1Codes.C_ENGINE_RESP: case ASN1Codes.C_TILING: case ASN1Codes.C_BORDERED_BOUNDING_BOX: { // BOOL // If there is no argument we need to indicate that so that it gets // the correct default value. if (m_p != endOfItem) { int intVal = ParseInt(endOfItem); // May raise an exception pNode.AddArg(new MHPBool(intVal != 0)); } break; } case ASN1Codes.C_INPUT_TYPE: case ASN1Codes.C_SLIDER_STYLE: case ASN1Codes.C_TERMINATION: case ASN1Codes.C_ORIENTATION: case ASN1Codes.C_HORIZONTAL_JUSTIFICATION: case ASN1Codes.C_BUTTON_STYLE: case ASN1Codes.C_START_CORNER: case ASN1Codes.C_LINE_ORIENTATION: case ASN1Codes.C_VERTICAL_JUSTIFICATION: case ASN1Codes.C_STORAGE: { // ENUM if (m_p != endOfItem) { int intVal = ParseInt(endOfItem); // May raise an exception pNode.AddArg(new MHPEnum(intVal)); } break; } case ASN1Codes.C_INITIAL_PORTION: case ASN1Codes.C_STEP_SIZE: case ASN1Codes.C_INPUT_EVENT_REGISTER: case ASN1Codes.C_INITIAL_VALUE: case ASN1Codes.C_IP_CONTENT_HOOK: case ASN1Codes.C_MAX_VALUE: case ASN1Codes.C_MIN_VALUE: case ASN1Codes.C_LINE_ART_CONTENT_HOOK: case ASN1Codes.C_BITMAP_CONTENT_HOOK: case ASN1Codes.C_TEXT_CONTENT_HOOK: case ASN1Codes.C_STREAM_CONTENT_HOOK: case ASN1Codes.C_MAX_LENGTH: case ASN1Codes.C_CHARACTER_SET: case ASN1Codes.C_ORIGINAL_TRANSPARENCY: case ASN1Codes.C_ORIGINAL_GC_PRIORITY: case ASN1Codes.C_LOOPING: case ASN1Codes.C_ORIGINAL_LINE_STYLE: case ASN1Codes.C_STANDARD_VERSION: case ASN1Codes.C_ORIGINAL_LINE_WIDTH: case ASN1Codes.C_CONTENT_HOOK: case ASN1Codes.C_CONTENT_CACHE_PRIORITY: case ASN1Codes.C_COMPONENT_TAG: case ASN1Codes.C_ORIGINAL_VOLUME: case ASN1Codes.C_PROGRAM_CONNECTION_TAG: case ASN1Codes.C_CONTENT_SIZE: { // INT if (m_p != endOfItem) { int intVal = ParseInt(endOfItem); // May raise an exception pNode.AddArg(new MHPInt(intVal)); } break; } case ASN1Codes.C_OBJECT_INFORMATION: case ASN1Codes.C_CONTENT_REFERENCE: case ASN1Codes.C_FONT_ATTRIBUTES: case ASN1Codes.C_CHAR_LIST: case ASN1Codes.C_NAME: case ASN1Codes.C_ORIGINAL_LABEL: { // STRING // Unlike INT, BOOL and ENUM we can't distinguish an empty string // from a missing string. MHOctetString str = new MHOctetString(); ParseString(endOfItem, str); pNode.AddArg(new MHPString(str)); break; } default: { // Everything else has either no argument or is self-describing // TODO: Handle indefinite length. Logging.Assert(endOfItem != INDEFINITE_LENGTH); // For the moment. while (m_p < endOfItem) { pNode.AddArg(DoParse()); } break; } } return(pNode); } else // Universal - i.e. a primitive type. // Tag values { switch (tagNumber) { case ASN1Codes.U_BOOL: // Boolean { int intVal = ParseInt(endOfItem); return(new MHPBool(intVal != 0)); } case ASN1Codes.U_INT: // Integer { int intVal = ParseInt(endOfItem); return(new MHPInt(intVal)); } case ASN1Codes.U_ENUM: // ENUM { int intVal = ParseInt(endOfItem); return(new MHPEnum(intVal)); } case ASN1Codes.U_STRING: // String { MHOctetString str = new MHOctetString(); ParseString(endOfItem, str); return(new MHPString(str)); } case ASN1Codes.U_NULL: // ASN1 NULL { return(new MHPNull()); } case ASN1Codes.U_SEQUENCE: // Sequence { MHParseSequence pNode = new MHParseSequence(); Logging.Assert(endOfItem != INDEFINITE_LENGTH); // TODO: Implement this. while (m_p < endOfItem) { pNode.Append(DoParse()); } Logging.Assert(m_p == endOfItem); return(pNode); } default: Logging.Assert(false); throw new MHEGException("Unknown universal"); } } }
public MHOctetStrVar() { m_OriginalValue = new MHOctetString(); m_Value = new MHOctetString(); }
public MHPString(MHOctetString v) : base(PNString) { m_Value = v; }
// UK MHEG. Interpret the font attributes. protected void InterpretAttributes(MHOctetString attrs, out int style, out int size, out int lineSpace, out int letterSpace) { // Set the defaults. style = 0; size = 0x18; lineSpace = 0x18; letterSpace = 0; if (attrs.Size == 5) // Short form. { style = attrs.GetAt(0); // Only the bottom nibble is significant. size = attrs.GetAt(1); lineSpace = attrs.GetAt(2); // Is this big-endian or little-endian? Assume big. letterSpace = attrs.GetAt(3) * 256 + attrs.GetAt(4); if (letterSpace > 32767) { letterSpace -= 65536; // Signed. } } else // Textual form. { String str = attrs.ToString() + "."; Logging.Assert(str != null); int q = str.IndexOf('.'); // Find the terminating dot if (q != -1) // plain, italic etc. { string type = str.Substring(0, q); str = str.Substring(q + 1); if (type.Equals("italic")) { style = 1; } else if (type.Equals("bold")) { style = 2; } else if (type.Equals("bold-italic")) { style = 3; } // else it's plain. q = str.IndexOf('.'); } if (q != -1) // Size { string s = str.Substring(0, q); str = str.Substring(q + 1); size = Convert.ToInt32(s); if (size == 0) { size = 0x18; } q = str.IndexOf('.'); // Find the next dot. } if (q != -1) // lineSpacing { string ls = str.Substring(0, q); str = str.Substring(q + 1); lineSpace = Convert.ToInt32(ls); if (lineSpace == 0) { size = 0x18; } q = str.IndexOf('.'); // Find the next dot. } if (q != -1) // letter spacing. May be zero or negative { string ls = str.Substring(0, q); letterSpace = Convert.ToInt32(ls); } } }