private static void FixFutureFunctions(TNameRecordList Names, Int32List FuturePos, TParsedTokenList Tokens, MemoryStream Data, int[] TokenOffset, ref TTokenOffset StreamPos) { if (FuturePos.Count == 0) { return; } List <byte> NewData = new List <byte>(Data.ToArray()); //we need to insert in any order for (int i = 0; i < FuturePos.Count; i++) { Tokens.MoveTo(FuturePos[i]); TBaseFunctionToken FuncToken = (TBaseFunctionToken)Tokens.GetToken(FuturePos[i]); for (int k = 0; k < FuncToken.ArgumentCount; k++) //this doesn't include the name. { Tokens.Flush(); } int TokPos = Tokens.SavePosition(); while (TokPos > 0) { if (!(Tokens.GetToken(TokPos - 1) is TIgnoreInCalcToken) || Tokens.GetToken(TokPos - 1) is TAttrToken) { break; } TokPos--; } int ofs = TokenOffset[TokPos]; WriteFutureName(NewData, ofs, FindName(Names, FuncToken.GetFunctionData().FutureName)); for (int k = TokPos; k < TokenOffset.Length; k++) { TokenOffset[k] += 5; } TTokenOffset NewStreamPos = new TTokenOffset(); foreach (int streamofs in StreamPos.Keys) { int sofs = streamofs; if (sofs >= ofs) { sofs += 5; } NewStreamPos.Add(sofs, StreamPos[streamofs]); } StreamPos = NewStreamPos; } Data.SetLength(0); Data.Write(NewData.ToArray(), 0, NewData.Count); }
private void CheckFutureFunction(TParsedTokenListBuilder TokenBuilder, ref int np, TNameRecordList Names, ref TCellFunctionData fd2, TTokenOffset TokenOffset, ref bool HasAggregate) { //We need to recursively read parameters in back order to find out the name, which is stored as far as possible from the function :( TParsedTokenList ParsedList = TokenBuilder.ToParsedTokenList(); ParsedList.ResetPositionToLast(); for (int i = 0; i < np; i++) //np is +1. But we will move below the name, then inc 1, so we know there isn't a "neutral" token like parent or memarea, intead of the real thing. { ParsedList.Flush(); } ParsedList.MoveBack(); TNameToken bp = ParsedList.ForwardPop() as TNameToken; if (bp is TNameXToken) { return; //This name isn't an internal 2007 name. } if (bp == null) { return; } if (bp.NameIndex <= 0 || bp.NameIndex > Names.Count) { return; } string FunctionName = Names[bp.NameIndex - 1].Name; if (FunctionName.StartsWith("_xlfn.", StringComparison.InvariantCultureIgnoreCase)) { TCellFunctionData fn = TXlsFunction.GetData(FunctionName.Substring("_xlfn.".Length)); if (fn != null) { if (fn.Index == (int)TFutureFunctions.Aggregate) { HasAggregate = true; } fd2 = fn; int tPos = ParsedList.SavePosition(); TokenBuilder.RemoveAt(tPos); TokenOffset.RemoveToken(tPos); np--; } } }