Пример #1
0
        /// <summary>
        /// Analyzes the contents of an OMF file as a library or non-library.
        /// </summary>
        private OmfSegment.ParseResult DoAnalyze(Formatter formatter, bool parseAsLibrary)
        {
            bool first  = true;
            int  offset = 0;
            int  len    = mFileData.Length;

            List <string> msgs = new List <string>();

            while (len > 0)
            {
                OmfSegment.ParseResult result = OmfSegment.ParseHeader(mFileData, offset,
                                                                       parseAsLibrary, msgs, out OmfSegment seg);
                if (result == OmfSegment.ParseResult.Success)
                {
                    if (!seg.ParseBody(formatter, msgs))
                    {
                        OmfSegment.AddErrorMsg(msgs, offset, "parsing of segment " +
                                               seg.SegNum + " '" + seg.SegName + "' incomplete");
                        //result = OmfSegment.ParseResult.Failure;
                    }
                }

                MessageList.Clear();
                foreach (string str in msgs)
                {
                    MessageList.Add(str);
                }

                if (result == OmfSegment.ParseResult.IsLibrary)
                {
                    // Need to start over in library mode.
                    Debug.WriteLine("Restarting in library mode");
                    return(result);
                }
                else if (result == OmfSegment.ParseResult.Failure)
                {
                    // Could be a library we failed to parse, could be a totally bad file.
                    // If we were on the first segment, fail immediately so we can retry as
                    // library.  If not, it's probably not a library (assuming the Library
                    // Dictionary segment appears first), but rather a partially-bad OMF.
                    if (first)
                    {
                        return(result);
                    }
                    break;
                }
                first = false;

                Debug.Assert(seg.FileLength > 0);

                SegmentList.Add(seg);
                offset += seg.FileLength;
                len    -= seg.FileLength;
                Debug.Assert(len >= 0);
            }

            Debug.WriteLine("Num segments = " + SegmentList.Count);
            return(OmfSegment.ParseResult.Success);
        }