Exemplo n.º 1
0
        public static bool CompileResultScript(SubRecord sr, out Record r2, out string msg)
        {
            msg=null;
            r2=null;
            r=new Record();
            string script=sr.GetStrData();
            locals.Clear();
            localList.Clear();
            edidRefs.Clear();
            refcount=0;
            errors.Clear();

            ts=new TokenStream(script, errors);
            if(errors.Count>0) return OutputErrors(out msg);
            schr=new SubRecord();
            schr.Name="SCHR";
            r.AddRecord(schr);
            scda=new SubRecord();
            scda.Name="SCDA";
            r.AddRecord(scda);
            sr=(SubRecord)sr.Clone();
            r.AddRecord(sr);

            bw=new BinaryWriter(new MemoryStream());

            while(ts.PeekNextStatement().Length>0) {
                try {
                    HandleResultsBlock();
                } catch(Exception ex) {
                    return ReturnError(ex.Message, out msg);
                }
            }

            if(errors.Count>0) {
                return OutputErrors(out msg);
            }

            byte[] header=new byte[20];
            TypeConverter.si2h(refcount, header, 4);
            TypeConverter.i2h((uint)bw.BaseStream.Length, header, 8);
            TypeConverter.si2h(localList.Count, header, 12);
            TypeConverter.si2h(0x10000, header, 16);
            schr.SetData(header);
            byte[] compileddata=((MemoryStream)bw.BaseStream).GetBuffer();
            if(compileddata.Length!=bw.BaseStream.Length) Array.Resize<byte>(ref compileddata, (int)bw.BaseStream.Length);
            scda.SetData(compileddata);
            bw.Close();
            r2=r;
            return true;
        }