private static void FixGotoAndMemTokens(TParsedTokenList Tokens, MemoryStream Data, int[] TokenOffset, TTokenOffset StreamPos) { foreach (int streamofs in StreamPos.Keys) { TBaseParsedToken Token = Tokens.GetToken(StreamPos[streamofs]); Data.Position = streamofs; TAttrOptIfToken oiftk = Token as TAttrOptIfToken; if (oiftk != null) { WriteWord(Data, TokenOffset[oiftk.PositionOfNextPtg] - (streamofs + 2)); continue; } TAttrOptChooseToken ctk = Token as TAttrOptChooseToken; if (ctk != null) { for (int i = 0; i < ctk.PositionOfNextPtg.Length; i++) { WriteWord(Data, TokenOffset[ctk.PositionOfNextPtg[i]] - streamofs); } continue; } TAttrGotoToken gtk = Token as TAttrGotoToken; if (gtk != null) { WriteWord(Data, TokenOffset[gtk.PositionOfNextPtg] - (streamofs + 2) - 1); continue; } TSimpleMemToken memtk = Token as TSimpleMemToken; if (memtk != null) { WriteWord(Data, TokenOffset[memtk.PositionOfNextPtg] - (streamofs + 2)); continue; } } }
private static void WriteAttr(Stream Data, TBaseParsedToken Token, TTokenOffset StreamPos, int TokenPos) { if (Token is TAttrVolatileToken) { Data.WriteByte(0x01); WriteWord(Data, 0); return; } if (Token is TAttrSumToken) { Data.WriteByte(0x10); WriteWord(Data, 0); return; } if (Token is TAttrSpaceToken) { int Id = 0x40; TAttrSpaceToken sp = (TAttrSpaceToken)Token; if (sp.Volatile) { Id |= 0x01; } Data.WriteByte((byte)Id); Data.WriteByte((byte)sp.SpaceType); Data.WriteByte((byte)sp.SpaceCount); return; } TAttrOptIfToken oiftk = Token as TAttrOptIfToken; if (oiftk != null) { Data.WriteByte(0x02); StreamPos.Add((int)Data.Position, TokenPos); WriteWord(Data, 0); return; } TAttrOptChooseToken ctk = Token as TAttrOptChooseToken; if (ctk != null) { Data.WriteByte(0x04); WriteWord(Data, ctk.PositionOfNextPtg.Length - 1); StreamPos.Add((int)Data.Position, TokenPos); for (int i = 0; i < ctk.PositionOfNextPtg.Length; i++) { WriteWord(Data, 0); } return; } TAttrGotoToken gtk = Token as TAttrGotoToken; if (gtk != null) { Data.WriteByte(0x08); StreamPos.Add((int)Data.Position, TokenPos); WriteWord(Data, 0); return; } XlsMessages.ThrowException(XlsErr.ErrInternal); //All tokens here should exist }